- java.lang.Object
-
- com.appslandia.common.record.DbManager
-
- All Implemented Interfaces:
AutoCloseable
public class DbManager extends Object implements AutoCloseable
- Author:
- Loc Ha
-
-
Constructor Summary
Constructors Constructor Description DbManager()DbManager(DataSource dataSource)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidassertNotAutoCommit()protected voidassertNotClosed()voidclose()voidcommit()intdelete(Record key, Table table)protected intdelete(Record key, Table table, boolean addBatch)voiddeleteBatch(Record key, Table table)voidexecuteBatch()List<Record>executeList(String sql)<T> List<T>executeList(String sql, ResultSetMapper<T> mapper)<T> List<T>executeList(String sql, ResultSetMapper<T> mapper, List<T> list)<T> List<Record>executeList(String pSql, Map<String,Object> params)<T> List<T>executeList(String pSql, Map<String,Object> params, ResultSetMapper<T> mapper)<T> List<T>executeList(String pSql, Map<String,Object> params, ResultSetMapper<T> mapper, List<T> list)<K,V>
Map<K,V>executeMap(String sql, ResultSetMapper<K> keyMapper, ResultSetMapper<V> valueMapper)<K,V>
Map<K,V>executeMap(String sql, ResultSetMapper<K> keyMapper, ResultSetMapper<V> valueMapper, Map<K,V> map)<K,V>
Map<K,V>executeMap(String sql, String keyColumn, String valueColumn)<K,V>
Map<K,V>executeMap(String sql, String keyColumn, String valueColumn, Map<K,V> map)<K,V>
Map<K,V>executeMap(String pSql, Map<String,Object> params, ResultSetMapper<K> keyMapper, ResultSetMapper<V> valueMapper)<K,V>
Map<K,V>executeMap(String pSql, Map<String,Object> params, ResultSetMapper<K> keyMapper, ResultSetMapper<V> valueMapper, Map<K,V> map)<K,V>
Map<K,V>executeMap(String pSql, Map<String,Object> params, String keyColumn, String valueColumn)<K,V>
Map<K,V>executeMap(String pSql, Map<String,Object> params, String keyColumn, String valueColumn, Map<K,V> map)voidexecuteQuery(String sql, ResultSetHandler handler)voidexecuteQuery(String pSql, Map<String,Object> params, ResultSetHandler handler)<T> TexecuteScalar(String sql)<T> TexecuteScalar(String pSql, Map<String,Object> params)RecordexecuteSingle(String sql)<T> TexecuteSingle(String sql, ResultSetMapper<T> mapper)RecordexecuteSingle(String pSql, Map<String,Object> params)<T> TexecuteSingle(String pSql, Map<String,Object> params, ResultSetMapper<T> mapper)intexecuteUpdate(String sql)intexecuteUpdate(String pSql, Map<String,Object> params)booleanexists(Record key, Table table)booleangetAutoCommit()ConnectiongetConnection()static DataSourcegetDataSource()RecordgetRecord(Record key, Table table)Objectinsert(Record record, Table table)protected Objectinsert(Record record, Table table, boolean addBatch)voidinsertBatch(Record record, Table table)voidrollback()voidsetAutoCommit(boolean autoCommit)static voidsetDataSource(DataSource ds)protected voidsetParameter(StatementImpl stat, String parameterName, Object val, int sqlType)protected voidsetParameters(StatementImpl stat, Map<String,Object> params)intupdate(Record record, Table table)protected intupdate(Record record, Table table, boolean addBatch)voidupdateBatch(Record record, Table table)
-
-
-
Constructor Detail
-
DbManager
public DbManager() throws SQLException- Throws:
SQLException
-
DbManager
public DbManager(DataSource dataSource) throws SQLException
- Throws:
SQLException
-
-
Method Detail
-
getConnection
public Connection getConnection()
-
setParameter
protected void setParameter(StatementImpl stat, String parameterName, Object val, int sqlType) throws SQLException
- Throws:
SQLException
-
setParameters
protected void setParameters(StatementImpl stat, Map<String,Object> params) throws SQLException
- Throws:
SQLException
-
insert
public Object insert(Record record, Table table) throws SQLException
- Throws:
SQLException
-
insertBatch
public void insertBatch(Record record, Table table) throws SQLException
- Throws:
SQLException
-
insert
protected Object insert(Record record, Table table, boolean addBatch) throws SQLException
- Throws:
SQLException
-
update
public int update(Record record, Table table) throws SQLException
- Throws:
SQLException
-
updateBatch
public void updateBatch(Record record, Table table) throws SQLException
- Throws:
SQLException
-
update
protected int update(Record record, Table table, boolean addBatch) throws SQLException
- Throws:
SQLException
-
delete
public int delete(Record key, Table table) throws SQLException
- Throws:
SQLException
-
deleteBatch
public void deleteBatch(Record key, Table table) throws SQLException
- Throws:
SQLException
-
delete
protected int delete(Record key, Table table, boolean addBatch) throws SQLException
- Throws:
SQLException
-
getRecord
public Record getRecord(Record key, Table table) throws SQLException
- Throws:
SQLException
-
exists
public boolean exists(Record key, Table table) throws SQLException
- Throws:
SQLException
-
executeList
public List<Record> executeList(String sql) throws SQLException
- Throws:
SQLException
-
executeList
public <T> List<Record> executeList(String pSql, Map<String,Object> params) throws SQLException
- Throws:
SQLException
-
executeSingle
public Record executeSingle(String sql) throws SQLException
- Throws:
SQLException
-
executeSingle
public Record executeSingle(String pSql, Map<String,Object> params) throws SQLException
- Throws:
SQLException
-
executeUpdate
public int executeUpdate(String sql) throws SQLException
- Throws:
SQLException
-
executeUpdate
public int executeUpdate(String pSql, Map<String,Object> params) throws SQLException
- Throws:
SQLException
-
executeMap
public <K,V> Map<K,V> executeMap(String sql, ResultSetMapper<K> keyMapper, ResultSetMapper<V> valueMapper) throws SQLException
- Throws:
SQLException
-
executeMap
public <K,V> Map<K,V> executeMap(String sql, ResultSetMapper<K> keyMapper, ResultSetMapper<V> valueMapper, Map<K,V> map) throws SQLException
- Throws:
SQLException
-
executeMap
public <K,V> Map<K,V> executeMap(String pSql, Map<String,Object> params, ResultSetMapper<K> keyMapper, ResultSetMapper<V> valueMapper) throws SQLException
- Throws:
SQLException
-
executeMap
public <K,V> Map<K,V> executeMap(String pSql, Map<String,Object> params, ResultSetMapper<K> keyMapper, ResultSetMapper<V> valueMapper, Map<K,V> map) throws SQLException
- Throws:
SQLException
-
executeMap
public <K,V> Map<K,V> executeMap(String sql, String keyColumn, String valueColumn) throws SQLException
- Throws:
SQLException
-
executeMap
public <K,V> Map<K,V> executeMap(String sql, String keyColumn, String valueColumn, Map<K,V> map) throws SQLException
- Throws:
SQLException
-
executeMap
public <K,V> Map<K,V> executeMap(String pSql, Map<String,Object> params, String keyColumn, String valueColumn) throws SQLException
- Throws:
SQLException
-
executeMap
public <K,V> Map<K,V> executeMap(String pSql, Map<String,Object> params, String keyColumn, String valueColumn, Map<K,V> map) throws SQLException
- Throws:
SQLException
-
executeList
public <T> List<T> executeList(String sql, ResultSetMapper<T> mapper) throws SQLException
- Throws:
SQLException
-
executeList
public <T> List<T> executeList(String sql, ResultSetMapper<T> mapper, List<T> list) throws SQLException
- Throws:
SQLException
-
executeList
public <T> List<T> executeList(String pSql, Map<String,Object> params, ResultSetMapper<T> mapper) throws SQLException
- Throws:
SQLException
-
executeList
public <T> List<T> executeList(String pSql, Map<String,Object> params, ResultSetMapper<T> mapper, List<T> list) throws SQLException
- Throws:
SQLException
-
executeSingle
public <T> T executeSingle(String sql, ResultSetMapper<T> mapper) throws SQLException
- Throws:
SQLException
-
executeSingle
public <T> T executeSingle(String pSql, Map<String,Object> params, ResultSetMapper<T> mapper) throws SQLException
- Throws:
SQLException
-
executeScalar
public <T> T executeScalar(String sql) throws SQLException
- Throws:
SQLException
-
executeScalar
public <T> T executeScalar(String pSql, Map<String,Object> params) throws SQLException
- Throws:
SQLException
-
executeQuery
public void executeQuery(String sql, ResultSetHandler handler) throws Exception
- Throws:
Exception
-
executeQuery
public void executeQuery(String pSql, Map<String,Object> params, ResultSetHandler handler) throws Exception
- Throws:
Exception
-
executeBatch
public void executeBatch() throws SQLException- Throws:
SQLException
-
setAutoCommit
public void setAutoCommit(boolean autoCommit) throws SQLException- Throws:
SQLException
-
getAutoCommit
public boolean getAutoCommit() throws SQLException- Throws:
SQLException
-
commit
public void commit() throws SQLException- Throws:
SQLException
-
rollback
public void rollback() throws SQLException- Throws:
SQLException
-
assertNotAutoCommit
protected void assertNotAutoCommit() throws SQLException- Throws:
SQLException
-
assertNotClosed
protected void assertNotClosed() throws SQLException- Throws:
SQLException
-
close
public void close() throws SQLException- Specified by:
closein interfaceAutoCloseable- Throws:
SQLException
-
getDataSource
public static DataSource getDataSource() throws IllegalStateException
- Throws:
IllegalStateException
-
setDataSource
public static void setDataSource(DataSource ds)
-
-