Search in sources :

Example 1 with ReflectionBasedAutoSerializer

use of org.apache.geode.pdx.ReflectionBasedAutoSerializer in project geode by apache.

the class PdxCopyOnReadQueryJUnitTest method testCopyOnReadPdxSerialization.

@Test
public void testCopyOnReadPdxSerialization() throws Exception {
    List<String> classes = new ArrayList<String>();
    classes.add(PortfolioPdx.class.getCanonicalName());
    ReflectionBasedAutoSerializer serializer = new ReflectionBasedAutoSerializer(classes.toArray(new String[0]));
    CacheFactory cf = new CacheFactory();
    cf.setPdxSerializer(serializer);
    cf.setPdxReadSerialized(false);
    cf.set(MCAST_PORT, "0");
    cache = cf.create();
    cache.setCopyOnRead(true);
    Region region = cache.createRegionFactory(RegionShortcut.REPLICATE).create("SimpleObjects");
    Region duplicates = cache.createRegionFactory(RegionShortcut.REPLICATE).create("SimpleObjects_Duplicates");
    for (int i = 0; i < 10; i++) {
        PortfolioPdx t = new PortfolioPdx(i);
        region.put(i, t);
        duplicates.put(i, t);
    }
    QueryService qs = cache.getQueryService();
    SelectResults rs = (SelectResults) qs.newQuery("select * from /SimpleObjects").execute();
    assertEquals(10, rs.size());
    Query query = qs.newQuery("select * from /SimpleObjects_Duplicates s where s in ($1)");
    SelectResults finalResults = (SelectResults) query.execute(new Object[] { rs });
    assertEquals(10, finalResults.size());
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) Query(org.apache.geode.cache.query.Query) QueryService(org.apache.geode.cache.query.QueryService) ReflectionBasedAutoSerializer(org.apache.geode.pdx.ReflectionBasedAutoSerializer) ArrayList(java.util.ArrayList) Region(org.apache.geode.cache.Region) PortfolioPdx(org.apache.geode.cache.query.data.PortfolioPdx) CacheFactory(org.apache.geode.cache.CacheFactory) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with ReflectionBasedAutoSerializer

use of org.apache.geode.pdx.ReflectionBasedAutoSerializer in project geode by apache.

the class RestInterfaceJUnitTest method setupGemFire.

@Before
public void setupGemFire() {
    AgentUtil agentUtil = new AgentUtil(GemFireVersion.getGemFireVersion());
    if (agentUtil.findWarLocation("geode-web-api") == null) {
        fail("unable to locate geode-web-api WAR file");
    }
    if (gemfireCache == null) {
        gemfireProperties = (gemfireProperties != null ? gemfireProperties : new Properties());
        gemfireCache = new CacheFactory().setPdxSerializer(new ReflectionBasedAutoSerializer(Person.class.getName().replaceAll("\\$", "."))).setPdxReadSerialized(true).setPdxIgnoreUnreadFields(false).set("name", getClass().getSimpleName()).set(MCAST_PORT, "0").set(LOG_LEVEL, "config").set(HTTP_SERVICE_BIND_ADDRESS, "localhost").set(HTTP_SERVICE_PORT, String.valueOf(getHttpServicePort())).set(START_DEV_REST_API, "true").create();
        RegionFactory<String, Object> peopleRegionFactory = gemfireCache.createRegionFactory();
        peopleRegionFactory.setDataPolicy(DataPolicy.PARTITION);
        peopleRegionFactory.setKeyConstraint(String.class);
        peopleRegionFactory.setValueConstraint(Object.class);
        people = peopleRegionFactory.create("People");
    }
}
Also used : ReflectionBasedAutoSerializer(org.apache.geode.pdx.ReflectionBasedAutoSerializer) AgentUtil(org.apache.geode.management.internal.AgentUtil) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) CacheFactory(org.apache.geode.cache.CacheFactory) Before(org.junit.Before)

Example 3 with ReflectionBasedAutoSerializer

use of org.apache.geode.pdx.ReflectionBasedAutoSerializer in project geode by apache.

the class TypeRegistry method setPdxSerializer.

