public static void commitTransactionIfNeeded(Ehcache cache) throws CacheException {
try {
switch (cache.getCacheConfiguration().getTransactionalMode()) {
case LOCAL:
TransactionController ctrl = cache.getCacheManager().getTransactionController();
ctrl.commit();
break;
case XA:
case XA_STRICT:
Object tm = ((net.sf.ehcache.Cache) cache).getTransactionManagerLookup().getTransactionManager();