/** * <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); } } }
/** * <p>Update entity in DB.</p> * @param <T> entity type * @param pAddParam additional param * @param pEntity entity * @throws Exception - an exception **/ @Override public final <T> void updateEntity( final Map<String, Object> pAddParam, final T pEntity) throws Exception { ColumnsValues columnsValues = evalColumnsValues(pAddParam, pEntity); String whereStr = evalWhereForUpdate(pEntity, columnsValues); prepareColumnValuesForUpdate(columnsValues, pEntity); int result = getSrvDatabase().executeUpdate(pEntity.getClass() .getSimpleName().toUpperCase(), columnsValues, whereStr); if (result != 1) { if (result == 0 && columnsValues.ifContains(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); } } }