Package org.xipki.datasource
Class DataSourceWrapper
- java.lang.Object
-
- org.xipki.datasource.DataSourceWrapper
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public abstract class DataSourceWrapper extends Object implements Closeable
A wrapper ofHikariDataSource.- Since:
- 2.0.0
- Author:
- Lijun Liao (xipki)
-
-
Method Summary
-
-
-
Field Detail
-
service
protected final com.zaxxer.hikari.HikariDataSource service
References the real data source implementation this class acts as pure proxy for. Derived classes must set this field at construction time.
-
name
protected final String name
-
-
Method Detail
-
getName
public final String getName()
-
getDatabaseType
public final DatabaseType getDatabaseType()
-
getMaximumPoolSize
public final int getMaximumPoolSize()
-
getConnection
public final Connection getConnection() throws DataAccessException
- Throws:
DataAccessException
-
returnConnection
public void returnConnection(Connection conn)
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
getLogWriter
public final PrintWriter getLogWriter() throws SQLException
- Throws:
SQLException
-
createStatement
public Statement createStatement(Connection conn) throws DataAccessException
- Throws:
DataAccessException
-
createStatement
public Statement createStatement() throws DataAccessException
- Throws:
DataAccessException
-
prepareStatement
public PreparedStatement prepareStatement(Connection conn, String sqlQuery) throws DataAccessException
- Throws:
DataAccessException
-
prepareStatement
public PreparedStatement prepareStatement(String sqlQuery) throws DataAccessException
- Throws:
DataAccessException
-
releaseResources
public void releaseResources(Statement ps, ResultSet rs, boolean returnConnection)
-
buildSelectFirstSql
public abstract String buildSelectFirstSql(int rows, String orderBy, String coreSql)
-
getFirstStringValue
public String getFirstStringValue(Connection conn, String table, String column, String criteria) throws DataAccessException
- Throws:
DataAccessException
-
getFirstIntValue
public Integer getFirstIntValue(Connection conn, String table, String column, String criteria) throws DataAccessException
- Throws:
DataAccessException
-
getFirstLongValue
public Long getFirstLongValue(Connection conn, String table, String column, String criteria) throws DataAccessException
- Throws:
DataAccessException
-
getMin
public long getMin(Connection conn, String table, String column) throws DataAccessException
- Throws:
DataAccessException
-
getMin
public long getMin(Connection conn, String table, String column, String condition) throws DataAccessException
- Throws:
DataAccessException
-
getCount
public int getCount(Connection conn, String table) throws DataAccessException
- Throws:
DataAccessException
-
getMax
public long getMax(Connection conn, String table, String column) throws DataAccessException
- Throws:
DataAccessException
-
getMax
public long getMax(Connection conn, String table, String column, String condition) throws DataAccessException
- Throws:
DataAccessException
-
deleteFromTable
public boolean deleteFromTable(Connection conn, String table, String idColumn, long id)
-
deleteFromTableWithException
public void deleteFromTableWithException(Connection conn, String table, String idColumn, long id) throws SQLException, DataAccessException
- Throws:
SQLExceptionDataAccessException
-
columnExists
public boolean columnExists(Connection conn, String table, String column, Object value) throws DataAccessException
- Throws:
DataAccessException
-
tableHasColumn
public boolean tableHasColumn(Connection conn, String table, String column) throws DataAccessException
- Throws:
DataAccessException
-
tableExists
public boolean tableExists(Connection conn, String table) throws DataAccessException
- Throws:
DataAccessException
-
buildCreateSequenceSql
protected abstract String buildCreateSequenceSql(String sequenceName, long startValue)
-
buildAndCacheNextSeqValueSql
protected final String buildAndCacheNextSeqValueSql(String sequenceName)
-
isUseSqlStateAsCode
protected boolean isUseSqlStateAsCode()
-
dropAndCreateSequence
public void dropAndCreateSequence(String sequenceName, long startValue) throws DataAccessException
- Throws:
DataAccessException
-
createSequence
public void createSequence(String sequenceName, long startValue) throws DataAccessException
- Throws:
DataAccessException
-
dropSequence
public void dropSequence(String sequenceName) throws DataAccessException
- Throws:
DataAccessException
-
setLastUsedSeqValue
public void setLastUsedSeqValue(String sequenceName, long sequenceValue)
-
nextSeqValue
public long nextSeqValue(Connection conn, String sequenceName) throws DataAccessException
- Throws:
DataAccessException
-
getSqlToDropPrimaryKey
protected String getSqlToDropPrimaryKey(String primaryKeyName, String table)
-
dropPrimaryKey
public void dropPrimaryKey(Connection conn, String primaryKeyName, String table) throws DataAccessException
- Throws:
DataAccessException
-
getSqlToAddPrimaryKey
protected String getSqlToAddPrimaryKey(String primaryKeyName, String table, String... columns)
-
addPrimaryKey
public void addPrimaryKey(Connection conn, String primaryKeyName, String table, String... columns) throws DataAccessException
- Throws:
DataAccessException
-
getSqlToDropForeignKeyConstraint
protected String getSqlToDropForeignKeyConstraint(String constraintName, String baseTable) throws DataAccessException
- Throws:
DataAccessException
-
dropForeignKeyConstraint
public void dropForeignKeyConstraint(Connection conn, String constraintName, String baseTable) throws DataAccessException
- Throws:
DataAccessException
-
getSqlToAddForeignKeyConstraint
protected String getSqlToAddForeignKeyConstraint(String constraintName, String baseTable, String baseColumn, String referencedTable, String referencedColumn, String onDeleteAction, String onUpdateAction)
-
addForeignKeyConstraint
public void addForeignKeyConstraint(Connection conn, String constraintName, String baseTable, String baseColumn, String referencedTable, String referencedColumn, String onDeleteAction, String onUpdateAction) throws DataAccessException
- Throws:
DataAccessException
-
dropIndex
public void dropIndex(Connection conn, String table, String indexName) throws DataAccessException
- Throws:
DataAccessException
-
getSqlToCreateIndex
protected String getSqlToCreateIndex(String indexName, String table, String... columns)
-
createIndex
public void createIndex(Connection conn, String indexName, String table, String... columns) throws DataAccessException
- Throws:
DataAccessException
-
getSqlToDropUniqueConstraint
protected String getSqlToDropUniqueConstraint(String constraintName, String table)
-
dropUniqueConstrain
public void dropUniqueConstrain(Connection conn, String constraintName, String table) throws DataAccessException
- Throws:
DataAccessException
-
getSqlToAddUniqueConstrain
protected String getSqlToAddUniqueConstrain(String constraintName, String table, String... columns)
-
addUniqueConstrain
public void addUniqueConstrain(Connection conn, String constraintName, String table, String... columns) throws DataAccessException
- Throws:
DataAccessException
-
translate
public DataAccessException translate(String sql, SQLException ex)
-
-