當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。