org.springframework.jdbc.datasource.ConnectionHolder Java Examples

The following examples show how to use org.springframework.jdbc.datasource.ConnectionHolder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StoredProcedureTests.java    From effectivejava with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddInvoicesWithinTransaction() throws Exception {
	given(callableStatement.execute()).willReturn(false);
	given(callableStatement.getUpdateCount()).willReturn(-1);
	given(callableStatement.getObject(3)).willReturn(4);
	given(connection.prepareCall("{call " + AddInvoice.SQL + "(?, ?, ?)}")
			).willReturn(callableStatement);
	TransactionSynchronizationManager.bindResource(dataSource, new ConnectionHolder(connection));
	try {
		testAddInvoice(1106, 3);
		verify(callableStatement).setObject(1, 1106, Types.INTEGER);
		verify(callableStatement).setObject(2, 3, Types.INTEGER);
		verify(callableStatement).registerOutParameter(3, Types.INTEGER);
		verify(connection, never()).close();
	}
	finally {
		TransactionSynchronizationManager.unbindResource(dataSource);
		connection.close();
	}
}
 
Example #2
Source File: StoredProcedureTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddInvoicesWithinTransaction() throws Exception {
	given(callableStatement.execute()).willReturn(false);
	given(callableStatement.getUpdateCount()).willReturn(-1);
	given(callableStatement.getObject(3)).willReturn(4);
	given(connection.prepareCall("{call " + AddInvoice.SQL + "(?, ?, ?)}")
			).willReturn(callableStatement);
	TransactionSynchronizationManager.bindResource(dataSource, new ConnectionHolder(connection));
	try {
		testAddInvoice(1106, 3);
		verify(callableStatement).setObject(1, 1106, Types.INTEGER);
		verify(callableStatement).setObject(2, 3, Types.INTEGER);
		verify(callableStatement).registerOutParameter(3, Types.INTEGER);
		verify(connection, never()).close();
	}
	finally {
		TransactionSynchronizationManager.unbindResource(dataSource);
		connection.close();
	}
}
 
Example #3
Source File: JpaTransactionManager.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected Object doGetTransaction() {
	JpaTransactionObject txObject = new JpaTransactionObject();
	txObject.setSavepointAllowed(isNestedTransactionAllowed());

	EntityManagerHolder emHolder = (EntityManagerHolder)
			TransactionSynchronizationManager.getResource(getEntityManagerFactory());
	if (emHolder != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Found thread-bound EntityManager [" + emHolder.getEntityManager() +
					"] for JPA transaction");
		}
		txObject.setEntityManagerHolder(emHolder, false);
	}

	if (getDataSource() != null) {
		ConnectionHolder conHolder = (ConnectionHolder)
				TransactionSynchronizationManager.getResource(getDataSource());
		txObject.setConnectionHolder(conHolder);
	}

	return txObject;
}
 
Example #4
Source File: JdoTransactionManager.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected Object doGetTransaction() {
	JdoTransactionObject txObject = new JdoTransactionObject();
	txObject.setSavepointAllowed(isNestedTransactionAllowed());

	PersistenceManagerHolder pmHolder = (PersistenceManagerHolder)
			TransactionSynchronizationManager.getResource(getPersistenceManagerFactory());
	if (pmHolder != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Found thread-bound PersistenceManager [" +
					pmHolder.getPersistenceManager() + "] for JDO transaction");
		}
		txObject.setPersistenceManagerHolder(pmHolder, false);
	}

	if (getDataSource() != null) {
		ConnectionHolder conHolder = (ConnectionHolder)
				TransactionSynchronizationManager.getResource(getDataSource());
		txObject.setConnectionHolder(conHolder);
	}

	return txObject;
}
 
