/** * <p>Start new transaction.</p> * @throws Exception - an exception **/ @Override public final void beginTransaction() throws Exception { getOrEstablishConnection(); }
/** * <p>Get SrvDatabase in lazy mode.</p> * @return SrvDatabase - SrvDatabase * @throws Exception - an exception */ @Override public final synchronized SrvDatabase lazyGetSrvDatabase() throws Exception { if (this.srvDatabase == null) { this.srvDatabase = new SrvDatabase(); this.srvDatabase.setLogger(lazyGetLogger()); this.srvDatabase.setHlpInsertUpdate(lazyGetHlpInsertUpdate()); this.srvDatabase.setDataSource(lazyGetDataSource()); this.srvDatabase.setSrvRecordRetriever(lazyGetSrvRecordRetriever()); lazyGetLogger().info(AFactoryAppBeans.class, "SrvDatabase has been created."); } return this.srvDatabase; }
final String pWhere) throws Exception { Statement stmt = null; String query = getHlpInsertUpdate().evalSqlUpdate(pTable, pColumnsVals, pWhere); try { getLogger().debug(SrvDatabase.class, "Thread ID=" + Thread.currentThread() .getId() + ", try to execute update: " + query); stmt = getOrEstablishConnection().createStatement(); return stmt.executeUpdate(query); } catch (SQLException sqle) {
/** * <p>Execute any SQL query that returns no data. * E.g. PRAGMA, etc.</p> * @param pQuery query * @throws Exception - an exception **/ @Override public final void executeQuery(final String pQuery) throws Exception { Statement stmt = null; try { getLogger().debug(SrvDatabase.class, "Thread ID=" + Thread.currentThread() .getId() + ", try to execute query: " + pQuery); stmt = getOrEstablishConnection().createStatement(); stmt.executeUpdate(pQuery); } catch (SQLException sqle) { String msg = sqle.getMessage() + ", RDBMS error code " + sqle.getErrorCode() + ", query:\n" + pQuery; throw new ExceptionWithCode(ASrvDatabase.SQL_EXEC_ERROR, msg); } finally { if (stmt != null) { stmt.close(); } } }
/** * <p>Rollback transaction to savepoint.</p> * @param pSavepointName savepoint name * @throws Exception - an exception **/ @Override public final void rollBackTransaction(final String pSavepointName) throws Exception { getLogger().debug(SrvDatabase.class, "try to rollback to savepoint: " + pSavepointName); this.threadConnection.get(). rollback(savepointsMap.get(pSavepointName)); savepointsMap.remove(pSavepointName); }
/** * <p>Get SrvDatabase in lazy mode.</p> * @return SrvDatabase - SrvDatabase * @throws Exception - an exception */ @Override public final synchronized SrvDatabase lazyGetSrvDatabase() throws Exception { String beanName = getSrvDatabaseName(); SrvDatabase srvDatabase = (SrvDatabase) getBeansMap().get(beanName); if (srvDatabase == null) { srvDatabase = new SrvDatabase(); srvDatabase.setLogger(lazyGetLogger()); srvDatabase.setHlpInsertUpdate(lazyGetHlpInsertUpdate()); srvDatabase.setDataSource(lazyGetDataSource()); getBeansMap().put(beanName, srvDatabase); lazyGetLogger().info(null, AFactoryAppBeansJdbc.class, beanName + " has been created."); } return srvDatabase; } }
/** * <p>Execute SQL INSERT that returns affected rows. * It is to adapt Android insert/update/delete interface. * </p> * @param pTable table name * @param pColumnsVals type-safe map column name - column value * @return row count affected * @throws Exception - an exception **/ @Override public final long executeInsert(final String pTable, final ColumnsValues pColumnsVals) throws Exception { Statement stmt = null; String query = getHlpInsertUpdate().evalSqlInsert(pTable, pColumnsVals); try { getLogger().debug(SrvDatabase.class, "Thread ID=" + Thread.currentThread() .getId() + ", try to execute insert: " + query); stmt = getOrEstablishConnection().createStatement(); return stmt.executeUpdate(query); } catch (SQLException sqle) { String msg = sqle.getMessage() + ", RDBMS error code " + sqle.getErrorCode() + ", query:\n" + query; throw new ExceptionWithCode(ASrvDatabase.SQL_EXEC_ERROR, msg); } finally { if (stmt != null) { stmt.close(); } } }
/** * <p>Retrieve records from DB.</p> * @param pSelect query SELECT * @return IRecordSet record set * @throws Exception - an exception **/ @Override public final IRecordSet<ResultSet> retrieveRecords(final String pSelect) throws Exception { try { getLogger().debug(SrvDatabase.class, "Thread ID=" + Thread.currentThread() .getId() + ", try to retrieve records: " + pSelect); final Statement stmt = getOrEstablishConnection().createStatement(); final ResultSet rs = stmt.executeQuery(pSelect); return new RecordSetJdbc(rs, stmt); } catch (SQLException sqle) { String msg = sqle.getMessage() + ", RDBMS error code " + sqle.getErrorCode() + ", query:\n" + pSelect; throw new ExceptionWithCode(ASrvDatabase.SQL_EXEC_ERROR, msg); } }
/** * <p>Rollback transaction to savepoint.</p> * @param pSavepointName savepoint name * @throws Exception - an exception **/ @Override public final void rollBackTransaction(final String pSavepointName) throws Exception { if (getLogger().getIsShowDebugMessagesFor(getClass())) { getLogger().debug(null, SrvDatabase.class, "try to rollback to savepoint: " + pSavepointName); } this.threadConnection.get(). rollback(savepointsMap.get(pSavepointName)); savepointsMap.remove(pSavepointName); }
final ColumnsValues pColumnsVals) throws Exception { Statement stmt = null; String query = getHlpInsertUpdate().evalSqlInsert(pTable, pColumnsVals); try { if (getLogger().getIsShowDebugMessagesFor(getClass()) && getLogger().getDetailLevel() > 30000) { getLogger().debug(null, SrvDatabase.class, "Thread ID=" + Thread.currentThread() .getId() + ", try to execute insert: " + query); stmt = getOrEstablishConnection().createStatement(); return stmt.executeUpdate(query); } catch (SQLException sqle) {
/** * <p>Execute any SQL query that returns no data. * E.g. PRAGMA, etc.</p> * @param pQuery query * @throws Exception - an exception **/ @Override public final void executeQuery(final String pQuery) throws Exception { Statement stmt = null; try { if (getLogger().getIsShowDebugMessagesFor(getClass()) && getLogger().getDetailLevel() > 30000) { getLogger().debug(null, SrvDatabase.class, "Thread ID=" + Thread.currentThread().getId() + ", try to execute query: " + pQuery); } stmt = getOrEstablishConnection().createStatement(); stmt.executeUpdate(pQuery); } catch (SQLException sqle) { String msg = sqle.getMessage() + ", RDBMS error code " + sqle.getErrorCode() + ", query:\n" + pQuery; throw new ExceptionWithCode(ASrvDatabase.SQL_EXEC_ERROR, msg); } finally { if (stmt != null) { stmt.close(); } } }
/** * <p>Start new transaction.</p> * @throws Exception - an exception **/ @Override public final void beginTransaction() throws Exception { getOrEstablishConnection(); }
final String pWhere) throws Exception { Statement stmt = null; String query = getHlpInsertUpdate().evalSqlUpdate(pTable, pColumnsVals, pWhere); try { if (getLogger().getIsShowDebugMessagesFor(getClass()) && getLogger().getDetailLevel() > 30000) { getLogger().debug(null, SrvDatabase.class, "Thread ID=" + Thread.currentThread().getId() + ", try to execute update: " + query); stmt = getOrEstablishConnection().createStatement(); return stmt.executeUpdate(query); } catch (SQLException sqle) {
/** * <p>Retrieve records from DB.</p> * @param pSelect query SELECT * @return IRecordSet record set * @throws Exception - an exception **/ @Override public final IRecordSet<ResultSet> retrieveRecords(final String pSelect) throws Exception { try { if (getLogger().getIsShowDebugMessagesFor(getClass()) && getLogger().getDetailLevel() > 30000) { getLogger().debug(null, SrvDatabase.class, "Thread ID=" + Thread.currentThread().getId() + ", try to retrieve records: " + pSelect); } final Statement stmt = getOrEstablishConnection().createStatement(); final ResultSet rs = stmt.executeQuery(pSelect); return new RecordSetJdbc(rs, stmt); } catch (SQLException sqle) { String msg = sqle.getMessage() + ", RDBMS error code " + sqle.getErrorCode() + ", query:\n" + pSelect; throw new ExceptionWithCode(ASrvDatabase.SQL_EXEC_ERROR, msg); } }
/** * <p>Get if an transaction is started.</p> * @return if autocommit * @throws Exception - an exception **/ @Override public final boolean getIsAutocommit() throws Exception { return getOrEstablishConnection().getAutoCommit(); }
getLogger().debug(SrvDatabase.class, "Thread ID=" + Thread.currentThread() .getId() + ", try to execute delete: " + query); stmt = getOrEstablishConnection().createStatement(); return stmt.executeUpdate(query); } catch (SQLException sqle) {
/** * <p>Set RDBMS autocommit mode.</p> * @param pIsAutocommit if autocommit * @throws Exception - an exception **/ @Override public final void setIsAutocommit( final boolean pIsAutocommit) throws Exception { getOrEstablishConnection().setAutoCommit(pIsAutocommit); }
if (getLogger().getIsShowDebugMessagesFor(getClass()) && getLogger().getDetailLevel() > 30000) { getLogger().debug(null, SrvDatabase.class, "Thread ID=" + Thread.currentThread().getId() + ", try to execute delete: " + query); stmt = getOrEstablishConnection().createStatement(); return stmt.executeUpdate(query); } catch (SQLException sqle) {
/** * <p>Get if an transaction is started.</p> * @param pIsAutocommit is autocommit * @throws Exception - an exception **/ @Override public final boolean getIsAutocommit() throws Exception { return getOrEstablishConnection().getAutoCommit(); }
/** * <p>Set RDBMS autocommit mode.</p> * @param pIsAutocommit if autocommit * @throws Exception - an exception **/ @Override public final void setIsAutocommit( final boolean pIsAutocommit) throws Exception { getOrEstablishConnection().setAutoCommit(pIsAutocommit); }