本文整理汇总了Java中org.springframework.jdbc.datasource.ConnectionHolder.getConnection方法的典型用法代码示例。如果您正苦于以下问题:Java ConnectionHolder.getConnection方法的具体用法?Java ConnectionHolder.getConnection怎么用?Java ConnectionHolder.getConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.jdbc.datasource.ConnectionHolder
的用法示例。
在下文中一共展示了ConnectionHolder.getConnection方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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();
}