public static void setPdxSerializer(PdxSerializer v) {
    if (v == null) {
        PdxSerializer oldValue = pdxSerializer.getAndSet(null);
        if (oldValue instanceof ReflectionBasedAutoSerializer) {
            asm.compareAndSet((AutoSerializableManager) ((ReflectionBasedAutoSerializer) oldValue).getManager(), null);
        }
    } else {
        pdxSerializerWasSet = true;
        pdxSerializer.set(v);
        if (v instanceof ReflectionBasedAutoSerializer) {
            asm.set((AutoSerializableManager) ((ReflectionBasedAutoSerializer) v).getManager());
        }
    }
}
Also used : PdxSerializer(org.apache.geode.pdx.PdxSerializer) ReflectionBasedAutoSerializer(org.apache.geode.pdx.ReflectionBasedAutoSerializer)

Example 4 with ReflectionBasedAutoSerializer

use of org.apache.geode.pdx.ReflectionBasedAutoSerializer in project immutables by immutables.

the class GeodeCqTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    this.clientCache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334).setPdxSerializer(new ReflectionBasedAutoSerializer(Person.class.getPackage().getName())).setPoolSubscriptionEnabled(true).create();
    this.region = clientCache.<String, Person>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create("persons");
    region.clear();
}
Also used : ReflectionBasedAutoSerializer(org.apache.geode.pdx.ReflectionBasedAutoSerializer) Person(org.immutables.criteria.personmodel.Person) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with ReflectionBasedAutoSerializer

use of org.apache.geode.pdx.ReflectionBasedAutoSerializer in project geode by apache.

the class PDXCommands method configurePDX.

