Search in sources :

Example 6 with AttributesFactory

use of org.apache.geode.cache.AttributesFactory in project geode by apache.

the class ClientCacheCreation method createClientDefaults.

private static RegionAttributes createClientDefaults() {
    AttributesFactory af = new AttributesFactory();
    af.setScope(Scope.LOCAL);
    // af.setIgnoreJTA(true); In 6.6 and later releases client regions support JTA
    af.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
    return af.create();
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes)

Example 7 with AttributesFactory

use of org.apache.geode.cache.AttributesFactory in project geode by apache.

the class RegionCreation method createRoot.

/**
   * Creates a root {@link Region} in a given <code>Cache</code> based on the description provided
   * by this <code>RegionCreation</code>.
   *
   * @throws TimeoutException
   * @throws CacheWriterException
   * @throws RegionExistsException
   */
void createRoot(Cache cache) throws TimeoutException, CacheWriterException, RegionExistsException {
    Region root = null;
    // Validate the attributes before creating the root region
    this.attrs.inheritAttributes(cache);
    this.attrs.setIndexes(this.indexes);
    this.attrs.prepareForValidation();
    extensionPoint.beforeCreate(cache);
    try {
        root = ((InternalCache) cache).basicCreateRegion(this.name, new AttributesFactory(this.attrs).create());
    } catch (RegionExistsException ex) {
        root = ex.getRegion();
        setMutableAttributes(root);
    } catch (RegionDestroyedException ex) {
        // Region was concurrently destroyed.
        cache.getLoggerI18n().warning(LocalizedStrings.RegionCreation_REGION_DESTROYED_DURING_INITIALIZATION, this.name);
    // do nothing
    }
    if (root != null) {
        fillIn(root);
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) RegionExistsException(org.apache.geode.cache.RegionExistsException)

Example 8 with AttributesFactory

use of org.apache.geode.cache.AttributesFactory in project geode by apache.

the class GeodeRedisServer method initializeRedis.

private void initializeRedis() {
    synchronized (this.cache) {
        Region<ByteArrayWrapper, ByteArrayWrapper> stringsRegion;
        Region<ByteArrayWrapper, HyperLogLogPlus> hLLRegion;
        Region<String, RedisDataType> redisMetaData;
        InternalCache gemFireCache = (InternalCache) cache;
        try {
            if ((stringsRegion = cache.getRegion(STRING_REGION)) == null) {
                RegionFactory<ByteArrayWrapper, ByteArrayWrapper> regionFactory = gemFireCache.createRegionFactory(this.DEFAULT_REGION_TYPE);
                stringsRegion = regionFactory.create(STRING_REGION);
            }
            if ((hLLRegion = cache.getRegion(HLL_REGION)) == null) {
                RegionFactory<ByteArrayWrapper, HyperLogLogPlus> regionFactory = gemFireCache.createRegionFactory(this.DEFAULT_REGION_TYPE);
                hLLRegion = regionFactory.create(HLL_REGION);
            }
            if ((redisMetaData = cache.getRegion(REDIS_META_DATA_REGION)) == null) {
                AttributesFactory af = new AttributesFactory();
                af.addCacheListener(metaListener);
                af.setDataPolicy(DataPolicy.REPLICATE);
                InternalRegionArguments ira = new InternalRegionArguments().setInternalRegion(true).setIsUsedForMetaRegion(true);
                redisMetaData = gemFireCache.createVMRegion(REDIS_META_DATA_REGION, af.create(), ira);
            }
        } catch (IOException | ClassNotFoundException e) {
            // only if loading snapshot, not here
            InternalGemFireError assErr = new InternalGemFireError(LocalizedStrings.GemFireCache_UNEXPECTED_EXCEPTION.toLocalizedString());
            assErr.initCause(e);
            throw assErr;
        }
        this.regionCache = new RegionProvider(stringsRegion, hLLRegion, redisMetaData, expirationFutures, expirationExecutor, this.DEFAULT_REGION_TYPE);
        redisMetaData.put(REDIS_META_DATA_REGION, RedisDataType.REDIS_PROTECTED);
        redisMetaData.put(HLL_REGION, RedisDataType.REDIS_PROTECTED);
        redisMetaData.put(STRING_REGION, RedisDataType.REDIS_PROTECTED);
    }
    checkForRegions();
}
Also used : RedisDataType(org.apache.geode.redis.internal.RedisDataType) RegionProvider(org.apache.geode.redis.internal.RegionProvider) InternalCache(org.apache.geode.internal.cache.InternalCache) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) IOException(java.io.IOException) AttributesFactory(org.apache.geode.cache.AttributesFactory) ByteArrayWrapper(org.apache.geode.redis.internal.ByteArrayWrapper) HyperLogLogPlus(org.apache.geode.internal.hll.HyperLogLogPlus) InternalGemFireError(org.apache.geode.InternalGemFireError)

