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
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
close
(Connection connection) Closes the providedConnection
object if there is no active transaction.static void
close
(Connection connection, PreparedStatement ps) Closes both the providedConnection
andPreparedStatement
objects.static void
Closes the providedPreparedStatement
object.
-
Constructor Details
-
TransactionJdbcUtils
public TransactionJdbcUtils()
-
-
Method Details
-
close
Closes both the providedConnection
andPreparedStatement
objects. 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 providedPreparedStatement
object. 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 providedConnection
object 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
-