當前位置: 首頁>>代碼示例>>Java>>正文


Java TransactionMode.ROLLBACK屬性代碼示例

本文整理匯總了Java中org.unitils.database.util.TransactionMode.ROLLBACK屬性的典型用法代碼示例。如果您正苦於以下問題:Java TransactionMode.ROLLBACK屬性的具體用法?Java TransactionMode.ROLLBACK怎麽用?Java TransactionMode.ROLLBACK使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.unitils.database.util.TransactionMode的用法示例。


在下文中一共展示了TransactionMode.ROLLBACK屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testReportingTransaction

@Test
@Transactional(TransactionMode.ROLLBACK)
public void testReportingTransaction() throws Exception {

	java.util.Date date = new java.util.Date();
	Timestamp timestamp = new Timestamp(date.getTime());

	Submission submission1 = new Submission();
	submission1.setParentId(new Long(1));
	submission1.setRevisionNumber(new Long(123));
	submission1.setRevisionUserId("user1");
	submission1.setName("Nurul");
	submission1.setType("TYPE1");
	submission1.setGroup("KME");
	submission1.setActive(10);
	submission1.setPostDate(timestamp);
	submission1.setArchivedDate(timestamp);
	submission1.setIpAddress("192.168.54.32");
	submission1.setUserAgent("Chrome");
	submission1.setUserId("nurul1988");
	submission1.setVersionNumber(new Long(12345));

	assertTrue("ID is not null.", submission1.getId() == null);

	Long id1 = dao.saveSubmission(submission1);
	LOG.debug("Submission 1 ID is: " + id1);
	assertTrue("Failed to save Submission1", id1 != null);

	Submission submission2 = new Submission();
	submission2.setParentId(new Long(1));
	submission2.setRevisionNumber(new Long(234));
	submission2.setRevisionUserId("user2");
	submission2.setName("Joe");
	submission2.setGroup("KME");
	submission2.setActive(15);
	submission2.setPostDate(timestamp);
	submission2.setArchivedDate(timestamp);
	submission2.setIpAddress("192.168.54.28");
	submission2.setUserAgent("Chrome");
	submission2.setUserId("joeswan");
	submission2.setVersionNumber(new Long(23546));

	assertTrue("ID is not null.", submission2.getId() == null);

	Long id2 = dao.saveSubmission(submission2);
	assertTrue("Failed to save Submission2", id2 != null);

	submission2.setType("TYPE2");

	Long id2s = dao.saveSubmission(submission2);

	assertTrue("Submission 2 updated but inserted a new row.", id2.compareTo(id2s) == 0);

	List<Submission> submissionList1 = dao.findAllSubmissions();
	assertTrue("No Submission found.", submissionList1 != null && submissionList1.size() > 0);
	assertTrue("Expected 2 Submissions, found " + submissionList1.size(), submissionList1.size() == 2);

	Submission submission3 = dao.findSubmissionById(submission2.getId());
	assertTrue("Failed to find submission by ID", submission3 != null);
	assertTrue("Submission found for ID " + submission2.getId() + " but objects are not equal.", submission2.equals(submission3));


	List<Submission> submissionList2 = dao.findAllSubmissionsByParentId(new Long(1));
	assertTrue("Failed to find submission by parent ID", submissionList2 != null && submissionList2.size() > 0);
	assertTrue("Expected 2 Submissions, found " + submissionList2.size(), submissionList2.size() == 2);
}
 
開發者ID:tamerman,項目名稱:mobile-starting-framework,代碼行數:66,代碼來源:ReportingDaoImplTest.java

示例2: testReportingTransaction

@Test
@Transactional(TransactionMode.ROLLBACK)
public void testReportingTransaction() throws Exception {

	java.util.Date date = new java.util.Date();
	Timestamp timestamp = new Timestamp(date.getTime());

	Submission submission1 = new Submission();
	submission1.setParentId(new Long(1));
	submission1.setRevisionNumber(new Long(123));
	submission1.setRevisionUserId("user1");
	submission1.setName("Nurul");
	submission1.setType("TYPE1");
	submission1.setGroup("KME");
	submission1.setActive(10);
	submission1.setPostDate(timestamp);
	submission1.setArchivedDate(timestamp);
	submission1.setIpAddress("192.168.54.32");
	submission1.setUserAgent("Chrome");
	submission1.setUserId("nurul1988");
	submission1.setVersionNumber(new Long(12345));

	assertTrue("ID is not null.", submission1.getId() == null);

	Long id1 = getService().saveSubmission(submission1);
	LOG.debug("Submission 1 ID is: " + id1);
	assertTrue("Failed to save Submission1", id1 != null);

	Submission submission2 = new Submission();
	submission2.setParentId(new Long(1));
	submission2.setRevisionNumber(new Long(234));
	submission2.setRevisionUserId("user2");
	submission2.setName("Joe");
	submission2.setGroup("KME");
	submission2.setActive(15);
	submission2.setPostDate(timestamp);
	submission2.setArchivedDate(timestamp);
	submission2.setIpAddress("192.168.54.28");
	submission2.setUserAgent("Chrome");
	submission2.setUserId("joeswan");
	submission2.setVersionNumber(new Long(23546));

	assertTrue("ID is not null.", submission2.getId() == null);

	Long id2 = getService().saveSubmission(submission2);
	assertTrue("Failed to save Submission2", id2 != null);

	submission2.setType("TYPE2");

	Long id2s = getService().saveSubmission(submission2);

	assertTrue("Submission 2 updated but inserted a new row.", id2.compareTo(id2s) == 0);

	List<Submission> submissionList1 = getService().findAllSubmissions();
	assertTrue("No Submission found.", submissionList1 != null && submissionList1.size() > 0);
	assertTrue("Expected 2 Submissions, found " + submissionList1.size(), submissionList1.size() == 2);

	Submission submission3 = getService().findSubmissionById(submission2.getId());
	assertTrue("Failed to find submission by ID", submission3 != null);
	assertTrue("Submission found for ID " + submission2.getId() + " but objects are not equal.", submission2.equals(submission3));


	List<Submission> submissionList2 = getService().findAllSubmissionsByParentId(new Long(1));
	assertTrue("Failed to find submission by parent ID", submissionList2 != null && submissionList2.size() > 0);
	assertTrue("Expected 2 Submissions, found " + submissionList2.size(), submissionList2.size() == 2);
}
 
