Java Code Examples for com.j256.ormlite.support.DatabaseConnection#rollback()

The following examples show how to use com.j256.ormlite.support.DatabaseConnection#rollback() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransactionManager.java    From ormlite-core with ISC License 5 votes vote down vote up
private static void rollBack(DatabaseConnection connection, Savepoint savePoint) throws SQLException {
	String name = (savePoint == null ? null : savePoint.getSavepointName());
	connection.rollback(savePoint);
	if (name == null) {
		logger.trace("rolled back savePoint transaction");
	} else {
		logger.trace("rolled back savePoint transaction {}", name);
	}
}
 
Example 2
Source File: TransactionManagerTest.java    From ormlite-core with ISC License 5 votes vote down vote up
@Test
public void testTransactionManagerRollback() throws Exception {
	ConnectionSource connectionSource = createMock(ConnectionSource.class);
	DatabaseConnection conn = createMock(DatabaseConnection.class);
	expect(conn.isAutoCommitSupported()).andReturn(false);
	Savepoint savePoint = createMock(Savepoint.class);
	expect(savePoint.getSavepointName()).andReturn("name").anyTimes();
	expect(conn.setSavePoint(isA(String.class))).andReturn(savePoint);
	conn.rollback(savePoint);
	expect(connectionSource.getDatabaseType()).andReturn(databaseType);
	expect(connectionSource.getReadWriteConnection(null)).andReturn(conn);
	expect(connectionSource.saveSpecialConnection(conn)).andReturn(true);
	connectionSource.clearSpecialConnection(conn);
	connectionSource.releaseConnection(conn);
	replay(connectionSource, conn, savePoint);
	TransactionManager tm = new TransactionManager(connectionSource);
	try {
		tm.callInTransaction(new Callable<Void>() {
			@Override
			public Void call() throws Exception {
				throw new SQLException("you better roll back!!");
			}
		});
		fail("expected an exception");
	} catch (SQLException e) {
		// expected
	}
	verify(connectionSource, conn, savePoint);
}
 
Example 3
Source File: TransactionManagerTest.java    From ormlite-core with ISC License 5 votes vote down vote up
@Test
public void testTransactionManagerRollbackNullSavePoint() throws Exception {
	ConnectionSource connectionSource = createMock(ConnectionSource.class);
	DatabaseConnection conn = createMock(DatabaseConnection.class);
	expect(conn.isAutoCommitSupported()).andReturn(false);
	expect(conn.setSavePoint(isA(String.class))).andReturn(null);
	conn.rollback(null);
	expect(connectionSource.getDatabaseType()).andReturn(databaseType);
	expect(connectionSource.getReadWriteConnection(null)).andReturn(conn);
	expect(connectionSource.saveSpecialConnection(conn)).andReturn(true);
	connectionSource.clearSpecialConnection(conn);
	connectionSource.releaseConnection(conn);
	replay(connectionSource, conn);
	TransactionManager tm = new TransactionManager(connectionSource);
	try {
		tm.callInTransaction(new Callable<Void>() {
			@Override
			public Void call() throws Exception {
				throw new SQLException("you better roll back!!");
			}
		});
		fail("expected an exception");
	} catch (SQLException e) {
		// expected
	}
	verify(connectionSource, conn);
}
 
Example 4
Source File: TransactionManagerTest.java    From ormlite-core with ISC License 5 votes vote down vote up
@Test
public void testTransactionManagerRollbackOtherException() throws Exception {
	ConnectionSource connectionSource = createMock(ConnectionSource.class);
	DatabaseConnection conn = createMock(DatabaseConnection.class);
	expect(conn.isAutoCommitSupported()).andReturn(false);
	Savepoint savePoint = createMock(Savepoint.class);
	expect(savePoint.getSavepointName()).andReturn("name").anyTimes();
	expect(conn.setSavePoint(isA(String.class))).andReturn(savePoint);
	conn.rollback(savePoint);
	expect(connectionSource.getDatabaseType()).andReturn(databaseType);
	expect(connectionSource.getReadWriteConnection(null)).andReturn(conn);
	expect(connectionSource.saveSpecialConnection(conn)).andReturn(true);
	connectionSource.clearSpecialConnection(conn);
	connectionSource.releaseConnection(conn);
	replay(connectionSource, conn, savePoint);
	TransactionManager tm = new TransactionManager(connectionSource);
	try {
		tm.callInTransaction(new Callable<Void>() {
			@Override
			public Void call() throws Exception {
				throw new Exception("you better roll back!!");
			}
		});
		fail("expected an exception");
	} catch (Exception e) {
		// expected
	}
	verify(connectionSource, conn, savePoint);
}
 
Example 5
Source File: BaseDaoImpl.java    From ormlite-core with ISC License 4 votes vote down vote up
@Override
public void rollBack(DatabaseConnection connection) throws SQLException {
	connection.rollback(null);
}