public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { try { Map<String, String> row; if (clustered) { row = AtomicMapLookup.getAtomicMap(infinispanManager.getCache(table), key, false); } else { Cache<String, Map<String, String>> cache = infinispanManager.getCache(table); row = cache.get(key); } if (row != null) { result.clear(); if (fields == null || fields.isEmpty()) { StringByteIterator.putAllAsByteIterators(result, row); } else { for (String field : fields) { result.put(field, new StringByteIterator(row.get(field))); } } } return Status.OK; } catch (Exception e) { LOGGER.error(e); return Status.ERROR; } }
public Status delete(String table, String key) { try { if (clustered) { AtomicMapLookup.removeAtomicMap(infinispanManager.getCache(table), key); } else { infinispanManager.getCache(table).remove(key); } return Status.OK; } catch (Exception e) { LOGGER.error(e); return Status.ERROR; } } }
public void testAtomicMapAfterFineGrainedAtomicMapPrimary() throws Exception { Cache<MagicKey, Object> cache1 = cache(0, "atomic"); MagicKey key = new MagicKey(cache1); getFineGrainedAtomicMap(cache1, key); expectException(IllegalStateException.class, () -> getAtomicMap(cache1, key)); }
@Test(expectedExceptions = IllegalStateException.class) public void testRemovalOfAtomicMap() throws SystemException, NotSupportedException, RollbackException, HeuristicRollbackException, HeuristicMixedException { AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, "key"); map.put("hello", "world"); TransactionManager tm = cache.getAdvancedCache().getTransactionManager(); tm.begin(); map = AtomicMapLookup.getAtomicMap(cache, "key"); map.put("hello2", "world2"); assert map.size() == 2; AtomicMapLookup.removeAtomicMap(cache, "key"); map.size(); tm.commit(); } }
@Override public Map<String, String> getObject(Cache cache, String key) { return AtomicMapLookup.getFineGrainedAtomicMap(cache, key, false); }
/** * Verifies we can create a new AtomicMap, use it and then remove it while in the same transaction * See also ISPN-2075. */ public void testDontFailOnImmediateRemovalOfAtomicMaps() throws Exception { final String key = "key1"; final String subKey = "subK"; TestingUtil.withTx(tm, () -> { FineGrainedAtomicMap<String, String> fineGrainedAtomicMap = AtomicMapLookup.getFineGrainedAtomicMap(cache, key); fineGrainedAtomicMap.put(subKey, "some value"); fineGrainedAtomicMap = AtomicMapLookup.getFineGrainedAtomicMap(cache, key); fineGrainedAtomicMap.get(subKey); fineGrainedAtomicMap.put(subKey, "v"); fineGrainedAtomicMap.put(subKey + 2, "v2"); fineGrainedAtomicMap = AtomicMapLookup.getFineGrainedAtomicMap(cache, key); Object object = fineGrainedAtomicMap.get(subKey); assertEquals("Wrong FGAM sub-key value.", "v", object); AtomicMapLookup.removeAtomicMap(cache, key); return null; }); }
public void testFineGrainedMapAfterAtomicMapPrimary() throws Exception { Cache<MagicKey, Object> cache1 = cache(0, "atomic"); MagicKey key = new MagicKey("key", cache1); getAtomicMap(cache1, key); expectException(IllegalStateException.class, () -> getFineGrainedAtomicMap(cache1, key)); }
public void testAtomicMap() { AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, "map"); assertIsEmpty(map); assertIsEmptyMap(cache, "map"); assert cache.containsKey("map"); map.put("blah", "blah"); assert map.size() == 1; assert map.get("blah").equals("blah"); assert map.containsKey("blah"); map.clear(); assertIsEmpty(map); assertIsEmptyMap(cache, "map"); assert cache.containsKey("map"); AtomicMapLookup.removeAtomicMap(cache, "map"); assert !cache.containsKey("map"); }
@Override protected <CK, K, V> Map<K, V> createAtomicMap(Cache<CK, Object> cache, CK key, boolean createIfAbsent) { return getFineGrainedAtomicMap(cache, key, createIfAbsent); }
public Status insert(String table, String key, Map<String, ByteIterator> values) { try { if (clustered) { AtomicMap<String, String> row = AtomicMapLookup.getAtomicMap(infinispanManager.getCache(table), key); row.clear(); StringByteIterator.putAllAsStrings(row, values); } else { infinispanManager.getCache(table).put(key, values); } return Status.OK; } catch (Exception e) { LOGGER.error(e); return Status.ERROR; } }
@Test(enabled = false, description = "Doesn't work when the originator isn't the primary owner, see ISPN-5988") public void testFineGrainedMapAfterAtomicMapBackup() throws Exception { Cache<MagicKey, Object> cache1 = cache(0, "atomic"); Cache<MagicKey, Object> cache2 = cache(1, "atomic"); MagicKey key = new MagicKey("key", cache2); getAtomicMap(cache1, key); try { getFineGrainedAtomicMap(cache1, key); fail("Should have failed with an IllegalArgumentException"); } catch (IllegalArgumentException e) { // Expected } }
@Override public Map<String, String> createObject(Cache cache, String key) { Map<String, String> map = AtomicMapLookup.getFineGrainedAtomicMap(cache, key); map.put("first", "first component of object with key=" + key); map.put("second", "second component of object with key=" + key); return map; }
protected <CK> void removeAtomicMap(Cache<CK, Object> cache, CK key) { AtomicMapLookup.removeAtomicMap(cache, key); }
public Status update(String table, String key, Map<String, ByteIterator> values) { try { if (clustered) { AtomicMap<String, String> row = AtomicMapLookup.getAtomicMap(infinispanManager.getCache(table), key); StringByteIterator.putAllAsStrings(row, values); } else { Cache<String, Map<String, String>> cache = infinispanManager.getCache(table); Map<String, String> row = cache.get(key); if (row == null) { row = StringByteIterator.getStringMap(values); cache.put(key, row); } else { StringByteIterator.putAllAsStrings(row, values); } } return Status.OK; } catch (Exception e) { LOGGER.error(e); return Status.ERROR; } }
public void testAtomicMapAfterFineGrainedAtomicMapBackup() throws Exception { Cache<MagicKey, Object> cache1 = cache(0, "atomic"); Cache<MagicKey, Object> cache2 = cache(1, "atomic"); MagicKey key = new MagicKey(cache2); getFineGrainedAtomicMap(cache1, key); Exceptions.expectException(IllegalStateException.class, "ISPN000457:.*", () -> getAtomicMap(cache1, key)); }
private Tuple getTupleFromCacheKey(EK cacheKey, Cache<EK, Map<String,Object>> cache) { FineGrainedAtomicMap<String, Object> atomicMap = AtomicMapLookup.getFineGrainedAtomicMap( cache, cacheKey, false ); if ( atomicMap == null ) { return null; } else { return new Tuple( new InfinispanTupleSnapshot( atomicMap ), SnapshotType.UPDATE ); } }
@Override public void removeTuple(EntityKey key, TupleContext tupleContext) { Cache<EK, Map<String, Object>> cache = getCacheManager().getEntityCache( key.getMetadata() ); EK cacheKey = getKeyProvider().getEntityCacheKey( key ); AtomicMapLookup.removeAtomicMap( cache, cacheKey ); }
private AtomicMap<Serializable, Void> getKeysPerCategoryCollection(String category) { return AtomicMapLookup.getAtomicMap(this.cache, category, true); } }
private Tuple getTupleFromCacheKey(EK cacheKey, Cache<EK, Map<String,Object>> cache) { FineGrainedAtomicMap<String, Object> atomicMap = AtomicMapLookup.getFineGrainedAtomicMap( cache, cacheKey, false ); if ( atomicMap == null ) { return null; } else { return new Tuple( new InfinispanTupleSnapshot( atomicMap ), SnapshotType.UPDATE ); } }
@Override public void removeAssociation(AssociationKey key, AssociationContext associationContext) { Cache<AK, Map<RowKey, Map<String, Object>>> cache = getCacheManager().getAssociationCache( key.getMetadata() ); AK cacheKey = getKeyProvider().getAssociationCacheKey( key ); AtomicMapLookup.removeAtomicMap( cache, cacheKey ); }