Beispiel #1
0
  /**
   * Before Save
   *
   * @param newRecord new
   * @return true
   */
  protected boolean beforeSave(boolean newRecord) {
    if (!isActive() || !isAllNodes()) setIsDefault(false);

    if (getAD_Table_ID() <= 0 || is_ValueChanged(COLUMNNAME_TreeType) || newRecord) {
      if (TREETYPE_Other.equals(getTreeType())) {
        if (getAD_Table_ID() <= 0) throw new FillMandatoryException(COLUMNNAME_AD_Table_ID);
      } else {
        final IADTableDAO adTableDAO = Services.get(IADTableDAO.class);

        final String tableName = getDefaultTableNameByTreeType(getTreeType());
        final int AD_Table_ID = adTableDAO.retrieveTableId(tableName);
        if (AD_Table_ID <= 0) {
          throw new FillMandatoryException(COLUMNNAME_AD_Table_ID);
        }
        setAD_Table_ID(AD_Table_ID);
      }
    }
    return true;
  } // beforeSabe
Beispiel #2
0
 /**
  * Is Virtual Column
  *
  * @return true if virtual column
  * @deprecated please use {@link IADTableDAO#isVirtualColumn(I_AD_Column)}
  */
 @Deprecated
 public boolean isVirtualColumn() {
   final IADTableDAO tableDAO = Services.get(IADTableDAO.class);
   return tableDAO.isVirtualColumn(this);
 } // isVirtualColumn
  @Override
  public DBException wrapIfNeededOrReturnNull(final Throwable t) {
    final Boolean referencingTableHasDLMLevel;

    if (DBException.isSQLState(t, PG_SQLSTATE_Referencing_Record_Has_Wrong_DLM_Level)) {
      referencingTableHasDLMLevel = true;
    } else if (DBException.isSQLState(t, PG_SQLSTATE_Referencing_Table_Has_No_DLM_LEvel)) {
      referencingTableHasDLMLevel = false;
    } else {
      return null;
    }

    //
    // parse the exception detail and extract the infos
    final SQLException sqlException = DBException.extractSQLExceptionOrNull(t);
    Check.errorUnless(
        sqlException instanceof PSQLException,
        "exception={} needs to be a PSQLExcetion",
        sqlException);

    final PSQLException psqlException = (PSQLException) sqlException;
    final ServerErrorMessage serverErrorMessage = psqlException.getServerErrorMessage();
    Check.errorIf(
        serverErrorMessage == null,
        "ServerErrorMessage of PSQLException={} may not be null",
        psqlException);

    final String detail = serverErrorMessage.getDetail();
    Check.errorIf(
        Check.isEmpty(detail, true),
        "DETAIL ServerErrorMessage={} from of PSQLException={} may not be null",
        serverErrorMessage,
        psqlException);

    final String[] infos = extractInfos(detail);

    //
    // the the "real" tables and column from the extracted lowercase infos
    final IADTableDAO adTableDAO = Services.get(IADTableDAO.class);

    final I_AD_Table referencedTable = adTableDAO.retrieveTable(infos[0]);
    Check.errorIf(
        referencedTable == null,
        "Unable to retrieve an AD_Table for referencedTable name={}",
        infos[0]);

    final I_AD_Table referencingTable = adTableDAO.retrieveTable(infos[2]);
    Check.errorIf(
        referencingTable == null,
        "Unable to retrieve an AD_Table for referencingTable name={}",
        infos[2]);

    final I_AD_Column referencingColumn =
        adTableDAO.retrieveColumn(referencingTable.getTableName(), infos[3]);
    Check.errorIf(
        referencingTable == null,
        "Unable to retrieve an AD_Column for referencingTable name={} and referencingColumn name={}",
        infos[2],
        infos[3]);

    return new DLMReferenceException(
        t,
        TableReferenceDescriptor.of(
            referencingTable.getTableName(),
            referencingColumn.getColumnName(),
            referencedTable.getTableName(),
            Integer.parseInt(infos[1])),
        referencingTableHasDLMLevel);
  }