Search in sources :

Example 6 with FieldKind

use of com.hazelcast.nio.serialization.FieldKind in project hazelcast by hazelcast.

the class DeserializedGenericRecord method getArrayOfNullableInt64.

@Nullable
@Override
public Long[] getArrayOfNullableInt64(@Nonnull String fieldName) {
    FieldKind fieldKind = check(fieldName, ARRAY_OF_INT64, ARRAY_OF_NULLABLE_INT64);
    if (fieldKind == ARRAY_OF_INT64) {
        long[] array = (long[]) objects.get(fieldName);
        Long[] result = new Long[array.length];
        Arrays.setAll(result, i -> array[i]);
        return result;
    }
    return (Long[]) objects.get(fieldName);
}
Also used : FieldKind(com.hazelcast.nio.serialization.FieldKind) Nullable(javax.annotation.Nullable)

Example 7 with FieldKind

use of com.hazelcast.nio.serialization.FieldKind in project hazelcast by hazelcast.

the class DeserializedGenericRecord method check.

private FieldKind check(@Nonnull String fieldName, @Nonnull FieldKind... kinds) {
    FieldDescriptor fd = schema.getField(fieldName);
    if (fd == null) {
        throw new HazelcastSerializationException("Invalid field name: '" + fieldName + " for " + schema);
    }
    boolean valid = false;
    FieldKind fieldKind = fd.getKind();
    for (FieldKind kind : kinds) {
        valid |= fieldKind == kind;
    }
    if (!valid) {
        throw new HazelcastSerializationException("Invalid field kind: '" + fieldName + " for " + schema + ", valid field kinds : " + Arrays.toString(kinds) + ", found : " + fieldKind);
    }
    return fieldKind;
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) FieldKind(com.hazelcast.nio.serialization.FieldKind)

Example 8 with FieldKind

use of com.hazelcast.nio.serialization.FieldKind in project hazelcast by hazelcast.

the class CompactInternalGenericRecord method getNullableInt16.

@Nullable
@Override
public Short getNullableInt16(@Nonnull String fieldName) {
    FieldDescriptor fd = getFieldDefinition(fieldName);
    FieldKind fieldKind = fd.getKind();
    switch(fieldKind) {
        case INT16:
            try {
                return in.readShort(readFixedSizePosition(fd));
            } catch (IOException e) {
                throw illegalStateException(e);
            }
        case NULLABLE_INT16:
            return getVariableSize(fd, ObjectDataInput::readShort);
        default:
            throw unexpectedFieldKind(fieldKind, fieldName);
    }
}
Also used : FieldKind(com.hazelcast.nio.serialization.FieldKind) IOException(java.io.IOException) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) Nullable(javax.annotation.Nullable)

Example 9 with FieldKind

use of com.hazelcast.nio.serialization.FieldKind in project hazelcast by hazelcast.

the class CompactInternalGenericRecord method getInt64.

@Override
public long getInt64(@Nonnull String fieldName) {
    FieldDescriptor fd = getFieldDefinition(fieldName);
    FieldKind fieldKind = fd.getKind();
    switch(fieldKind) {
        case INT64:
            try {
                return in.readLong(readFixedSizePosition(fd));
            } catch (IOException e) {
                throw illegalStateException(e);
            }
        case NULLABLE_INT64:
            return getVariableSizeAsNonNull(fd, ObjectDataInput::readLong, "Int64");
        default:
            throw unexpectedFieldKind(fieldKind, fieldName);
    }
}
Also used : FieldKind(com.hazelcast.nio.serialization.FieldKind) IOException(java.io.IOException) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput) ObjectDataInput(com.hazelcast.nio.ObjectDataInput)

Example 10 with FieldKind

use of com.hazelcast.nio.serialization.FieldKind in project hazelcast by hazelcast.

the class CompactInternalGenericRecord method getArrayOfNullable.

private <T> T[] getArrayOfNullable(@Nonnull String fieldName, Reader<T> reader, Function<Integer, T[]> constructor, FieldKind primitiveKind, FieldKind nullableKind) {
    FieldDescriptor fd = getFieldDefinition(fieldName);
    FieldKind fieldKind = fd.getKind();
    if (fieldKind == primitiveKind) {
        return getPrimitiveArrayAsNullableArray(fd, constructor, reader);
    } else if (fieldKind == nullableKind) {
        return getArrayOfVariableSize(fd, constructor, reader);
    }
    throw unexpectedFieldKind(fieldKind, fieldName);
}
Also used : FieldKind(com.hazelcast.nio.serialization.FieldKind)

Aggregations

FieldKind (com.hazelcast.nio.serialization.FieldKind)40 Nullable (javax.annotation.Nullable)24 BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)17 ObjectDataInput (com.hazelcast.nio.ObjectDataInput)16 IOException (java.io.IOException)14 Nonnull (javax.annotation.Nonnull)3 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)2 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)2 DeserializedSchemaBoundGenericRecordBuilder (com.hazelcast.internal.serialization.impl.compact.DeserializedSchemaBoundGenericRecordBuilder)1 Schema (com.hazelcast.internal.serialization.impl.compact.Schema)1 FieldTypeToFieldKind (com.hazelcast.internal.serialization.impl.portable.FieldTypeToFieldKind)1 FAILING_TOP_LEVEL_INJECTOR (com.hazelcast.jet.sql.impl.inject.UpsertInjector.FAILING_TOP_LEVEL_INJECTOR)1 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)1 GenericRecordBuilder (com.hazelcast.nio.serialization.GenericRecordBuilder)1 QueryException (com.hazelcast.sql.impl.QueryException)1 BigDecimal (java.math.BigDecimal)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 LocalTime (java.time.LocalTime)1 OffsetDateTime (java.time.OffsetDateTime)1