Package fr.paris.lutece.util.sql
Class Transaction
java.lang.Object
fr.paris.lutece.util.sql.Transaction
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
MultiPluginTransaction
Transaction
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intStatus for committed transactionsstatic final intStatus for opened transactionsstatic final intStatus for roll backed transactions -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Checks that the transaction has been committed (or rolled back) before being destroyed and release all transaction resources (statement, connection, ...) if not.voidcommit()Commit the transactionvoidExecute the current statementThe current prepared statementintReturn the transaction statusprepareStatement(String strSQL) Gets a prepared statementprepareStatement(String strSQL, boolean bLogQueries) Gets a prepared statementprepareStatement(String strSQL, Integer autoGeneratedKeys) Gets a prepared statementprepareStatement(String strSQL, Integer autoGeneratedKeys, boolean bLogQueries) Gets a prepared statementvoidrollback()Rollback the transactionvoidRollback the transaction
-
Field Details
-
OPENED
public static final int OPENEDStatus for opened transactions- See Also:
-
COMMITTED
public static final int COMMITTEDStatus for committed transactions- See Also:
-
ROLLEDBACK
public static final int ROLLEDBACKStatus for roll backed transactions- See Also:
-
-
Constructor Details
-
Transaction
public Transaction()Constructor -
Transaction
Constructor- Parameters:
plugin- The plugin owner of the transaction
-
-
Method Details
-
prepareStatement
Gets a prepared statement- Parameters:
strSQL- The SQL statement- Returns:
- The prepared statement
- Throws:
SQLException- If an SQL error occurs
-
prepareStatement
public PreparedStatement prepareStatement(String strSQL, Integer autoGeneratedKeys) throws SQLException Gets a prepared statement- Parameters:
strSQL- The SQL statement- Returns:
- The prepared statement
- Throws:
SQLException- If an SQL error occurs
-
prepareStatement
Gets a prepared statement- Parameters:
strSQL- The SQL statement- Returns:
- The prepared statement
- Throws:
SQLException- If an SQL error occurs
-
prepareStatement
public PreparedStatement prepareStatement(String strSQL, Integer autoGeneratedKeys, boolean bLogQueries) throws SQLException Gets a prepared statement- Parameters:
strSQL- The SQL statementautoGeneratedKeys- a flag indicating whether auto-generated keys should be returned; For example one ofStatement.RETURN_GENERATED_KEYSorStatement.NO_GENERATED_KEYS. SeePreparedStatement#prepareStatement(String, int)- Returns:
- The prepared statement
- Throws:
SQLException- If an SQL error occurs- Since:
- 6.0.0
-
getStatement
The current prepared statement- Returns:
- The current statement
-
executeStatement
Execute the current statement- Throws:
SQLException- If an SQL error occurs
-
commit
public void commit()Commit the transaction -
rollback
public void rollback()Rollback the transaction -
rollback
Rollback the transaction- Parameters:
e- The exception that cause the rollback
-
getStatus
public int getStatus()Return the transaction status- Returns:
- The transaction status
-
close
public void close()Checks that the transaction has been committed (or rolled back) before being destroyed and release all transaction resources (statement, connection, ...) if not.- Specified by:
closein interfaceAutoCloseable
-