Package com.appslandia.common.easyrecord
Class DbManager
- java.lang.Object
-
- com.appslandia.common.easyrecord.DbManager
-
- All Implemented Interfaces:
AutoCloseable
public class DbManager extends Object implements AutoCloseable
- Author:
- Loc Ha
-
-
Constructor Summary
Constructors Constructor Description DbManager()DbManager(Connection conn)DbManager(DataSource dataSource)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidassertNotClosed()voidbeginTransaction()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)<K,V>
Map<K,V>executeMap(String sql, String keyColumn, String valueColumn)RecordexecuteSingle(String sql)intexecuteUpdate(String sql)booleanexists(Record key, Table table)List<Record>getAll(Table table)ConnectiongetConnection()static DataSourcegetDataSource()RecordgetRecord(Record key, Table table)protected com.appslandia.common.easyrecord.DbManager.StatCachegetStatCache(String tableName)longinsert(Record record, Table table)protected longinsert(Record record, Table table, boolean addBatch)voidinsertBatch(Record record, Table table)voidrollback()static voidsetDataSource(DataSource dataSource)protected voidsetParameter(StatementImpl stat, String parameterName, Object val, int sqlType)protected ObjecttoSqlObject(Object val, int sqlType)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(Connection conn)
-
DbManager
public DbManager(DataSource dataSource) throws SQLException
- Throws:
SQLException
-
-
Method Detail
-
getConnection
public Connection getConnection()
-
insert
public long insert(Record record, Table table) throws SQLException
- Throws:
SQLException
-
insertBatch
public void insertBatch(Record record, Table table) throws SQLException
- Throws:
SQLException
-
setParameter
protected void setParameter(StatementImpl stat, String parameterName, Object val, int sqlType) throws SQLException
- Throws:
SQLException
-
getStatCache
protected com.appslandia.common.easyrecord.DbManager.StatCache getStatCache(String tableName)
-
insert
protected long 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
-
getAll
public List<Record> getAll(Table table) throws SQLException
- Throws:
SQLException
-
executeSingle
public Record executeSingle(String sql) throws SQLException
- Throws:
SQLException
-
executeList
public List<Record> executeList(String sql) throws SQLException
- Throws:
SQLException
-
executeUpdate
public int executeUpdate(String sql) throws SQLException
- Throws:
SQLException
-
executeMap
public <K,V> Map<K,V> executeMap(String sql, String keyColumn, String valueColumn) throws SQLException
- Throws:
SQLException
-
executeBatch
public void executeBatch() throws SQLException- Throws:
SQLException
-
beginTransaction
public void beginTransaction() throws SQLException- Throws:
SQLException
-
commit
public void commit() throws SQLException- Throws:
SQLException
-
rollback
public void rollback() 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()
-
setDataSource
public static void setDataSource(DataSource dataSource)
-
-