開發者ID:tamerman,項目名稱:mobile-starting-framework,代碼行數:66,代碼來源:ReportingServiceImplTest.java

示例3: testFileService

@Test
@Transactional(TransactionMode.ROLLBACK)
public void testFileService() {
	File file = new File();
	try {
		InputStream in = this.getClass().getClassLoader().getResourceAsStream(FILE_NAME);
		byte[] inputFile = IOUtils.toByteArray(in);
		file.setBytes(inputFile);
		file.setFileSize(inputFile.length);
	} catch (IOException ioe) {
		LOG.error(ioe.getLocalizedMessage(), ioe);
	}
	file.setFileName(FILE_NAME);
	file.setContentType(CONTENT_TYPE);
	file.setPostedTimestamp(new Timestamp(Calendar.getInstance().getTimeInMillis()));

	assertTrue("File has an ID and should not have.", file.getId() == null);

	Long fileId = getService().saveFile(file);

	LOG.debug("New file id is: " + fileId);

	assertTrue("Could not save file.", fileId != null && fileId.intValue() > 0);

	File lookupFile = getService().findFileById(fileId);

	assertTrue("Failed to find file for ID " + fileId, lookupFile != null);

	List<File> listOfFiles = getService().findFilesByName(FILE_NAME);

	assertTrue("Failed to find files for name " + FILE_NAME, listOfFiles != null && listOfFiles.size() == 1);

	List<File> allFiles = getService().findAllFiles();

	assertTrue("Failed to find all files.", allFiles != null && allFiles.size() == 1);

	File fileToRemove = allFiles.get(0);
	boolean didRemove = getService().removeFile(fileToRemove);

	assertTrue("Failed to remove file ID " + fileToRemove.getId(), didRemove);

	allFiles = getService().findAllFiles();

	assertTrue("Found files and should not have.", allFiles == null || allFiles.size() == 0);
}
 
開發者ID:tamerman,項目名稱:mobile-starting-framework,代碼行數:45,代碼來源:FileServiceImplTest.java

示例4: testFileDao

@Test
@Transactional(TransactionMode.ROLLBACK)
public void testFileDao() {
	File file = new File();
	try {
		InputStream in = this.getClass().getClassLoader().getResourceAsStream(FILE_NAME);
		byte[] inputFile = IOUtils.toByteArray(in);
		file.setBytes(inputFile);
		file.setFileSize(inputFile.length);
	} catch (IOException ioe) {
		LOG.error(ioe.getLocalizedMessage(), ioe);
	}
	file.setFileName(FILE_NAME);
	file.setContentType(CONTENT_TYPE);
	file.setPostedTimestamp(new Timestamp(Calendar.getInstance().getTimeInMillis()));

	assertTrue("File has an ID and should not have.", file.getId() == null);

	Long fileId = getDao().saveFile(file);

	LOG.debug("New file id is: " + fileId);

	assertTrue("Could not save file.", fileId != null && fileId.intValue() > 0);

	file.setContentType("text/xml");
	Long fileId2 = getDao().saveFile(file);

	assertTrue("File was inserted again, not updated.", fileId.compareTo(fileId2) == 0);

	File lookupFile = getDao().findFileById(fileId);

	assertTrue("Failed to find file for ID " + fileId, lookupFile != null);

	List<File> listOfFiles = getDao().findFilesByName(FILE_NAME);

	assertTrue("Failed to find files for name " + FILE_NAME, listOfFiles != null && listOfFiles.size() == 1);

	List<File> allFiles = getDao().findAllFiles();

	assertTrue("Failed to find all files.", allFiles != null && allFiles.size() == 1);

	File fileToRemove = allFiles.get(0);
	boolean didRemove = getDao().removeFile(fileToRemove);

	assertTrue("Failed to remove file ID " + fileToRemove.getId(), didRemove);

	allFiles = getDao().findAllFiles();

	assertTrue("Found files and should not have.", allFiles == null || allFiles.size() == 0);

	didRemove = getDao().removeFile(null);
	assertFalse("Removed a null file. How is that possible?", didRemove);

	Long nullId = getDao().saveFile(null);
	assertTrue("Saved a null file. How is that possible?", nullId == null);
}
 
開發者ID:tamerman,項目名稱:mobile-starting-framework,代碼行數:56,代碼來源:FileDaoImplTest.java


注:本文中的org.unitils.database.util.TransactionMode.ROLLBACK屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。