Search in sources :

Example 6 with FieldDefinition

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

the class MorphingPortableReader method readBoolean.

@Override
public boolean readBoolean(String fieldName) throws IOException {
    FieldDefinition fd = cd.getField(fieldName);
    if (fd == null) {
        return false;
    }
    validateTypeCompatibility(fd, BOOLEAN);
    return super.readBoolean(fieldName);
}
Also used : FieldDefinition(com.hazelcast.nio.serialization.FieldDefinition)

Example 7 with FieldDefinition

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

the class MorphingPortableReader method readIntArray.

@Override
public int[] readIntArray(String fieldName) throws IOException {
    FieldDefinition fd = cd.getField(fieldName);
    if (fd == null) {
        return null;
    }
    validateTypeCompatibility(fd, INT_ARRAY);
    return super.readIntArray(fieldName);
}
Also used : FieldDefinition(com.hazelcast.nio.serialization.FieldDefinition)

Example 8 with FieldDefinition

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

the class MorphingPortableReader method readLongArray.

@Override
public long[] readLongArray(String fieldName) throws IOException {
    FieldDefinition fd = cd.getField(fieldName);
    if (fd == null) {
        return null;
    }
    validateTypeCompatibility(fd, LONG_ARRAY);
    return super.readLongArray(fieldName);
}
Also used : FieldDefinition(com.hazelcast.nio.serialization.FieldDefinition)

Example 9 with FieldDefinition

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

the class PortableContextImpl method getFieldDefinition.

@Override
public // TODO cache the result
FieldDefinition getFieldDefinition(ClassDefinition classDef, String name) {
    FieldDefinition fd = classDef.getField(name);
    if (fd == null) {
        if (name.contains(".")) {
            String[] fieldNames = NESTED_FIELD_PATTERN.split(name);
            if (fieldNames.length <= 1) {
                return fd;
            }
            ClassDefinition currentClassDef = classDef;
            for (int i = 0; i < fieldNames.length; i++) {
                fd = currentClassDef.getField(fieldNames[i]);
                if (fd == null) {
                    fd = currentClassDef.getField(extractAttributeNameNameWithoutArguments(fieldNames[i]));
                }
                // This is not enough to fully implement issue: https://github.com/hazelcast/hazelcast/issues/3927
                if (i == fieldNames.length - 1) {
                    break;
                }
                if (fd == null) {
                    throw new IllegalArgumentException("Unknown field: " + name);
                }
                currentClassDef = lookupClassDefinition(fd.getFactoryId(), fd.getClassId(), fd.getVersion());
                if (currentClassDef == null) {
                    throw new IllegalArgumentException("Not a registered Portable field: " + fd);
                }
            }
        } else {
            fd = classDef.getField(extractAttributeNameNameWithoutArguments(name));
        }
    }
    return fd;
}
Also used : FieldDefinition(com.hazelcast.nio.serialization.FieldDefinition) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition)

Example 10 with FieldDefinition

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

the class PortablePositionFactoryTest method createSinglePortablePosition.

@Test
public void createSinglePortablePosition() {
    // GIVEN
    FieldDefinition fd = new FieldDefinitionImpl(1, "field", FieldType.PORTABLE, 0);
    int streamPosition = 100;
    int factoryId = 123, classId = 546;
    boolean nil = false, leaf = true;
    // WHEN
    PortablePosition p = PortablePositionFactory.createSinglePortablePosition(fd, streamPosition, factoryId, classId, nil, leaf);
    // THEN
    assertFalse(p.isNull());
    assertFalse(p.isEmpty());
    assertFalse(p.isNullOrEmpty());
    assertEquals(nil, p.isNull());
    assertEquals(leaf, p.isLeaf());
    assertFalse(p.isAny());
    assertEquals(fd.getType(), p.getType());
    assertEquals(-1, p.getLen());
    assertEquals(classId, p.getClassId());
    assertEquals(factoryId, p.getFactoryId());
    assertEquals(-1, p.getIndex());
    assertEquals(streamPosition, p.getStreamPosition());
    assertFalse(p.isMultiPosition());
    assertAsMultiPositionThrowsException(p);
}
Also used : FieldDefinition(com.hazelcast.nio.serialization.FieldDefinition) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

FieldDefinition (com.hazelcast.nio.serialization.FieldDefinition)32 ParallelTest (com.hazelcast.test.annotation.ParallelTest)11 QuickTest (com.hazelcast.test.annotation.QuickTest)11 Test (org.junit.Test)11 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)5 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)2 PortableContext (com.hazelcast.internal.serialization.PortableContext)1 DefaultPortableReader (com.hazelcast.internal.serialization.impl.DefaultPortableReader)1 Data (com.hazelcast.nio.serialization.Data)1 Portable (com.hazelcast.nio.serialization.Portable)1 PortableReader (com.hazelcast.nio.serialization.PortableReader)1