当前位置: 首页>>代码示例>>Java>>正文


Java ConnectionHolder类代码示例

本文整理汇总了Java中org.springframework.jdbc.datasource.ConnectionHolder的典型用法代码示例。如果您正苦于以下问题:Java ConnectionHolder类的具体用法?Java ConnectionHolder怎么用?Java ConnectionHolder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ConnectionHolder类属于org.springframework.jdbc.datasource包,在下文中一共展示了ConnectionHolder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doGetTransaction

import org.springframework.jdbc.datasource.ConnectionHolder; //导入依赖的package包/类
@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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:JpaTransactionManager.java

示例2: doGetTransaction

import org.springframework.jdbc.datasource.ConnectionHolder; //导入依赖的package包/类
@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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:JdoTransactionManager.java

示例3: doGetTransaction

import org.springframework.jdbc.datasource.ConnectionHolder; //导入依赖的package包/类
@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;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:JpaTransactionManager.java

示例4: testAddInvoicesWithinTransaction

import org.springframework.jdbc.datasource.ConnectionHolder; //导入依赖的package包/类
@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();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:StoredProcedureTests.java

示例5: addTenantForSchema

import org.springframework.jdbc.datasource.ConnectionHolder; //导入依赖的package包/类
@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);
        }
    }

}
 
开发者ID:grails,项目名称:gorm-hibernate5,代码行数:24,代码来源:HibernateDatastore.java

示例6: getEntityManager

import org.springframework.jdbc.datasource.ConnectionHolder; //导入依赖的package包/类
/**
 * 获得EntityManager
 * 
 * @return
 */
protected final EntityManager getEntityManager() {
    TransactionMode tx = jefEmf.getDefault().getTxType();
    EntityManager em;
    switch (tx) {
    case JPA:
    case JTA:
        em = EntityManagerFactoryUtils.doGetTransactionalEntityManager(entityManagerFactory, null);
        if (em == null) { // 当无事务时。Spring返回null
            em = entityManagerFactory.createEntityManager(null, Collections.EMPTY_MAP);
        }
        break;
    case JDBC:
        ConnectionHolder conn = (ConnectionHolder) TransactionSynchronizationManager.getResource(jefEmf.getDefault().getDataSource());
        if (conn == null) {// 基于数据源的Spring事务
            em = entityManagerFactory.createEntityManager(null, Collections.EMPTY_MAP);
        } else {
            ManagedTransactionImpl session = new ManagedTransactionImpl(jefEmf.getDefault(), conn.getConnection());
            em = new JefEntityManager(entityManagerFactory, null, session);
        }
        break;
    default:
        throw new UnsupportedOperationException(tx.name());
    }
    return em;
}
 
开发者ID:GeeQuery,项目名称:ef-orm,代码行数:31,代码来源:BaseDao.java

示例7: getEntityManager

import org.springframework.jdbc.datasource.ConnectionHolder; //导入依赖的package包/类
/**
 * 获得EntityManager
 * 
 * @return
 */
public static final EntityManager getEntityManager(JefEntityManagerFactory jefEmf) {
    TransactionMode tx = jefEmf.getDefault().getTxType();
    EntityManager em;
    switch (tx) {
    case JPA:
    case JTA:
        em = EntityManagerFactoryUtils.doGetTransactionalEntityManager(jefEmf, null);
        if (em == null) { // 当无事务时。Spring返回null
            em = jefEmf.createEntityManager(null, Collections.EMPTY_MAP);
        }
        break;
    case JDBC:
        ConnectionHolder conn = (ConnectionHolder) TransactionSynchronizationManager.getResource(jefEmf.getDefault().getDataSource());
        if (conn == null) {// 基于数据源的Spring事务
            em = jefEmf.createEntityManager(null, Collections.EMPTY_MAP);
        } else {
            ManagedTransactionImpl session = new ManagedTransactionImpl(jefEmf.getDefault(), conn.getConnection());
            em = new JefEntityManager(jefEmf, null, session);
        }
        break;
    default:
        throw new UnsupportedOperationException(tx.name());
    }
    return em;
}
 
开发者ID:GeeQuery,项目名称:ef-orm,代码行数:31,代码来源:QueryUtils.java

