Simple helper to handle update / insert / delete in a SAFE mode.
Add maven dependency :
<dependency>
<groupId>org.fugerit.java</groupId>
<artifactId>sql-safe-helper</artifactId>
<version>${sql-safe-helper-version}</version>
</dependency>
Sample usage :
try ( Connection conn = ... ) {
String sql = "DELETE FROM sql_safe_test WHERE id = 1";
int expectedUpdateResult = 1;
SqlSafeHelperOutput output = facade.update( conn, expectedUpdateResult, sql );
log.info( "isRollback() : {}", output.isRollback() ); // true if a rollback has been needed
log.info( "updateResult() : {}", output.getValue() ); // update result
}
When executing the update sql, if the result is different from the expected one, there will be a rollback for the transaction.