Search in sources :

Example 1 with TransactionMap

use of com.tangosol.util.TransactionMap in project teiid by teiid.

the class CoherenceConnectionImpl method update.

public void update(Object key, Object object) throws ResourceException {
    NamedCache sourceCache = getCache();
    if (!sourceCache.containsKey(key)) {
        throw new ResourceException("Unable to update object for key: " + key + " to cache " + this.cacheName + ", because it already exist");
    }
    TransactionMap tmap = CacheFactory.getLocalTransaction(sourceCache);
    tmap.setTransactionIsolation(TransactionMap.TRANSACTION_REPEATABLE_GET);
    tmap.setConcurrency(TransactionMap.CONCUR_PESSIMISTIC);
    tmap.begin();
    try {
        tmap.put(key, object);
        tmap.prepare();
        tmap.commit();
    } catch (Exception e) {
        throw new ResourceException(e);
    }
    sourceCache = getCache();
    if (!sourceCache.containsKey(key)) {
        throw new ResourceException("Problem updating object for key: " + key + " to the cache " + this.cacheName + ", object not found after add");
    }
}
Also used : ResourceException(javax.resource.ResourceException) TransactionMap(com.tangosol.util.TransactionMap) ResourceException(javax.resource.ResourceException) NamedCache(com.tangosol.net.NamedCache)

Example 2 with TransactionMap

use of com.tangosol.util.TransactionMap in project teiid by teiid.

the class CoherenceConnectionImpl method add.

public void add(Object key, Object value) throws ResourceException {
    NamedCache sourceCache = getCache();
    if (sourceCache.containsKey(key)) {
        throw new ResourceException("Unable to add object for key: " + key + " to cache " + this.cacheName + ", because it already exist");
    }
    TransactionMap tmap = CacheFactory.getLocalTransaction(sourceCache);
    tmap.setTransactionIsolation(TransactionMap.TRANSACTION_REPEATABLE_GET);
    tmap.setConcurrency(TransactionMap.CONCUR_PESSIMISTIC);
    tmap.begin();
    try {
        tmap.put(key, value);
        tmap.prepare();
        tmap.commit();
    } catch (Exception e) {
        throw new ResourceException(e);
    }
    sourceCache = getCache();
    if (!sourceCache.containsKey(key)) {
        throw new ResourceException("Problem adding object for key: " + key + " to the cache " + this.cacheName + ", object not found after add");
    }
}
Also used : ResourceException(javax.resource.ResourceException) TransactionMap(com.tangosol.util.TransactionMap) ResourceException(javax.resource.ResourceException) NamedCache(com.tangosol.net.NamedCache)

Example 3 with TransactionMap

use of com.tangosol.util.TransactionMap in project teiid by teiid.

the class CoherenceConnectionImpl method remove.

public void remove(Object key) throws ResourceException {
    System.out.println("Remove: " + key);
    NamedCache sourceCache = getCache();
    if (!sourceCache.containsKey(key)) {
        throw new ResourceException("Unable to remove object for key: " + key + " from cache " + this.cacheName + ", because it doesn't exist");
    }
    TransactionMap tmap = CacheFactory.getLocalTransaction(sourceCache);
    tmap.setTransactionIsolation(TransactionMap.TRANSACTION_REPEATABLE_GET);
    tmap.setConcurrency(TransactionMap.CONCUR_OPTIMISTIC);
    tmap.begin();
    try {
        tmap.remove(key);
        tmap.prepare();
        tmap.commit();
    } catch (Exception e) {
        throw new ResourceException(e);
    }
    if (getCache().containsKey(key)) {
        throw new ResourceException("Unable to remove object for key: " + key + " from the cache " + this.cacheName);
    }
}
Also used : ResourceException(javax.resource.ResourceException) TransactionMap(com.tangosol.util.TransactionMap) ResourceException(javax.resource.ResourceException) NamedCache(com.tangosol.net.NamedCache)

Aggregations

NamedCache (com.tangosol.net.NamedCache)3 TransactionMap (com.tangosol.util.TransactionMap)3 ResourceException (javax.resource.ResourceException)3