@Test public void testReplace() throws Exception { transactionManager.begin(); assertEquals("Cache should be empty to start", 0, cache.getSize()); assertEquals("Cach1 should be empty to start", 0, cach1.getSize()); assertNull(cache.replace(new Element("blah", "someValue"))); cache.put(new Element("blah", "value")); assertNotNull(cache.replace(new Element("blah", "someValue"))); transactionManager.commit(); transactionManager.begin(); assertNotNull(cache.get("blah")); assertEquals("someValue", cache.get("blah").getValue()); transactionManager.commit(); transactionManager.begin(); cache.put(new Element("key", "value")); transactionManager.commit(); transactionManager.begin(); cach1.put(new Element("random", "things")); cache.replace(new Element("key", "newValue")); Transaction tx1 = transactionManager.suspend(); transactionManager.begin(); cache.remove("key"); transactionManager.commit(); transactionManager.resume(tx1); try { transactionManager.commit(); fail("Transaction should have failed, element is deleted already"); } catch (RollbackException e) { } transactionManager.begin(); assertNull(cache.get("key")); transactionManager.commit(); transactionManager.begin(); cache.put(new Element("key", "value")); transactionManager.commit(); transactionManager.begin(); cach1.put(new Element("random", "things")); cache.replace(new Element("key", "newValue")); tx1 = transactionManager.suspend(); transactionManager.begin(); cache.put(new Element("key", "allNewValue")); transactionManager.commit(); transactionManager.resume(tx1); try { transactionManager.commit(); fail("Transaction should have failed, element is deleted already"); } catch (RollbackException e) { } transactionManager.begin(); assertNotNull(cache.get("key")); assertNotNull("allNewValue", cache.get("key").getValue()); transactionManager.commit(); transactionManager.begin(); cache.put(new Element("key", "value")); transactionManager.commit(); transactionManager.begin(); cach1.put(new Element("random", "things")); cache.replace(new Element("key", "newValue")); tx1 = transactionManager.suspend(); transactionManager.begin(); cache.put(new Element("key", "allNewValue")); transactionManager.commit(); transactionManager.resume(tx1); try { transactionManager.commit(); fail("Transaction should have failed, element value has changed"); } catch (RollbackException e) { } transactionManager.begin(); assertNotNull(cache.get("key")); assertNotNull("allNewValue", cache.get("key").getValue()); transactionManager.commit(); transactionManager.begin(); cache.put(new Element("key", "value")); transactionManager.commit(); transactionManager.begin(); cach1.put(new Element("random", "things")); cache.replace(new Element("key", "value")); tx1 = transactionManager.suspend(); transactionManager.begin(); cache.put(new Element("key", "newValue")); transactionManager.commit(); transactionManager.resume(tx1); try { transactionManager.commit(); fail("Transaction should have failed, element has changed in the meantime!"); } catch (RollbackException e) { } transactionManager.begin(); assertNotNull(cache.get("key")); assertEquals("newValue", cache.get("key").getValue()); transactionManager.commit(); }
public boolean replace(Element old, Element element) throws NullPointerException, IllegalArgumentException { TransactionContext context = getOrCreateTransactionContext(); Element previous = getCurrentElement(element.getKey(), context); boolean replaced = false; if (previous != null && previous.getValue().equals(old.getValue())) { context.addCommand(new StoreReplaceElementCommand(old, element), element); replaced = true; } return replaced; }
XATransactionalStore extends AbstractStore { public boolean replace(Element old, Element element) throws NullPointerException, IllegalArgumentException { TransactionContext context = getOrCreateTransactionContext(); Element previous = getCurrentElement(element.getKey(), context); boolean replaced = false; if (previous != null && previous.getValue().equals(old.getValue())) { context.addCommand(new StoreReplaceElementCommand(old, element), element); replaced = true; } return replaced; } }
XATransactionalStore extends AbstractStore { public boolean replace(Element old, Element element) throws NullPointerException, IllegalArgumentException { TransactionContext context = getOrCreateTransactionContext(); Element previous = getCurrentElement(element.getKey(), context); boolean replaced = false; if (previous != null && previous.getValue().equals(old.getValue())) { context.addCommand(new StoreReplaceElementCommand(old, element), element); replaced = true; } return replaced; } XATransactionalStore(Ehcache cache, EhcacheXAStore ehcacheXAStore,
                                TransactionManagerLookup transactionManagerLookup, TransactionManager txnManager); }
