- java.lang.Object
-
- aeonics.entity.Database.PooledConnection
-
- All Implemented Interfaces:
java.lang.AutoCloseable
- Enclosing class:
- Database
public static class Database.PooledConnection extends java.lang.Object implements java.lang.AutoCloseable
This class is a wrapper around a java.sql.Connection class to be used with the pooledDatabase.Type
.
-
-
Constructor Summary
Constructors Constructor Description PooledConnection(Database.Type pool, java.sql.Connection connection)
Creates a new connection attached to the specified pool
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Return this connection to the pool after a query operation is complete.Data
columns(java.lang.String table)
Returns the list of columns in the specified table.void
destroy()
Closes the underlying database connection.boolean
isValid()
Returns true if the underlying database connection is ready to perform a queryData
query(java.lang.String sql, java.lang.Object... params)
Performs a query.Data
tables()
Returns the list of tables that can be accessed from this connection.
-
-
-
Constructor Detail
-
PooledConnection
public PooledConnection(Database.Type pool, java.sql.Connection connection)
Creates a new connection attached to the specified pool- Parameters:
pool
- the connection poolconnection
- the underlying jdbc connection
-
-
Method Detail
-
destroy
public void destroy()
Closes the underlying database connection. Do not confuse this method with theclose()
method that simply returns this object to the connection pool.
-
isValid
public boolean isValid()
Returns true if the underlying database connection is ready to perform a query- Returns:
- true if the underlying database connection is ready to perform a query
-
query
public Data query(java.lang.String sql, java.lang.Object... params) throws java.sql.SQLException
Performs a query.CAUTION : use in a
try...with
statement or do not forget toclose()
after use to return to the pool The returned column names should ALWAYS be lower case.The parameters provided for substitution will be provided to the underlying connection using
PreparedStatement.setObject(int, Object)
so that the compatibility with String values is maximized. (see JDBC 4.3 Specification (JSR 221) Table B.5 for Conversions Performed by setObject and setNull Between Java Object Types and Target JDBC Types)- Parameters:
sql
- the parameterized query to performparams
- the parameters to substitute.- Returns:
- the resulset (Data list), the inserted primary key (Data object), or the number of affected rows depending on the case
- Throws:
java.sql.SQLException
- if an error occurs at the database level
-
close
public void close()
Return this connection to the pool after a query operation is complete.You should not need to call this method manually if used in a
try...with
statement.- Specified by:
close
in interfacejava.lang.AutoCloseable
-
tables
public Data tables() throws java.sql.SQLException
Returns the list of tables that can be accessed from this connection.The returned data is a list of table descriptions that include:
- name: the table name
- schema: the table schema
- database: the table database (or catalog in JDBC terms)
- Returns:
- the list of tables
- Throws:
java.sql.SQLException
- if an error happens- See Also:
DatabaseMetaData.getTables(String, String, String, String[])
-
columns
public Data columns(java.lang.String table) throws java.sql.SQLException
Returns the list of columns in the specified table.The returned data is a list of table descriptions that include:
- name: the column name
- size: the column data type size
- auto: whether or not the column has a default or auto-increment value
- null: whether or not the column accepts null values
- type: the JDBC data type as a string
- primary: whether or not the column is part of a primary key
- Parameters:
table
- the name of the table- Returns:
- the list of columns
- Throws:
java.sql.SQLException
- if an error happens- See Also:
DatabaseMetaData.getColumns(String, String, String, String)
,JDBCType
-
-