Example #5
Source File: StoredProcedureTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testAddInvoicesWithinTransaction() throws Exception {
	given(callableStatement.execute()).willReturn(false);
	given(callableStatement.getUpdateCount()).willReturn(-1);
	given(callableStatement.getObject(3)).willReturn(4);
	given(connection.prepareCall("{call " + AddInvoice.SQL + "(?, ?, ?)}")
			).willReturn(callableStatement);
	TransactionSynchronizationManager.bindResource(dataSource, new ConnectionHolder(connection));
	try {
		testAddInvoice(1106, 3);
		verify(callableStatement).setObject(1, 1106, Types.INTEGER);
		verify(callableStatement).setObject(2, 3, Types.INTEGER);
		verify(callableStatement).registerOutParameter(3, Types.INTEGER);
		verify(connection, never()).close();
	}
	finally {
		TransactionSynchronizationManager.unbindResource(dataSource);
		connection.close();
	}
}
 
Example #6
Source File: JpaTransactionManager.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
protected Object doGetTransaction() {
	JpaTransactionObject txObject = new JpaTransactionObject();
	txObject.setSavepointAllowed(isNestedTransactionAllowed());

	EntityManagerHolder emHolder = (EntityManagerHolder)
			TransactionSynchronizationManager.getResource(obtainEntityManagerFactory());
	if (emHolder != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Found thread-bound EntityManager [" + emHolder.getEntityManager() +
					"] for JPA transaction");
		}
		txObject.setEntityManagerHolder(emHolder, false);
	}

	if (getDataSource() != null) {
		ConnectionHolder conHolder = (ConnectionHolder)
				TransactionSynchronizationManager.getResource(getDataSource());
		txObject.setConnectionHolder(conHolder);
	}

	return txObject;
}
 
Example #7
Source File: JdoTransactionManager.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
protected Object doGetTransaction() {
	JdoTransactionObject txObject = new JdoTransactionObject();
	txObject.setSavepointAllowed(isNestedTransactionAllowed());

	PersistenceManagerHolder pmHolder = (PersistenceManagerHolder)
			TransactionSynchronizationManager.getResource(getPersistenceManagerFactory());
	if (pmHolder != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Found thread-bound PersistenceManager [" +
					pmHolder.getPersistenceManager() + "] for JDO transaction");
		}
		txObject.setPersistenceManagerHolder(pmHolder, false);
	}

	if (getDataSource() != null) {
		ConnectionHolder conHolder = (ConnectionHolder)
				TransactionSynchronizationManager.getResource(getDataSource());
		txObject.setConnectionHolder(conHolder);
	}

	return txObject;
}
 
Example #8
Source File: JpaTransactionManager.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
protected Object doGetTransaction() {
	JpaTransactionObject txObject = new JpaTransactionObject();
	txObject.setSavepointAllowed(isNestedTransactionAllowed());

	EntityManagerHolder emHolder = (EntityManagerHolder)
			TransactionSynchronizationManager.getResource(obtainEntityManagerFactory());
	if (emHolder != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Found thread-bound EntityManager [" + emHolder.getEntityManager() +
					"] for JPA transaction");
		}
		txObject.setEntityManagerHolder(emHolder, false);
	}

	if (getDataSource() != null) {
		ConnectionHolder conHolder = (ConnectionHolder)
				TransactionSynchronizationManager.getResource(getDataSource());
		txObject.setConnectionHolder(conHolder);
	}

	return txObject;
}
 
Example #9
Source File: StoredProcedureTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testAddInvoicesWithinTransaction() throws Exception {
	given(callableStatement.execute()).willReturn(false);
	given(callableStatement.getUpdateCount()).willReturn(-1);
	given(callableStatement.getObject(3)).willReturn(4);
	given(connection.prepareCall("{call " + AddInvoice.SQL + "(?, ?, ?)}")
			).willReturn(callableStatement);
	TransactionSynchronizationManager.bindResource(dataSource, new ConnectionHolder(connection));
	try {
		testAddInvoice(1106, 3);
		verify(callableStatement).setObject(1, 1106, Types.INTEGER);
		verify(callableStatement).setObject(2, 3, Types.INTEGER);
		verify(callableStatement).registerOutParameter(3, Types.INTEGER);
		verify(connection, never()).close();
	}
	finally {
		TransactionSynchronizationManager.unbindResource(dataSource);
		connection.close();
	}
}
 
