Class TransactionJdbcUtils
java.lang.Object
io.github.blyznytsiaorg.bibernate.transaction.TransactionJdbcUtils
The
TransactionJdbcUtils class provides utility methods for handling JDBC resources in the context of transactions.
It encapsulates methods to close JDBC connections and prepared statements, considering the transactional context.
The class includes methods to close both PreparedStatement and Connection objects,
ensuring proper handling of resources and exceptions.
This utility class is designed to simplify the management of JDBC resources, ensuring proper handling of exceptions and avoiding common pitfalls related to connection management in transactional contexts.
- Since:
- 1.0
- Author:
- Blyzhnytsia Team
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclose(Connection connection) Closes the providedConnectionobject if there is no active transaction.static voidclose(Connection connection, PreparedStatement ps) Closes both the providedConnectionandPreparedStatementobjects.static voidCloses the providedPreparedStatementobject.
-
Constructor Details
-
TransactionJdbcUtils
public TransactionJdbcUtils()
-
-
Method Details
-
close
Closes both the providedConnectionandPreparedStatementobjects. This method ensures proper resource handling, and any exceptions during the process are encapsulated in aBibernateGeneralException.- Parameters:
connection- The JDBC connection to closeps- The prepared statement to close- Throws:
BibernateGeneralException- If an error occurs while closing the resources
-
close
Closes the providedPreparedStatementobject. This method ensures proper resource handling, and any exceptions during the process are encapsulated in aBibernateGeneralException.- Parameters:
ps- The prepared statement to close- Throws:
BibernateGeneralException- If an error occurs while closing the prepared statement
-
close
Closes the providedConnectionobject if there is no active transaction. This method checks if there is an active transaction using theTransactionHolder, and only closes the connection if there is no active transaction. Any exceptions during the process are encapsulated in aBibernateGeneralException.- Parameters:
connection- The JDBC connection to close- Throws:
BibernateGeneralException- If an error occurs while closing the connection
-