List of usage examples for org.springframework.transaction CannotCreateTransactionException CannotCreateTransactionException
public CannotCreateTransactionException(String msg, Throwable cause)
From source file:org.develspot.data.orientdb.transaction.OrientDBTransactionManager.java
@Override protected void doBegin(Object transaction, TransactionDefinition definition) throws TransactionException { OrientDBTransactionObject txObject = (OrientDBTransactionObject) transaction; try {// www . j a v a 2 s . c om if (txObject.getConnectionHolder() == null) { OGraphDatabase con = this.orientDataSource.getConnection(); txObject.setConnectionHolder(new GraphDatabaseHolder(con)); } txObject.getConnectionHolder().setTransactionActive(true); TransactionSynchronizationManager.bindResource(getDataSource(), txObject.getConnectionHolder()); txObject.getConnectionHolder().getConnection().begin(); } catch (Exception e) { release(txObject); throw new CannotCreateTransactionException(e.getMessage(), e); } }
From source file:org.springextensions.neodatis.NeoDatisTransactionManager.java
@Override protected void doBegin(Object transaction, TransactionDefinition transactionDefinition) throws TransactionException { if (transactionDefinition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) { throw new InvalidIsolationLevelException("NeoDatis does not support an isolation level concept."); }//from w ww .j ava2s.c o m ODB odb = null; try { NeoDatisTransactionObject transactionObject = (NeoDatisTransactionObject) transaction; if (transactionObject.getODBHolder() == null) { odb = getOdb(); logger.debug("Using given ODB [{}] for the current thread transaction.", odb); transactionObject.setODBHolder(new ODBHolder(odb)); } ODBHolder odbHolder = transactionObject.getODBHolder(); odbHolder.setSynchronizedWithTransaction(true); // start transaction // no-op // register timeout if (transactionDefinition.getTimeout() != TransactionDefinition.TIMEOUT_DEFAULT) { transactionObject.getODBHolder().setTimeoutInSeconds(transactionDefinition.getTimeout()); } //Bind session holder to the thread TransactionSynchronizationManager.bindResource(getOdb(), odbHolder); } catch (Exception e) { throw new CannotCreateTransactionException("Can not create an NeoDatis transaction.", e); } }
From source file:com.becool.base.spring.tx.ChainedTransactionManager.java
public MultiTransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException { MultiTransactionStatus mts = new MultiTransactionStatus(transactionManagers.get(0)); if (!synchronizationManager.isSynchronizationActive()) { synchronizationManager.initSynchronization(); mts.setNewSynchonization();// www . java 2s .c o m } try { for (PlatformTransactionManager transactionManager : transactionManagers) { mts.registerTransactionManager(definition, transactionManager); } } catch (Exception ex) { Map<PlatformTransactionManager, TransactionStatus> transactionStatuses = mts.getTransactionStatuses(); for (PlatformTransactionManager transactionManager : transactionManagers) { try { if (transactionStatuses.get(transactionManager) != null) { transactionManager.rollback(transactionStatuses.get(transactionManager)); } } catch (Exception ex2) { LOGGER.warn("Rollback exception (" + transactionManager + ") " + ex2.getMessage(), ex2); } } if (mts.isNewSynchonization()) { synchronizationManager.clearSynchronization(); } throw new CannotCreateTransactionException(ex.getMessage(), ex); } return mts; }
From source file:org.grails.datastore.mapping.transactions.DatastoreTransactionManager.java
@Override protected void doBegin(Object o, TransactionDefinition definition) throws TransactionException { TransactionObject txObject = (TransactionObject) o; Session session = null;// w w w . ja va 2 s.c o m try { session = txObject.getSessionHolder().getSession(); if (definition.isReadOnly()) { // Just set to NEVER in case of a new Session for this transaction. session.setFlushMode(FlushModeType.COMMIT); } Transaction<?> tx; // Register transaction timeout. int timeout = determineTimeout(definition); if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) { tx = session.beginTransaction(); tx.setTimeout(timeout); } else { // Open a plain Datastore transaction without specified timeout. tx = session.beginTransaction(); } // Add the Datastore transaction to the session holder. txObject.setTransaction(tx); // Bind the session holder to the thread. if (txObject.isNewSessionHolder()) { TransactionSynchronizationManager.bindResource(getDatastore(), txObject.getSessionHolder()); } txObject.getSessionHolder().setSynchronizedWithTransaction(true); } catch (Exception ex) { if (txObject.isNewSession()) { try { if (session != null && session.getTransaction().isActive()) { session.getTransaction().rollback(); } } catch (Throwable ex2) { logger.debug("Could not rollback Session after failed transaction begin", ex); } finally { DatastoreUtils.closeSession(session); } } throw new CannotCreateTransactionException("Could not open Datastore Session for transaction", ex); } }
From source file:org.springextensions.db4o.Db4oTransactionManager.java
protected void doBegin(Object transaction, TransactionDefinition transactionDefinition) throws TransactionException { if (transactionDefinition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) { throw new InvalidIsolationLevelException("Db4o does not support an isolation level concept"); }/*from www . ja v a 2 s. c o m*/ ObjectContainer container = null; try { Db4oTransactionObject txObject = (Db4oTransactionObject) transaction; if (txObject.getObjectContainerHolder() == null) { // use the given container container = getObjectContainer(); logger.debug("Using given objectContainer [{}] for the current thread transaction", container); txObject.setObjectContainerHolder(new ObjectContainerHolder(container)); } ObjectContainerHolder containerHolder = txObject.getObjectContainerHolder(); containerHolder.setSynchronizedWithTransaction(true); /* * We have no notion of flushing inside a db4o object container * if (transactionDefinition.isReadOnly() && txObject.isNewObjectContainerHolder()) { containerHolder.setReadOnly(true); } if (!transactionDefinition.isReadOnly() && !txObject.isNewObjectContainerHolder()) { if (containerHolder.isReadOnly()) { containerHolder.setReadOnly(false); } } */ // start the transaction // no-op // Register transaction timeout. if (transactionDefinition.getTimeout() != TransactionDefinition.TIMEOUT_DEFAULT) { txObject.getObjectContainerHolder().setTimeoutInSeconds(transactionDefinition.getTimeout()); } // Bind the session holder to the thread. TransactionSynchronizationManager.bindResource(getObjectContainer(), containerHolder); } catch (Exception ex) { throw new CannotCreateTransactionException("Could not start db4o object container transaction", ex); } }
From source file:org.grails.datastore.mapping.redis.RedisSession.java
@Override protected Transaction<RedisTemplate> beginTransactionInternal() { try {/*from w ww. ja va 2 s .co m*/ redisTemplate.multi(); } catch (Exception e) { throw new CannotCreateTransactionException("Error starting Redis transaction: " + e.getMessage(), e); } return new RedisTransaction(redisTemplate); }
From source file:com.zhengmo.data.transaction.ChainedTransactionManager.java
@Override public MultiTransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException { MultiTransactionStatus mts = new MultiTransactionStatus(transactionManagers.get(0)); if (!synchronizationManager.isSynchronizationActive()) { synchronizationManager.initSynchronization(); mts.setNewSynchonization();/* ww w .ja v a2 s . c o m*/ } try { for (PlatformTransactionManager transactionManager : transactionManagers) { mts.registerTransactionManager(definition, transactionManager); } } catch (Exception ex) { Map<PlatformTransactionManager, TransactionStatus> transactionStatuses = mts.getTransactionStatuses(); for (PlatformTransactionManager transactionManager : transactionManagers) { try { if (transactionStatuses.get(transactionManager) != null) { transactionManager.rollback(transactionStatuses.get(transactionManager)); } } catch (Exception ex2) { LOGGER.warn("Rollback exception (" + transactionManager + ") " + ex2.getMessage(), ex2); } } if (mts.isNewSynchonization()) { synchronizationManager.clearSynchronization(); } throw new CannotCreateTransactionException(ex.getMessage(), ex); } return mts; }
From source file:org.cfr.capsicum.datasource.CayenneTransactionManager.java
/** * This implementation sets the isolation level but ignores the timeout. *///from w w w. j a v a 2s .c o m @Override protected void doBegin(Object transaction, TransactionDefinition definition) { CayenneTransactionObject txObject = (CayenneTransactionObject) transaction; Connection con = null; try { if (txObject.getConnectionHolder() == null || txObject.getConnectionHolder().isSynchronizedWithTransaction()) { Connection newCon = this.dataSource.getConnection(); if (logger.isDebugEnabled()) { logger.debug("Acquired Connection [" + newCon + "] for JDBC transaction"); } ObjectContext context = null; if (definition.getPropagationBehavior() == TransactionDefinition.PROPAGATION_REQUIRES_NEW) { Injector injector = this.cayenneRuntime.getInjector(); context = injector.getInstance(ObjectContextFactory.class).createContext(); } else { context = BaseContext.getThreadObjectContext(); } txObject.setConnectionHolder(new CayenneConnectionHolder(newCon, context), true); BaseContext.bindThreadObjectContext(context); } txObject.getConnectionHolder().setSynchronizedWithTransaction(true); con = txObject.getConnectionHolder().getConnection(); Integer previousIsolationLevel = DataSourceUtils.prepareConnectionForTransaction(con, definition); txObject.setPreviousIsolationLevel(previousIsolationLevel); // Switch to manual commit if necessary. This is very expensive in // some // JDBC drivers, // so we don't want to do it unnecessarily (for example if we've // explicitly // configured the connection pool to set it already). if (con.getAutoCommit()) { txObject.setMustRestoreAutoCommit(true); if (logger.isDebugEnabled()) { logger.debug("Switching JDBC Connection [" + con + "] to manual commit"); } con.setAutoCommit(false); } txObject.getConnectionHolderEx().setTransactionActive(true); int timeout = determineTimeout(definition); if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) { txObject.getConnectionHolder().setTimeoutInSeconds(timeout); } // Bind the session holder to the thread. if (txObject.isNewConnectionHolder()) { TransactionSynchronizationManager.bindResource(getDataSource(), txObject.getConnectionHolder()); } } catch (SQLException ex) { DataSourceUtils.releaseConnection(con, this.dataSource); throw new CannotCreateTransactionException("Could not open JDBC Connection for transaction", exceptionTranslator.convertJdbcAccessException(ex)); } }
From source file:org.guzz.web.context.spring.GuzzTransactionManager.java
@Override protected void doBegin(Object transaction, TransactionDefinition definition) { GuzzTransactionObject txObject = (GuzzTransactionObject) transaction; //TODO: checkout the outside DataSourceTransactionManager // if (txObject.hasConnectionHolder() && !txObject.getConnectionHolder().isSynchronizedWithTransaction()) { // throw new IllegalTransactionStateException( // "Pre-bound JDBC Connection found! GuzzTransactionManager does not support " + // "running within DataSourceTransactionManager if told to manage the DataSource itself. ") ; // }/* w ww . j a v a2s. c o m*/ WriteTranSession writeTranSession = null; try { if (txObject.getSessionHolder() == null || txObject.getSessionHolder().isSynchronizedWithTransaction()) { writeTranSession = getTransactionManager().openRWTran(false); if (logger.isDebugEnabled()) { logger.debug("Opened new Session [" + TransactionManagerUtils.toString(writeTranSession) + "] for Guzz transaction"); } txObject.setWriteTranSession(writeTranSession); } writeTranSession = txObject.getSessionHolder().getWriteTranSession(); if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) { // We should set a specific isolation level but are not allowed to... IsolationsSavePointer oldSavePointer = writeTranSession .setTransactionIsolation(definition.getIsolationLevel()); txObject.setIsolationsSavePointer(oldSavePointer); } // Register transaction timeout. int timeout = determineTimeout(definition); if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) { txObject.getSessionHolder().setTimeoutInSeconds(timeout); } // Bind the session holder to the thread. if (txObject.isNewWriteTranSessionHolder()) { TransactionSynchronizationManager.bindResource(getTransactionManager(), txObject.getSessionHolder()); } txObject.getSessionHolder().setSynchronizedWithTransaction(true); } catch (Exception ex) { if (txObject.isNewWriteTranSession()) { try { if (writeTranSession != null) { //TransactionIsolation????? writeTranSession.rollback(); } } catch (Throwable ex2) { logger.debug("Could not rollback WriteTranSession after failed transaction begin", ex); } finally { TransactionManagerUtils.closeSession(writeTranSession); } } throw new CannotCreateTransactionException("Could not open Guzz WriteTranSession for transaction", ex); } }
From source file:com._4dconcept.springframework.data.marklogic.datasource.ContentSourceTransactionManager.java
/** * This implementation sets the isolation level but ignores the timeout. *//*from w ww . ja v a2s. c o m*/ @Override protected void doBegin(Object transaction, TransactionDefinition definition) { ContentSourceTransactionObject txObject = (ContentSourceTransactionObject) transaction; Session ses = null; try { if (txObject.getSessionHolder() == null || txObject.getSessionHolder().isSynchronizedWithTransaction()) { Session newSes = this.contentSource.newSession(); if (logger.isDebugEnabled()) { logger.debug("Acquired Session [" + newSes + "] for XDBC transaction"); } txObject.setSessionHolder(new SessionHolder(newSes), true); } txObject.getSessionHolder().setSynchronizedWithTransaction(true); ses = txObject.getSessionHolder().getSession(); Integer previousIsolationLevel = ContentSourceUtils.prepareSessionForTransaction(ses, definition); txObject.setPreviousIsolationLevel(previousIsolationLevel); txObject.getSessionHolder().setTransactionActive(true); int timeout = determineTimeout(definition); if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) { txObject.getSessionHolder().setTimeoutInSeconds(timeout); } // Bind the session holder to the thread. if (txObject.isNewSessionHolder()) { TransactionSynchronizationManager.bindResource(getContentSource(), txObject.getSessionHolder()); } } catch (Throwable ex) { if (txObject.isNewSessionHolder()) { ContentSourceUtils.releaseSession(ses, this.contentSource); txObject.setSessionHolder(null, false); } throw new CannotCreateTransactionException("Could not open XDBC Session for transaction", ex); } }