use of java.sql.Savepoint in project spanner-jdbc by olavloite.
the class SavepointTest method testRollbackSavepoint.
@Test
public void testRollbackSavepoint() throws SQLException {
connection.createStatement().execute("insert into foo (id, col1) values (1, 'test 1')");
assertEquals(1, connection.getTransaction().getNumberOfBufferedMutations());
Savepoint savepoint = connection.setSavepoint();
connection.createStatement().execute("insert into foo (id, col1) values (2, 'test 2')");
assertEquals(2, connection.getTransaction().getNumberOfBufferedMutations());
connection.rollback(savepoint);
assertEquals(1, connection.getTransaction().getNumberOfBufferedMutations());
}
use of java.sql.Savepoint in project spanner-jdbc by olavloite.
the class SavepointTest method testNamedEqualsAndHashcode.
@Test
public void testNamedEqualsAndHashcode() throws SQLException {
Savepoint s1 = connection.setSavepoint("test1");
Savepoint s2 = connection.setSavepoint("test2");
assertFalse(s1.equals(s2));
assertTrue(s1.equals(s1));
assertTrue(s2.equals(s2));
assertNotEquals(s1.hashCode(), s2.hashCode());
s1 = connection.setSavepoint("test");
s2 = connection.setSavepoint("test");
assertTrue(s1.equals(s2));
assertTrue(s1.equals(s1));
assertTrue(s2.equals(s2));
assertEquals(s1.hashCode(), s2.hashCode());
}
use of java.sql.Savepoint in project spanner-jdbc by olavloite.
the class SavepointTest method testRollbackToBegin.
@Test
public void testRollbackToBegin() throws SQLException {
Savepoint savepoint = connection.setSavepoint();
connection.createStatement().execute("insert into foo (id, col1) values (1, 'test 1')");
connection.createStatement().execute("insert into foo (id, col1) values (2, 'test 2')");
connection.createStatement().execute("insert into foo (id, col1) values (3, 'test 3')");
connection.createStatement().execute("insert into foo (id, col1) values (4, 'test 4')");
assertEquals(4, connection.getTransaction().getNumberOfBufferedMutations());
connection.rollback(savepoint);
assertEquals(0, connection.getTransaction().getNumberOfBufferedMutations());
}
use of java.sql.Savepoint in project spanner-jdbc by olavloite.
the class SavepointTest method testRollbackMultipleMutations.
@Test
public void testRollbackMultipleMutations() throws SQLException {
connection.createStatement().execute("insert into foo (id, col1) values (1, 'test 1')");
Savepoint savepoint = connection.setSavepoint();
connection.createStatement().execute("insert into foo (id, col1) values (2, 'test 2')");
connection.createStatement().execute("insert into foo (id, col1) values (3, 'test 3')");
connection.createStatement().execute("insert into foo (id, col1) values (4, 'test 4')");
assertEquals(4, connection.getTransaction().getNumberOfBufferedMutations());
connection.rollback(savepoint);
assertEquals(1, connection.getTransaction().getNumberOfBufferedMutations());
}
use of java.sql.Savepoint in project opentheso by miledrousset.
the class RelationsHelper method addRelationMT.
/**
* Cette fonction permet de rajouter une relation type Groupe ou domaine à
* un concept
*
* @param conn
* @param idConcept
* @param idGroup
* @param idThesaurus
* @param idUser
* @return boolean
*/
public boolean addRelationMT(Connection conn, String idConcept, String idThesaurus, String idGroup, int idUser) {
Statement stmt;
boolean status = false;
String query;
Savepoint savepoint = null;
try {
// Get connection from pool
savepoint = conn.setSavepoint();
try {
stmt = conn.createStatement();
try {
/* if (!new RelationsHelper().addRelationHistorique(conn, idConcept, idThesaurus, idConcept, "MT", idUser, "ADD")) {
return false;
}*/
query = "Insert into concept_group_concept" + "(idgroup, idthesaurus, idconcept)" + " values (" + "'" + idGroup + "'" + ",'" + idThesaurus + "'" + ",'" + idConcept + "')";
stmt.executeUpdate(query);
status = true;
} finally {
stmt.close();
}
} finally {
// conn.close();
}
} catch (SQLException sqle) {
// Log exception
if (sqle.getSQLState().equalsIgnoreCase("23505")) {
try {
if (savepoint != null) {
conn.rollback(savepoint);
status = true;
}
} catch (SQLException ex) {
Logger.getLogger(RelationsHelper.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
log.error("Error while adding relation Group of Concept : " + idConcept, sqle);
}
}
return status;
}
Aggregations