Search in sources :

Example 1 with PortableGenericRecord

use of com.hazelcast.internal.serialization.impl.portable.PortableGenericRecord in project hazelcast by hazelcast.

the class PortableGetter method getValue.

@Override
Object getValue(Object target, String fieldPath) throws Exception {
    InternalGenericRecord record;
    if (target instanceof PortableGenericRecord) {
        record = (InternalGenericRecord) target;
    } else {
        record = serializationService.readAsInternalGenericRecord((Data) target);
    }
    GenericRecordQueryReader reader = new GenericRecordQueryReader(record);
    return reader.read(fieldPath);
}
Also used : PortableGenericRecord(com.hazelcast.internal.serialization.impl.portable.PortableGenericRecord) GenericRecordQueryReader(com.hazelcast.internal.serialization.impl.GenericRecordQueryReader) Data(com.hazelcast.internal.serialization.Data) InternalGenericRecord(com.hazelcast.internal.serialization.impl.InternalGenericRecord)

Example 2 with PortableGenericRecord

use of com.hazelcast.internal.serialization.impl.portable.PortableGenericRecord in project hazelcast by hazelcast.

the class Extractors method instantiateGetter.

private Getter instantiateGetter(Object targetObject, String attributeName, boolean failOnMissingReflectiveAttribute) {
    String attributeNameWithoutArguments = extractAttributeNameNameWithoutArguments(attributeName);
    ValueExtractor valueExtractor = extractors.get(attributeNameWithoutArguments);
    if (valueExtractor != null) {
        Object arguments = argumentsParser.parse(extractArgumentsFromAttributeName(attributeName));
        return new ExtractorGetter(ss, valueExtractor, arguments);
    } else if (targetObject instanceof Data) {
        return instantiateGetterForData((Data) targetObject);
    } else if (targetObject instanceof HazelcastJsonValue) {
        return JsonGetter.INSTANCE;
    } else if (targetObject instanceof PortableGenericRecord) {
        if (portableGetter == null) {
            // will be initialised a couple of times in the worst case
            portableGetter = new PortableGetter(ss);
        }
        return portableGetter;
    } else if (targetObject instanceof CompactGenericRecord) {
        if (compactGetter == null) {
            // will be initialised a couple of times in the worst case
            compactGetter = new CompactGetter(ss);
        }
        return compactGetter;
    } else {
        return ReflectionHelper.createGetter(targetObject, attributeName, failOnMissingReflectiveAttribute);
    }
}
Also used : PortableGenericRecord(com.hazelcast.internal.serialization.impl.portable.PortableGenericRecord) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) CompactGenericRecord(com.hazelcast.internal.serialization.impl.compact.CompactGenericRecord) Data(com.hazelcast.internal.serialization.Data) ValueExtractor(com.hazelcast.query.extractor.ValueExtractor)

Example 3 with PortableGenericRecord

use of com.hazelcast.internal.serialization.impl.portable.PortableGenericRecord in project hazelcast by hazelcast.

the class SampleMetadataResolver method resolve.

@Nullable
@SuppressWarnings("checkstyle:returncount")
static Metadata resolve(InternalSerializationService ss, Object target, boolean key) {
    try {
        if (target instanceof Data) {
            Data data = (Data) target;
            if (data.isPortable()) {
                ClassDefinition classDefinition = ss.getPortableContext().lookupClassDefinition(data);
                return resolvePortable(classDefinition, key);
            } else if (data.isCompact()) {
                return resolveCompact(ss.extractSchemaFromData(data), key);
            } else if (data.isJson()) {
                return null;
            } else {
                return resolveJava(ss.toObject(data).getClass(), key);
            }
        } else if (target instanceof VersionedPortable) {
            VersionedPortable portable = (VersionedPortable) target;
            ClassDefinition classDefinition = ss.getPortableContext().lookupClassDefinition(portable.getFactoryId(), portable.getClassId(), portable.getClassVersion());
            return resolvePortable(classDefinition, key);
        } else if (target instanceof Portable) {
            Portable portable = (Portable) target;
            ClassDefinition classDefinition = ss.getPortableContext().lookupClassDefinition(portable.getFactoryId(), portable.getClassId(), 0);
            return resolvePortable(classDefinition, key);
        } else if (target instanceof PortableGenericRecord) {
            return resolvePortable(((PortableGenericRecord) target).getClassDefinition(), key);
        } else if (target instanceof CompactGenericRecord) {
            return resolveCompact(((CompactGenericRecord) target).getSchema(), key);
        } else if (ss.isCompactSerializable(target)) {
            Schema schema = ss.extractSchemaFromObject(target);
            return resolveCompact(schema, key);
        } else if (target instanceof HazelcastJsonValue) {
            return null;
        } else {
            return resolveJava(target.getClass(), key);
        }
    } catch (Exception e) {
        return null;
    }
}
Also used : VersionedPortable(com.hazelcast.nio.serialization.VersionedPortable) Portable(com.hazelcast.nio.serialization.Portable) PortableGenericRecord(com.hazelcast.internal.serialization.impl.portable.PortableGenericRecord) Schema(com.hazelcast.internal.serialization.impl.compact.Schema) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) CompactGenericRecord(com.hazelcast.internal.serialization.impl.compact.CompactGenericRecord) Data(com.hazelcast.internal.serialization.Data) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) VersionedPortable(com.hazelcast.nio.serialization.VersionedPortable) Nullable(javax.annotation.Nullable)

Aggregations

Data (com.hazelcast.internal.serialization.Data)3 PortableGenericRecord (com.hazelcast.internal.serialization.impl.portable.PortableGenericRecord)3 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)2 CompactGenericRecord (com.hazelcast.internal.serialization.impl.compact.CompactGenericRecord)2 GenericRecordQueryReader (com.hazelcast.internal.serialization.impl.GenericRecordQueryReader)1 InternalGenericRecord (com.hazelcast.internal.serialization.impl.InternalGenericRecord)1 Schema (com.hazelcast.internal.serialization.impl.compact.Schema)1 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)1 Portable (com.hazelcast.nio.serialization.Portable)1 VersionedPortable (com.hazelcast.nio.serialization.VersionedPortable)1 ValueExtractor (com.hazelcast.query.extractor.ValueExtractor)1 Nullable (javax.annotation.Nullable)1