Example #10
Source File: HibernateDatastore.java    From gorm-hibernate5 with Apache License 2.0 6 votes vote down vote up
@Override
public void addTenantForSchema(String schemaName) {
    addTenantForSchemaInternal(schemaName);
    registerAllEntitiesWithEnhancer();
    HibernateConnectionSource defaultConnectionSource = (HibernateConnectionSource) connectionSources.getDefaultConnectionSource();
    DataSource dataSource = defaultConnectionSource.getDataSource();
    if(dataSource instanceof TransactionAwareDataSourceProxy) {
        dataSource = ((TransactionAwareDataSourceProxy) dataSource).getTargetDataSource();
    }
    Object existing = TransactionSynchronizationManager.getResource(dataSource);
    if(existing instanceof ConnectionHolder) {
        ConnectionHolder connectionHolder = (ConnectionHolder) existing;
        Connection connection = connectionHolder.getConnection();
        try {
            if(!connection.isClosed() && !connection.isReadOnly()) {
                schemaHandler.useDefaultSchema(connection);
            }
        } catch (SQLException e) {
            throw new DatastoreConfigurationException("Failed to reset to default schema: " + e.getMessage(), e);
        }
    }

}
 
Example #11
Source File: JpaTransactionManager.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
protected Object doGetTransaction() {
	JpaTransactionObject txObject = new JpaTransactionObject();
	txObject.setSavepointAllowed(isNestedTransactionAllowed());

	EntityManagerHolder emHolder = (EntityManagerHolder)
			TransactionSynchronizationManager.getResource(getEntityManagerFactory());
	if (emHolder != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Found thread-bound EntityManager [" + emHolder.getEntityManager() +
					"] for JPA transaction");
		}
		txObject.setEntityManagerHolder(emHolder, false);
	}

	if (getDataSource() != null) {
		ConnectionHolder conHolder = (ConnectionHolder)
				TransactionSynchronizationManager.getResource(getDataSource());
		txObject.setConnectionHolder(conHolder);
	}

	return txObject;
}
 
Example #12
Source File: OpenJpaDialect.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public Object createSavepoint() throws TransactionException {
	this.savepointCounter++;
	String savepointName = ConnectionHolder.SAVEPOINT_NAME_PREFIX + this.savepointCounter;
	this.entityManager.setSavepoint(savepointName);
	return savepointName;
}
 
Example #13
Source File: HibernateTransactionManager.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Object doGetTransaction() {
	HibernateTransactionObject txObject = new HibernateTransactionObject();
	txObject.setSavepointAllowed(isNestedTransactionAllowed());

	SessionHolder sessionHolder =
			(SessionHolder) TransactionSynchronizationManager.getResource(getSessionFactory());
	if (sessionHolder != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Found thread-bound Session [" +
					SessionFactoryUtils.toString(sessionHolder.getSession()) + "] for Hibernate transaction");
		}
		txObject.setSessionHolder(sessionHolder);
	}
	else if (this.hibernateManagedSession) {
		try {
			Session session = getSessionFactory().getCurrentSession();
			if (logger.isDebugEnabled()) {
				logger.debug("Found Hibernate-managed Session [" +
						SessionFactoryUtils.toString(session) + "] for Spring-managed transaction");
			}
			txObject.setExistingSession(session);
		}
		catch (HibernateException ex) {
			throw new DataAccessResourceFailureException(
					"Could not obtain Hibernate-managed Session for Spring-managed transaction", ex);
		}
	}

	if (getDataSource() != null) {
		ConnectionHolder conHolder = (ConnectionHolder)
				TransactionSynchronizationManager.getResource(getDataSource());
		txObject.setConnectionHolder(conHolder);
	}

	return txObject;
}
 
