@Override
  public I_M_AttributeSetExclude retrieveAttributeSetExclude(
      I_M_AttributeSet attributeSet, int columnId, boolean isSOTrx) {
    if (columnId <= 0) {
      return null;
    }

    final Properties ctx = InterfaceWrapperHelper.getCtx(attributeSet);
    final String trxName = InterfaceWrapperHelper.getTrxName(attributeSet);
    final I_AD_Column column =
        InterfaceWrapperHelper.create(ctx, columnId, I_AD_Column.class, trxName);
    // guard against null, when column was not found
    if (column == null) {
      return null;
    }

    return Services.get(IQueryBL.class)
        .createQueryBuilder(I_M_AttributeSetExclude.class, attributeSet)
        .addEqualsFilter(I_M_AttributeSetExclude.COLUMNNAME_AD_Table_ID, column.getAD_Table_ID())
        .addEqualsFilter(I_M_AttributeSetExclude.COLUMNNAME_IsSOTrx, isSOTrx)
        .addEqualsFilter(
            I_M_AttributeSetExclude.COLUMNNAME_M_AttributeSet_ID,
            attributeSet.getM_AttributeSet_ID())
        .addOnlyActiveRecordsFilter()
        .create()
        .firstOnly(I_M_AttributeSetExclude.class);
  }
Example #2
0
 @Override
 public boolean isVirtualColumn(final I_AD_Column column) {
   final String s = column.getColumnSQL();
   return !Check.isEmpty(s, true);
 }
  @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);
  }