Package net.tirasa.connid.commons.db
Class DatabaseConnection
- java.lang.Object
-
- net.tirasa.connid.commons.db.DatabaseConnection
-
public class DatabaseConnection extends Object
The DatabaseConnection wraps the JDBC connection. Define the test method meaning the wrapped connection is still valid Defines come useful method to work with prepared statements *
-
-
Constructor Summary
Constructors Constructor Description DatabaseConnection(Connection conn)Use theConfigurationpassed in to immediately connect to a database.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcommit()commit transactionvoiddispose()Closes the internalConnection.ConnectiongetConnection()Get the internal JDBC connection.CallableStatementprepareCall(String sql, List<SQLParam> params)Indirect call of prepareCall statement with mapped callable statement parametersPreparedStatementprepareStatement(String sql, List<SQLParam> params)Indirect call of prepare statement with mapped prepare statement parametersPreparedStatementprepareStatement(DatabaseQueryBuilder query)Indirect call of prepare statement using the query builder objectvoidsetConnection(Connection connection)Set the internal JDBC connection.voidtest()Determines if the underlying JDBCConnectionis valid.
-
-
-
Constructor Detail
-
DatabaseConnection
public DatabaseConnection(Connection conn)
Use theConfigurationpassed in to immediately connect to a database. If theConnectionfails aRuntimeExceptionwill be thrown.- Parameters:
conn- a connection- Throws:
RuntimeException- if there is a problem creating aConnection.
-
-
Method Detail
-
dispose
public void dispose()
Closes the internalConnection.
-
test
public void test()
Determines if the underlying JDBCConnectionis valid.- Throws:
RuntimeException- if the underlying JDBCConnectionis not valid otherwise do nothing.
-
getConnection
public Connection getConnection()
Get the internal JDBC connection.- Returns:
- the connection
-
setConnection
public void setConnection(Connection connection)
Set the internal JDBC connection.- Parameters:
connection- new connection
-
prepareStatement
public PreparedStatement prepareStatement(String sql, List<SQLParam> params) throws SQLException
Indirect call of prepare statement with mapped prepare statement parameters- Parameters:
sql- aStringsql statement definitionparams- the bind parameter values- Returns:
- return a prepared statement
- Throws:
SQLException- an exception in statement
-
prepareStatement
public PreparedStatement prepareStatement(DatabaseQueryBuilder query) throws SQLException
Indirect call of prepare statement using the query builder object- Parameters:
query- DatabaseQueryBuilder query- Returns:
- return a prepared statement
- Throws:
SQLException- an exception in statement
-
prepareCall
public CallableStatement prepareCall(String sql, List<SQLParam> params) throws SQLException
Indirect call of prepareCall statement with mapped callable statement parameters- Parameters:
sql- aStringsql statement definitionparams- the bind parameter values- Returns:
- return a callable statement
- Throws:
SQLException- an exception in statement
-
commit
public void commit()
commit transaction
-
-