Example #14
Source File: HibernateTransactionManager.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Object doGetTransaction() {
	HibernateTransactionObject txObject = new HibernateTransactionObject();
	txObject.setSavepointAllowed(isNestedTransactionAllowed());

	SessionHolder sessionHolder =
			(SessionHolder) TransactionSynchronizationManager.getResource(getSessionFactory());
	if (sessionHolder != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Found thread-bound Session [" + sessionHolder.getSession() + "] for Hibernate transaction");
		}
		txObject.setSessionHolder(sessionHolder);
	}
	else if (this.hibernateManagedSession) {
		try {
			Session session = this.sessionFactory.getCurrentSession();
			if (logger.isDebugEnabled()) {
				logger.debug("Found Hibernate-managed Session [" + session + "] for Spring-managed transaction");
			}
			txObject.setExistingSession(session);
		}
		catch (HibernateException ex) {
			throw new DataAccessResourceFailureException(
					"Could not obtain Hibernate-managed Session for Spring-managed transaction", ex);
		}
	}

	if (getDataSource() != null) {
		ConnectionHolder conHolder = (ConnectionHolder)
				TransactionSynchronizationManager.getResource(getDataSource());
		txObject.setConnectionHolder(conHolder);
	}

	return txObject;
}
 
Example #15
Source File: HibernateTransactionManager.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected Object doGetTransaction() {
	HibernateTransactionObject txObject = new HibernateTransactionObject();
	txObject.setSavepointAllowed(isNestedTransactionAllowed());

	SessionHolder sessionHolder =
			(SessionHolder) TransactionSynchronizationManager.getResource(getSessionFactory());
	if (sessionHolder != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Found thread-bound Session [" +
					SessionFactoryUtils.toString(sessionHolder.getSession()) + "] for Hibernate transaction");
		}
		txObject.setSessionHolder(sessionHolder);
	}
	else if (this.hibernateManagedSession) {
		try {
			Session session = getSessionFactory().getCurrentSession();
			if (logger.isDebugEnabled()) {
				logger.debug("Found Hibernate-managed Session [" +
						SessionFactoryUtils.toString(session) + "] for Spring-managed transaction");
			}
			txObject.setExistingSession(session);
		}
		catch (HibernateException ex) {
			throw new DataAccessResourceFailureException(
					"Could not obtain Hibernate-managed Session for Spring-managed transaction", ex);
		}
	}

	if (getDataSource() != null) {
		ConnectionHolder conHolder = (ConnectionHolder)
				TransactionSynchronizationManager.getResource(getDataSource());
		txObject.setConnectionHolder(conHolder);
	}

	return txObject;
}
 
Example #16
Source File: TXAspectProcessor.java    From tcc-transaction with Apache License 2.0 5 votes vote down vote up
private void assertTransactional()throws Throwable{
    DataSource dataSource= dataSourceAdaptor.getDataSource();
    Assert.notNull(dataSource,"datasource can not empty");
    ConnectionHolder conHolder = (ConnectionHolder) TransactionSynchronizationManager.getResource(dataSource);
    if (conHolder == null || conHolder.getConnectionHandle()==null || !conHolder.isSynchronizedWithTransaction()) {
        throw new DistributedTransactionException("transaction connection is null");
    }
}
 
Example #17
Source File: HibernateTransactionManager.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Object doGetTransaction() {
	HibernateTransactionObject txObject = new HibernateTransactionObject();
	txObject.setSavepointAllowed(isNestedTransactionAllowed());

	SessionHolder sessionHolder =
			(SessionHolder) TransactionSynchronizationManager.getResource(getSessionFactory());
	if (sessionHolder != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Found thread-bound Session [" + sessionHolder.getSession() + "] for Hibernate transaction");
		}
		txObject.setSessionHolder(sessionHolder);
	}
	else if (this.hibernateManagedSession) {
		try {
			Session session = this.sessionFactory.getCurrentSession();
			if (logger.isDebugEnabled()) {
				logger.debug("Found Hibernate-managed Session [" + session + "] for Spring-managed transaction");
			}
			txObject.setExistingSession(session);
		}
		catch (HibernateException ex) {
			throw new DataAccessResourceFailureException(
					"Could not obtain Hibernate-managed Session for Spring-managed transaction", ex);
		}
	}

	if (getDataSource() != null) {
		ConnectionHolder conHolder = (ConnectionHolder)
				TransactionSynchronizationManager.getResource(getDataSource());
		txObject.setConnectionHolder(conHolder);
	}

	return txObject;
}
 
Example #18
Source File: DynamicSpringManagedTransaction.java    From hsweb-framework with Apache License 2.0 5 votes vote down vote up
@Override
public Integer getTimeout() throws SQLException {
    ConnectionHolder holder = (ConnectionHolder) TransactionSynchronizationManager.getResource(dataSource);
    if (holder != null && holder.hasTimeout()) {
        return holder.getTimeToLiveInSeconds();
    }
    return null;
}
 
