Search in sources :

Example 16 with ClassDefinition

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

the class PortableContextImpl method lookupClassDefinition.

@Override
public ClassDefinition lookupClassDefinition(Data data) throws IOException {
    if (!data.isPortable()) {
        throw new IllegalArgumentException("Data is not Portable!");
    }
    BufferObjectDataInput in = serializationService.createObjectDataInput(data);
    int factoryId = in.readInt();
    int classId = in.readInt();
    int version = in.readInt();
    ClassDefinition classDefinition = lookupClassDefinition(factoryId, classId, version);
    if (classDefinition == null) {
        classDefinition = readClassDefinition(in, factoryId, classId, version);
    }
    return classDefinition;
}
Also used : ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput)

Example 17 with ClassDefinition

use of com.hazelcast.nio.serialization.ClassDefinition 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 18 with ClassDefinition

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

the class PortableSerializer method setupPositionAndDefinition.

public ClassDefinition setupPositionAndDefinition(BufferObjectDataInput in, int factoryId, int classId, int version) throws IOException {
    int effectiveVersion = version;
    if (effectiveVersion < 0) {
        effectiveVersion = context.getVersion();
    }
    ClassDefinition cd = context.lookupClassDefinition(factoryId, classId, effectiveVersion);
    if (cd == null) {
        int begin = in.position();
        cd = context.readClassDefinition(in, factoryId, classId, effectiveVersion);
        in.position(begin);
    }
    return cd;
}
Also used : ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition)

Example 19 with ClassDefinition

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

the class PortableSerializer method createReader.

public DefaultPortableReader createReader(BufferObjectDataInput in, int factoryId, int classId, int version, int portableVersion) throws IOException {
    ClassDefinition cd = setupPositionAndDefinition(in, factoryId, classId, version);
    DefaultPortableReader reader;
    if (portableVersion == cd.getVersion()) {
        reader = new DefaultPortableReader(this, in, cd);
    } else {
        reader = new MorphingPortableReader(this, in, cd);
    }
    return reader;
}
Also used : ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition)

Example 20 with ClassDefinition

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

the class PortableSerializer method readAsGenericRecord.

<T> T readAsGenericRecord(BufferObjectDataInput in, int factoryId, int classId, boolean readGenericLazy) throws IOException {
    if (readGenericLazy) {
        int version = in.readInt();
        ClassDefinition cd = setupPositionAndDefinition(in, factoryId, classId, version);
        PortableInternalGenericRecord reader = new PortableInternalGenericRecord(this, in, cd, true);
        return (T) reader;
    }
    return readPortableGenericRecord(in, factoryId, classId);
}
Also used : ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition)

Aggregations

ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)70 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)37 Test (org.junit.Test)25 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)16 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)15 QuickTest (com.hazelcast.test.annotation.QuickTest)15 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)10 FieldDefinition (com.hazelcast.nio.serialization.FieldDefinition)7 GenericRecordBuilder (com.hazelcast.nio.serialization.GenericRecordBuilder)7 Parameters (junitparams.Parameters)7 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)6 MappingField (com.hazelcast.sql.impl.schema.MappingField)6 Portable (com.hazelcast.nio.serialization.Portable)5 PortableFactory (com.hazelcast.nio.serialization.PortableFactory)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 SerializationConfig (com.hazelcast.config.SerializationConfig)3 BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)3 Data (com.hazelcast.internal.serialization.Data)3 BufferObjectDataInput (com.hazelcast.nio.BufferObjectDataInput)3