/** * <p>Retrieve 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 T retrieveEntityById(final Map<String, Object> pAddParam, final Object pId) throws Exception { addAccSettingsIntoAttrs(pAddParam); T entity = getSrvOrm().retrieveEntityById(getEntityClass(), pId); @SuppressWarnings("unchecked") Map<String, String[]> parameterMap = (Map<String, String[]>) pAddParam. get("parameterMap"); if (parameterMap.get("actionAdd") != null && "full".equals(parameterMap.get("actionAdd")[0])) { IAttributes attributes = (IAttributes) pAddParam.get("attributes"); attributes.setAttribute("accEntries", srvAccEntry .retrieveAccEntriesFor(pAddParam, entity)); } retrieveOtherDataFor(pAddParam, entity); return entity; }
/** * <p>Delete entity from DB.</p> * @param pAddParam additional param * @param pEntity entity * @throws Exception - an exception **/ @Override public final void deleteEntity(final Map<String, Object> pAddParam, final T pEntity) throws Exception { if (!pEntity.getIdDatabaseBirth().equals(getSrvOrm().getIdDatabase())) { throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER, "can_not_delete_foreign_src"); } deleteEntity(pAddParam, pEntity.getItsId()); }
final Map<String, Object> pAddParam, final Object pId) throws Exception { T entity = getSrvOrm() .retrieveCopyEntity(getEntityClass(), pId); @SuppressWarnings("unchecked") "Attempt to double reverse! " + pAddParam.get("user")); T entityReversed = getSrvOrm() .retrieveEntityById(getEntityClass(), pId); Long docId = entityReversed.getItsId(); entity.setItsDate(new Date()); entity.setIdDatabaseBirth(getSrvOrm().getIdDatabase()); entity.setIsNew(true); entity.setHasMadeAccEntries(false);
getSrvOrm().insertEntity(pEntity); if (pEntity.getReversedId() != null) { T reversed; if (pEntity.getIdDatabaseBirth().equals(pEntity reversed = getSrvOrm().retrieveEntityById( getEntityClass(), pEntity.getReversedId()); } else { //reversing foreign doc .getReversedId() + " and " + tblNm + ".IDDATABASEBIRTH=" + pEntity .getReversedIdDatabaseBirth(); reversed = getSrvOrm().retrieveEntityWithConditions( getEntityClass(), whereStr); getSrvOrm().updateEntity(reversed); srvAccEntry.reverseEntries(pAddParam, pEntity, reversed); if (!pEntity.getIdDatabaseBirth().equals(getSrvOrm().getIdDatabase())) { throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER, "can_not_change_foreign_src"); T oldEntity = getSrvOrm() .retrieveEntityById(getEntityClass(), pEntity.getItsId()); if (oldEntity.getHasMadeAccEntries()) { if (parameterMap.get("actionAdd") == null || !"makeAccEntries".equals(parameterMap.get("actionAdd")[0])) { getSrvOrm().updateEntity(pEntity);