Example #19
Source File: OpenJpaDialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object createSavepoint() throws TransactionException {
	this.savepointCounter++;
	String savepointName = ConnectionHolder.SAVEPOINT_NAME_PREFIX + this.savepointCounter;
	this.entityManager.setSavepoint(savepointName);
	return savepointName;
}
 
Example #20
Source File: HibernateTransactionManager.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected Object doGetTransaction() {
	HibernateTransactionObject txObject = new HibernateTransactionObject();
	txObject.setSavepointAllowed(isNestedTransactionAllowed());

	SessionHolder sessionHolder =
			(SessionHolder) TransactionSynchronizationManager.getResource(getSessionFactory());
	if (sessionHolder != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Found thread-bound Session [" + sessionHolder.getSession() + "] for Hibernate transaction");
		}
		txObject.setSessionHolder(sessionHolder);
	}
	else if (this.hibernateManagedSession) {
		try {
			Session session = this.sessionFactory.getCurrentSession();
			if (logger.isDebugEnabled()) {
				logger.debug("Found Hibernate-managed Session [" + session + "] for Spring-managed transaction");
			}
			txObject.setExistingSession(session);
		}
		catch (HibernateException ex) {
			throw new DataAccessResourceFailureException(
					"Could not obtain Hibernate-managed Session for Spring-managed transaction", ex);
		}
	}

	if (getDataSource() != null) {
		ConnectionHolder conHolder = (ConnectionHolder)
				TransactionSynchronizationManager.getResource(getDataSource());
		txObject.setConnectionHolder(conHolder);
	}

	return txObject;
}
 
Example #21
Source File: DataSourceTransactionManagerHandlerTest.java    From opensharding-spi-impl with Apache License 2.0 5 votes vote down vote up
@Test
public void assertUnbindResource() {
    ConnectionHolder holder = mock(ConnectionHolder.class);
    Connection connection = mock(Connection.class);
    when(holder.getConnection()).thenReturn(connection);
    TransactionSynchronizationManager.bindResource(dataSource, holder);
    dataSourceTransactionManagerHandler.unbindResource();
    assertNull(TransactionSynchronizationManager.getResource(dataSource));
}
 
Example #22
Source File: OpenJpaDialect.java    From syncope with Apache License 2.0 5 votes vote down vote up
@Override
public Object createSavepoint() throws TransactionException {
    this.savepointCounter++;
    String savepointName = ConnectionHolder.SAVEPOINT_NAME_PREFIX + this.savepointCounter;
    this.entityManager.setSavepoint(savepointName);
    return savepointName;
}
 
Example #23
Source File: HibernateTransactionManager.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected Object doGetTransaction() {
	HibernateTransactionObject txObject = new HibernateTransactionObject();
	txObject.setSavepointAllowed(isNestedTransactionAllowed());

	SessionFactory sessionFactory = obtainSessionFactory();
	SessionHolder sessionHolder =
			(SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory);
	if (sessionHolder != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Found thread-bound Session [" + sessionHolder.getSession() + "] for Hibernate transaction");
		}
		txObject.setSessionHolder(sessionHolder);
	}
	else if (this.hibernateManagedSession) {
		try {
			Session session = sessionFactory.getCurrentSession();
			if (logger.isDebugEnabled()) {
				logger.debug("Found Hibernate-managed Session [" + session + "] for Spring-managed transaction");
			}
			txObject.setExistingSession(session);
		}
		catch (HibernateException ex) {
			throw new DataAccessResourceFailureException(
					"Could not obtain Hibernate-managed Session for Spring-managed transaction", ex);
		}
	}

	if (getDataSource() != null) {
		ConnectionHolder conHolder = (ConnectionHolder)
				TransactionSynchronizationManager.getResource(getDataSource());
		txObject.setConnectionHolder(conHolder);
	}

	return txObject;
}
 