Example 9 with AttributesFactory

use of org.apache.geode.cache.AttributesFactory in project geode by apache.

the class CompiledInDUnitTest method createReplicateRegion.

private void createReplicateRegion() {
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setDataPolicy(DataPolicy.REPLICATE);
    createRegion(this.regionName, this.rootRegionName, factory.create());
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory)

Example 10 with AttributesFactory

use of org.apache.geode.cache.AttributesFactory in project geode by apache.

the class LikePredicateJUnitTest method testUndefined.

@Test
public void testUndefined() throws Exception {
    String[] queries = { "select * from /pos where status.toUpperCase() like '%ACT%'", "select * from /pos where status.toUpperCase() like 'ACT%'", "select * from /pos where status.toUpperCase() like '%IVE'", "select * from /pos where status.toUpperCase() like 'ACT_VE'", "select * from /pos where status like '%CT%'", "select * from /pos where status like 'ACT%'", "select * from /pos where status like 'ACT_VE'", "select * from /pos where position1.secId like '%B%'", "select * from /pos where position1.secId like 'IB%'", "select * from /pos where position1.secId like 'I_M'", "select * from /pos p, p.positions.values pos where pos.secId like '%B%'", "select * from /pos p, p.positions.values pos where pos.secId like 'IB%'", "select * from /pos p, p.positions.values pos where pos.secId like 'I_M'" };
    Cache cache = CacheUtils.getCache();
    AttributesFactory attributesFactory = new AttributesFactory();
    RegionAttributes regionAttributes = attributesFactory.create();
    Region region = cache.createRegion("pos", regionAttributes);
    for (int i = 0; i < 10; i++) {
        Portfolio p = new Portfolio(i);
        if (i % 2 == 0) {
            p.status = null;
            p.position1 = null;
            p.positions = null;
        } else {
            p.position1 = new Position("IBM", 0);
            p.status = "ACTIVE";
        }
        region.put("key-" + i, p);
    }
    SelectResults[][] res = new SelectResults[queries.length][2];
    QueryService qs = CacheUtils.getCache().getQueryService();
    SelectResults results = null;
    for (int i = 0; i < queries.length; i++) {
        Query q = qs.newQuery(queries[i]);
        try {
            results = (SelectResults) q.execute();
            res[i][0] = results;
        } catch (Exception e) {
            fail("Query execution failed for query " + queries[i] + " with exception: " + e);
        }
        if (i < 10) {
            assertEquals("Query " + queries[i] + " should return 5 results and not " + results.size(), 5, results.size());
        } else {
            assertEquals("Query " + queries[i] + " should return 1 results and not " + results.size(), 1, results.size());
        }
    }
    try {
        qs.createIndex("status", "status", region.getFullPath());
        qs.createIndex("position1secId", "pos1.secId", region.getFullPath());
        qs.createIndex("secId", "pos.secId", region.getFullPath() + " pos, pos.secId");
    } catch (Exception e) {
        fail("Index creation failed");
    }
    for (int i = 0; i < queries.length; i++) {
        Query q = qs.newQuery(queries[i]);
        try {
            results = (SelectResults) q.execute();
            res[i][1] = results;
        } catch (Exception e) {
            fail("Query execution failed for query " + queries[i] + " with exception: " + e);
        }
        if (i < 10) {
            assertEquals("Query " + queries[i] + " should return 5 results and not " + results.size(), 5, results.size());
        } else {
            assertEquals("Query " + queries[i] + " should return 1 results and not " + results.size(), 1, results.size());
        }
    }
    CacheUtils.compareResultsOfWithAndWithoutIndex(res);
}
Also used : Query(org.apache.geode.cache.query.Query) RegionAttributes(org.apache.geode.cache.RegionAttributes) Position(org.apache.geode.cache.query.data.Position) Portfolio(org.apache.geode.cache.query.data.Portfolio) AttributesFactory(org.apache.geode.cache.AttributesFactory) SelectResults(org.apache.geode.cache.query.SelectResults) QueryService(org.apache.geode.cache.query.QueryService) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

AttributesFactory (org.apache.geode.cache.AttributesFactory)1156 Region (org.apache.geode.cache.Region)565 Test (org.junit.Test)550 RegionAttributes (org.apache.geode.cache.RegionAttributes)471 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)468 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)356 VM (org.apache.geode.test.dunit.VM)304 Host (org.apache.geode.test.dunit.Host)288 Properties (java.util.Properties)244 CacheException (org.apache.geode.cache.CacheException)243 Cache (org.apache.geode.cache.Cache)229 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)206 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)201 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)199 LocalRegion (org.apache.geode.internal.cache.LocalRegion)173 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)156 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)139 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)129 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)126 IgnoredException (org.apache.geode.test.dunit.IgnoredException)125