本文整理汇总了Java中org.springframework.transaction.support.TransactionSynchronizationManager.unbindResource方法的典型用法代码示例。如果您正苦于以下问题:Java TransactionSynchronizationManager.unbindResource方法的具体用法?Java TransactionSynchronizationManager.unbindResource怎么用?Java TransactionSynchronizationManager.unbindResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.transaction.support.TransactionSynchronizationManager
的用法示例。
在下文中一共展示了TransactionSynchronizationManager.unbindResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: afterCompletion
import org.springframework.transaction.support.TransactionSynchronizationManager; //导入方法依赖的package包/类
@Override
public void afterCompletion(WebRequest request, Exception ex) throws DataAccessException {
String participateAttributeName = getParticipateAttributeName();
Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
if (count != null) {
// Do not modify the PersistenceManager: just clear the marker.
if (count > 1) {
request.setAttribute(participateAttributeName, count - 1, WebRequest.SCOPE_REQUEST);
}
else {
request.removeAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
}
}
else {
PersistenceManagerHolder pmHolder = (PersistenceManagerHolder)
TransactionSynchronizationManager.unbindResource(getPersistenceManagerFactory());
logger.debug("Closing JDO PersistenceManager in OpenPersistenceManagerInViewInterceptor");
PersistenceManagerFactoryUtils.releasePersistenceManager(
pmHolder.getPersistenceManager(), getPersistenceManagerFactory());
}
}
示例2: afterCompletion
import org.springframework.transaction.support.TransactionSynchronizationManager; //导入方法依赖的package包/类
/**
* Unbind the Hibernate {@code Session} from the thread and close it (in
* single session mode), or process deferred close for all sessions that have
* been opened during the current request (in deferred close mode).
* @see org.springframework.transaction.support.TransactionSynchronizationManager
*/
@Override
public void afterCompletion(WebRequest request, Exception ex) throws DataAccessException {
if (!decrementParticipateCount(request)) {
if (isSingleSession()) {
// single session mode
SessionHolder sessionHolder =
(SessionHolder) TransactionSynchronizationManager.unbindResource(getSessionFactory());
logger.debug("Closing single Hibernate Session in OpenSessionInViewInterceptor");
SessionFactoryUtils.closeSession(sessionHolder.getSession());
}
else {
// deferred close mode
SessionFactoryUtils.processDeferredClose(getSessionFactory());
}
}
}
示例3: doCleanupAfterCompletion
import org.springframework.transaction.support.TransactionSynchronizationManager; //导入方法依赖的package包/类
@Override
protected void doCleanupAfterCompletion(Object transaction) {
JpaTransactionObject txObject = (JpaTransactionObject) transaction;
// Remove the entity manager holder from the thread, if still there.
// (Could have been removed by EntityManagerFactoryUtils in order
// to replace it with an unsynchronized EntityManager).
if (txObject.isNewEntityManagerHolder()) {
TransactionSynchronizationManager.unbindResourceIfPossible(getEntityManagerFactory());
}
txObject.getEntityManagerHolder().clear();
// Remove the JDBC connection holder from the thread, if exposed.
if (txObject.hasConnectionHolder()) {
TransactionSynchronizationManager.unbindResource(getDataSource());
try {
getJpaDialect().releaseJdbcConnection(txObject.getConnectionHolder().getConnectionHandle(),
txObject.getEntityManagerHolder().getEntityManager());
}
catch (Exception ex) {
// Just log it, to keep a transaction-related exception.
logger.error("Could not close JDBC connection after transaction", ex);
}
}
getJpaDialect().cleanupTransaction(txObject.getTransactionData());
// Remove the entity manager holder from the thread.
if (txObject.isNewEntityManagerHolder()) {
EntityManager em = txObject.getEntityManagerHolder().getEntityManager();
if (logger.isDebugEnabled()) {
logger.debug("Closing JPA EntityManager [" + em + "] after transaction");
}
EntityManagerFactoryUtils.closeEntityManager(em);
}
else {
logger.debug("Not closing pre-bound JPA EntityManager after transaction");
}
}
示例4: invoke
import org.springframework.transaction.support.TransactionSynchronizationManager; //导入方法依赖的package包/类
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
SessionFactory sf = getSessionFactory();
if (!TransactionSynchronizationManager.hasResource(sf)) {
// New Session to be bound for the current method's scope...
Session session = openSession();
try {
TransactionSynchronizationManager.bindResource(sf, new SessionHolder(session));
return invocation.proceed();
}
finally {
SessionFactoryUtils.closeSession(session);
TransactionSynchronizationManager.unbindResource(sf);
}
}
else {
// Pre-bound Session found -> simply proceed.
return invocation.proceed();
}
}
示例5: clearSynchronization
import org.springframework.transaction.support.TransactionSynchronizationManager; //导入方法依赖的package包/类
/**
* Cleans out transaction resources if present
*/
private static void clearSynchronization()
{
if (TransactionSynchronizationManager.hasResource(RESOURCE_KEY_TXN_SYNCH))
{
Object txnSynch = TransactionSynchronizationManager.unbindResource(RESOURCE_KEY_TXN_SYNCH);
// done
if (logger.isDebugEnabled())
{
logger.debug("Unbound txn synch:" + txnSynch);
}
}
}
示例6: doCleanupAfterCompletion
import org.springframework.transaction.support.TransactionSynchronizationManager; //导入方法依赖的package包/类
@Override
protected void doCleanupAfterCompletion(Object transaction) {
// Remove the connection holder from the thread, if exposed.
if (checkNewConnectionHolder(transaction)&&null!= TransactionSynchronizationManager.getResource(getDataSource())) {
TransactionSynchronizationManager.unbindResource(getDataSource());
}
}
开发者ID:zhangkewei,项目名称:dubbo-transaction,代码行数:8,代码来源:DubboTransactionDataSourceTransactonManager.java
示例7: doCleanupAfterCompletion
import org.springframework.transaction.support.TransactionSynchronizationManager; //导入方法依赖的package包/类
@Override
protected void doCleanupAfterCompletion(Object transaction) {
long txId = getTransactionId();
logger.info(" [LITX]结束事务 [TX ID: " + txId + "]");
super.doCleanupAfterCompletion(transaction);
TransactionSynchronizationManager.unbindResource(LitxConstant.TRANSACTION_CONTEXT_KEY);
TransactionSynchronizationManager.unbindResource(LitxConstant.TRANSACTION_ID_KEY);
}
示例8: suspend
import org.springframework.transaction.support.TransactionSynchronizationManager; //导入方法依赖的package包/类
@Override
public void suspend() {
if (this.holderActive) {
TransactionSynchronizationManager.unbindResource(this.sessionFactory);
// Eagerly disconnect the Session here, to make release mode "on_close" work on JBoss.
getCurrentSession().disconnect();
}
}
示例9: doSuspend
import org.springframework.transaction.support.TransactionSynchronizationManager; //导入方法依赖的package包/类
@Override
protected Object doSuspend(Object transaction) {
DataSourceTransactionObject txObject = (DataSourceTransactionObject) transaction;
txObject.setConnectionHolder(null);
ConnectionHolder conHolder = (ConnectionHolder)
TransactionSynchronizationManager.unbindResource(this.dataSource);
return conHolder;
}
示例10: beforeCompletion
import org.springframework.transaction.support.TransactionSynchronizationManager; //导入方法依赖的package包/类
@Override
public void beforeCompletion() {
// Release Connection early if the holder is not open anymore
// (that is, not used by another resource like a Hibernate Session
// that has its own cleanup via transaction synchronization),
// to avoid issues with strict JTA implementations that expect
// the close call before transaction completion.
if (!this.connectionHolder.isOpen()) {
TransactionSynchronizationManager.unbindResource(this.dataSource);
this.holderActive = false;
if (this.connectionHolder.hasConnection()) {
releaseConnection(this.connectionHolder.getConnection(), this.dataSource);
}
}
}
示例11: doFilterInternal
import org.springframework.transaction.support.TransactionSynchronizationManager; //导入方法依赖的package包/类
@Override
protected void doFilterInternal(
HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
PersistenceManagerFactory pmf = lookupPersistenceManagerFactory(request);
boolean participate = false;
if (TransactionSynchronizationManager.hasResource(pmf)) {
// Do not modify the PersistenceManager: just set the participate flag.
participate = true;
}
else {
logger.debug("Opening JDO PersistenceManager in OpenPersistenceManagerInViewFilter");
PersistenceManager pm = PersistenceManagerFactoryUtils.getPersistenceManager(pmf, true);
TransactionSynchronizationManager.bindResource(pmf, new PersistenceManagerHolder(pm));
}
try {
filterChain.doFilter(request, response);
}
finally {
if (!participate) {
PersistenceManagerHolder pmHolder = (PersistenceManagerHolder)
TransactionSynchronizationManager.unbindResource(pmf);
logger.debug("Closing JDO PersistenceManager in OpenPersistenceManagerInViewFilter");
PersistenceManagerFactoryUtils.releasePersistenceManager(pmHolder.getPersistenceManager(), pmf);
}
}
}
示例12: doResume
import org.springframework.transaction.support.TransactionSynchronizationManager; //导入方法依赖的package包/类
@Override
protected void doResume(Object transaction, Object suspendedResources) {
SuspendedResourcesHolder resourcesHolder = (SuspendedResourcesHolder) suspendedResources;
if (TransactionSynchronizationManager.hasResource(getSessionFactory())) {
// From non-transactional code running in active transaction synchronization
// -> can be safely removed, will be closed on transaction completion.
TransactionSynchronizationManager.unbindResource(getSessionFactory());
}
TransactionSynchronizationManager.bindResource(getSessionFactory(), resourcesHolder.getSessionHolder());
if (getDataSource() != null) {
TransactionSynchronizationManager.bindResource(getDataSource(), resourcesHolder.getConnectionHolder());
}
}
示例13: unbindLogProcessContext
import org.springframework.transaction.support.TransactionSynchronizationManager; //导入方法依赖的package包/类
private void unbindLogProcessContext(){
TransactionSynchronizationManager.unbindResource(LOG_PROCESS_CONTEXT);
}
示例14: postProcess
import org.springframework.transaction.support.TransactionSynchronizationManager; //导入方法依赖的package包/类
@Override
public <T> void postProcess(NativeWebRequest request, Callable<T> task, Object concurrentResult) {
TransactionSynchronizationManager.unbindResource(this.sessionFactory);
}
示例15: doSuspend
import org.springframework.transaction.support.TransactionSynchronizationManager; //导入方法依赖的package包/类
@Override
protected Object doSuspend(Object transaction) {
CciLocalTransactionObject txObject = (CciLocalTransactionObject) transaction;
txObject.setConnectionHolder(null);
return TransactionSynchronizationManager.unbindResource(getConnectionFactory());
}