示例#1
0
  @Override
  public void onTableNameRename(final I_AD_Table table) {
    Check.assumeNotNull(table, "table not null");
    final I_AD_Table tableOld = InterfaceWrapperHelper.createOld(table, I_AD_Table.class);
    final String tableNameOld = tableOld.getTableName();
    final String tableNameNew = table.getTableName();

    // Do nothing if the table name was not actually changed
    if (Check.equals(tableNameOld, tableNameNew)) {
      return;
    }

    final Properties ctx = InterfaceWrapperHelper.getCtx(table);
    Services.get(ISequenceDAO.class).renameTableSequence(ctx, tableNameOld, tableNameNew);
  }
示例#2
0
 @Override
 public String retrieveWindowName(final Properties ctx, final String tableName) {
   // NOTE: atm we use MTable.get because that's the only place where we have the table cached.
   // In future we shall replace it with something which is database independent.
   final I_AD_Table adTable = MTable.get(ctx, tableName);
   if (adTable == null) {
     return "";
   }
   final I_AD_Window adWindow = adTable.getAD_Window();
   if (adWindow == null) {
     return "";
   }
   final I_AD_Window adWindowTrl = InterfaceWrapperHelper.translate(adWindow, I_AD_Window.class);
   return adWindowTrl.getName();
 }
示例#3
0
  @Test
  public void test_addWhereClause() throws Exception {
    final String whereClause = "TableName IN (?,?)";
    final Query query =
        new Query(getCtx(), "AD_Table", whereClause, getTrxName())
            .setParameters(new Object[] {"C_Invoice", "M_InOut"})
            .setOrderBy("TableName");
    {
      final I_AD_Table table = query.first(I_AD_Table.class);
      assertEquals("Invalid object", "C_Invoice", table.getTableName());
    }

    Assert.assertNotSame("Query shall be cloned", query, query.addWhereClause(true, null));
    Assert.assertNotSame("Query shall be cloned", query, query.addWhereClause(false, null));
    Assert.assertNotSame("Query shall be cloned", query, query.addWhereClause(true, ""));
    Assert.assertNotSame("Query shall be cloned", query, query.addWhereClause(true, "   "));

    {
      final String whereClause2 = "TableName='M_InOut'";
      final Query query2 = query.addWhereClause(true, whereClause2);
      Assert.assertNotSame("New query shall be created", query, query2);

      Assert.assertEquals(
          "Invalid whereClause was build",
          "(" + whereClause + ") AND (" + whereClause2 + ")",
          query2.getWhereClause());

      final I_AD_Table table = query2.first(I_AD_Table.class);
      assertEquals("Invalid object", "M_InOut", table.getTableName());
    }

    {
      final String whereClause2 = "TableName='M_InOut'";
      final Query query2 = query.addWhereClause(false, whereClause2);
      Assert.assertNotSame("New query shall be created", query, query2);

      Assert.assertEquals(
          "Invalid whereClause was build",
          "(" + whereClause + ") OR (" + whereClause2 + ")",
          query2.getWhereClause());

      final I_AD_Table table = query2.first(I_AD_Table.class);
      assertEquals("Invalid object", "C_Invoice", table.getTableName());
    }
  }
  @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);
  }