use of java.sql.Savepoint in project sqlite-jna by gwenn.
the class SavepointTest method rollback.
@Test
public void rollback() throws SQLException {
String select = "select * from trans;";
ResultSet rs;
stat1.executeUpdate("create table trans (c1);");
Savepoint sp = conn1.setSavepoint();
stat1.executeUpdate("insert into trans values (3);");
rs = stat1.executeQuery(select);
assertTrue(rs.next());
rs.close();
conn1.rollback(sp);
rs = stat1.executeQuery(select);
assertFalse(rs.next());
rs.close();
}
use of java.sql.Savepoint in project sqlite-jna by gwenn.
the class TransactionTest method unnamedSavepoint.
@Test
public void unnamedSavepoint() throws SQLException {
Savepoint spt = conn1.setSavepoint();
conn1.rollback(spt);
conn1.releaseSavepoint(spt);
}
use of java.sql.Savepoint in project jOOQ by jOOQ.
the class DefaultTransactionProvider method begin.
@Override
public final void begin(TransactionContext ctx) {
Deque<Savepoint> savepoints = savepoints(ctx.configuration());
// This is the top-level transaction
if (savepoints.isEmpty())
brace(ctx.configuration(), true);
Savepoint savepoint = setSavepoint(ctx.configuration());
if (savepoint == UNSUPPORTED_SAVEPOINT && !savepoints.isEmpty())
throw new DataAccessException("Cannot nest transactions because Savepoints are not supported");
savepoints.push(savepoint);
}
use of java.sql.Savepoint in project robovm by robovm.
the class OldConnectionTest method testSetSavepoint_String.
// TODO setSavepoint is not supported
public void testSetSavepoint_String() throws SQLException {
String testSavepoint = "testSavepoint";
conn.setAutoCommit(false);
try {
Savepoint sp = conn.setSavepoint(testSavepoint);
} catch (SQLException e) {
// ok not supported
}
/*
Statement st = null;
Statement st1 = null;
ResultSet rs1 = null;
try {
conn.setAutoCommit(false);
st = conn.createStatement();
st
.execute("insert into zoo (id, name, family) values (3, 'Vorobey', 'sparrow');");
st
.execute("insert into zoo (id, name, family) values (4, 'Orel', 'eagle');");
if (!conn.getAutoCommit()) {
st1 = conn.createStatement();
st1.execute("select * from zoo");
rs1 = st1.getResultSet();
assertEquals(4, getCount(rs1));
Statement st2 = null;
ResultSet rs2 = null;
try {
Savepoint sp = conn.setSavepoint("one");
st
.execute("insert into zoo (id, name, family) values (5, 'chayka', 'gull');");
conn.rollback(sp);
st2 = conn.createStatement();
st2.execute("select * from zoo");
rs2 = st2.getResultSet();
assertEquals(4, getCount(rs2));
} catch (SQLException e) {
fail("SQLException is thrown: " + e.toString());
} finally {
try {
rs2.close();
st2.close();
} catch (Exception ee) {
}
}
try {
Savepoint sp1 = conn.setSavepoint("one");
st
.execute("insert into zoo (id, name, family) values (5, 'chayka', 'gull');");
Savepoint sp2 = conn.setSavepoint("two");
st
.execute("insert into zoo (id, name, family) values (6, 'grach', 'rook');");
conn.rollback(sp1);
st2 = conn.createStatement();
st2.execute("select * from zoo");
rs2 = st2.getResultSet();
assertEquals(4, getCount(rs2));
} catch (SQLException e) {
fail("SQLException is thrown: " + e.toString());
} finally {
try {
rs2.close();
st2.close();
} catch (SQLException ee) {
}
}
try {
Savepoint sp1 = conn.setSavepoint("three");
st
.execute("insert into zoo (id, name, family) values (5, 'chayka', 'gull');");
Savepoint sp2 = conn.setSavepoint("four");
st
.execute("insert into zoo (id, name, family) values (6, 'grach', 'rook');");
conn.rollback();
st2 = conn.createStatement();
st2.execute("select * from zoo");
rs2 = st2.getResultSet();
assertEquals(4, getCount(rs2));
} catch (SQLException e) {
fail("SQLException is thrown: " + e.toString());
} finally {
try {
rs2.close();
st2.close();
} catch (SQLException ee) {
}
}
} else {
st1 = conn.createStatement();
st1.execute("select * from zoo");
rs1 = st1.getResultSet();
assertEquals(4, getCount(rs1));
try {
Savepoint sp = conn.setSavepoint("five");
st
.execute("insert into zoo (id, name, family) values (5, 'chayka', 'gull');");
conn.rollback(sp);
fail("SQLException is not thrown");
} catch (SQLException sqle) {
// expected
}
}
} catch (SQLException sqle) {
fail("SQLException is thrown: " + sqle.toString());
} finally {
try {
rs1.close();
st.close();
st1.close();
} catch (SQLException ee) {
}
}
*/
}
use of java.sql.Savepoint in project robovm by robovm.
the class OldConnectionTest method testRollback_Savepoint.
// TODO Savepoint is not supported
public void testRollback_Savepoint() throws SQLException {
Savepoint sp = new DummySavePoint();
conn.setAutoCommit(false);
try {
conn.rollback(sp);
} catch (SQLException e) {
//ok
}
/*
Statement st = null;
Statement st1 = null;
ResultSet rs1 = null;
try {
conn.setAutoCommit(false);
st = conn.createStatement();
st
.execute("insert into zoo (id, name, family) values (3, 'Vorobey', 'sparrow');");
st
.execute("insert into zoo (id, name, family) values (4, 'Orel', 'eagle');");
if (!conn.getAutoCommit()) {
st1 = conn.createStatement();
st1.execute("select * from zoo");
rs1 = st1.getResultSet();
assertEquals(4, getCount(rs1));
Statement st2 = null;
ResultSet rs2 = null;
try {
Savepoint sp = conn.setSavepoint("one");
st
.execute("insert into zoo (id, name, family) values (5, 'chayka', 'gull');");
conn.rollback(sp);
st2 = conn.createStatement();
st2.execute("select * from zoo");
rs2 = st2.getResultSet();
assertEquals(4, getCount(rs2));
} catch (SQLException e) {
fail("SQLException is thrown: " + e.toString());
} finally {
try {
rs2.close();
st2.close();
} catch (Exception ee) {
}
}
try {
Savepoint sp1 = conn.setSavepoint("one");
st
.execute("insert into zoo (id, name, family) values (5, 'chayka', 'gull');");
Savepoint sp2 = conn.setSavepoint("two");
st
.execute("insert into zoo (id, name, family) values (6, 'grach', 'rook');");
conn.rollback(sp1);
st2 = conn.createStatement();
st2.execute("select * from zoo");
rs2 = st2.getResultSet();
assertEquals(4, getCount(rs2));
} catch (SQLException e) {
fail("SQLException is thrown: " + e.toString());
} finally {
try {
rs2.close();
st2.close();
} catch (SQLException ee) {
}
}
try {
Savepoint sp1 = conn.setSavepoint("three");
st
.execute("insert into zoo (id, name, family) values (5, 'chayka', 'gull');");
Savepoint sp2 = conn.setSavepoint("four");
st
.execute("insert into zoo (id, name, family) values (6, 'grach', 'rook');");
conn.rollback();
st2 = conn.createStatement();
st2.execute("select * from zoo");
rs2 = st2.getResultSet();
assertEquals(4, getCount(rs2));
} catch (SQLException e) {
fail("SQLException is thrown: " + e.toString());
} finally {
try {
rs2.close();
st2.close();
} catch (SQLException ee) {
}
}
} else {
st1 = conn.createStatement();
st1.execute("select * from zoo");
rs1 = st1.getResultSet();
assertEquals(4, getCount(rs1));
try {
Savepoint sp = conn.setSavepoint("five");
st
.execute("insert into zoo (id, name, family) values (5, 'chayka', 'gull');");
conn.rollback(sp);
fail("SQLException is not thrown");
} catch (SQLException sqle) {
// expected
}
}
} catch (SQLException sqle) {
fail("SQLException is thrown: " + sqle.toString());
} finally {
try {
rs1.close();
st.close();
st1.close();
} catch (SQLException ee) {
}
}
*/
}
Aggregations