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


Java RollbackException类代码示例

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


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

示例1: testPasswordConverter

import javax.transaction.RollbackException; //导入依赖的package包/类
@Test
public void testPasswordConverter() {
	logger.info("starting persistence converter test");
	Citizen citizen = new Citizen();
	citizen.setPassword("prova");
	try {
		userTransaction.begin();
		entityManager.persist(citizen);
		userTransaction.commit();
	} catch (NotSupportedException | SystemException | IllegalStateException | SecurityException
			| HeuristicMixedException | HeuristicRollbackException | RollbackException e) {
		fail();
	}
	Citizen citizenFromDB = (Citizen) entityManager.createQuery("from citizen").getSingleResult();
	assertEquals("the password is always converted by the converter", "prova", citizenFromDB.getPassword());
	assertEquals("this is the password we have in the database", "cHJvdmE=", NEVER_DO_IT);
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:18,代码来源:ConverterTestCase.java

示例2: testSingleTable

import javax.transaction.RollbackException; //导入依赖的package包/类
/**
 * Tests annotation literals in a jar archive
 */
@Test
@SuppressWarnings("unchecked")
public void testSingleTable() {
	logger.info("starting single table inheritance test");
	Pet pet = new Pet("jackrussell", "dog");
	Dog dog = new Dog("mastino", "dog");
	try {
		userTransaction.begin();
		entityManager.persist(pet);
		entityManager.persist(dog);
		userTransaction.commit();
	} catch (NotSupportedException | SystemException | IllegalStateException | SecurityException
			| HeuristicMixedException | HeuristicRollbackException | RollbackException e) {
		fail();
	}
	List<Pet> petsFromDB = entityManager.createNativeQuery("select * from pet").getResultList();
	assertEquals("only the pet table exists", 2, petsFromDB.size());
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:22,代码来源:InheritanceTestCase.java

示例3: testTablePerClass

import javax.transaction.RollbackException; //导入依赖的package包/类
/**
 * Tests annotation literals in a jar archive
 */
@Test
@SuppressWarnings("unchecked")
public void testTablePerClass() {
	logger.info("starting table per class inheritance test");
	Vehicle vehicle = new Vehicle("peugeot", "car");
	Car car = new Car("fiat", "car");
	try {
		userTransaction.begin();
		entityManager.persist(vehicle);
		entityManager.persist(car);
		userTransaction.commit();
	} catch (NotSupportedException | SystemException | IllegalStateException | SecurityException
			| HeuristicMixedException | HeuristicRollbackException | RollbackException e) {
		fail();
	}
	List<Vehicle> vehiclesFromDB = entityManager.createNativeQuery("select * from vehicle").getResultList();
	assertEquals("the vehicle table exists", 1, vehiclesFromDB.size());
	List<Car> carsFromDB = entityManager.createNativeQuery("select * from car").getResultList();
	assertEquals("the car table exists", 1, carsFromDB.size());
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:24,代码来源:InheritanceTestCase.java

示例4: testJoin

import javax.transaction.RollbackException; //导入依赖的package包/类
/**
 * Tests annotation literals in a jar archive
 */
@Test
@SuppressWarnings("unchecked")
public void testJoin() {
	logger.info("starting joined inheritance event test");
	Watch watch = new Watch();
	TopicWatch topicWatch = new TopicWatch();
	try {
		userTransaction.begin();
		entityManager.persist(watch);
		entityManager.persist(topicWatch);
		userTransaction.commit();
	} catch (NotSupportedException | SystemException | IllegalStateException | SecurityException
			| HeuristicMixedException | HeuristicRollbackException | RollbackException e) {
		fail();
	}
	List<Watch> watchesFromDB = entityManager.createNativeQuery("select * from JBP_FORUMS_WATCH").getResultList();
	assertEquals("the watch table exists", 2, watchesFromDB.size());
	List<TopicWatch> topicWatchesFromDB = entityManager.createNativeQuery("select * from JBP_FORUMS_TOPICSWATCH")
			.getResultList();
	assertEquals("the topic watch table exists", 1, topicWatchesFromDB.size());
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:25,代码来源:InheritanceTestCase.java

示例5: testSearch

import javax.transaction.RollbackException; //导入依赖的package包/类
@Test
public void testSearch() {
	Forum forum = entityManager.find(Forum.class, 0);
	Poster poster = new Poster("root");
	Topic topic = new Topic(forum, TOPIC_TEXT);
	topic.setPoster(poster);
	Post post = new Post(topic, POST_TEXT);
	post.setCreateDate(new Date());
	post.setPoster(poster);
	try {
		userTransaction.begin();
		entityManager.persist(poster);
		entityManager.persist(topic);
		entityManager.persist(post);
		userTransaction.commit();
	} catch (NotSupportedException | SystemException | IllegalStateException | SecurityException
			| HeuristicMixedException | HeuristicRollbackException | RollbackException e) {
		e.printStackTrace();
	}
	List<Topic> topics = findTopics();
	List<Post> posts = findPosts();
	assertEquals("find topics", 1, topics.size());
	assertEquals("find posts", 1, posts.size());
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:25,代码来源:SearchTestCase.java

示例6: testDeleteManyToMany

import javax.transaction.RollbackException; //导入依赖的package包/类
@Test
public void testDeleteManyToMany() {
	logger.info("starting merge many to many cascade test");
	testPersistManyToMany();
	try {
		userTransaction.begin();
		Author davide_scala = (Author) entityManager.createQuery("from Author where fullName = :fullName")
				.setParameter("fullName", "Davide Scala").getSingleResult();
		davide_scala.remove();
		entityManager.remove(davide_scala);
		userTransaction.commit();
	} catch (NotSupportedException | SystemException | IllegalStateException | SecurityException
			| HeuristicMixedException | HeuristicRollbackException | RollbackException e) {
		fail();
	}
	@SuppressWarnings("unchecked")
	List<Book> booksFromDb = entityManager.createNativeQuery("select * from Book").getResultList();
	assertEquals("the book table exists", 2, booksFromDb.size());
	@SuppressWarnings("unchecked")
	List<Author> authorsFromDb = entityManager.createNativeQuery("select * from Author").getResultList();
	assertEquals("the author table exists", 2, authorsFromDb.size());
	@SuppressWarnings("unchecked")
	List<Author> bookAuthorsFromDb = entityManager.createNativeQuery("select * from Book_Author").getResultList();
	assertEquals("the author table exists", 4, bookAuthorsFromDb.size());
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:26,代码来源:CascadeTestCase.java

示例7: testDeleteBooksAllManyToMany

import javax.transaction.RollbackException; //导入依赖的package包/类
@Test
public void testDeleteBooksAllManyToMany() {
	logger.info("starting merge many to many cascade test");
	testPersistManyToMany();
	try {
		userTransaction.begin();
		PMAuthor davide_scala = (PMAuthor) entityManager.createQuery("from PMAuthor where fullName = :fullName")
				.setParameter("fullName", "Davide Scala").getSingleResult();
		entityManager.remove(davide_scala);
		userTransaction.commit();
	} catch (NotSupportedException | SystemException | IllegalStateException | SecurityException
			| HeuristicMixedException | HeuristicRollbackException | RollbackException e) {
		fail();
	}
	@SuppressWarnings("unchecked")
	List<PMBook> booksFromDb = entityManager.createNativeQuery("select * from PMBook").getResultList();
	assertEquals("the pm book table exists", 1, booksFromDb.size());
	@SuppressWarnings("unchecked")
	List<PMAuthor> authorsFromDb = entityManager.createNativeQuery("select * from PMAuthor").getResultList();
	assertEquals("the pm author table exists", 2, authorsFromDb.size());
	@SuppressWarnings("unchecked")
	List<PMAuthor> bookAuthorsFromDb = entityManager.createNativeQuery("select * from Book_PM_Author")
			.getResultList();
	assertEquals("the pm book author table exists", 2, bookAuthorsFromDb.size());
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:26,代码来源:CascadeTestCase.java

示例8: testDeleteBooksJoinTableAllManyToMany

import javax.transaction.RollbackException; //导入依赖的package包/类
@Test
public void testDeleteBooksJoinTableAllManyToMany() {
	logger.info("starting merge many to many cascade test");
	testPersistManyToMany();
	try {
		userTransaction.begin();
		AllAuthor davide_scala = (AllAuthor) entityManager.createQuery("from AllAuthor where fullName = :fullName")
				.setParameter("fullName", "Davide Scala").getSingleResult();
		entityManager.remove(davide_scala);
		userTransaction.commit();
	} catch (NotSupportedException | SystemException | IllegalStateException | SecurityException
			| HeuristicMixedException | HeuristicRollbackException | RollbackException e) {
		fail();
	}
	@SuppressWarnings("unchecked")
	List<AllBook> booksFromDb = entityManager.createNativeQuery("select * from AllBook").getResultList();
	assertEquals("the all book table doesn't exist", 0, booksFromDb.size());
	@SuppressWarnings("unchecked")
	List<AllAuthor> authorsFromDb = entityManager.createNativeQuery("select * from AllAuthor").getResultList();
	assertEquals("the all author table doesn't exist", 0, authorsFromDb.size());
	@SuppressWarnings("unchecked")
	List<AllAuthor> bookAuthorsFromDb = entityManager.createNativeQuery("select * from Book_All_Author")
			.getResultList();
	assertEquals("the all book author table exists", 0, bookAuthorsFromDb.size());
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:26,代码来源:CascadeTestCase.java

示例9: testSimpleTransaction

import javax.transaction.RollbackException; //导入依赖的package包/类
/**
 * Tests the fire of the event inside a transaction
 */
@Test
public void testSimpleTransaction() {
	try {
		userTransaction.begin();
		Bill bill = fire();
		assertEquals(
				"The id generation passes through the always and it is incremented only by inprogess always observer method",
				1, bill.getId());
		userTransaction.commit();
		assertEquals(
				"The id generation passes through the always and it is incremented only by transactional observer methods",
				4, bill.getId());
	} catch (NotSupportedException | SystemException | SecurityException | IllegalStateException | RollbackException
			| HeuristicMixedException | HeuristicRollbackException e) {
		fail("no fail for the transaction");
	}

}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:22,代码来源:EventTestCase.java

示例10: testFailedTransaction

import javax.transaction.RollbackException; //导入依赖的package包/类
/**
 * Tests the fire of the event inside a failed transaction
 */
@Test
public void testFailedTransaction() {
	Bill bill = null;
	try {
		userTransaction.begin();
		bill = fire();
		assertEquals(
				"The id generation passes through the always and it is incremented only by inprogess always observer method",
				1, bill.getId());
		throw new RollbackException();
	} catch (NotSupportedException | SystemException | SecurityException | IllegalStateException
			| RollbackException e) {
		try {
			userTransaction.rollback();
			assertEquals(
					"The id generation passes through the always and it is incremented only by transactional failure observer methods",
					3, bill.getId());
		} catch (SystemException se) {

		}
	}

}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:27,代码来源:EventTestCase.java

示例11: commit

import javax.transaction.RollbackException; //导入依赖的package包/类
public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
        SecurityException, SystemException
{
    try
    {
        if (isRollBackOnly)
        {
            throw new RollbackException("Commit failed: Transaction marked for rollback");
        }

    }
    finally
    {
        transaction.set(null);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:17,代码来源:SimpleTransaction.java

示例12: createUsers

import javax.transaction.RollbackException; //导入依赖的package包/类
private void createUsers() throws HeuristicRollbackException, RollbackException, HeuristicMixedException, SystemException, NotSupportedException
    {
        txn = transactionService.getUserTransaction();
        txn.begin();
        for (UserInfo user : userInfos)
        {
            String username = user.getUserName();
            NodeRef nodeRef = personService.getPersonOrNull(username);
            boolean create = nodeRef == null;
            if (create)
            {
                PropertyMap testUser = new PropertyMap();
                testUser.put(ContentModel.PROP_USERNAME, username);
                testUser.put(ContentModel.PROP_FIRSTNAME, user.getFirstName());
                testUser.put(ContentModel.PROP_LASTNAME, user.getLastName());
                testUser.put(ContentModel.PROP_EMAIL, user.getUserName() + "@acme.test");
                testUser.put(ContentModel.PROP_PASSWORD, "password");

                nodeRef = personService.createPerson(testUser);
            }
            userNodeRefs.add(nodeRef);
//            System.out.println((create ? "create" : "existing")+" user " + username + " nodeRef=" + nodeRef);
        }
        txn.commit();
    }
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:26,代码来源:PeopleTest.java

示例13: test_RollbackExceptionHandling_rollbackafterthrown

import javax.transaction.RollbackException; //导入依赖的package包/类
@Test
public void test_RollbackExceptionHandling_rollbackafterthrown()
        throws Exception {
    TransactionManager tm = mockTm();
    when(tm.getStatus()).thenReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE, Status.STATUS_MARKED_ROLLBACK);
    doThrow(new RollbackException().initCause(new OptimisticLockException())).when(tm).commit();
    XAJpaTemplate tx = new XAJpaTemplate(emSupplier, tm, coordinator);
    try {
        tx.tx(TransactionType.Required, new EmConsumer() {
            public void accept(EntityManager em) {
                em.persist(new Object());
            }
        });
    } catch (RuntimeException e) {
        // this is ok
    }
    verify(tm, times(5)).getStatus();
    verify(tm, times(1)).commit();
    verify(tm, times(1)).rollback();
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:21,代码来源:XAJpaTemplateTest.java

示例14: testPostRollbackCommitDetection

import javax.transaction.RollbackException; //导入依赖的package包/类
public void testPostRollbackCommitDetection() throws Exception
{
    testNoTxnStatus();

    txn.begin();
    txn.rollback();
    try
    {
        txn.commit();
        fail("Failed to detect rolled back txn");
    }
    catch (RollbackException e)
    {
        // expected
    }
    checkNoStatusOnThread();
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:18,代码来源:SpringAwareUserTransactionTest.java

示例15: testPostSetRollbackOnlyCommitDetection

import javax.transaction.RollbackException; //导入依赖的package包/类
public void testPostSetRollbackOnlyCommitDetection() throws Exception
{
    testNoTxnStatus();

    txn.begin();
    txn.setRollbackOnly();
    try
    {
        txn.commit();
        fail("Failed to detect set rollback");
    }
    catch (RollbackException e)
    {
        // expected
        txn.rollback();
    }
    checkNoStatusOnThread();
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:19,代码来源:SpringAwareUserTransactionTest.java


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