/** * <p>Delete entity with NON-COMPLEX ID from DB.</p> * @param <T> entity type * @param <K> ID type * @param pEntity entity * @throws Exception - an exception **/ @Override public final <T> void deleteEntity( final T pEntity) throws Exception { TableSql tableSql = this.getTablesMap().get(pEntity.getClass() .getSimpleName()); Field fieldId = this.utlReflection.retrieveField(pEntity.getClass(), tableSql.getIdName()); fieldId.setAccessible(true); Object id = fieldId.get(pEntity); deleteEntity(pEntity.getClass(), id); }
/** * <p>Process entity request.</p> * @param pAddParam additional param, e.g. return this line's * document in "nextEntity" for farther process * @param pRequestData Request Data * @param pEntity Entity to process * @return Entity processed for farther process or null * @throws Exception - an exception **/ @Override public final T process( final Map<String, Object> pAddParam, final T pEntity, final IRequestData pRequestData) throws Exception { this.srvOrm.deleteEntity(pAddParam, pEntity); String ownerFieldName = this.srvOrm.getTablesMap() .get(pEntity.getClass().getSimpleName()).getOwnerFieldName(); Method getter = this.gettersRapiHolder .getFor(pEntity.getClass(), ownerFieldName); @SuppressWarnings("unchecked") T owner = (T) getter.invoke(pEntity); pAddParam.put("nameOwnerEntity", owner.getClass().getSimpleName()); pAddParam.put("nextEntity", owner); return null; }
/** * <p>Evaluate SQL SELECT statement for the entity with ID.</p> * @param <T> entity type * @param pEntityClass entity class * @param pId ID * @return String SQL DML query * @throws Exception - an exception **/ public final <T> String evalSqlSelect( 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(); } return evalSqlSelect(pEntityClass) + " where " + pEntityClass.getSimpleName().toUpperCase() + "." + tableSql.getIdName().toUpperCase() + "=" + idStr + ";\n"; }
/** * <p>Refresh entity from DB by given entity with ID.</p> * @param <T> entity type * @param pEntity entity * @return entity or null * @throws Exception - an exception **/ @Override public final <T> T retrieveEntity(final T pEntity) throws Exception { @SuppressWarnings("unchecked") Class<T> entityClass = (Class<T>) pEntity.getClass(); TableSql tableSql = getTablesMap().get(entityClass.getSimpleName()); Field fieldId = getUtlReflection().retrieveField(entityClass, tableSql.getIdName()); fieldId.setAccessible(true); Object id = fieldId.get(pEntity); return retrieveEntityById(entityClass, id); }
/** * <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>Evaluate SQL create table statement.</p> * @param pEntityName entity simple name * @return SQL create table **/ public final String evalSqlCreateTable(final String pEntityName) { TableSql tableSql = getTablesMap().get(pEntityName); StringBuffer result = new StringBuffer("create table " + pEntityName.toUpperCase() + " (\n"); boolean isFirstField = true; for (String fieldName : tableSql.getFieldsMap().keySet()) { if (isFirstField) { isFirstField = false; } else { result.append(",\n"); } result.append(fieldName.toUpperCase() + " " + tableSql.getFieldsMap().get(fieldName).getDefinition()); } if (tableSql.getConstraint() != null) { result.append(",\n" + tableSql.getConstraint()); } result.append(");\n"); return result.toString(); }
/** * <p>Return owner field name in owned entity e.g. "itsInvoice" * in invoiceLine.</p> * @param pEntityOwnedClass Entity Owned Class * @param pEntityOwnerClass Entity Owner Class * @return owner field name * @throws Exception an exception **/ public final String evalOwnerFieldName( final Class<?> pEntityOwnedClass, final Class<?> pEntityOwnerClass) throws Exception { TableSql tableSqlEod = getTablesMap().get(pEntityOwnedClass .getSimpleName()); String ownerFieldName = null; for (Map.Entry<String, FieldSql> entry : tableSqlEod.getFieldsMap() .entrySet()) { if (pEntityOwnerClass .getSimpleName().equals(entry.getValue().getForeignEntity())) { ownerFieldName = entry.getKey(); } } if (ownerFieldName == null) { String msg = "Can't find owner field name for subentity/entity: " + pEntityOwnedClass + "/" + pEntityOwnerClass; throw new ExceptionWithCode(ExceptionWithCode.CONFIGURATION_MISTAKE, msg); } return ownerFieldName; }
/** * <p>Evaluate Where conditions the entity.</p> * @param <T> entity type * @param pEntity entity * @param pColumnsValues columns values * @return where conditions e.g. "itsId=1 AND itsVersion=2" * @throws Exception an exception **/ public final <T> String evalWhereForUpdate( final T pEntity, final ColumnsValues pColumnsValues) throws Exception { String whereVer = ""; if (pColumnsValues.ifContains(ISrvOrm.VERSION_NAME)) { whereVer = " and ITSVERSION=" + pColumnsValues.evalSqlValue(ISrvOrm.VERSIONOLD_NAME); } String idName = getTablesMap().get(pEntity.getClass() .getSimpleName()).getIdName(); return idName.toUpperCase() + "=" + pColumnsValues.evalSqlValue(idName) + whereVer; }
/** * <p>Evaluate Android compatible values map of given entity. * For "itsVersion" evaluate new one and set it in the entity, * old version stored in column "itsVersionOld". * Used in INSERT/UPDATE statement.</p> * @param <T> entity type * @param pAddParam additional params, expected "isOnlyId"-true for * converting only ID field. * @param pEntity entity * @return ColumnsValues type-safe map fieldName-fieldValue * @throws Exception an exception **/ public final <T> ColumnsValues evalColumnsValues(final Map<String, Object> pAddParam, final T pEntity) throws Exception { TableSql tableSql = getTablesMap().get(pEntity.getClass().getSimpleName()); if (tableSql.getFieldsMap().containsKey(ISrvOrm.VERSION_NAME)) { pAddParam.put("versionAlgorithm", tableSql.getVersionAlgorithm()); } @SuppressWarnings("unchecked") IConverter<T, ColumnsValues> convToColVal = (IConverter<T, ColumnsValues>) this.factoryCnvEntityToColumnsValues .lazyGet(pAddParam, pEntity.getClass()); ColumnsValues result = convToColVal.convert(pAddParam, pEntity); if (tableSql.getFieldsMap().containsKey(ISrvOrm.VERSION_NAME)) { pAddParam.remove("versionAlgorithm"); } return result; }
new StringBuffer(); boolean isFirstField = true; TableSql tableSql = getTablesMap().get(pEntityClass.getSimpleName()); if (tableSql == null) { throw new ExceptionWithCode(ExceptionWithCode.CONFIGURATION_MISTAKE, + entry.getKey().toUpperCase() + " as " + columnName); } else { TableSql foreignTableSql = getTablesMap() .get(entry.getValue().getForeignEntity()); String tableForeign = entry.getValue().getForeignEntity().toUpperCase();
/** * <p>Process entity request.</p> * @param pAddParam additional param, e.g. return this line's * document in "nextEntity" for farther process * @param pRequestData Request Data * @param pEntity Entity to process * @return Entity processed for farther process or null * @throws Exception - an exception **/ @Override public final T process( final Map<String, Object> pAddParam, final T pEntity, final IRequestData pRequestData) throws Exception { if (pEntity.getIsNew()) { this.srvOrm.insertEntity(pAddParam, pEntity); pEntity.setIsNew(false); } else { this.srvOrm.updateEntity(pAddParam, pEntity); } String ownerFieldName = this.srvOrm.getTablesMap() .get(pEntity.getClass().getSimpleName()).getOwnerFieldName(); Method getter = this.gettersRapiHolder .getFor(pEntity.getClass(), ownerFieldName); @SuppressWarnings("unchecked") T owner = (T) getter.invoke(pEntity); pAddParam.put("nameOwnerEntity", owner.getClass().getSimpleName()); pAddParam.put("nextEntity", owner); return null; }
String ownerFieldName = this.srvOrm.getTablesMap() .get(pEntity.getClass().getSimpleName()).getOwnerFieldName(); Method getter = this.gettersRapiHolder
/** * <p>Retrieve copy of entity from DB by given ID.</p> * @param <T> entity type * @param pEntityClass entity class * @param pId ID * @return entity or null * @throws Exception - an exception **/ @Override public final <T> T retrieveCopyEntity( final Class<T> pEntityClass, final Object pId) throws Exception { T entity = retrieveEntityById(pEntityClass, pId); TableSql tableSql = getTablesMap().get(pEntityClass.getSimpleName()); Field fieldId = getUtlReflection().retrieveField(pEntityClass, tableSql.getIdName()); fieldId.setAccessible(true); fieldId.set(entity, null); if (APersistableBase.class.isAssignableFrom(pEntityClass)) { initPersistableBase(entity); } return entity; }
StringBuffer joints = new StringBuffer(); boolean isFirstField = true; TableSql tableSql = getTablesMap().get(pEntityClass.getSimpleName()); if (tableSql == null) { throw new ExceptionWithCode(ExceptionWithCode.CONFIGURATION_MISTAKE,
/** * <p>Evaluate SQL create table statement.</p> * @param pEntityName entity simple name * @return SQL create table **/ public final String evalSqlCreateTable(final String pEntityName) { TableSql tableSql = getTablesMap().get(pEntityName); StringBuffer result = new StringBuffer("create table " + pEntityName.toUpperCase() + " (\n"); boolean isFirstField = true; for (Map.Entry<String, FieldSql> entry : tableSql.getFieldsMap().entrySet()) { if (!(entry.getValue().getTypeField().equals(ETypeField.COMPOSITE_FK) || entry.getValue().getTypeField() .equals(ETypeField.COMPOSITE_FK_PK))) { if (isFirstField) { isFirstField = false; } else { result.append(",\n"); } result.append(entry.getKey().toUpperCase() + " " + tableSql.getFieldsMap().get(entry.getKey()).getDefinition()); } } if (tableSql.getConstraint() != null) { result.append(",\n" + tableSql.getConstraint()); } result.append(");\n"); return result.toString(); }
.getDeclaredConstructor(); Object entityOwner = constrEntityOwner.newInstance(); TableSql tableSqlEntityOwner = getTablesMap() .get(pEntityOwnerClass.getSimpleName()); Field fieldIdEntityOwner = getUtlReflection().retrieveField(
this.srvOrm.updateEntity(pAddParam, pEntity); String ownerFieldName = this.srvOrm.getTablesMap() .get(pEntity.getClass().getSimpleName()).getOwnerFieldName(); Method getter = this.gettersRapiHolder
final Object pEntityOwner) throws Exception { List<T> result = new ArrayList<T>(); TableSql tableSqlOwner = getTablesMap().get(pEntityOwner.getClass() .getSimpleName()); Field fieldIdOwner = getUtlReflection().retrieveField(pEntityOwner
this.ormSettingsBaseFile); fctBcCnvEntityToColumnsValues .setTablesMap(srvOrm.getTablesMap()); lazyGetFctBnCnvBnFromRs().setTablesMap(srvOrm.getTablesMap()); lazyGetFctBnCnvIbnToColumnValues().setTablesMap(srvOrm.getTablesMap()); fillerEntitiesFromRs.setTablesMap(srvOrm.getTablesMap()); Map<String, Object> addParam = new HashMap<String, Object>(); lazyGetLogger().info(null, AFactoryAppBeans.class,
.get(dies.getSourceType())); IDrawItemSource drawed = fctDis.create(pAddParam); String fldIdName = this.srvOrm.getTablesMap() .get(drawed.getClass().getSimpleName()).getIdFieldName(); Method setterId = this.settersRapiHolder