示例8: prepare

import org.springframework.jdbc.datasource.ConnectionHolder; //导入依赖的package包/类
public boolean prepare(){
    try {
        if (status.getTransaction() instanceof JdbcTransactionObjectSupport) {
            JdbcTransactionObjectSupport support = (JdbcTransactionObjectSupport) status.getTransaction();
            ConnectionHolder holder = support.getConnectionHolder();
            Connection con = holder.getConnection();
            return !con.isClosed() && !con.isReadOnly();
        }
    }catch (Exception e){
    }
    return false;
}
 
开发者ID:zhangkewei,项目名称:dubbo-transaction,代码行数:13,代码来源:DBTransaction.java

示例9: commit

import org.springframework.jdbc.datasource.ConnectionHolder; //导入依赖的package包/类
@Override
public boolean commit() throws SQLException {
    logger.debug("[realDbCommit]"+getTransactionId().getCurrentId());
    if(status.getTransaction() instanceof JdbcTransactionObjectSupport){
        JdbcTransactionObjectSupport support=(JdbcTransactionObjectSupport)status.getTransaction();
        ConnectionHolder holder=support.getConnectionHolder();
        Connection con = holder.getConnection();
        con.commit();
        logger.debug("[realDbCommit]["+getTransactionId().getCurrentId()+"]"+con);
    }
    clearConnection();
    return true;
}
 
开发者ID:zhangkewei,项目名称:dubbo-transaction,代码行数:14,代码来源:DBTransaction.java

示例10: rollback

import org.springframework.jdbc.datasource.ConnectionHolder; //导入依赖的package包/类
@Override
public boolean rollback() throws SQLException {
    if(status.getTransaction() instanceof JdbcTransactionObjectSupport) {
        JdbcTransactionObjectSupport support = (JdbcTransactionObjectSupport) status.getTransaction();
        ConnectionHolder holder = support.getConnectionHolder();
        Connection con = holder.getConnection();
        con.rollback();
    }
    clearConnection();
    return true;
}
 
开发者ID:zhangkewei,项目名称:dubbo-transaction,代码行数:12,代码来源:DBTransaction.java

示例11: createSavepoint

import org.springframework.jdbc.datasource.ConnectionHolder; //导入依赖的package包/类
@Override
public Object createSavepoint() throws TransactionException {
	this.savepointCounter++;
	String savepointName = ConnectionHolder.SAVEPOINT_NAME_PREFIX + this.savepointCounter;
	this.entityManager.setSavepoint(savepointName);
	return savepointName;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:OpenJpaDialect.java

示例12: doGetTransaction

import org.springframework.jdbc.datasource.ConnectionHolder; //导入依赖的package包/类
@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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:36,代码来源:HibernateTransactionManager.java

示例13: doGetTransaction

import org.springframework.jdbc.datasource.ConnectionHolder; //导入依赖的package包/类
@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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:38,代码来源:HibernateTransactionManager.java

示例14: getConnection

import org.springframework.jdbc.datasource.ConnectionHolder; //导入依赖的package包/类
public Connection getConnection() {
    ConnectionHolder conHolder =
        (ConnectionHolder) TransactionSynchronizationManager.getResource(
        dataSource);

    if (conHolder == null) {
        throw new IllegalStateException("It seems not to be existing a transaction.");
    }

    return conHolder.getConnection();
}
 
开发者ID:mirage-sql,项目名称:mirage-integration,代码行数:12,代码来源:SpringConnectionProvider.java

示例15: getTimeout

import org.springframework.jdbc.datasource.ConnectionHolder; //导入依赖的package包/类
@Override
public Integer getTimeout() throws SQLException {
    ConnectionHolder holder = (ConnectionHolder) TransactionSynchronizationManager.getResource(dataSource);
    if (holder != null && holder.hasTimeout()) {
        return holder.getTimeToLiveInSeconds();
    }
    return null;
}
 
开发者ID:hs-web,项目名称:hsweb-framework,代码行数:9,代码来源:DynamicSpringManagedTransaction.java


注:本文中的org.springframework.jdbc.datasource.ConnectionHolder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。