@CliCommand(value = CliStrings.CONFIGURE_PDX, help = CliStrings.CONFIGURE_PDX__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_REGION)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result configurePDX(@CliOption(key = CliStrings.CONFIGURE_PDX__READ__SERIALIZED, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONFIGURE_PDX__READ__SERIALIZED__HELP) Boolean readSerialized, @CliOption(key = CliStrings.CONFIGURE_PDX__IGNORE__UNREAD_FIELDS, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONFIGURE_PDX__IGNORE__UNREAD_FIELDS__HELP) Boolean ignoreUnreadFields, @CliOption(key = CliStrings.CONFIGURE_PDX__DISKSTORE, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, specifiedDefaultValue = "", help = CliStrings.CONFIGURE_PDX__DISKSTORE__HELP) String diskStore, @CliOption(key = CliStrings.CONFIGURE_PDX__AUTO__SERIALIZER__CLASSES, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, specifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONFIGURE_PDX__AUTO__SERIALIZER__CLASSES__HELP) String[] patterns, @CliOption(key = CliStrings.CONFIGURE_PDX__PORTABLE__AUTO__SERIALIZER__CLASSES, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, specifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONFIGURE_PDX__PORTABLE__AUTO__SERIALIZER__CLASSES__HELP) String[] portablePatterns) {
    Result result = null;
    try {
        InfoResultData ird = ResultBuilder.createInfoResultData();
        CacheCreation cache = new CacheCreation(true);
        if ((portablePatterns != null && portablePatterns.length > 0) && (patterns != null && patterns.length > 0)) {
            return ResultBuilder.createUserErrorResult(CliStrings.CONFIGURE_PDX__ERROR__MESSAGE);
        }
        if (!CliUtil.getAllNormalMembers(CliUtil.getCacheIfExists()).isEmpty()) {
            ird.addLine(CliStrings.CONFIGURE_PDX__NORMAL__MEMBERS__WARNING);
        }
        // Set persistent and the disk-store
        if (diskStore != null) {
            cache.setPdxPersistent(true);
            ird.addLine(CliStrings.CONFIGURE_PDX__PERSISTENT + " = " + cache.getPdxPersistent());
            if (!diskStore.equals("")) {
                cache.setPdxDiskStore(diskStore);
                ird.addLine(CliStrings.CONFIGURE_PDX__DISKSTORE + " = " + cache.getPdxDiskStore());
            } else {
                ird.addLine(CliStrings.CONFIGURE_PDX__DISKSTORE + " = " + "DEFAULT");
            }
        } else {
            cache.setPdxPersistent(CacheConfig.DEFAULT_PDX_PERSISTENT);
            ird.addLine(CliStrings.CONFIGURE_PDX__PERSISTENT + " = " + cache.getPdxPersistent());
        }
        // Set read-serialized
        if (readSerialized != null) {
            cache.setPdxReadSerialized(readSerialized);
        } else {
            cache.setPdxReadSerialized(CacheConfig.DEFAULT_PDX_READ_SERIALIZED);
        }
        ird.addLine(CliStrings.CONFIGURE_PDX__READ__SERIALIZED + " = " + cache.getPdxReadSerialized());
        // Set ingoreUnreadFields
        if (ignoreUnreadFields != null) {
            cache.setPdxIgnoreUnreadFields(ignoreUnreadFields);
        } else {
            cache.setPdxIgnoreUnreadFields(CacheConfig.DEFAULT_PDX_IGNORE_UNREAD_FIELDS);
        }
        ird.addLine(CliStrings.CONFIGURE_PDX__IGNORE__UNREAD_FIELDS + " = " + cache.getPdxIgnoreUnreadFields());
        if (portablePatterns != null) {
            ReflectionBasedAutoSerializer autoSerializer = new ReflectionBasedAutoSerializer(portablePatterns);
            cache.setPdxSerializer(autoSerializer);
            ird.addLine("PDX Serializer " + cache.getPdxSerializer().getClass().getName());
            ird.addLine("Portable classes " + Arrays.toString(portablePatterns));
        }
        if (patterns != null) {
            ReflectionBasedAutoSerializer nonPortableAutoSerializer = new ReflectionBasedAutoSerializer(true, patterns);
            cache.setPdxSerializer(nonPortableAutoSerializer);
            ird.addLine("PDX Serializer : " + cache.getPdxSerializer().getClass().getName());
            ird.addLine("Non portable classes :" + Arrays.toString(patterns));
        }
        final StringWriter stringWriter = new StringWriter();
        final PrintWriter printWriter = new PrintWriter(stringWriter);
        CacheXmlGenerator.generate(cache, printWriter, true, false, false);
        printWriter.close();
        String xmlDefinition = stringWriter.toString();
        // TODO jbarrett - shouldn't this use the same loadXmlDefinition that other constructors use?
        XmlEntity xmlEntity = XmlEntity.builder().withType(CacheXml.PDX).withConfig(xmlDefinition).build();
        result = ResultBuilder.buildResult(ird);
        persistClusterConfiguration(result, () -> getSharedConfiguration().addXmlEntity(xmlEntity, null));
    } catch (Exception e) {
        return ResultBuilder.createGemFireErrorResult(e.getMessage());
    }
    return result;
}
Also used : XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) InfoResultData(org.apache.geode.management.internal.cli.result.InfoResultData) StringWriter(java.io.StringWriter) ReflectionBasedAutoSerializer(org.apache.geode.pdx.ReflectionBasedAutoSerializer) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) Result(org.apache.geode.management.cli.Result) PrintWriter(java.io.PrintWriter) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Aggregations

ReflectionBasedAutoSerializer (org.apache.geode.pdx.ReflectionBasedAutoSerializer)8 ClientCacheFactory (org.apache.geode.cache.client.ClientCacheFactory)3 Properties (java.util.Properties)2 CacheFactory (org.apache.geode.cache.CacheFactory)2 Region (org.apache.geode.cache.Region)2 QueryService (org.apache.geode.cache.query.QueryService)2 SelectResults (org.apache.geode.cache.query.SelectResults)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 CacheClosedException (org.apache.geode.cache.CacheClosedException)1 Declarable (org.apache.geode.cache.Declarable)1 ClientCache (org.apache.geode.cache.client.ClientCache)1 Query (org.apache.geode.cache.query.Query)1 PortfolioPdx (org.apache.geode.cache.query.data.PortfolioPdx)1 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)1 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)1 CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)1 CliMetaData (org.apache.geode.management.cli.CliMetaData)1 Result (org.apache.geode.management.cli.Result)1