/** * <p>Print entity.</p> * @param pReq - servlet request * @throws Exception - an exception */ @Override public final void print(final HttpServletRequest pReq) throws Exception { try { this.srvDatabase.setIsAutocommit(false); this.srvDatabase. setTransactionIsolation(ISrvDatabase.TRANSACTION_READ_UNCOMMITTED); this.srvDatabase.beginTransaction(); retrieveEntityAndPutIntoRequest(pReq); this.srvDatabase.commitTransaction(); } catch (Exception ex) { this.srvDatabase.rollBackTransaction(); throw ex; } finally { this.srvDatabase.releaseResources(); } }
/** * <p>Geter for database ID.</p> * @return ID database **/ @Override public final int getIdDatabase() { return this.srvDatabase.getIdDatabase(); }
int preparedEntitiesCount = 0; try { this.srvDatabase.setIsAutocommit(false); this.srvDatabase. setTransactionIsolation(ISrvDatabase.TRANSACTION_READ_UNCOMMITTED); this.srvDatabase.beginTransaction(); for (Class<?> entityClass : this.classes) { if (APersistableBase.class.isAssignableFrom(entityClass)) { + entityClass.getSimpleName().toUpperCase() + ";"; Integer maxId = this.srvDatabase .evalIntegerResult(queryMaxId, "MAXID"); if (maxId != null) { maxId++; String querySec = "alter sequence " + entityClass.getSimpleName() .toUpperCase() + "_ITSID_SEQ restart with " + maxId + ";"; this.srvDatabase.executeQuery(querySec); this.srvDatabase.commitTransaction(); } catch (Exception ex) { this.srvDatabase.rollBackTransaction(); throw ex; } finally { this.srvDatabase.releaseResources();
Integer nextVersion = srvDatabase.getVersionDatabase() + 1; String upgradeSqlName = "upgrade_" + nextVersion + ".sql"; String upgradeSql = loadString(pUpgradeDir + upgradeSqlName); this.srvDatabase.setIsAutocommit(false); this.srvDatabase.setTransactionIsolation(ISrvDatabase .TRANSACTION_READ_UNCOMMITTED); this.srvDatabase.beginTransaction(); for (String upgradeSingle : upgradeSql.split("\n")) { if (upgradeSingle.trim().length() > 1 && !upgradeSingle.startsWith("/")) { srvDatabase.executeQuery(upgradeSingle); this.srvDatabase.commitTransaction(); } catch (Exception ex) { this.srvDatabase.rollBackTransaction(); throw ex;
try { for (Map.Entry<String, TableSql> entry : getTablesMap().entrySet()) { IRecordSet rs = srvDatabase.retrieveRecords(queryExistanceTable .replace(ISrvOrm.TABLE_PARAM_NAME_IN_EXISTENCE_QUERY, entry.getKey().toUpperCase())); if (!rs.moveToFirst()) { //cause problemable SQL identifier standard rs = srvDatabase.retrieveRecords(queryExistanceTable .replace(ISrvOrm.TABLE_PARAM_NAME_IN_EXISTENCE_QUERY, entry.getKey().toLowerCase())); ifCreatedOrAdded = true; String ddlStatment = evalSqlCreateTable(entry.getKey()); srvDatabase.executeQuery(ddlStatment); } else { ifAllTablesCreated = false; for (String initSingle : initSql.split("\n")) { if (initSingle.trim().length() > 1 && !initSingle.startsWith("/")) { srvDatabase.executeQuery(initSingle); if (insertSingle.trim().length() > 1 && !insertSingle.startsWith("/")) { srvDatabase.executeQuery(insertSingle); srvDatabase.releaseResources(); //close connection
recordSet = getSrvDatabase().retrieveRecords(query); if (recordSet.moveToFirst()) { Long itsDateLong = null; do { AccountingEntry accEntry = new AccountingEntry(); accEntry.setIdDatabaseBirth(getSrvDatabase().getIdDatabase()); if (itsDateLong == null) { itsDateLong = getSrvDatabase().getSrvRecordRetriever() .getDate(recordSet.getRecordSet(), "ITSDATE").getTime(); getSrvBalance().handleNewAccountEntry(null, null, String accDebitId = getSrvDatabase().getSrvRecordRetriever() .getString(recordSet.getRecordSet(), "ACCDEBIT"); Account accDebit = new Account(); accDebit.setItsId(accDebitId); accEntry.setAccDebit(accDebit); accEntry.setSubaccDebitType(getSrvDatabase().getSrvRecordRetriever() .getInteger(recordSet.getRecordSet(), "SUBACCDEBITTYPE")); accEntry.setSubaccDebitId(getSrvDatabase().getSrvRecordRetriever() .getLong(recordSet.getRecordSet(), "SUBACCDEBITID")); accEntry.setSubaccDebit(getSrvDatabase().getSrvRecordRetriever() .getString(recordSet.getRecordSet(), "SUBACCDEBIT")); accEntry.setDebit(getSrvDatabase().getSrvRecordRetriever() .getBigDecimal(recordSet.getRecordSet(), "DEBIT").setScale( getSrvAccSettings().lazyGetAccSettings().getCostPrecision(), getSrvAccSettings().lazyGetAccSettings().getRoundingMode())); String accCreditId = getSrvDatabase().getSrvRecordRetriever() .getString(recordSet.getRecordSet(), "ACCCREDIT"); Account accCredit = new Account();
Integer classCount = 0; boolean isDbPreparedBefore = false; int databaseVersion = this.srvDatabase.getVersionDatabase(); for (Class<?> entityClass : this.mngSettings.getClasses()) { int entitiesReceived = 0; if (requestedDatabaseId != null) { if (Integer.parseInt(requestedDatabaseId) == getSrvDatabase().getIdDatabase()) { throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER, "requested_database_must_be_different");
/** * <p>Delete entity with condition, e.g. complex ID.</p> * @param <T> entity type * @param pEntityClass entity class * @param pWhere Not Null e.g. "WAREHOUSESITE=1 and PRODUCT=1" * @throws Exception - an exception **/ @Override public final <T> void deleteEntityWhere( final Class<T> pEntityClass, final String pWhere) throws Exception { if (pWhere == null) { throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER, "param_null_not_accepted"); } getSrvDatabase().executeDelete(pEntityClass.getSimpleName() .toUpperCase(), pWhere); }
/** * <p>Calculate total rows for pagination.</p> * @param <T> - type of business object, * @param pEntityClass entity class * @return Integer row count * @throws Exception - an exception */ @Override public final <T> Integer evalRowCount( final Class<T> pEntityClass) throws Exception { String query = "select count(*) as TOTALROWS from " + pEntityClass .getSimpleName().toUpperCase() + ";"; return getSrvDatabase().evalIntegerResult(query, "TOTALROWS"); }
/** * <p>Delete entity from DB by given NON-COMPLEX ID.</p> * @param <T> entity type * @param pEntityClass entity class * @param pId ID * @throws Exception - an exception **/ @Override public final <T> void deleteEntity( final Class<T> pEntityClass, final Object pId) throws Exception { TableSql tableSql = this.getTablesMap().get(pEntityClass.getSimpleName()); String idStr; if (pId instanceof String) { idStr = "'" + pId.toString() + "'"; } else { idStr = pId.toString(); } getSrvDatabase().executeDelete(pEntityClass.getSimpleName().toUpperCase(), tableSql.getIdName() + "=" + idStr); }
/** * <p>Calculate total rows for pagination.</p> * @param <T> - type of business object, * @param pEntityClass entity class * @param pWhere not null e.g. "ITSID > 33" * @return Integer row count * @throws Exception - an exception */ @Override public final <T> Integer evalRowCountWhere( final Class<T> pEntityClass, final String pWhere) throws Exception { if (pWhere == null) { throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER, "param_null_not_accepted"); } String query = "select count(*) as TOTALROWS from " + pEntityClass .getSimpleName().toUpperCase() + " where " + pWhere + ";"; return getSrvDatabase().evalIntegerResult(query, "TOTALROWS"); }
/** * <p>Confirm delete entity from owned list.</p> * @param pReq - servlet request, * @throws Exception - an exception */ @Override public final void confirmDeleteFromOwnedList( final HttpServletRequest pReq) throws Exception { try { this.srvDatabase.setIsAutocommit(false); this.srvDatabase. setTransactionIsolation(ISrvDatabase.TRANSACTION_READ_UNCOMMITTED); this.srvDatabase.beginTransaction(); retrieveEntityFromOwnedListAndPutIntoRequest(pReq); this.srvDatabase.commitTransaction(); } catch (Exception ex) { this.srvDatabase.rollBackTransaction(); throw ex; } finally { this.srvDatabase.releaseResources(); } }
/** * <p>Init database birth and ID birth of entity.</p> * @param pEntity entity * @throws Exception an exception **/ public final void initPersistableBase(final Object pEntity) throws Exception { Field fieldIdDbBirth = getUtlReflection().retrieveField(pEntity.getClass(), APersistableBase.ID_DATABASE_BIRTH_NAME); fieldIdDbBirth.setAccessible(true); if (getSrvDatabase() != null) { //for test purpose, otherwise it must be set fieldIdDbBirth.set(pEntity, getSrvDatabase().getIdDatabase()); } Field fieldIdBirth = getUtlReflection().retrieveField(pEntity.getClass(), APersistableBase.ID_BIRTH_NAME); fieldIdBirth.setAccessible(true); fieldIdBirth.set(pEntity, null); }
getLogger().info(SrvBalanceStd.class, SrvBalanceStd.class.getSimpleName() + ": deleting all stored balances cause period has changed"); getSrvDatabase().executeDelete(BalanceAt.class.getSimpleName() .toUpperCase(), null); lazyGetBalanceAtAllDirtyCheck().setIsPeriodChanged(false);
/** * <p>Confirm delete entity.</p> * @param pReq - servlet request * @throws Exception - an exception */ @Override public final void confirmDelete( final HttpServletRequest pReq) throws Exception { try { this.srvDatabase.setIsAutocommit(false); this.srvDatabase. setTransactionIsolation(ISrvDatabase.TRANSACTION_READ_UNCOMMITTED); this.srvDatabase.beginTransaction(); retrieveEntityAndPutIntoRequest(pReq); this.srvDatabase.commitTransaction(); } catch (Exception ex) { this.srvDatabase.rollBackTransaction(); throw ex; } finally { this.srvDatabase.releaseResources(); } }
/** * <p>Create entity.</p> * @param pAddParam additional param * @return entity instance * @throws Exception - an exception **/ @Override public final AccountingEntry createEntity( final Map<String, Object> pAddParam) throws Exception { AccountingEntry entity = new AccountingEntry(); entity.setIdDatabaseBirth(getSrvDatabase().getIdDatabase()); entity.setSourceDatabaseBirth(getSrvDatabase().getIdDatabase()); entity.setIsNew(true); entity.setItsDate(new Date()); addAccSettingsIntoAttrs(pAddParam); return entity; }
/** * <p>Edit entity from owned list.</p> * @param pReq - servlet request, * @throws Exception - an exception */ @Override public final void editFromOwnedList( final HttpServletRequest pReq) throws Exception { try { this.srvDatabase.setIsAutocommit(false); this.srvDatabase. setTransactionIsolation(ISrvDatabase.TRANSACTION_READ_UNCOMMITTED); this.srvDatabase.beginTransaction(); retrieveEntityFromOwnedListAndPutIntoRequest(pReq); this.srvDatabase.commitTransaction(); } catch (Exception ex) { this.srvDatabase.rollBackTransaction(); throw ex; } finally { this.srvDatabase.releaseResources(); } }
/** * <p>Retrieve copy of entity from DB by given ID.</p> * @param pAddParam additional param * @param pId ID * @return entity or null * @throws Exception - an exception **/ @Override public final AccountingEntry retrieveCopyEntity( final Map<String, Object> pAddParam, final Object pId) throws Exception { AccountingEntry entity = getSrvOrm().retrieveCopyEntity( AccountingEntry.class, pId); if (!entity.getIdDatabaseBirth() .equals(getSrvOrm().getIdDatabase())) { throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER, "can_not_make_entry_for_foreign_src"); } entity.setIdDatabaseBirth(getSrvDatabase().getIdDatabase()); entity.setSourceDatabaseBirth(getSrvDatabase().getIdDatabase()); entity.setIsNew(true); addAccSettingsIntoAttrs(pAddParam); return entity; }
/** * <p>View entity.</p> * @param pReq - servlet request * @throws Exception - an exception */ @Override public final void view(final HttpServletRequest pReq) throws Exception { try { this.srvDatabase.setIsAutocommit(false); this.srvDatabase. setTransactionIsolation(ISrvDatabase.TRANSACTION_READ_UNCOMMITTED); this.srvDatabase.beginTransaction(); retrieveEntityAndPutIntoRequest(pReq); this.srvDatabase.commitTransaction(); } catch (Exception ex) { this.srvDatabase.rollBackTransaction(); throw ex; } finally { this.srvDatabase.releaseResources(); } }
entity.setIdDatabaseBirth(getSrvDatabase().getIdDatabase()); entity.setSourceDatabaseBirth(getSrvDatabase().getIdDatabase()); entity.setIsNew(true); entity.setItsDate(new Date());