XATransactionalStore extends AbstractStore { public boolean replace(Element old, Element element) throws NullPointerException, IllegalArgumentException { TransactionContext context = getOrCreateTransactionContext(); Element previous = getCurrentElement(element.getKey(), context); boolean replaced = false; if (previous != null && previous.getValue().equals(old.getValue())) { context.addCommand(new StoreReplaceElementCommand(old, element), element); replaced = true; } return replaced; } XATransactionalStore(Ehcache cache, EhcacheXAStore ehcacheXAStore,
                                TransactionManagerLookup transactionManagerLookup, TransactionManager txnManager); boolean put(final Element element); boolean putWithWriter(final Element element, final CacheWriterManager writerManager); Element get(final Object key); Element getQuiet(final Object key); Object[] getKeyArray(); Element remove(final Object key); Element removeWithWriter(final Object key, final CacheWriterManager writerManager); void removeAll(); void dispose(); int getSize(); int getOnDiskSize(); int getInMemorySize(); int getTerracottaClusteredSize(); long getInMemorySizeInBytes(); long getOnDiskSizeInBytes(); Status getStatus(); boolean containsKey(final Object key); boolean containsKeyInMemory(final Object key); boolean containsKeyOnDisk(final Object key); void expireElements(); void flush(); boolean bufferFull(); Policy getInMemoryEvictionPolicy(); void setInMemoryEvictionPolicy(final Policy policy); Object getInternalContext(); @Override boolean isCacheCoherent(); @Override boolean isClusterCoherent(); @Override boolean isNodeCoherent(); @Override void setNodeCoherent(boolean coherent); @Override void waitUntilClusterCoherent(); Element putIfAbsent(Element element); Element removeElement(Element element); boolean replace(Element old, Element element); Element replace(Element element); EhcacheXAResource getOrCreateXAResource(); }
XATransactionalStore extends AbstractStore { public boolean replace(Element old, Element element) throws NullPointerException, IllegalArgumentException { TransactionContext context = getOrCreateTransactionContext(); Element previous = getCurrentElement(element.getKey(), context); boolean replaced = false; if (previous != null && previous.getValue().equals(old.getValue())) { context.addCommand(new StoreReplaceElementCommand(old, element), element); replaced = true; } return replaced; } XATransactionalStore(Ehcache cache, EhcacheXAStore ehcacheXAStore,
                                TransactionManagerLookup transactionManagerLookup, TransactionManager txnManager); boolean put(final Element element); boolean putWithWriter(final Element element, final CacheWriterManager writerManager); Element get(final Object key); Element getQuiet(final Object key); Object[] getKeyArray(); Element remove(final Object key); Element removeWithWriter(final Object key, final CacheWriterManager writerManager); void removeAll(); void dispose(); int getSize(); int getOnDiskSize(); int getInMemorySize(); int getTerracottaClusteredSize(); long getInMemorySizeInBytes(); long getOnDiskSizeInBytes(); Status getStatus(); boolean containsKey(final Object key); boolean containsKeyInMemory(final Object key); boolean containsKeyOnDisk(final Object key); void expireElements(); void flush(); boolean bufferFull(); Policy getInMemoryEvictionPolicy(); void setInMemoryEvictionPolicy(final Policy policy); Object getInternalContext(); @Override boolean isCacheCoherent(); @Override boolean isClusterCoherent(); @Override boolean isNodeCoherent(); @Override void setNodeCoherent(boolean coherent); @Override void waitUntilClusterCoherent(); Element putIfAbsent(Element element); Element removeElement(Element element); boolean replace(Element old, Element element); Element replace(Element element); EhcacheXAResource getOrCreateXAResource();  }