本文整理汇总了Java中javax.transaction.UserTransaction类的典型用法代码示例。如果您正苦于以下问题:Java UserTransaction类的具体用法?Java UserTransaction怎么用?Java UserTransaction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UserTransaction类属于javax.transaction包,在下文中一共展示了UserTransaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startUserTransaction
import javax.transaction.UserTransaction; //导入依赖的package包/类
/**
* If <em>wrapInUserTransaction</em> is true, starts a new UserTransaction
* and returns it. Otherwise, or if establishing the transaction fail, it
* will return null.
*/
private UserTransaction startUserTransaction() {
if (wrapInUserTransaction == false) {
return null;
}
UserTransaction userTransaction = null;
try {
userTransaction = UserTransactionHelper.lookupUserTransaction();
userTransaction.begin();
} catch (Throwable t) {
UserTransactionHelper.returnUserTransaction(userTransaction);
userTransaction = null;
getLog().error("Failed to start UserTransaction for plugin: " + getName(), t);
}
return userTransaction;
}
示例2: carLifecycleXA
import javax.transaction.UserTransaction; //导入依赖的package包/类
/**
* Create, find and delete car using XA Transactions
* @param ut
* @param em
* @throws Exception
*/
protected void carLifecycleXA(UserTransaction ut, EntityManager em) throws Exception {
ut.begin();
em.joinTransaction();
delete(em, Car.class, BLUE_PLATE);
em.persist(createBlueCar());
ut.commit();
Car c = em.find(Car.class, BLUE_PLATE);
assertBlueCar(c);
ut.begin();
em.joinTransaction();
delete(em, Car.class, BLUE_PLATE);
ut.commit();
}
示例3: truckLifecycleXA
import javax.transaction.UserTransaction; //导入依赖的package包/类
/**
* Create, find and delete car using XA Transactions
* @param ut
* @param em
* @throws Exception
*/
protected void truckLifecycleXA(UserTransaction ut, EntityManager em) throws Exception {
ut.begin();
em.joinTransaction();
delete(em, Truck.class, BLUE_PLATE);
em.persist(createBlueTruck());
ut.commit();
Truck t = em.find(Truck.class, BLUE_PLATE);
assertBlueTruck(t);
ut.begin();
em.joinTransaction();
delete(em, Truck.class, BLUE_PLATE);
ut.commit();
}
示例4: testMNT10533
import javax.transaction.UserTransaction; //导入依赖的package包/类
public void testMNT10533() throws Exception
{
String GROUP_NAME = "testMNT10533";
String GROUP_FULL_NAME = "GROUP_" + GROUP_NAME;
policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "beforeDeleteNode"), ContentModel.TYPE_AUTHORITY_CONTAINER, new JavaBehaviour(
new GroupBehaviour(), "beforeDeleteNode"));
UserTransaction transaction = null;
transaction = transactionService.getUserTransaction();
transaction.begin();
try
{
authorityService.createAuthority(AuthorityType.GROUP, GROUP_NAME);
assertNotNull(authorityService.getAuthorityNodeRef(GROUP_FULL_NAME));
authorityService.deleteAuthority(GROUP_FULL_NAME);
assertNull(authorityService.getAuthorityNodeRef(GROUP_FULL_NAME));
}
finally
{
transaction.commit();
}
}
示例5: findUserTransaction
import javax.transaction.UserTransaction; //导入依赖的package包/类
/**
* Find the JTA UserTransaction through a default JNDI lookup:
* "java:comp/UserTransaction".
* @return the JTA UserTransaction reference, or {@code null} if not found
* @see #DEFAULT_USER_TRANSACTION_NAME
*/
protected UserTransaction findUserTransaction() {
String jndiName = DEFAULT_USER_TRANSACTION_NAME;
try {
UserTransaction ut = getJndiTemplate().lookup(jndiName, UserTransaction.class);
if (logger.isDebugEnabled()) {
logger.debug("JTA UserTransaction found at default JNDI location [" + jndiName + "]");
}
this.userTransactionObtainedFromJndi = true;
return ut;
}
catch (NamingException ex) {
if (logger.isDebugEnabled()) {
logger.debug("No JTA UserTransaction found at default JNDI location [" + jndiName + "]", ex);
}
return null;
}
}
示例6: createUser
import javax.transaction.UserTransaction; //导入依赖的package包/类
private void createUser(String userName) throws Exception
{
UserTransaction txn = transactionService.getUserTransaction();
try
{
txn.begin();
authenticationService.createAuthentication(userName, userName.toCharArray());
PropertyMap ppOne = new PropertyMap(4);
ppOne.put(ContentModel.PROP_USERNAME, userName);
ppOne.put(ContentModel.PROP_FIRSTNAME, userName.substring(0, userName.length()-4));
ppOne.put(ContentModel.PROP_LASTNAME, "user");
ppOne.put(ContentModel.PROP_EMAIL, userName + "@email.com");
ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle");
personService.createPerson(ppOne);
txn.commit();
}
catch (Exception e)
{
txn.rollback();
throw e;
}
}
示例7: createGroup
import javax.transaction.UserTransaction; //导入依赖的package包/类
private void createGroup(String groupName) throws Exception
{
UserTransaction txn = transactionService.getUserTransaction();
try
{
txn.begin();
authorityService.createAuthority(AuthorityType.GROUP, groupName);
txn.commit();
}
catch (Exception e)
{
txn.rollback();
throw e;
}
}
示例8: setSiteMembership
import javax.transaction.UserTransaction; //导入依赖的package包/类
private void setSiteMembership(String authority, String siteName, String doAsUser)
throws SystemException, Exception
{
String currentUser = authenticationComponent.getCurrentUserName();
UserTransaction txn = transactionService.getUserTransaction();
try
{
if (doAsUser != null)
authenticationComponent.setCurrentUser(doAsUser);
txn.begin();
siteService.setMembership(siteName, authority, SiteModel.SITE_COLLABORATOR);
txn.commit();
}
catch (Exception e)
{
txn.rollback();
throw e;
}
finally
{
authenticationComponent.setCurrentUser(currentUser);
}
}
示例9: tearDown
import javax.transaction.UserTransaction; //导入依赖的package包/类
@Override
public void tearDown() throws Exception
{
// Deleting created test environment
logger.debug("tearDown ");
UserTransaction txn = transactionService.getUserTransaction();
txn.begin();
List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, companyHomePathInStore + "/" + NamespaceService.CONTENT_MODEL_PREFIX + ":" + IMAP_FOLDER_NAME, null,
namespaceService, false);
if (nodeRefs != null && nodeRefs.size() > 0)
{
fileFolderService.delete(nodeRefs.get(0));
}
authenticationService.deleteAuthentication(anotherUserName);
personService.deletePerson(anotherUserName);
txn.commit();
// Closing client connection
folder.close(false);
store.close();
logger.debug("tearDown end");
}
示例10: behaviourHierarchyTestWork
import javax.transaction.UserTransaction; //导入依赖的package包/类
public void behaviourHierarchyTestWork(QName createDocType, ClassFilter... disableTypes) throws Exception
{
UserTransaction transaction = trxService.getUserTransaction();
try
{
transaction.begin();
disableBehaviours(disableTypes);
try
{
createDocOfType(createDocType);
}
finally
{
enableBehaviours(disableTypes);
}
transaction.commit();
}
catch(Exception e)
{
try { transaction.rollback(); } catch (IllegalStateException ee) {}
throw e;
}
}
示例11: pushLinkCreatedDateBack
import javax.transaction.UserTransaction; //导入依赖的package包/类
/**
* Monkeys with the created date on a link
*/
private void pushLinkCreatedDateBack(String name, int daysAgo) throws Exception
{
NodeRef container = siteService.getContainer(SITE_SHORT_NAME_LINKS, "links");
NodeRef node = nodeService.getChildByName(container, ContentModel.ASSOC_CONTAINS, name);
Date created = (Date)nodeService.getProperty(node, ContentModel.PROP_CREATED);
Date newCreated = new Date(created.getTime() - daysAgo*24*60*60*1000);
UserTransaction txn = transactionService.getUserTransaction();
txn.begin();
this.policyBehaviourFilter.disableBehaviour(ContentModel.ASPECT_AUDITABLE);
internalNodeService.setProperty(node, ContentModel.PROP_CREATED, newCreated);
this.policyBehaviourFilter.enableBehaviour(ContentModel.ASPECT_AUDITABLE);
txn.commit();
// Now chance something else on the node to have it re-indexed
nodeService.setProperty(node, ContentModel.PROP_CREATED, newCreated);
nodeService.setProperty(node, ContentModel.PROP_DESCRIPTION, "Forced change");
}
示例12: getQuote
import javax.transaction.UserTransaction; //导入依赖的package包/类
/**
* @see TradeServices#getQuote(String)
*/
public QuoteDataBean getQuote(String symbol) throws Exception {
QuoteDataBean quoteData = null;
Connection conn = null;
UserTransaction txn = null;
try {
if (Log.doTrace())
Log.trace("TradeDirect:getQuote - inSession(" + this.inSession
+ ")", symbol);
conn = getConn();
quoteData = getQuote(conn, symbol);
commit(conn);
} catch (Exception e) {
Log.error("TradeDirect:getQuote -- error getting quote", e);
rollBack(conn, e);
} finally {
releaseConn(conn);
}
return quoteData;
}
示例13: testIndexOnCommitForInvalidate
import javax.transaction.UserTransaction; //导入依赖的package包/类
@Test
public void testIndexOnCommitForInvalidate() throws Exception {
AttributesFactory af = new AttributesFactory();
af.setDataPolicy(DataPolicy.REPLICATE);
Region region = cache.createRegion("sample", af.create());
qs.createIndex("foo", IndexType.FUNCTIONAL, "age", "/sample");
Context ctx = cache.getJNDIContext();
UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
Integer x = new Integer(0);
utx.begin();
region.create(x, new Person("xyz", 45));
utx.commit();
Query q = qs.newQuery("select * from /sample where age < 50");
assertEquals(1, ((SelectResults) q.execute()).size());
Person dsample = (Person) CopyHelper.copy(region.get(x));
dsample.setAge(55);
utx.begin();
region.invalidate(x);
utx.commit();
CacheUtils.log(((Person) region.get(x)));
assertEquals(0, ((SelectResults) q.execute()).size());
}
示例14: pushCreatedDateBack
import javax.transaction.UserTransaction; //导入依赖的package包/类
/**
* Monkeys with the created and published dates on a topic+posts
*/
private void pushCreatedDateBack(NodeRef node, int daysAgo) throws Exception
{
Date created = (Date)nodeService.getProperty(node, ContentModel.PROP_CREATED);
Date newCreated = new Date(created.getTime() - daysAgo*24*60*60*1000);
Date published = (Date)nodeService.getProperty(node, ContentModel.PROP_PUBLISHED);
if(published == null) published = created;
Date newPublished = new Date(published.getTime() - daysAgo*24*60*60*1000);
UserTransaction txn = transactionService.getUserTransaction();
txn.begin();
this.policyBehaviourFilter.disableBehaviour(ContentModel.ASPECT_AUDITABLE);
internalNodeService.setProperty(node, ContentModel.PROP_CREATED, newCreated);
internalNodeService.setProperty(node, ContentModel.PROP_MODIFIED, newCreated);
internalNodeService.setProperty(node, ContentModel.PROP_PUBLISHED, newPublished);
this.policyBehaviourFilter.enableBehaviour(ContentModel.ASPECT_AUDITABLE);
txn.commit();
// Now chance something else on the node to have it re-indexed
nodeService.setProperty(node, ContentModel.PROP_CREATED, newCreated);
nodeService.setProperty(node, ContentModel.PROP_MODIFIED, newCreated);
nodeService.setProperty(node, ContentModel.PROP_PUBLISHED, newPublished);
nodeService.setProperty(node, ContentModel.PROP_DESCRIPTION, "Forced change");
// Finally change any children (eg if updating a topic, do the posts)
for(ChildAssociationRef ref : nodeService.getChildAssocs(node))
{
pushCreatedDateBack(ref.getChildRef(), daysAgo);
}
}
示例15: locateUserTransaction
import javax.transaction.UserTransaction; //导入依赖的package包/类
@Override
protected UserTransaction locateUserTransaction() {
try {
final Class jbossUtClass = serviceRegistry()
.getService( ClassLoaderService.class )
.classForName( JBOSS_UT_CLASS_NAME );
return (UserTransaction) jbossUtClass.getMethod( "userTransaction" ).invoke( null );
}
catch ( Exception e ) {
throw new JtaPlatformException( "Could not obtain JBoss Transactions user transaction instance", e );
}
}