Search in sources :

Example 1 with GenericRecordQueryReader

use of com.hazelcast.internal.serialization.impl.GenericRecordQueryReader 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 GenericRecordQueryReader

use of com.hazelcast.internal.serialization.impl.GenericRecordQueryReader in project hazelcast by hazelcast.

the class CompactGetter method getValue.

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

Example 3 with GenericRecordQueryReader

use of com.hazelcast.internal.serialization.impl.GenericRecordQueryReader in project hazelcast by hazelcast.

the class CompactStreamSerializerTest method testBits.

@Test
public void testBits() throws IOException {
    InternalSerializationService ss1 = createSerializationService();
    InternalSerializationService ss2 = createSerializationService();
    BitsDTO bitsDTO = new BitsDTO();
    bitsDTO.a = true;
    bitsDTO.h = true;
    bitsDTO.id = 121;
    bitsDTO.booleans = new boolean[8];
    bitsDTO.booleans[0] = true;
    bitsDTO.booleans[4] = true;
    Data data = ss1.toData(bitsDTO);
    // hash(4) + typeid(4) + schemaId(8) + (4 byte length) + (1 bytes for 8 bits) + (4 bytes for int)
    // (4 byte length of byte array) + (1 byte for booleans array of 8 bits) + (1 byte offset bytes)
    assertEquals(31, data.toByteArray().length);
    GenericRecordQueryReader reader = new GenericRecordQueryReader(ss2.readAsInternalGenericRecord(data));
    assertEquals(121, reader.read("id"));
    assertTrue((Boolean) reader.read("a"));
    assertFalse((Boolean) reader.read("b"));
    assertFalse((Boolean) reader.read("c"));
    assertFalse((Boolean) reader.read("d"));
    assertFalse((Boolean) reader.read("e"));
    assertFalse((Boolean) reader.read("f"));
    assertFalse((Boolean) reader.read("g"));
    assertTrue((Boolean) reader.read("h"));
    assertTrue((Boolean) reader.read("booleans[0]"));
    assertFalse((Boolean) reader.read("booleans[1]"));
    assertFalse((Boolean) reader.read("booleans[2]"));
    assertFalse((Boolean) reader.read("booleans[3]"));
    assertTrue((Boolean) reader.read("booleans[4]"));
    assertFalse((Boolean) reader.read("booleans[5]"));
    assertFalse((Boolean) reader.read("booleans[6]"));
    assertFalse((Boolean) reader.read("booleans[7]"));
    Object object = ss2.toObject(data);
    BitsDTO o = (BitsDTO) object;
    assertEquals(bitsDTO, o);
}
Also used : GenericRecordQueryReader(com.hazelcast.internal.serialization.impl.GenericRecordQueryReader) BitsDTO(example.serialization.BitsDTO) Data(com.hazelcast.internal.serialization.Data) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with GenericRecordQueryReader

use of com.hazelcast.internal.serialization.impl.GenericRecordQueryReader in project hazelcast by hazelcast.

the class DefaultPortableReaderQuickTest method reader.

// 
// Utilities
// 
public GenericRecordQueryReader reader(Portable portable) throws IOException {
    SerializationConfig serializationConfig = new SerializationConfig();
    serializationConfig.addPortableFactory(TestPortableFactory.ID, new TestPortableFactory());
    InternalSerializationService ss = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
    ss.toData(NON_EMPTY_PORSCHE);
    return new GenericRecordQueryReader(ss.readAsInternalGenericRecord(ss.toData(portable)));
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationConfig(com.hazelcast.config.SerializationConfig) GenericRecordQueryReader(com.hazelcast.internal.serialization.impl.GenericRecordQueryReader) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService)

Example 5 with GenericRecordQueryReader

use of com.hazelcast.internal.serialization.impl.GenericRecordQueryReader in project hazelcast by hazelcast.

the class PortableTest method testSerializationService_createPortableReader.

@Test
public void testSerializationService_createPortableReader() throws IOException {
    InternalSerializationService serializationService = new DefaultSerializationServiceBuilder().build();
    long timestamp1 = System.nanoTime();
    ChildPortableObject child = new ChildPortableObject(timestamp1);
    long timestamp2 = System.currentTimeMillis();
    ParentPortableObject parent = new ParentPortableObject(timestamp2, child);
    long timestamp3 = timestamp1 + timestamp2;
    GrandParentPortableObject grandParent = new GrandParentPortableObject(timestamp3, parent);
    Data data = serializationService.toData(grandParent);
    GenericRecordQueryReader reader = new GenericRecordQueryReader(serializationService.readAsInternalGenericRecord(data));
    assertEquals(grandParent.timestamp, reader.read("timestamp"));
    assertEquals(parent.timestamp, reader.read("child.timestamp"));
    assertEquals(child.timestamp, reader.read("child.child.timestamp"));
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) GenericRecordQueryReader(com.hazelcast.internal.serialization.impl.GenericRecordQueryReader) Data(com.hazelcast.internal.serialization.Data) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) QuickTest(com.hazelcast.test.annotation.QuickTest) CustomSerializationTest(com.hazelcast.internal.serialization.impl.CustomSerializationTest) Test(org.junit.Test)

Aggregations

GenericRecordQueryReader (com.hazelcast.internal.serialization.impl.GenericRecordQueryReader)11 Data (com.hazelcast.internal.serialization.Data)8 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)6 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)5 Test (org.junit.Test)5 SerializationConfig (com.hazelcast.config.SerializationConfig)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 InternalGenericRecord (com.hazelcast.internal.serialization.impl.InternalGenericRecord)3 CompactSerializationConfig (com.hazelcast.config.CompactSerializationConfig)2 SchemaService (com.hazelcast.internal.serialization.impl.compact.SchemaService)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 CustomSerializationTest (com.hazelcast.internal.serialization.impl.CustomSerializationTest)1 CompactInternalGenericRecord (com.hazelcast.internal.serialization.impl.compact.CompactInternalGenericRecord)1 GroupObject (com.hazelcast.internal.serialization.impl.compact.reader.CompactValueReaderTestStructure.GroupObject)1 NestedGroupObject (com.hazelcast.internal.serialization.impl.compact.reader.CompactValueReaderTestStructure.NestedGroupObject)1 PrimitiveObject (com.hazelcast.internal.serialization.impl.compact.reader.CompactValueReaderTestStructure.PrimitiveObject)1 PortableGenericRecord (com.hazelcast.internal.serialization.impl.portable.PortableGenericRecord)1 TestPortableFactory (com.hazelcast.internal.serialization.impl.portable.portablereader.DefaultPortableReaderTestStructure.TestPortableFactory)1 DefaultValueCollector (com.hazelcast.query.impl.DefaultValueCollector)1 MultiResult (com.hazelcast.query.impl.getters.MultiResult)1