- java.lang.Object
-
- com.appslandia.common.record.DbContext
-
- All Implemented Interfaces:
AutoCloseable
public class DbContext extends Object implements AutoCloseable
- Author:
- Loc Ha
-
-
Constructor Summary
Constructors Constructor Description DbContext()DbContext(DataSource dataSource)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidassertNotClosed()protected voidassertTransactional()voidclose()voidcommit()intdelete(Record key, Table table)protected intdelete(Record key, Table table, boolean addBatch)voiddeleteBatch(Record key, Table table)voidexecuteBatch()booleanexecuteExists(String sql)booleanexecuteExists(String pSql, Object... params)booleanexecuteExists(String pSql, Map<String,Object> params)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, Object... params)<T> List<T>executeList(String pSql, Object[] params, ResultSetMapper<T> mapper)<T> List<T>executeList(String pSql, Object[] params, 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 pSql, Object[] params, ResultSetMapper<K> keyMapper, ResultSetMapper<V> valueMapper)<K,V>
Map<K,V>executeMap(String pSql, Object[] params, ResultSetMapper<K> keyMapper, ResultSetMapper<V> valueMapper, Map<K,V> map)<K,V>
Map<K,V>executeMap(String pSql, Object[] params, String keyColumn, String valueColumn)<K,V>
Map<K,V>executeMap(String pSql, Object[] params, String keyColumn, String valueColumn, 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, Object[] params, ResultSetHandler handler)voidexecuteQuery(String pSql, Map<String,Object> params, ResultSetHandler handler)<T> TexecuteScalar(String sql)<T> TexecuteScalar(String pSql, Object... params)<T> TexecuteScalar(String pSql, Map<String,Object> params)RecordexecuteSingle(String sql)<T> TexecuteSingle(String sql, ResultSetMapper<T> mapper)RecordexecuteSingle(String pSql, Object... params)<T> TexecuteSingle(String pSql, Object[] params, 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, Object... params)intexecuteUpdate(String pSql, Map<String,Object> params)booleanexists(Record key, Table table)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)booleanisTransactional()voidrollback()static voidsetDataSource(DataSource ds)protected voidsetParameter(StatementImpl stat, String parameterName, Object val, int sqlType)voidsetTransactional()intupdate(Record record, Table table)protected intupdate(Record record, Table table, boolean addBatch)voidupdateBatch(Record record, Table table)
-
-
-
Constructor Detail
-
DbContext
public DbContext() throws SQLException- Throws:
SQLException
-
DbContext
public DbContext(DataSource dataSource) throws SQLException
- Throws:
SQLException
-
-
Method Detail
-
getConnection
public Connection getConnection() throws SQLException
- Throws:
SQLException
-
setParameter
protected void setParameter(StatementImpl stat, String parameterName, Object val, int sqlType) 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, Object... params) 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, Object... params) 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, Object... params) 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, 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) throws SQLException
- Throws:
SQLException
-
executeMap
public <K,V> Map<K,V> executeMap(String pSql, 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 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, 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) throws SQLException
- Throws:
SQLException
-
executeMap
public <K,V> Map<K,V> executeMap(String pSql, Object[] params, 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, 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, Object[] params, ResultSetMapper<T> mapper) 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, Object[] params, 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, 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, Object[] params, 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, Object... params) throws SQLException
- Throws:
SQLException
-
executeScalar
public <T> T executeScalar(String pSql, Map<String,Object> params) throws SQLException
- Throws:
SQLException
-
executeExists
public boolean executeExists(String sql) throws SQLException
- Throws:
SQLException
-
executeExists
public boolean executeExists(String pSql, Object... params) throws SQLException
- Throws:
SQLException
-
executeExists
public boolean executeExists(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, Object[] params, 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
-
setTransactional
public void setTransactional() throws SQLException- Throws:
SQLException
-
isTransactional
public boolean isTransactional() throws SQLException- Throws:
SQLException
-
commit
public void commit() throws SQLException- Throws:
SQLException
-
rollback
public void rollback() throws SQLException- Throws:
SQLException
-
assertTransactional
protected void assertTransactional() 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)
-
-