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; } } }
protected <CK> void removeAtomicMap(Cache<CK, Object> cache, CK key) { AtomicMapLookup.removeAtomicMap(cache, key); }
@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 ); }
@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 ); }
@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 ); }
@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 ); }
@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(); } }
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"); }
/** * 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; }); }