/** * Sets the TransactionManagerLookup that needs to be used for this cache to lookup the TransactionManager * This needs to be set before {@link Cache#initialise()} is called * @param lookup The {@link net.sf.ehcache.transaction.manager.TransactionManagerLookup} instance */ public void setTransactionManagerLookup(TransactionManagerLookup lookup) { TransactionManagerLookup oldValue = getTransactionManagerLookup(); this.transactionManagerLookup = lookup; firePropertyChange("TransactionManagerLookup", oldValue, lookup); }
/** * Check if a transaction has begun on the current thread if the cache is configured as * transactional, otherwise always return false. * @param cache the cache to check if a transaction started for * @return true if the cache is transactional and a transaction started, false otherwise * @throws CacheException if anything wrong happens */ public static boolean isTransactionStarted(Ehcache cache) throws CacheException { try { switch (cache.getCacheConfiguration().getTransactionalMode()) { case LOCAL: TransactionController ctrl = cache.getCacheManager().getTransactionController(); return ctrl.getCurrentTransactionContext() != null; case XA: case XA_STRICT: Object tm = ((net.sf.ehcache.Cache) cache).getTransactionManagerLookup().getTransactionManager(); return ((Integer) tm.getClass().getMethod("getStatus").invoke(tm)) != XA_STATUS_NO_TRANSACTION; case OFF: default: return false; } } catch (Exception e) { e.printStackTrace(); throw new CacheException("error checking if transaction started: " + e); } }
/** * Begin a transaction on the current thread if the cache is configured as transactional, * otherwise this method does nothing. * * @param cache the cache to begin a transaction for * @throws CacheException if anything wrong happens */ public static void beginTransactionIfNeeded(Ehcache cache) throws CacheException { try { switch (cache.getCacheConfiguration().getTransactionalMode()) { case LOCAL: TransactionController ctrl = cache.getCacheManager().getTransactionController(); ctrl.begin(); break; case XA: case XA_STRICT: Object tm = ((net.sf.ehcache.Cache) cache).getTransactionManagerLookup().getTransactionManager(); tm.getClass().getMethod("begin").invoke(tm); break; case OFF: default: break; } } catch (Exception e) { e.printStackTrace(); throw new CacheException("error beginning transaction:" + e); } }
Object tm = ((net.sf.ehcache.Cache) cache).getTransactionManagerLookup().getTransactionManager(); tm.getClass().getMethod("commit").invoke(tm); break;
/** * Sets the TransactionManagerLookup that needs to be used for this cache to lookup the TransactionManager * This needs to be set before {@link Cache#initialise()} is called * @param lookup The {@link net.sf.ehcache.transaction.manager.TransactionManagerLookup} instance */ public void setTransactionManagerLookup(TransactionManagerLookup lookup) { TransactionManagerLookup oldValue = getTransactionManagerLookup(); this.transactionManagerLookup = lookup; firePropertyChange("TransactionManagerLookup", oldValue, lookup); }
/** * Sets the TransactionManagerLookup that needs to be used for this cache to lookup the TransactionManager * This needs to be set before {@link Cache#initialise()} is called * @param lookup The {@link net.sf.ehcache.transaction.manager.TransactionManagerLookup} instance */ public void setTransactionManagerLookup(TransactionManagerLookup lookup) { TransactionManagerLookup oldValue = getTransactionManagerLookup(); this.transactionManagerLookup = lookup; firePropertyChange("TransactionManagerLookup", oldValue, lookup); }
/** * Sets the TransactionManagerLookup that needs to be used for this cache to lookup the TransactionManager * This needs to be set before {@link Cache#initialise()} is called * @param lookup The {@link net.sf.ehcache.transaction.manager.TransactionManagerLookup} instance */ public void setTransactionManagerLookup(TransactionManagerLookup lookup) { TransactionManagerLookup oldValue = getTransactionManagerLookup(); this.transactionManagerLookup = lookup; firePropertyChange("TransactionManagerLookup", oldValue, lookup); }
protected boolean hasTransaction() { TransactionManagerLookup transactionManagerLookup = cache.getTransactionManagerLookup(); if (transactionManagerLookup == null) { return false; } TransactionManager transactionManager = transactionManagerLookup.getTransactionManager(); if (transactionManager == null) { return false; } Transaction transaction; try { transaction = transactionManager.getTransaction(); } catch (SystemException e) { throw new RuntimeException(e); } return transaction != null; }
/** * Check if a transaction has begun on the current thread if the cache is configured as * transactional, otherwise always return false. * @param cache the cache to check if a transaction started for * @return true if the cache is transactional and a transaction started, false otherwise * @throws CacheException if anything wrong happens */ public static boolean isTransactionStarted(Ehcache cache) throws CacheException { try { switch (cache.getCacheConfiguration().getTransactionalMode()) { case LOCAL: TransactionController ctrl = cache.getCacheManager().getTransactionController(); return ctrl.getCurrentTransactionContext() != null; case XA: case XA_STRICT: Object tm = ((net.sf.ehcache.Cache) cache).getTransactionManagerLookup().getTransactionManager(); return ((Integer) tm.getClass().getMethod("getStatus").invoke(tm)) != XA_STATUS_NO_TRANSACTION; case OFF: default: return false; } } catch (Exception e) { e.printStackTrace(); throw new CacheException("error checking if transaction started: " + e); } }
Object tm = ((net.sf.ehcache.Cache) cache).getTransactionManagerLookup().getTransactionManager(); tm.getClass().getMethod("commit").invoke(tm); break;
Object tm = ((net.sf.ehcache.Cache) cache).getTransactionManagerLookup().getTransactionManager(); tm.getClass().getMethod("commit").invoke(tm); break;
/** * Begin a transaction on the current thread if the cache is configured as transactional, * otherwise this method does nothing. * * @param cache the cache to begin a transaction for * @throws CacheException if anything wrong happens */ public static void beginTransactionIfNeeded(Ehcache cache) throws CacheException { try { switch (cache.getCacheConfiguration().getTransactionalMode()) { case LOCAL: TransactionController ctrl = cache.getCacheManager().getTransactionController(); ctrl.begin(); break; case XA: case XA_STRICT: Object tm = ((net.sf.ehcache.Cache) cache).getTransactionManagerLookup().getTransactionManager(); tm.getClass().getMethod("begin").invoke(tm); break; case OFF: default: break; } } catch (Exception e) { e.printStackTrace(); throw new CacheException("error beginning transaction:" + e); } }
/** * Begin a transaction on the current thread if the cache is configured as transactional, * otherwise this method does nothing. * * @param cache the cache to begin a transaction for * @throws CacheException if anything wrong happens */ public static void beginTransactionIfNeeded(Ehcache cache) throws CacheException { try { switch (cache.getCacheConfiguration().getTransactionalMode()) { case LOCAL: TransactionController ctrl = cache.getCacheManager().getTransactionController(); ctrl.begin(); break; case XA: case XA_STRICT: Object tm = ((net.sf.ehcache.Cache) cache).getTransactionManagerLookup().getTransactionManager(); tm.getClass().getMethod("begin").invoke(tm); break; case OFF: default: break; } } catch (Exception e) { e.printStackTrace(); throw new CacheException("error beginning transaction:" + e); } }
/** * Check if a transaction has begun on the current thread if the cache is configured as * transactional, otherwise always return false. * @param cache the cache to check if a transaction started for * @return true if the cache is transactional and a transaction started, false otherwise * @throws CacheException if anything wrong happens */ public static boolean isTransactionStarted(Ehcache cache) throws CacheException { try { switch (cache.getCacheConfiguration().getTransactionalMode()) { case LOCAL: TransactionController ctrl = cache.getCacheManager().getTransactionController(); return ctrl.getCurrentTransactionContext() != null; case XA: case XA_STRICT: Object tm = ((net.sf.ehcache.Cache) cache).getTransactionManagerLookup().getTransactionManager(); return ((Integer) tm.getClass().getMethod("getStatus").invoke(tm)) != XA_STATUS_NO_TRANSACTION; case OFF: default: return false; } } catch (Exception e) { e.printStackTrace(); throw new CacheException("error checking if transaction started: " + e); } }
/** * Check if a transaction has begun on the current thread if the cache is configured as * transactional, otherwise always return false. * @param cache the cache to check if a transaction started for * @return true if the cache is transactional and a transaction started, false otherwise * @throws CacheException if anything wrong happens */ public static boolean isTransactionStarted(Ehcache cache) throws CacheException { try { switch (cache.getCacheConfiguration().getTransactionalMode()) { case LOCAL: TransactionController ctrl = cache.getCacheManager().getTransactionController(); return ctrl.getCurrentTransactionContext() != null; case XA: case XA_STRICT: Object tm = ((net.sf.ehcache.Cache) cache).getTransactionManagerLookup().getTransactionManager(); return ((Integer) tm.getClass().getMethod("getStatus").invoke(tm)) != XA_STATUS_NO_TRANSACTION; case OFF: default: return false; } } catch (Exception e) { e.printStackTrace(); throw new CacheException("error checking if transaction started: " + e); } }
Object tm = ((net.sf.ehcache.Cache) cache).getTransactionManagerLookup().getTransactionManager(); tm.getClass().getMethod("commit").invoke(tm); break;
/** * Begin a transaction on the current thread if the cache is configured as transactional, * otherwise this method does nothing. * * @param cache the cache to begin a transaction for * @throws CacheException if anything wrong happens */ public static void beginTransactionIfNeeded(Ehcache cache) throws CacheException { try { switch (cache.getCacheConfiguration().getTransactionalMode()) { case LOCAL: TransactionController ctrl = cache.getCacheManager().getTransactionController(); ctrl.begin(); break; case XA: case XA_STRICT: Object tm = ((net.sf.ehcache.Cache) cache).getTransactionManagerLookup().getTransactionManager(); tm.getClass().getMethod("begin").invoke(tm); break; case OFF: default: break; } } catch (Exception e) { e.printStackTrace(); throw new CacheException("error beginning transaction:" + e); } }
private synchronized void initializeNonstopStore() { if (nonstopStore == null) { if (!cache.getCacheConfiguration().isTerracottaClustered()) { throw new AssertionError("NonstopStore supported for Terracotta clustered caches only"); } if (!cache.getCacheConfiguration().getTerracottaConfiguration().isNonstopEnabled()) { throw new AssertionError("Nonstop is not enabled"); } nonstopStore = new NonstopStoreImpl(this, cache.getCacheCluster(), cache.getCacheConfiguration() .getTerracottaConfiguration().getNonstopConfiguration(), cache.getCacheConfiguration().getTransactionalMode(), cache.getTransactionManagerLookup()); } }