Example #24
Source File: TXAspectProcessor.java    From galaxy with Apache License 2.0 5 votes vote down vote up
private void assertTransactional()throws Throwable{
    DataSource dataSource= dataSourceAdaptor.getDataSource();
    Assert.notNull(dataSource,"datasource can not empty");
    ConnectionHolder conHolder = (ConnectionHolder) TransactionSynchronizationManager.getResource(dataSource);
    if (conHolder == null || conHolder.getConnectionHandle()==null || !conHolder.isSynchronizedWithTransaction()) {
        throw new DistributedTransactionException("transaction connection is null");
    }
}
 
Example #25
Source File: HibernateTransactionManager.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected Object doGetTransaction() {
	HibernateTransactionObject txObject = new HibernateTransactionObject();
	txObject.setSavepointAllowed(isNestedTransactionAllowed());

	SessionFactory sessionFactory = obtainSessionFactory();
	SessionHolder sessionHolder =
			(SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory);
	if (sessionHolder != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Found thread-bound Session [" + sessionHolder.getSession() + "] for Hibernate transaction");
		}
		txObject.setSessionHolder(sessionHolder);
	}
	else if (this.hibernateManagedSession) {
		try {
			Session session = sessionFactory.getCurrentSession();
			if (logger.isDebugEnabled()) {
				logger.debug("Found Hibernate-managed Session [" + session + "] for Spring-managed transaction");
			}
			txObject.setExistingSession(session);
		}
		catch (HibernateException ex) {
			throw new DataAccessResourceFailureException(
					"Could not obtain Hibernate-managed Session for Spring-managed transaction", ex);
		}
	}

	if (getDataSource() != null) {
		ConnectionHolder conHolder = (ConnectionHolder)
				TransactionSynchronizationManager.getResource(getDataSource());
		txObject.setConnectionHolder(conHolder);
	}

	return txObject;
}
 
Example #26
Source File: HibernateTransactionManager.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected Object doGetTransaction() {
	HibernateTransactionObject txObject = new HibernateTransactionObject();
	txObject.setSavepointAllowed(isNestedTransactionAllowed());

	SessionHolder sessionHolder =
			(SessionHolder) TransactionSynchronizationManager.getResource(getSessionFactory());
	if (sessionHolder != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Found thread-bound Session [" + sessionHolder.getSession() + "] for Hibernate transaction");
		}
		txObject.setSessionHolder(sessionHolder);
	}
	else if (this.hibernateManagedSession) {
		try {
			Session session = this.sessionFactory.getCurrentSession();
			if (logger.isDebugEnabled()) {
				logger.debug("Found Hibernate-managed Session [" + session + "] for Spring-managed transaction");
			}
			txObject.setExistingSession(session);
		}
		catch (HibernateException ex) {
			throw new DataAccessResourceFailureException(
					"Could not obtain Hibernate-managed Session for Spring-managed transaction", ex);
		}
	}

	if (getDataSource() != null) {
		ConnectionHolder conHolder = (ConnectionHolder)
				TransactionSynchronizationManager.getResource(getDataSource());
		txObject.setConnectionHolder(conHolder);
	}

	return txObject;
}
 
Example #27
Source File: DataSourceTransactionManagerHandler.java    From opensharding-spi-impl with Apache License 2.0 5 votes vote down vote up
@Override
protected Connection getConnectionFromTransactionManager() {
    try {
        Connection result = transactionManager.getDataSource().getConnection();
        TransactionSynchronizationManager.bindResource(transactionManager.getDataSource(), new ConnectionHolder(result));
        return result;
    } catch (final SQLException ex) {
        throw new ShardingException("Could not open JDBC Connection before transaction", ex);
    }
}
 
Example #28
Source File: HibernateTransactionManager.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private ConnectionHolder getConnectionHolder() {
	return this.connectionHolder;
}
 
Example #29
Source File: JdoTransactionManager.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private ConnectionHolder getConnectionHolder() {
	return this.connectionHolder;
}
 
Example #30
Source File: HibernateTransactionManager.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private SuspendedResourcesHolder(SessionHolder sessionHolder, ConnectionHolder conHolder) {
	this.sessionHolder = sessionHolder;
	this.connectionHolder = conHolder;
}