improced commit-rollback behaviour on multi-step transactions
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -198,11 +198,17 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
rs.close();
|
||||
delete().from(TABLE_POSITIONS).where(DOCUMENT_ID,equal(docId)).execute(db);
|
||||
delete().from(TABLE_DOCUMENTS).where(ID,equal(docId)).execute(db);
|
||||
db.setAutoCommit(true);
|
||||
if (number != null) return number;
|
||||
throw failedToDropObject(t(DOCUMENT_WITH_ID, ID,docId));
|
||||
} catch (SQLException e){
|
||||
try {
|
||||
db.rollback();
|
||||
} catch (SQLException ignored){};
|
||||
throw failedToDropObject(t(DOCUMENT_WITH_ID, ID,docId)).causedBy(e);
|
||||
} finally {
|
||||
try {
|
||||
db.setAutoCommit(true);
|
||||
} catch (SQLException ignored){};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,10 +223,16 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
stmt.setLong(2,pos);
|
||||
stmt.execute();
|
||||
stmt.close();
|
||||
db.setAutoCommit(true);
|
||||
return pos;
|
||||
} catch (SQLException e) {
|
||||
try {
|
||||
db.rollback();
|
||||
} catch (SQLException ignored){};
|
||||
throw failedToDropObjectFromObject(POSITION,pos,t(Text.DOCUMENT),docId).causedBy(e);
|
||||
} finally {
|
||||
try {
|
||||
db.setAutoCommit(true);
|
||||
} catch (SQLException ignored){};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -582,9 +594,15 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
update(TABLE_POSITIONS).set(POS).where(DOCUMENT_ID,equal(docId)).where(POS,equal(pair.left())).prepare(db).apply(-pair.right()).close();
|
||||
update(TABLE_POSITIONS).set(POS).where(DOCUMENT_ID,equal(docId)).where(POS,equal(pair.right())).prepare(db).apply(pair.left()).close();
|
||||
update(TABLE_POSITIONS).set(POS).where(DOCUMENT_ID,equal(docId)).where(POS,equal(-pair.right())).prepare(db).apply(pair.right()).close();
|
||||
db.setAutoCommit(true);
|
||||
} catch (SQLException e) {
|
||||
try {
|
||||
db.rollback();
|
||||
} catch (SQLException ignored){};
|
||||
throw databaseException(FAILED_TO_SWITCH_POSITIONS,"a",pair.left(),"b",pair.right(),docId).causedBy(e);
|
||||
} finally {
|
||||
try {
|
||||
db.setAutoCommit(true);
|
||||
} catch (SQLException ignored){};
|
||||
}
|
||||
return pair;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user