improced commit-rollback behaviour on multi-step transactions
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -63,10 +63,16 @@ public class SqliteDb extends BaseDb implements StockDb {
|
||||
rs.close();
|
||||
if (propertyId == null || propertyId == 0) throw failedToStoreObject(t(PROPERTY));
|
||||
insertInto(TABLE_ITEM_PROPERTIES,ITEM_ID,PROPERTY_ID,VALUE).values(itemId,propertyId,value).execute(db).close();
|
||||
db.setAutoCommit(true);
|
||||
return new Property(propertyId,name,value,unit);
|
||||
} catch (SQLException e) {
|
||||
try {
|
||||
db.rollback();
|
||||
} catch (SQLException ignored){};
|
||||
throw failedToStoreObject(t(PROPERTY)).causedBy(e);
|
||||
} finally {
|
||||
try {
|
||||
db.setAutoCommit(true);
|
||||
} catch (SQLException ignored){};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -601,13 +607,16 @@ public class SqliteDb extends BaseDb implements StockDb {
|
||||
replaceLocationsTable();
|
||||
replaceItemsTable();
|
||||
replaceItemPropsTable();
|
||||
db.setAutoCommit(true);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
db.rollback();
|
||||
} catch (SQLException ignored) {
|
||||
}
|
||||
throw databaseException(FAILED_TO_UPDATE_OBJECT, OBJECT, t(TABLE_WITH_NAME,NAME,TABLE_LOCATIONS)).causedBy(e);
|
||||
} finally {
|
||||
try {
|
||||
db.setAutoCommit(true);
|
||||
} catch (SQLException ignored){};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user