Java Code Examples for org.apache.ignite.IgniteCache#getConfiguration()
The following examples show how to use
org.apache.ignite.IgniteCache#getConfiguration() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IgniteDatastoreProvider.java From hibernate-ogm-ignite with GNU Lesser General Public License v2.1 | 6 votes |
/** * Converting entity key to cache key * * @param key entity key * @return string key */ public Object createKeyObject(EntityKey key) { Object result = null; if ( key.getColumnValues().length == 1 ) { IgniteCache<Object, BinaryObject> entityCache = getEntityCache( key.getMetadata() ); CacheConfiguration cacheConfig = entityCache.getConfiguration( CacheConfiguration.class ); result = toValidKeyObject( key.getColumnValues()[0], cacheConfig.getKeyType() ); } else { BinaryObjectBuilder builder = createBinaryObjectBuilder( findKeyType( key.getMetadata() ) ); for ( int i = 0; i < key.getColumnNames().length; i++ ) { builder.setField( StringHelper.stringAfterPoint( key.getColumnNames()[i] ), key.getColumnValues()[i] ); } result = builder.build(); } return result; }
Example 2
Source File: GridCacheVersionTopologyChangeTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @param cache Cache. * @param vers Current versions. */ @SuppressWarnings("unchecked") private void checkVersionIncrease(IgniteCache<Object, Object> cache, Map<Integer, Comparable> vers) { for (Integer k : vers.keySet()) { cache.put(k, k); Comparable curVer = vers.get(k); CacheEntry entry = cache.getEntry(k); if (entry != null) { Comparable newVer = entry.version(); assertTrue(newVer.compareTo(curVer) > 0); vers.put(k, newVer); } else { CacheConfiguration ccfg = cache.getConfiguration(CacheConfiguration.class); assertEquals(0, ccfg.getBackups()); } } }
Example 3
Source File: CacheSerializableTransactionsTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @param cache Cache. * @return Test keys. * @throws Exception If failed. */ private List<Integer> testKeys(IgniteCache<Integer, Integer> cache) throws Exception { CacheConfiguration ccfg = cache.getConfiguration(CacheConfiguration.class); List<Integer> keys = new ArrayList<>(); if (!cache.unwrap(Ignite.class).configuration().isClientMode()) { if (ccfg.getCacheMode() == PARTITIONED) keys.add(nearKey(cache)); keys.add(primaryKey(cache)); if (ccfg.getBackups() != 0) keys.add(backupKey(cache)); } else keys.add(nearKey(cache)); return keys; }
Example 4
Source File: CacheOptimisticTransactionsWithFilterTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @param cache Cache. * @return Test keys. * @throws Exception If failed. */ private List<Integer> testKeys(IgniteCache<Integer, Integer> cache) throws Exception { CacheConfiguration ccfg = cache.getConfiguration(CacheConfiguration.class); List<Integer> keys = new ArrayList<>(); if (!cache.unwrap(Ignite.class).configuration().isClientMode()) { if (ccfg.getCacheMode() == PARTITIONED && serversNumber() > 1) keys.add(nearKey(cache)); keys.add(primaryKey(cache)); if (ccfg.getBackups() != 0 && serversNumber() > 1) keys.add(backupKey(cache)); } else keys.add(nearKey(cache)); return keys; }
Example 5
Source File: CacheGetEntryAbstractTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @param e Entry. * @param cache Cache. * @throws Exception If failed. */ private void compareVersionWithPrimaryNode(CacheEntry<Integer, ?> e, IgniteCache<Integer, TestValue> cache) throws Exception { CacheConfiguration cfg = cache.getConfiguration(CacheConfiguration.class); if (cfg.getCacheMode() != LOCAL) { Ignite prim = primaryNode(e.getKey(), cache.getName()); GridCacheAdapter<Object, Object> cacheAdapter = ((IgniteKernal)prim).internalCache(cache.getName()); if (cfg.getNearConfiguration() != null) cacheAdapter = ((GridNearCacheAdapter)cacheAdapter).dht(); IgniteCacheObjectProcessor cacheObjects = cacheAdapter.context().cacheObjects(); CacheObjectContext cacheObjCtx = cacheAdapter.context().cacheObjectContext(); GridCacheEntryEx mapEntry = cacheAdapter.entryEx(cacheObjects.toCacheKeyObject( cacheObjCtx, cacheAdapter.context(), e.getKey(), true)); mapEntry.unswap(); assertNotNull("No entry for key: " + e.getKey(), mapEntry); assertEquals(mapEntry.version(), e.version()); } }
Example 6
Source File: IgniteDatastoreProvider.java From hibernate-ogm-ignite with GNU Lesser General Public License v2.1 | 5 votes |
/** * Finds key type name for cache for entities with composite id * @param keyMetadata * @return */ private String findKeyType(EntityKeyMetadata keyMetadata) { String result = compositeIdTypes.get( keyMetadata.getTable() ); if ( result == null ) { String cacheType = getEntityTypeName( keyMetadata.getTable() ); IgniteCache<Object, BinaryObject> cache = getEntityCache( keyMetadata ); CacheConfiguration cacheConfig = cache.getConfiguration( CacheConfiguration.class ); if ( cacheConfig.getQueryEntities() != null ) { for ( QueryEntity qe : (Collection<QueryEntity>) cacheConfig.getQueryEntities() ) { if ( qe.getValueType() != null && cacheType.equalsIgnoreCase( qe.getValueType() ) ) { result = qe.getKeyType(); break; } } } if ( result == null ) { if ( cacheConfig.getKeyType() != null ) { result = cacheConfig.getKeyType().getSimpleName(); } if ( result == null ) { // if nothing found we use id field name result = StringHelper.stringBeforePoint( keyMetadata.getColumnNames()[0] ); result = capitalize( result ); } } compositeIdTypes.put( keyMetadata.getTable(), result ); } return result; }
Example 7
Source File: JettyRestProcessorAbstractSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param cacheName Cache name to create. * @param mode Expected cache mode. * @param backups Expected number of backups. * @param wrtSync Expected cache write synchronization mode. * @param params Optional cache params. */ private void checkGetOrCreateAndDestroy( String cacheName, CacheMode mode, int backups, CacheWriteSynchronizationMode wrtSync, String cacheGrp, String dataRegion, String... params ) throws Exception { String ret = content(cacheName, GridRestCommand.GET_OR_CREATE_CACHE, params); info("GetOrCreateCache command result: " + ret); validateJsonResponse(ret); IgniteCache<String, String> cache = grid(0).cache(cacheName); cache.put("1", "1"); CacheConfiguration ccfg = cache.getConfiguration(CacheConfiguration.class); assertEquals(backups, ccfg.getBackups()); assertEquals(mode, ccfg.getCacheMode()); assertEquals(wrtSync, ccfg.getWriteSynchronizationMode()); if (!F.isEmpty(cacheGrp)) assertEquals(cacheGrp, ccfg.getGroupName()); if (!F.isEmpty(dataRegion)) assertEquals(dataRegion, ccfg.getDataRegionName()); ret = content(cacheName, GridRestCommand.DESTROY_CACHE); assertTrue(validateJsonResponse(ret).isNull()); assertNull(grid(0).cache(cacheName)); }
Example 8
Source File: IgniteCacheConfigurationDefaultTemplateTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param ignite Ignite. * @param name Cache name. * @param expBackups Expected number of backups. */ private void checkGetOrCreate(Ignite ignite, String name, int expBackups) { IgniteCache cache = ignite.getOrCreateCache(name); assertNotNull(cache); CacheConfiguration cfg = (CacheConfiguration)cache.getConfiguration(CacheConfiguration.class); assertEquals(name, cfg.getName()); assertEquals(expBackups, cfg.getBackups()); }
Example 9
Source File: IgniteCacheConfigurationTemplateTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param ignite Ignite. * @param name Cache name. * @param expBackups Expected number of backups. */ private void checkGetOrCreate(Ignite ignite, String name, int expBackups) { IgniteCache cache = ignite.getOrCreateCache(name); assertNotNull(cache); CacheConfiguration cfg = (CacheConfiguration)cache.getConfiguration(CacheConfiguration.class); assertEquals(name, cfg.getName()); assertEquals(expBackups, cfg.getBackups()); }
Example 10
Source File: IgniteCacheConfigurationTemplateTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param ignite Ignite. * @param name Cache name. * @param expBackups Expected number of backups. */ private void checkCreate(final Ignite ignite, final String name, int expBackups) { IgniteCache cache = ignite.createCache(name); assertNotNull(cache); CacheConfiguration cfg = (CacheConfiguration)cache.getConfiguration(CacheConfiguration.class); assertEquals(name, cfg.getName()); assertEquals(expBackups, cfg.getBackups()); }
Example 11
Source File: IgniteTestHelper.java From hibernate-ogm-ignite with GNU Lesser General Public License v2.1 | 4 votes |
private static CacheConfiguration getCacheConfiguration(OgmSessionFactory sessionFactory, Class<?> entityClass) { OgmEntityPersister entityPersister = (OgmEntityPersister) ( (SessionFactoryImplementor) sessionFactory ).locateEntityPersister( entityClass ); IgniteCache<Object, BinaryObject> cache = getProvider( sessionFactory ).getEntityCache( entityPersister.getEntityKeyMetadata() ); return cache.getConfiguration( CacheConfiguration.class ); }
Example 12
Source File: CacheMvccTransactionsTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @param cache Cache. * @return Test keys. * @throws Exception If failed. */ private List<Integer> testKeys(IgniteCache<Integer, Integer> cache) throws Exception { CacheConfiguration ccfg = cache.getConfiguration(CacheConfiguration.class); List<Integer> keys = new ArrayList<>(); if (ccfg.getCacheMode() == PARTITIONED) keys.add(nearKey(cache)); keys.add(primaryKey(cache)); if (ccfg.getBackups() != 0) keys.add(backupKey(cache)); return keys; }
Example 13
Source File: CacheMetricsManageTest.java From ignite with Apache License 2.0 | 4 votes |
/** * */ @Test public void testPublicApiStatisticsEnable() throws Exception { Ignite ig1 = startGrid(1); startGrid(2); IgniteCache<Object, Object> cache1 = ig1.cache(CACHE1); CacheConfiguration<Object, Object> cacheCfg2 = new CacheConfiguration<Object, Object>(cache1.getConfiguration(CacheConfiguration.class)); cacheCfg2.setName(CACHE2); cacheCfg2.setStatisticsEnabled(true); ig1.getOrCreateCache(cacheCfg2); assertCachesStatisticsMode(false, true); cache1.enableStatistics(true); assertCachesStatisticsMode(true, true); ig1.cluster().enableStatistics(Arrays.asList(CACHE1, CACHE2), false); assertCachesStatisticsMode(false, false); }
Example 14
Source File: IgniteCacheConfigurationDefaultTemplateTest.java From ignite with Apache License 2.0 | 3 votes |
/** * @param ignite Ignite. * @param cacheName Cache name. */ private void checkDefaultTemplate(final Ignite ignite, final String cacheName) { checkGetOrCreate(ignite, cacheName, 0); IgniteCache cache = ignite.getOrCreateCache(cacheName); assertNotNull(cache); CacheConfiguration cfg = (CacheConfiguration)cache.getConfiguration(CacheConfiguration.class); assertEquals(CacheConfiguration.DFLT_CACHE_ATOMICITY_MODE, cfg.getAtomicityMode()); }
Example 15
Source File: CacheMetricsManageTest.java From ignite with Apache License 2.0 | 2 votes |
/** * */ @Test public void testMultiThreadStatisticsEnable() throws Exception { startGrids(5); IgniteCache<?, ?> cache1 = grid(0).cache(CACHE1); CacheConfiguration<Object, Object> cacheCfg2 = new CacheConfiguration<Object, Object>(cache1.getConfiguration(CacheConfiguration.class)); cacheCfg2.setName(CACHE2); grid(0).getOrCreateCache(cacheCfg2); awaitPartitionMapExchange(); final CyclicBarrier barrier = new CyclicBarrier(10); final AtomicInteger gridIdx = new AtomicInteger(-1); IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() { @Override public void run() { try { Ignite ignite = grid(gridIdx.incrementAndGet() % 5); barrier.await(); ignite.cluster().enableStatistics(Arrays.asList(CACHE1, CACHE2), true); assertCachesStatisticsMode(true, true); barrier.await(); ignite.cluster().enableStatistics(Arrays.asList(CACHE1, CACHE2), false); assertCachesStatisticsMode(false, false); barrier.await(); ignite.cluster().enableStatistics(Collections.singletonList(CACHE1), true); assertCachesStatisticsMode(true, false); } catch (InterruptedException | BrokenBarrierException | IgniteCheckedException e) { fail("Unexpected exception: " + e); } } }, 10); fut.get(); startGrid(5); assertCachesStatisticsMode(true, false); }