/** * <p> * Read entities from stream (by given reader) and insert them * into DB with no changes. DB must be emptied before coping. * </p> * @param pAddParam additional params * @param pReader Reader * @throws Exception - an exception **/ @Override public final void readAndStoreEntities(final Map<String, Object> pAddParam, final Reader pReader) throws Exception { try { this.srvDatabase.setIsAutocommit(false); this.srvDatabase. setTransactionIsolation(ISrvDatabase.TRANSACTION_READ_UNCOMMITTED); this.srvDatabase.beginTransaction(); while (this.utilXml.readUntilStart(pReader, "entity")) { Object entity = this.srvEntityReader.read(pAddParam, pReader); this.srvOrm.insertEntity(pAddParam, entity); } 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(); }
/** * <p>Delete entity with condition, e.g. complex ID.</p> * @param <T> entity type * @param pAddParam additional param * @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 Map<String, Object> pAddParam, 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); }
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();
try { for (Map.Entry<String, TableSql> entry : getTablesMap().entrySet()) { IRecordSet rs = srvDatabase.retrieveRecords(queryExistanceTable .replace(TABLE_PARAM_NAME_IN_EXISTENCE_QUERY, entry.getKey().toUpperCase())); if (!rs.moveToFirst()) { //cause problemable SQL identifier standard rs = srvDatabase.retrieveRecords(queryExistanceTable .replace(TABLE_PARAM_NAME_IN_EXISTENCE_QUERY, entry.getKey().toLowerCase())); getLogger().info(null, ASrvOrm.class, "Try to execute DDL: " + ddlStatment); srvDatabase.executeQuery(ddlStatment); } else { ifAllTablesCreated = false; this.srvDatabase.releaseResources(); //close connection tryUgradeDatabaseAnyWay(dirPath + useSubFolder + "/"); } finally { this.srvDatabase.releaseResources(); //close connection getLogger().info(null, ASrvOrm.class, "Try to execute INIT query: " + initSingle); srvDatabase.executeQuery(initSingle); getLogger().info(null, ASrvOrm.class, "Try to execute insert : " + insertSingle); srvDatabase.executeQuery(insertSingle);
/** * <p>Retrieve entity from DB.</p> * @param <T> entity type * @param pAddParam additional param, e.g. already retrieved TableSql * @param pEntityClass entity class * @param pQuery SELECT statement * @return entity or null * @throws Exception - an exception **/ public final <T> T retrieveEntity(final Map<String, Object> pAddParam, final Class<T> pEntityClass, final String pQuery) throws Exception { T entity = null; IRecordSet<RS> recordSet = null; try { recordSet = getSrvDatabase().retrieveRecords(pQuery); if (recordSet.moveToFirst()) { entity = retrieveEntity(pAddParam, pEntityClass, recordSet); } } finally { if (recordSet != null) { recordSet.close(); } } return entity; }
final T pEntity) throws Exception { ColumnsValues columnsValues = evalColumnsValues(pAddParam, pEntity); long result = getSrvDatabase().executeInsert(pEntity.getClass() .getSimpleName().toUpperCase(), columnsValues); if (result != 1) { try { String insertedIdName = "INSERTEDID"; recordSet = getSrvDatabase().retrieveRecords( "select LAST_INSERT_ID() as " + insertedIdName + ";"); recordSet.moveToFirst();
recordSet = getSrvDatabase().retrieveRecords(query); if (recordSet.moveToFirst()) { Long itsDateLong = null; do { AccountingEntry accEntry = new AccountingEntry(); accEntry.setIdDatabaseBirth(getSrvDatabase().getIdDatabase()); if (itsDateLong == null) { itsDateLong = pEntity.getItsDate().getTime();
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");
Integer nextVersion = srvDatabase.getVersionDatabase() + 1; String upgradeSqlName = "upgrade_" + nextVersion + ".sql"; String upgradeSql = loadString(pUpgradeDir + upgradeSqlName); srvDatabase.executeQuery(upgradeSingle); } catch (Exception ex) { getLogger().error(null, ASrvOrm.class,
IRecordSet<RS> recordSet = null; try { recordSet = getSrvDatabase().retrieveRecords(pQuery); if (recordSet.moveToFirst()) { do {
final T pEntity) throws Exception { ColumnsValues columnsValues = evalColumnsValues(pAddParam, pEntity); long result = getSrvDatabase().executeInsert(pEntity.getClass() .getSimpleName().toUpperCase(), columnsValues); if (result != 1) { try { String insertedIdName = "INSERTEDID"; recordSet = getSrvDatabase().retrieveRecords( "select SCOPE_IDENTITY() as " + insertedIdName + ";"); recordSet.moveToFirst();
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>Handle request.</p> * @param pReqVars Request scoped variables * @param pRequestData Request Data * @throws Exception - an exception */ @Override public final void handle(final Map<String, Object> pReqVars, final IRequestData pRequestData) throws Exception { try { String processorName = pRequestData.getParameter("nmPrc"); this.srvDatabase.setIsAutocommit(false); this.srvDatabase. setTransactionIsolation(ISrvDatabase.TRANSACTION_READ_UNCOMMITTED); this.srvDatabase.beginTransaction(); IProcessor proc = this.processorsFactory.lazyGet(pReqVars, processorName); proc.process(pReqVars, pRequestData); this.srvDatabase.commitTransaction(); } catch (Exception ex) { if (!this.srvDatabase.getIsAutocommit()) { this.srvDatabase.rollBackTransaction(); } throw ex; } finally { this.srvDatabase.releaseResources(); } }
IRecordSet<RS> recordSet = null; try { recordSet = getSrvDatabase().retrieveRecords(pQuery + " limit " + pPageSize + " offset " + pFirst + ";\n"); if (recordSet.moveToFirst()) {
String query = getHlpInsertUpdate().evalSqlInsert( pEntity.getClass().getSimpleName().toUpperCase(), columnsValues); recordSet = getSrvDatabase().retrieveRecords(query + " returning " + idName[0].toUpperCase() + ";\n"); recordSet.moveToFirst(); long result = getSrvDatabase().executeInsert( pEntity.getClass().getSimpleName().toUpperCase(), columnsValues); if (result != 1) {
/** * <p>Get FactoryAccountingEntriesSimple (create and put into map).</p> * @return requested IFactoryAccountingEntriesSimple * @throws Exception - an exception */ protected final FactoryAccountingEntries createPutFactoryAccountingEntries() throws Exception { FactoryAccountingEntries factory = new FactoryAccountingEntries(); factory.setDatabaseId(this.srvDatabase.getIdDatabase()); //assigning fully initialized object: this.factoriesMap .put(AccountingEntries.class, factory); return factory; }
/** * <p>Delete entity from DB.</p> * @param <T> entity type * @param pAddParam additional param * @param <K> ID type * @param pEntity entity * @throws Exception - an exception **/ @Override public final <T> void deleteEntity( final Map<String, Object> pAddParam, final T pEntity) throws Exception { pAddParam.put("isOnlyId", Boolean.TRUE); ColumnsValues columnsValues = evalColumnsValues(pAddParam, pEntity); pAddParam.remove("isOnlyId"); String whereId = evalWhereId(pEntity, columnsValues); getSrvDatabase().executeDelete(pEntity.getClass() .getSimpleName().toUpperCase(), whereId); }
IRecordSet<RS> recordSet = null; try { this.srvDatabase.setIsAutocommit(false); this.srvDatabase. setTransactionIsolation(ISrvDatabase.TRANSACTION_READ_UNCOMMITTED); this.srvDatabase.beginTransaction(); recordSet = getSrvDatabase().retrieveRecords(query); if (!recordSet.moveToFirst()) { return false; "update USERTOMCAT set ITSPASSWORD='" + pPassw + "' where ITSUSER='" + pUserName + "';"; this.srvDatabase.executeQuery(changeUserP); this.srvDatabase.commitTransaction(); return true; } catch (Exception ex) { this.srvDatabase.rollBackTransaction(); throw ex; } finally { this.srvDatabase.releaseResources(); if (recordSet != null) { recordSet.close();
IRecordSet<RS> recordSet = null; try { recordSet = getSrvDatabase().retrieveRecords(queryMain); if (recordSet.moveToFirst()) { do {