/** * <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(); } } }
final String pWhere) throws Exception { Statement stmt = null; String query = getHlpInsertUpdate().evalSqlUpdate(pTable, pColumnsVals, pWhere); try {
/** * <p>Get HlpInsertUpdate in lazy mode.</p> * @return HlpInsertUpdate - HlpInsertUpdate * @throws Exception - an exception */ public final synchronized HlpInsertUpdate lazyGetHlpInsertUpdate( ) throws Exception { if (this.hlpInsertUpdate == null) { this.hlpInsertUpdate = new HlpInsertUpdate(); lazyGetLogger().info(AFactoryAppBeans.class, "HlpInsertUpdate has been created."); } return this.hlpInsertUpdate; }
String query = getHlpInsertUpdate().evalSqlInsert( pEntity.getClass().getSimpleName().toUpperCase(), columnsValues); recordSet = getSrvDatabase().retrieveRecords(query pEntity.getClass().getSimpleName().toUpperCase(), columnsValues); if (result != 1) { String query = getHlpInsertUpdate().evalSqlInsert(pEntity.getClass() .getSimpleName().toUpperCase(), columnsValues); throw new ExceptionWithCode(ISrvDatabase.ERROR_INSERT_UPDATE,
/** * <p>Update entity in DB.</p> * @param <T> entity type * @param pEntity entity * @throws Exception - an exception **/ @Override public final <T> void updateEntity( final T pEntity) throws Exception { ColumnsValues columnsValues = evalColumnsValuesAndFillNewVersion(pEntity); String whereStr = evalWhereForUpdate(pEntity, columnsValues); columnsValues.getLongsMap().remove(ISrvOrm.VERSIONOLD_NAME); TableSql tableSql = this.tablesMap.get(pEntity.getClass().getSimpleName()); columnsValues.getLongsMap().remove(tableSql.getIdName()); int result = getSrvDatabase().executeUpdate(pEntity.getClass() .getSimpleName().toUpperCase(), columnsValues, whereStr); if (result != 1) { if (result == 0 && columnsValues.ifContains(ISrvOrm.VERSION_NAME)) { throw new ExceptionWithCode(ISrvDatabase.DIRTY_READ, "dirty_read"); } else { String query = hlpInsertUpdate.evalSqlUpdate(pEntity.getClass() .getSimpleName().toUpperCase(), columnsValues, whereStr); throw new ExceptionWithCode(ISrvDatabase.ERROR_INSERT_UPDATE, "It should be 1 row updated but it was " + result + ", query:\n" + query); } } }
.getSimpleName().toUpperCase(), columnsValues); if (result != 1) { String query = getHlpInsertUpdate().evalSqlInsert(pEntity.getClass() .getSimpleName().toUpperCase(), columnsValues); throw new ExceptionWithCode(ISrvDatabase.ERROR_INSERT_UPDATE,
throw new ExceptionWithCode(ISrvDatabase.DIRTY_READ, "dirty_read"); } else { String query = hlpInsertUpdate.evalSqlUpdate(pEntity.getClass() .getSimpleName().toUpperCase(), columnsValues, pWhere);
.getSimpleName().toUpperCase(), columnsValues); if (result != 1) { String query = getHlpInsertUpdate().evalSqlInsert( pEntity.getClass().getSimpleName().toUpperCase(), columnsValues);
.getSimpleName().toUpperCase(), columnsValues); if (result != 1) { String query = getHlpInsertUpdate().evalSqlInsert(pEntity.getClass() .getSimpleName().toUpperCase(), columnsValues); throw new ExceptionWithCode(ISrvDatabase.ERROR_INSERT_UPDATE,