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


Java Transaction类代码示例

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


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

示例1: main

import javax.transaction.Transaction; //导入依赖的package包/类
public static void main(String[] args) {
	Configuration cfg=null;
	SessionFactory factory=null;
	Session ses=null;
	Transaction tx=null;
			cfg=new Configuration().configure("com/app/cfgs/hibernate.cfg.xml");
			factory=cfg.buildSessionFactory();
		ses=factory.openSession();
	
		 String hql="select item_name from bigbazarModel where bazarid=:id";
		 Query q=ses.createQuery(hql);
		 		q.setParameter("id", 1001);
		 			String s=(String) q.uniqueResult();
		 			System.out.println("\t\t"+s);
		 			
		 			factory.close();

}
 
开发者ID:pratikdimble,项目名称:Hibernate_HQL_UniqueResult_ExecuteUpdate_CopyData_Delete_Update,代码行数:19,代码来源:TestClass.java

示例2: getTransactionId

import javax.transaction.Transaction; //导入依赖的package包/类
/**
 * Get the transaction identifier used to store it in the transaction map.
 * 
 * @param tx Transaction
 * @param storeRef StoreRef
 * @return - the transaction id
 */
@SuppressWarnings("unchecked")
private String getTransactionId(Transaction tx, StoreRef storeRef)
{
    if (tx instanceof SimpleTransaction)
    {
        SimpleTransaction simpleTx = (SimpleTransaction) tx;
        return simpleTx.getGUID();
    }
    else if (TransactionSynchronizationManager.isSynchronizationActive())
    {
        Map<StoreRef, LuceneIndexer> indexers = (Map<StoreRef, LuceneIndexer>) AlfrescoTransactionSupport.getResource(indexersKey);
        if (indexers != null)
        {
            LuceneIndexer indexer = indexers.get(storeRef);
            if (indexer != null)
            {
                return indexer.getDeltaId();
            }
        }
    }
    return null;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:30,代码来源:AbstractLuceneIndexerAndSearcherFactory.java

示例3: suspend

import javax.transaction.Transaction; //导入依赖的package包/类
/**
 * Suspends the current transaction (if any) during the given handler is
 * called.
 * 
 * @param delegate
 * @return
 */
private static IInvocationHandler suspend(final IInvocationHandler delegate) {
    return new IInvocationHandler() {

        public Object call(Callable<Object> callable,
                IInvocationHandler.IInvocationCtx ctx) throws Exception {
            final Transaction suspended = ctx.getTransactionManager()
                    .suspend();
            try {
                return delegate.call(callable, ctx);
            } finally {
                if (suspended != null) {
                    ctx.getTransactionManager().resume(suspended);
                }
            }
        }
    };
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:25,代码来源:TransactionInvocationHandlers.java

示例4: connectionClosed

import javax.transaction.Transaction; //导入依赖的package包/类
/**
 * Implementation of call back function from ConnectionEventListener interface. This callback will
 * be invoked on connection close event.
 * 
 * @param event Connection event object
 */
public void connectionClosed(ConnectionEvent event) {
  if (isActive) {
    try {
      XAConnection conn = (XAConnection) event.getSource();
      XAResource xar = (XAResource) xaResourcesMap.get(conn);
      xaResourcesMap.remove(conn);
      Transaction txn = transManager.getTransaction();
      if (txn != null && xar != null)
        txn.delistResource(xar, XAResource.TMSUCCESS);
      provider.returnConnection(conn);
    } catch (Exception e) {
      String exception =
          "GemFireTransactionDataSource::connectionClosed: Exception occured due to " + e;
      if (logger.isDebugEnabled()) {
        logger.debug(exception, e);
      }
    }
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:26,代码来源:GemFireTransactionDataSource.java

示例5: registerTranxConnection

import javax.transaction.Transaction; //导入依赖的package包/类
/**
 *  
 */
void registerTranxConnection(XAConnection xaConn) throws Exception {
  try {
    synchronized (this) {
      if (transManager == null) {
        transManager = JNDIInvoker.getTransactionManager();
      }
    }
    Transaction txn = transManager.getTransaction();
    if (txn != null) {
      XAResource xar = xaConn.getXAResource();
      txn.enlistResource(xar);
      // Add in the Map after successful registration of XAResource
      this.xaResourcesMap.put(xaConn, xar);
    }
  } catch (Exception ex) {
    Exception e = new Exception(
        LocalizedStrings.GemFireTransactionDataSource_GEMFIRETRANSACTIONDATASOURCEREGISTERTRANXCONNECTION_EXCEPTION_IN_REGISTERING_THE_XARESOURCE_WITH_THE_TRANSACTIONEXCEPTION_OCCURED_0
            .toLocalizedString(ex));
    e.initCause(ex);
    throw e;
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:26,代码来源:GemFireTransactionDataSource.java

示例6: connectionClosed

import javax.transaction.Transaction; //导入依赖的package包/类
/**
 * Callback for Connection Closed.
 * 
 * @param event ConnectionEvent Object.
 */
public void connectionClosed(ConnectionEvent event) {
  if (isActive) {
    ManagedConnection conn = (ManagedConnection) event.getSource();
    TransactionManagerImpl transManager = TransactionManagerImpl.getTransactionManager();
    try {
      Transaction txn = transManager.getTransaction();
      if (txn == null) {
        mannPoolCache.returnPooledConnectionToPool(conn);
      }
    } catch (Exception se) {
      String exception =
          "FacetsJCAConnectionManagerImpl::connectionClosed: Exception occured due to "
              + se.getMessage();
      if (logger.isDebugEnabled()) {
        logger.debug(exception, se);
      }
    }
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:25,代码来源:FacetsJCAConnectionManagerImpl.java

示例7: suspend

import javax.transaction.Transaction; //导入依赖的package包/类
/**
 * @see javax.transaction.TransactionManager#suspend()
 */
public Transaction suspend() throws SystemException {
  if (!isActive) {
    throw new SystemException(
        LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGER_INVALID.toLocalizedString());
  }
  Transaction txn = getTransaction();

  if (null != txn) {
    GlobalTransaction gtx = getGlobalTransaction(txn);
    gtx.suspend();
    transactionMap.remove(Thread.currentThread());
    LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
    if (writer.infoEnabled())
      writer.info(
          LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGERIMPLSUSPENDTRANSACTION_SUSPENDED);
  }

  return txn;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:23,代码来源:TransactionManagerImpl.java

示例8: testBug46169

import javax.transaction.Transaction; //导入依赖的package包/类
@Test
public void testBug46169() throws Exception {
  String tableName = CacheUtils.init("CacheTest");
  assertFalse(tableName == null || tableName.equals(""));
  logger.debug("Table name: " + tableName);

  logger.debug("init for bug46169 Successful!");
  Cache cache = CacheUtils.getCache();

  TransactionManager xmanager =
      (TransactionManager) cache.getJNDIContext().lookup("java:/TransactionManager");
  assertNotNull(xmanager);

  Transaction trans = xmanager.suspend();
  assertNull(trans);

  try {
    logger.debug("Destroying table: " + tableName);
    CacheUtils.destroyTable(tableName);
    logger.debug("Closing cache...");
    logger.debug("destroyTable for bug46169 Successful!");
  } finally {
    CacheUtils.closeCache();
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:26,代码来源:JtaIntegrationJUnitTest.java

示例9: main

import javax.transaction.Transaction; //导入依赖的package包/类
public static void main(String[] args) {

        ClassLoader scl = ClassLoader.getSystemClassLoader();
        ClassLoader pcl = ClassLoader.getPlatformClassLoader();
        assertTrue(pcl.getParent() == null);

        Transaction transaction = new Transaction();
        Scope scope = transaction.getScope();

        // javax.transaction.Transaction should be in module java.transaction
        // and defined by the platform class loader
        assertTrue(Transaction.class.getModule().getName().equals("java.transaction"));
        assertTrue(Transaction.class.getClassLoader() == pcl);

        // javax.enterprise.context.Scope should be in module java.enterprise
        // and defined by the application class loader
        assertTrue(Scope.class.getModule().getName().equals("java.enterprise"));
        assertTrue(Scope.class.getClassLoader() == scl);
    }
 
开发者ID:campolake,项目名称:openjdk9,代码行数:20,代码来源:Main.java

示例10: suspend

import javax.transaction.Transaction; //导入依赖的package包/类
public static Transaction suspend() throws GenericTransactionException {
    try {
        if (TransactionUtil.getStatus() != STATUS_NO_TRANSACTION) {
            TransactionManager txMgr = TransactionFactoryLoader.getInstance().getTransactionManager();
            if (txMgr != null) {
                pushTransactionBeginStackSave(clearTransactionBeginStack());
                pushSetRollbackOnlyCauseSave(clearSetRollbackOnlyCause());
                Transaction trans = txMgr.suspend();
                pushSuspendedTransaction(trans);
                return trans;
            } else {
                return null;
            }
        } else {
            Debug.logWarning("No transaction in place, so not suspending.", module);
            return null;
        }
    } catch (SystemException e) {
        throw new GenericTransactionException("System error, could not suspend transaction", e);
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:22,代码来源:TransactionUtil.java

示例11: jtaTransactionManagerWithPropagationNotSupported

import javax.transaction.Transaction; //导入依赖的package包/类
@Test
public void jtaTransactionManagerWithPropagationNotSupported() throws Exception {
	UserTransaction ut = mock(UserTransaction.class);
	TransactionManager tm = mock(TransactionManager.class);
	Transaction tx = mock(Transaction.class);
	given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
	given(tm.suspend()).willReturn(tx);

	JtaTransactionManager ptm = newJtaTransactionManager(ut, tm);
	TransactionTemplate tt = new TransactionTemplate(ptm);
	tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_NOT_SUPPORTED);
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	tt.execute(new TransactionCallbackWithoutResult() {
		@Override
		protected void doInTransactionWithoutResult(TransactionStatus status) {
			assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
			status.setRollbackOnly();
		}
	});
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());

	verify(tm).resume(tx);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:JtaTransactionManagerTests.java

示例12: jtaTransactionManagerWithPropagationRequiresNewAndExisting

import javax.transaction.Transaction; //导入依赖的package包/类
@Test
public void jtaTransactionManagerWithPropagationRequiresNewAndExisting() throws Exception {
	UserTransaction ut = mock(UserTransaction.class);
	TransactionManager tm = mock(TransactionManager.class);
	Transaction tx = mock(Transaction.class);
	given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
	given(tm.suspend()).willReturn(tx);

	JtaTransactionManager ptm = newJtaTransactionManager(ut, tm);
	TransactionTemplate tt = new TransactionTemplate(ptm);
	tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	tt.execute(new TransactionCallbackWithoutResult() {
		@Override
		protected void doInTransactionWithoutResult(TransactionStatus status) {
			assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
		}
	});
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());

	verify(ut).begin();
	verify(ut).commit();
	verify(tm).resume(tx);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:JtaTransactionManagerTests.java

示例13: jtaTransactionManagerWithPropagationRequiresNewAndAdapter

import javax.transaction.Transaction; //导入依赖的package包/类
@Test
public void jtaTransactionManagerWithPropagationRequiresNewAndAdapter() throws Exception {
	TransactionManager tm = mock(TransactionManager.class);
	Transaction tx = mock(Transaction.class);
	given(tm.getStatus()).willReturn(Status.STATUS_ACTIVE);
	given(tm.suspend()).willReturn(tx);

	JtaTransactionManager ptm = newJtaTransactionManager(tm);
	TransactionTemplate tt = new TransactionTemplate(ptm);
	tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	tt.execute(new TransactionCallbackWithoutResult() {
		@Override
		protected void doInTransactionWithoutResult(TransactionStatus status) {
			assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
		}
	});
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());

	verify(tm).begin();
	verify(tm).commit();
	verify(tm).resume(tx);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:JtaTransactionManagerTests.java

示例14: connectionClosed

import javax.transaction.Transaction; //导入依赖的package包/类
/**
 * Callback for Connection Closed.
 * 
 * @param event ConnectionEvent Object.
 */
public void connectionClosed(ConnectionEvent event) {
  if (isActive) {
    ManagedConnection conn = (ManagedConnection) event.getSource();
    XAResource xar = null;
    if (xaResourcesMap.get(conn) != null)
        xar = (XAResource) xaResourcesMap.get(conn);
    xaResourcesMap.remove(conn);
    try {
      Transaction txn = transManager.getTransaction();
      if (txn != null && xar != null) {
        txn.delistResource(xar, XAResource.TMSUCCESS);
      }
    }
    catch (Exception se) {
      String exception = "JCAConnectionManagerImpl::connectionClosed: Exception occured due to "
          + se;
      LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
      if (writer.fineEnabled()) writer.fine(exception, se);
    }
    mannPoolCache.returnPooledConnectionToPool(conn);
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:28,代码来源:JCAConnectionManagerImpl.java

示例15: connectionClosed

import javax.transaction.Transaction; //导入依赖的package包/类
/**
 * Callback for Connection Closed.
 * 
 * @param event ConnectionEvent Object.
 */
public void connectionClosed(ConnectionEvent event) {
  if (isActive) {
    ManagedConnection conn = (ManagedConnection) event.getSource();
    TransactionManagerImpl transManager = TransactionManagerImpl
        .getTransactionManager();
    try {
      Transaction txn = transManager.getTransaction();
      if (txn == null) {
        mannPoolCache.returnPooledConnectionToPool(conn);
      }
    }
    catch (Exception se) {
      String exception = "FacetsJCAConnectionManagerImpl::connectionClosed: Exception occured due to "
          + se;
      LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
      if (writer.fineEnabled()) writer.fine(exception, se);
    }
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:25,代码来源:FacetsJCAConnectionManagerImpl.java


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