@Override
  public void startElement(Properties ctx, Element element) throws SAXException {
    String elementValue = element.getElementValue();
    int AD_Backup_ID = -1;
    String Object_Status = null;

    log.info(elementValue);
    Attributes atts = element.attributes;
    String DBType = atts.getValue("DBType");
    String sql = atts.getValue("statement").trim();
    if (sql.endsWith(";")) sql = sql.substring(0, sql.length() - 1);
    PreparedStatement pstmt = DB.prepareStatement(sql, getTrxName(ctx));
    try {
      if (DBType.equals("ALL")) {
        int n = pstmt.executeUpdate();
        log.info("Executed SQL Statement: " + atts.getValue("statement"));
      } else if (DB.isOracle() == true && DBType.equals("Oracle")) {
        pstmt.executeUpdate();
        log.info("Executed SQL Statement for Oracle: " + atts.getValue("statement"));
      } else if (DB.isPostgreSQL()
          && (DBType.equals("Postgres")
              || DBType.equals(
                  "PostgreSQL") // backward compatibility with old packages developed by hand
          )) {
        // Avoid convert layer - command specific for postgresql
        //
        // pstmt = DB.prepareStatement(sql, null);
        // pstmt.executeUpdate();
        //
        Connection m_con = DB.getConnectionRW();
        try {
          Statement stmt = m_con.createStatement();
          int n = stmt.executeUpdate(atts.getValue("statement"));
          log.info("Executed SQL Statement for PostgreSQL: " + atts.getValue("statement"));
          // Postgres needs to commit DDL statements
          if (m_con != null && !m_con.getAutoCommit()) m_con.commit();
          stmt.close();
        } finally {
          m_con.close();
        }
      }
      pstmt.close();
    } catch (Exception e) {
      log.log(Level.SEVERE, "SQLSatement", e);
    }
  }
  public void startElement(Properties ctx, Element element) throws SAXException {
    String elementValue = element.getElementValue();
    log.info(elementValue);
    int roleid = 0;
    int workflowid = 0;
    StringBuffer sqlB = null;
    Attributes atts = element.attributes;
    if (getStringValue(atts, "rolename") != null) {
      String name = atts.getValue("rolename");
      sqlB = new StringBuffer("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?");
      roleid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), name);
    }

    if (getStringValue(atts, "workflowname") != null) {
      String name = atts.getValue("workflowname");
      sqlB = new StringBuffer("SELECT AD_Workflow_ID FROM AD_Workflow WHERE Name= ?");
      workflowid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), name);
    }

    sqlB =
        new StringBuffer(
            "SELECT count(*) FROM AD_Workflow_Access WHERE AD_Role_ID=? and AD_Workflow_ID=?");
    int count = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), roleid, workflowid);
    @SuppressWarnings("unused")
    int AD_Backup_ID = -1;
    @SuppressWarnings("unused")
    String Object_Status = null;
    if (count > 0) {
      Object_Status = "Update";
      sqlB =
          new StringBuffer("UPDATE AD_Workflow_Access ")
              .append("SET isActive = '" + atts.getValue("isActive"))
              .append("', isReadWrite = '" + atts.getValue("isReadWrite"))
              .append("' WHERE AD_Role_ID = " + roleid)
              .append(" and AD_Workflow_ID = " + workflowid);

      int no = DB.executeUpdate(sqlB.toString(), getTrxName(ctx));
      if (no == -1) {
        log.info("Update to workflow access failed");
        throw new DatabaseAccessException("Update to workflow access failed");
      }
    } else {
      Object_Status = "New";
      AD_Backup_ID = 0;
      sqlB =
          new StringBuffer("INSERT INTO AD_Workflow_Access")
              .append("(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, ")
              .append("AD_Role_ID, AD_Workflow_ID, isActive, isReadWrite) ")
              .append("VALUES(")
              .append(" " + Env.getAD_Client_ID(ctx))
              .append(", " + Env.getAD_Org_ID(ctx))
              .append(", " + Env.getAD_User_ID(ctx))
              .append(", " + Env.getAD_User_ID(ctx))
              .append(", " + roleid)
              .append(", " + workflowid)
              .append(", '" + atts.getValue("isActive"))
              .append("', '" + atts.getValue("isReadWrite") + "')");

      int no = DB.executeUpdate(sqlB.toString(), getTrxName(ctx));
      if (no == -1) {
        log.info("Insert to workflow access failed");
        throw new DatabaseAccessException("Insert to workflow access failed");
      }
    }
  }
  public void startElement(Properties ctx, Element element) throws SAXException {
    String elementValue = element.getElementValue();
    int AD_Backup_ID = -1;
    String Object_Status = null;
    Attributes atts = element.attributes;
    log.info(elementValue + " " + atts.getValue("Name"));

    String name = atts.getValue("Name");
    int id = get_IDWithColumn(ctx, "AD_PrintFormat", "Name", name);
    X_AD_PrintFormat m_PrintFormat = new X_AD_PrintFormat(ctx, id, getTrxName(ctx));
    if (id <= 0
        && atts.getValue("AD_PrintFormat_ID") != null
        && Integer.parseInt(atts.getValue("AD_PrintFormat_ID")) <= PackOut.MAX_OFFICIAL_ID)
      m_PrintFormat.setAD_PrintFormat_ID(Integer.parseInt(atts.getValue("AD_PrintFormat_ID")));
    if (id > 0) {
      AD_Backup_ID = copyRecord(ctx, "AD_PrintFormat", m_PrintFormat);
      Object_Status = "Update";
    } else {
      Object_Status = "New";
      AD_Backup_ID = 0;
    }

    name = atts.getValue("ADReportviewnameID");
    if (name != null && name.trim().length() > 0) {
      id = get_IDWithColumn(ctx, "AD_ReportView", "Name", name);
      if (id <= 0) {
        element.defer = true;
        return;
      }
      m_PrintFormat.setAD_ReportView_ID(id);
    }

    name = atts.getValue("ADTableNameID");
    id = get_IDWithColumn(ctx, "AD_Table", "TableName", name);
    if (id == 0) {
      MTable m_Table = new MTable(ctx, 0, getTrxName(ctx));
      m_Table.setAccessLevel("3");
      m_Table.setName(name);
      m_Table.setTableName(name);
      if (m_Table.save(getTrxName(ctx)) == true) {
        record_log(
            ctx,
            1,
            m_Table.getName(),
            "Table",
            m_Table.get_ID(),
            0,
            "New",
            "AD_Table",
            get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Table"));
      } else {
        record_log(
            ctx,
            0,
            m_Table.getName(),
            "Table",
            m_Table.get_ID(),
            0,
            "New",
            "AD_Table",
            get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Table"));
      }
      id = get_IDWithColumn(ctx, "AD_Table", "TableName", name);
    }
    m_PrintFormat.setAD_Table_ID(id);

    name = atts.getValue("ADPrintTableFormatID");
    if (name != null && name.trim().length() > 0) {
      id = get_IDWithColumn(ctx, "AD_PrintTableFormat", "Name", name);
      if (id <= 0) {
        element.defer = true;
        return;
      }
      m_PrintFormat.setAD_PrintTableFormat_ID(id);
    }

    name = atts.getValue("ADPrintColorID");
    if (name != null && name.trim().length() > 0) {
      id = get_IDWithColumn(ctx, "AD_PrintColor", "Name", name);
      if (id <= 0) {
        element.defer = true;
        return;
      }
      m_PrintFormat.setAD_PrintColor_ID(id);
    }

    name = atts.getValue("ADPrintFontID");
    if (name != null && name.trim().length() > 0) {
      id = get_IDWithColumn(ctx, "AD_PrintFont", "Name", name);
      if (id <= 0) {
        element.defer = true;
        return;
      }
      m_PrintFormat.setAD_PrintFont_ID(id);
    }

    name = atts.getValue("ADPrintPaperID");
    if (name != null && name.trim().length() > 0) {
      id = get_IDWithColumn(ctx, "AD_PrintPaper", "Name", name);
      if (id <= 0) {
        element.defer = true;
        return;
      }
      m_PrintFormat.setAD_PrintPaper_ID(id);
    }

    m_PrintFormat.setDescription(getStringValue(atts, "Description"));
    m_PrintFormat.setName(atts.getValue("Name"));
    m_PrintFormat.setPrinterName(getStringValue(atts, "PrinterName"));
    m_PrintFormat.setFooterMargin(Integer.parseInt(atts.getValue("FooterMargin")));

    m_PrintFormat.setHeaderMargin(Integer.parseInt(atts.getValue("HeaderMargin")));
    m_PrintFormat.setCreateCopy(atts.getValue("CreateCopy"));
    m_PrintFormat.setIsActive(
        atts.getValue("isActive") != null
            ? Boolean.valueOf(atts.getValue("isActive")).booleanValue()
            : true);

    m_PrintFormat.setIsTableBased(Boolean.valueOf(atts.getValue("isTableBased")).booleanValue());
    m_PrintFormat.setIsForm(Boolean.valueOf(atts.getValue("isForm")).booleanValue());
    m_PrintFormat.setIsStandardHeaderFooter(
        Boolean.valueOf(atts.getValue("isStandardHeader")).booleanValue());

    m_PrintFormat.setIsDefault(Boolean.valueOf(atts.getValue("isDefault")).booleanValue());
    if (m_PrintFormat.save(getTrxName(ctx)) == true) {
      record_log(
          ctx,
          1,
          m_PrintFormat.getName(),
          "PrintFormat",
          m_PrintFormat.get_ID(),
          AD_Backup_ID,
          Object_Status,
          "AD_PrintFormat",
          get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_PrintFormat"));
      element.recordId = m_PrintFormat.getAD_PrintFormat_ID();
    } else {
      record_log(
          ctx,
          0,
          m_PrintFormat.getName(),
          "PrintFormat",
          m_PrintFormat.get_ID(),
          AD_Backup_ID,
          Object_Status,
          "AD_PrintFormat",
          get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_PrintFormat"));
      throw new POSaveFailedException("Failed to save Print Format");
    }
  }
  public void startElement(Properties ctx, Element element) throws SAXException {
    String elementValue = element.getElementValue();
    int AD_Backup_ID = -1;
    String Object_Status = null;
    Attributes atts = element.attributes;
    log.info(elementValue + " " + atts.getValue("Name"));
    // TODO: Solve for date issues with valuefrom valueto
    String entitytype = atts.getValue("EntityType");
    if (isProcessElement(ctx, entitytype)) {
      if (element.parent != null && element.parent.skip) {
        element.skip = true;
        return;
      }
      String name = atts.getValue("Name");
      String value = atts.getValue("Value");
      int AD_Reference_ID = 0;
      if (element.parent != null
          && element.parent.getElementValue().equals("reference")
          && element.parent.recordId > 0) {
        AD_Reference_ID = element.parent.recordId;
      } else {
        AD_Reference_ID =
            get_IDWithColumn(ctx, "AD_Reference", "Name", atts.getValue("ADRefenceNameID"));
      }

      int AD_Ref_List_ID =
          get_IDWithMasterAndColumn(
              ctx, "AD_Ref_List", "Value", value, "AD_Reference", AD_Reference_ID);
      X_AD_Ref_List m_Ref_List = new X_AD_Ref_List(ctx, AD_Ref_List_ID, getTrxName(ctx));
      if (AD_Ref_List_ID <= 0
          && atts.getValue("AD_Ref_List_ID") != null
          && Integer.parseInt(atts.getValue("AD_Ref_List_ID")) <= PackOut.MAX_OFFICIAL_ID)
        m_Ref_List.setAD_Ref_List_ID(Integer.parseInt(atts.getValue("AD_Ref_List_ID")));
      if (AD_Ref_List_ID > 0) {
        AD_Backup_ID = copyRecord(ctx, "AD_Ref_List", m_Ref_List);
        Object_Status = "Update";
      } else {
        Object_Status = "New";
        AD_Backup_ID = 0;
      }

      m_Ref_List.setAD_Reference_ID(AD_Reference_ID);
      m_Ref_List.setDescription(getStringValue(atts, "Description"));
      m_Ref_List.setEntityType(atts.getValue("EntityType"));
      m_Ref_List.setName(atts.getValue("Name"));
      m_Ref_List.setValue(value);
      m_Ref_List.setIsActive(
          atts.getValue("isActive") != null
              ? Boolean.valueOf(atts.getValue("isActive")).booleanValue()
              : true);

      if (m_Ref_List.save(getTrxName(ctx)) == true) {
        record_log(
            ctx,
            1,
            m_Ref_List.getName(),
            "Reference List",
            m_Ref_List.get_ID(),
            AD_Backup_ID,
            Object_Status,
            "AD_Ref_List",
            get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Ref_List"));
      } else {
        record_log(
            ctx,
            0,
            m_Ref_List.getName(),
            "Reference List",
            m_Ref_List.get_ID(),
            AD_Backup_ID,
            Object_Status,
            "AD_Ref_List",
            get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Ref_List"));
        throw new POSaveFailedException("ReferenceList");
      }
    } else {
      element.skip = true;
    }
  }
  public void startElement(Properties ctx, Element element) throws SAXException {
    String elementValue = element.getElementValue();
    Attributes atts = element.attributes;
    log.info(elementValue + " " + atts.getValue("Name"));
    int id = 0;
    String entitytype = atts.getValue("EntityType");
    if (isProcessElement(ctx, entitytype)) {
      String value = atts.getValue("Value");

      // Get New process.
      id = get_IDWithColumn(ctx, "AD_Process", "Value", value);

      X_AD_Process m_Process = null;
      int AD_Backup_ID = -1;
      String Object_Status = null;
      if (id > 0) {
        m_Process = new X_AD_Process(ctx, id, getTrxName(ctx));
        AD_Backup_ID = copyRecord(ctx, "AD_Process", m_Process);
        Object_Status = "Update";
      } else {
        m_Process = new X_AD_Process(ctx, id, getTrxName(ctx));
        if (id <= 0
            && atts.getValue("AD_Process_ID") != null
            && Integer.parseInt(atts.getValue("AD_Process_ID")) <= PackOut.MAX_OFFICIAL_ID)
          m_Process.setAD_Process_ID(Integer.parseInt(atts.getValue("AD_Process_ID")));
        Object_Status = "New";
        AD_Backup_ID = 0;
      }

      String name = atts.getValue("Name");
      m_Process.setName(name);

      name = atts.getValue("ADWorkflowNameID");
      if (name != null && name.trim().length() > 0) {
        id = get_IDWithColumn(ctx, "AD_Workflow", "Name", name);
        if (id <= 0) {
          element.defer = true;
          element.unresolved = "AD_Workflow: " + name;
          return;
        }
        m_Process.setAD_Workflow_ID(id);
      }

      name = atts.getValue("ADPrintFormatNameID");
      if (name != null && name.trim().length() > 0) {
        id = get_IDWithColumn(ctx, "AD_PrintFormat", "Name", name);
        if (id <= 0) {
          if (element.pass == 1) {
            element.defer = true;
            element.unresolved = "AD_PrintFormat: " + name;
            return;
          } else {
            log.warning(
                "AD_PrintFormat: " + name + " not found for Process: " + m_Process.getName());
          }
        }
        if (id > 0) m_Process.setAD_PrintFormat_ID(id);
      }

      name = atts.getValue("ADReportViewNameID");
      if (name != null && name.trim().length() > 0) {
        id = get_IDWithColumn(ctx, "AD_ReportView", "Name", name);
        if (id <= 0) {
          if (element.pass == 1) {
            element.defer = true;
            element.unresolved = "AD_ReportView: " + name;
            return;
          } else {
            log.warning(
                "AD_ReportView: " + name + " not found for Process: " + m_Process.getName());
          }
        }
        if (id > 0) m_Process.setAD_ReportView_ID(id);
      }

      name = atts.getValue("ADFormNameID");
      if (name != null && name.trim().length() > 0) {
        id = get_IDWithColumn(ctx, "AD_Form", "Name", name);
        if (id <= 0) {
          element.defer = true;
          element.unresolved = "AD_Form: " + name;
          return;
        }
        m_Process.setAD_Form_ID(id);
      }

      name = atts.getValue("ADBrowseNameID");
      if (name != null && name.trim().length() > 0) {
        id = get_IDWithColumn(ctx, "AD_Browse", "Name", name);
        if (id <= 0) {
          element.defer = true;
          element.unresolved = "AD_Browse: " + name;
          return;
        }
        m_Process.setAD_Browse_ID(id);
      }

      m_Process.setAccessLevel(atts.getValue("AccessLevel"));
      m_Process.setClassname(getStringValue(atts, "Classname"));
      m_Process.setDescription(getStringValue(atts, "Description"));
      m_Process.setEntityType(atts.getValue("EntityType"));
      m_Process.setHelp(getStringValue(atts, "Help"));
      m_Process.setIsBetaFunctionality(
          Boolean.valueOf(atts.getValue("isBetaFunctionality")).booleanValue());
      m_Process.setIsDirectPrint(Boolean.valueOf(atts.getValue("isDirectPrint")).booleanValue());
      m_Process.setIsReport(Boolean.valueOf(atts.getValue("isReport")).booleanValue());
      m_Process.setName(atts.getValue("Name"));

      m_Process.setProcedureName(getStringValue(atts, "ProcedureName"));
      m_Process.setStatistic_Count(0);
      m_Process.setIsActive(
          atts.getValue("isActive") != null
              ? Boolean.valueOf(atts.getValue("isActive")).booleanValue()
              : true);
      m_Process.setStatistic_Seconds(0);
      m_Process.setValue(atts.getValue("Value"));
      m_Process.setWorkflowValue(atts.getValue("WorkflowValue"));
      m_Process.setShowHelp((getStringValue(atts, "ShowHelp")));
      m_Process.setJasperReport(getStringValue(atts, "JasperReport"));
      if (m_Process.save(getTrxName(ctx)) == true) {
        record_log(
            ctx,
            1,
            m_Process.getName(),
            "Process",
            m_Process.get_ID(),
            AD_Backup_ID,
            Object_Status,
            "AD_Process",
            get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Process"));
        element.recordId = m_Process.getAD_Process_ID();
      } else {
        record_log(
            ctx,
            0,
            m_Process.getName(),
            "Process",
            m_Process.get_ID(),
            AD_Backup_ID,
            Object_Status,
            "AD_Process",
            get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Process"));
        throw new POSaveFailedException("Process");
      }
    } else {
      element.skip = true;
    }
  }
  public void startElement(Properties ctx, Element element) throws SAXException {
    String elementValue = element.getElementValue();
    Attributes atts = element.attributes;
    if (log.isLoggable(Level.INFO)) log.info(elementValue + " " + atts.getValue("ADFormNameID"));

    String entitytype = atts.getValue("EntityType");
    if (isProcessElement(ctx, entitytype)) {
      String name = atts.getValue("ADFormNameID");
      int id = get_ID(ctx, "AD_Form", name);
      MForm m_Form = new MForm(ctx, id, getTrxName(ctx));
      int AD_Backup_ID = -1;
      String Object_Status = null;
      if (id <= 0
          && atts.getValue("AD_Form_ID") != null
          && Integer.parseInt(atts.getValue("AD_Form_ID")) <= PackOut.MAX_OFFICIAL_ID)
        m_Form.setAD_Form_ID(Integer.parseInt(atts.getValue("AD_Form_ID")));
      if (id > 0) {
        AD_Backup_ID = copyRecord(ctx, "AD_Form", m_Form);
        Object_Status = "Update";
      } else {
        Object_Status = "New";
        AD_Backup_ID = 0;
      }
      m_Form.setClassname(atts.getValue("Classname"));
      m_Form.setIsBetaFunctionality(
          Boolean.valueOf(atts.getValue("isBetaFunctionality")).booleanValue());
      m_Form.setAccessLevel(atts.getValue("AccessLevel"));
      m_Form.setDescription(getStringValue(atts, "Description"));
      m_Form.setEntityType(atts.getValue("EntityType"));
      m_Form.setHelp(getStringValue(atts, "Help"));
      m_Form.setIsActive(
          atts.getValue("isActive") != null
              ? Boolean.valueOf(atts.getValue("isActive")).booleanValue()
              : true);
      m_Form.setName(atts.getValue("Name"));

      if (m_Form.save(getTrxName(ctx)) == true) {
        record_log(
            ctx,
            1,
            m_Form.getName(),
            "Form",
            m_Form.get_ID(),
            AD_Backup_ID,
            Object_Status,
            "AD_Form",
            get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Form"));
      } else {
        record_log(
            ctx,
            0,
            m_Form.getName(),
            "Form",
            m_Form.get_ID(),
            AD_Backup_ID,
            Object_Status,
            "AD_Form",
            get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Form"));
        throw new POSaveFailedException("Failed to save form definition");
      }
    } else {
      element.skip = true;
    }
  }
  public void startElement(Properties ctx, Element element) throws SAXException {
    PackIn packIn = (PackIn) ctx.get("PackInProcess");
    String elementValue = element.getElementValue();
    Attributes atts = element.attributes;
    log.info(elementValue + " " + atts.getValue("ColumnName"));
    int success = 0;
    String entitytype = atts.getValue("EntityType");
    if (isProcessElement(ctx, entitytype)) {
      if (element.parent != null
          && element.parent.getElementValue().equals("table")
          && element.parent.defer) {
        element.defer = true;
        return;
      }
      String columnName = atts.getValue("ColumnName");
      String tableName = atts.getValue("ADTableNameID");
      int tableid = 0;
      if (element.parent != null
          && element.parent.getElementValue().equals("table")
          && element.parent.recordId > 0) {
        tableid = element.parent.recordId;
      } else {
        tableid = packIn.getTableId(tableName);
      }
      if (tableid <= 0) {
        tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", tableName);
        if (tableid > 0) packIn.addTable(tableName, tableid);
      }
      int id = packIn.getColumnId(tableName, columnName);
      if (id <= 0) {
        id =
            get_IDWithMasterAndColumn(
                ctx, "AD_Column", "ColumnName", columnName, "AD_Table", tableid);
        if (id > 0) {
          packIn.addColumn(tableName, columnName, id);
        }
      }
      MColumn m_Column = new MColumn(ctx, id, getTrxName(ctx));
      if (id <= 0
          && atts.getValue("AD_Column_ID") != null
          && Integer.parseInt(atts.getValue("AD_Column_ID")) <= PackOut.MAX_OFFICIAL_ID)
        m_Column.setAD_Column_ID(Integer.parseInt(atts.getValue("AD_Column_ID")));
      int AD_Backup_ID = -1;
      String Object_Status = null;
      if (id > 0) {
        AD_Backup_ID = copyRecord(ctx, "AD_Column", m_Column);
        Object_Status = "Update";
      } else {
        Object_Status = "New";
        AD_Backup_ID = 0;
      }
      m_Column.setColumnName(columnName);

      // Process
      String processName = atts.getValue("ADProcessNameID");
      int AD_Process_ID = get_IDWithColumn(ctx, "AD_Process", "Value", processName);
      if (AD_Process_ID <= 0
      /** TODO PackOut version check 005 */
      ) {
        AD_Process_ID = get_IDWithColumn(ctx, "AD_Process", "Name", processName);
      }
      m_Column.setAD_Process_ID(AD_Process_ID);
      //
      String Name = atts.getValue("ADReferenceNameID");
      id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
      m_Column.setAD_Reference_ID(id);
      // log.info("Column ID ->"+id);
      Name = atts.getValue("ADTableNameID");
      id = get_IDWithColumn(ctx, "AD_Table", "TableName", Name);
      m_Column.setAD_Table_ID(id);

      Name = atts.getValue("ADValRuleNameID");
      id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", Name);
      m_Column.setAD_Val_Rule_ID(id);
      Name = atts.getValue("ADReferenceNameValueID");
      id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
      m_Column.setAD_Reference_Value_ID(id);
      m_Column.setCallout(getStringValue(atts, "Callout"));
      m_Column.setColumnSQL(getStringValue(atts, "ColumnSQL"));

      m_Column.setColumnName(atts.getValue("ColumnName"));
      m_Column.setDefaultValue(getStringValue(atts, "DefaultValue"));
      m_Column.setDescription(getStringValue(atts, "Description"));
      m_Column.setEntityType(atts.getValue("EntityType"));

      if (Integer.parseInt(atts.getValue("FieldLength")) > 0)
        m_Column.setFieldLength(Integer.parseInt(atts.getValue("FieldLength")));
      m_Column.setHelp(getStringValue(atts, "Help"));
      m_Column.setIsActive(
          atts.getValue("isActive") != null
              ? Boolean.valueOf(atts.getValue("isActive")).booleanValue()
              : true);
      m_Column.setIsAlwaysUpdateable(
          (Boolean.valueOf(atts.getValue("isAlwaysUpdateable")).booleanValue()));
      // m_Column.setIsEncrypted(atts.getValue("isEncrypted"));
      m_Column.setIsIdentifier((Boolean.valueOf(atts.getValue("isIdentifier")).booleanValue()));
      m_Column.setIsKey((Boolean.valueOf(atts.getValue("isKey")).booleanValue()));
      m_Column.setIsMandatory((Boolean.valueOf(atts.getValue("isMandatory")).booleanValue()));

      m_Column.setIsParent((Boolean.valueOf(atts.getValue("isParent")).booleanValue()));
      m_Column.setIsSelectionColumn(
          (Boolean.valueOf(atts.getValue("isSelectionColumn")).booleanValue()));
      m_Column.setIsSyncDatabase(atts.getValue("getIsSyncDatabase"));

      m_Column.setIsTranslated((Boolean.valueOf(atts.getValue("isTranslated")).booleanValue()));
      m_Column.setIsUpdateable((Boolean.valueOf(atts.getValue("isUpdateable")).booleanValue()));
      m_Column.setName(atts.getValue("Name"));
      m_Column.setReadOnlyLogic(getStringValue(atts, "ReadOnlyLogic"));

      if (Integer.parseInt(atts.getValue("SeqNo")) > 0)
        m_Column.setSeqNo(Integer.parseInt(atts.getValue("SeqNo")));
      m_Column.setVFormat(getStringValue(atts, "VFormat"));
      if (getStringValue(atts, "ValueMax") != null) m_Column.setValueMax(atts.getValue("ValueMax"));
      if (getStringValue(atts, "ValueMin") != null) m_Column.setValueMin(atts.getValue("ValueMin"));
      if (getStringValue(atts, "Version") != null)
        m_Column.setVersion(new BigDecimal(atts.getValue("Version")));

      m_Column.setInfoFactoryClass(getStringValue(atts, "InfoFactoryClass"));

      // Setup Element.
      id = get_IDWithColumn(ctx, "AD_Element", "ColumnName", m_Column.getColumnName());
      X_AD_Element adElement = new X_AD_Element(ctx, id, getTrxName(ctx));

      String Object_Status_col = Object_Status;
      if (adElement.getAD_Element_ID() == 0) {
        // Object_Status = "New";
        adElement.setColumnName(m_Column.getColumnName());
        adElement.setEntityType(m_Column.getEntityType());
        adElement.setPrintName(m_Column.getColumnName());

        adElement.setName(m_Column.getColumnName());
        if (adElement.save(getTrxName(ctx)) == true) {
          record_log(
              ctx,
              1,
              m_Column.getName(),
              "Element",
              adElement.getAD_Element_ID(),
              AD_Backup_ID,
              "New",
              "AD_Element",
              get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Element"));
        } else {
          record_log(
              ctx,
              0,
              m_Column.getName(),
              "Element",
              adElement.getAD_Element_ID(),
              AD_Backup_ID,
              "New",
              "AD_Element",
              get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Element"));
        }
      }

      Object_Status = Object_Status_col;
      m_Column.setAD_Element_ID(adElement.getAD_Element_ID());

      boolean recreateColumn =
          (m_Column.is_new()
              || m_Column.is_ValueChanged("AD_Reference_ID")
              || m_Column.is_ValueChanged("FieldLength")
              || m_Column.is_ValueChanged("ColumnName")
              || m_Column.is_ValueChanged("IsMandatory"));

      // ignore fieldlength change for clob and lob
      if (!m_Column.is_ValueChanged("AD_Reference_ID") && m_Column.is_ValueChanged("FieldLength")) {
        if (DisplayType.isLOB(m_Column.getAD_Reference_ID())) {
          recreateColumn = false;
        }
      }

      // changed default ??
      // m_Column.is_ValueChanged("DefaultValue") doesn't work well with
      // nulls
      if (!recreateColumn) {
        String oldDefault = (String) m_Column.get_ValueOld("DefaultValue");
        String newDefault = m_Column.getDefaultValue();
        if (oldDefault != null && oldDefault.length() == 0) oldDefault = null;
        if (newDefault != null && newDefault.length() == 0) newDefault = null;
        if ((oldDefault == null && newDefault != null)
            || (oldDefault != null && newDefault == null)) {
          recreateColumn = true;
        } else if (oldDefault != null && newDefault != null) {
          if (!oldDefault.equals(newDefault)) recreateColumn = true;
        }
      }

      // Don't create database column for virtual columns
      boolean syncDatabase = "Y".equalsIgnoreCase(atts.getValue("getIsSyncDatabase"));
      if (recreateColumn) {
        if (m_Column.isVirtualColumn() || !syncDatabase) recreateColumn = false;
      }

      if (m_Column.save(getTrxName(ctx)) == true) {
        record_log(
            ctx,
            1,
            m_Column.getName(),
            "Column",
            m_Column.get_ID(),
            AD_Backup_ID,
            Object_Status,
            "AD_Column",
            get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Column"));
        element.recordId = m_Column.getAD_Column_ID();
      } else {
        record_log(
            ctx,
            0,
            m_Column.getName(),
            "Column",
            m_Column.get_ID(),
            AD_Backup_ID,
            Object_Status,
            "AD_Column",
            get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Column"));
        throw new POSaveFailedException("Failed to import column.");
      }

      if (recreateColumn || syncDatabase) {
        MTable table = new MTable(ctx, m_Column.getAD_Table_ID(), getTrxName(ctx));
        if (!table.isView() && !m_Column.isVirtualColumn()) {
          success = createColumn(ctx, table, m_Column, recreateColumn);

          if (success == 1) {
            record_log(
                ctx,
                1,
                m_Column.getColumnName(),
                "dbColumn",
                m_Column.get_ID(),
                0,
                Object_Status,
                atts.getValue("ADTableNameID").toUpperCase(),
                get_IDWithColumn(
                    ctx, "AD_Table", "TableName", atts.getValue("ADTableNameID").toUpperCase()));
          } else {
            record_log(
                ctx,
                0,
                m_Column.getColumnName(),
                "dbColumn",
                m_Column.get_ID(),
                0,
                Object_Status,
                atts.getValue("ADTableNameID").toUpperCase(),
                get_IDWithColumn(
                    ctx, "AD_Table", "TableName", atts.getValue("ADTableNameID").toUpperCase()));
            throw new DatabaseAccessException(
                "Failed to create column or related constraint for " + m_Column.getColumnName());
          }
        }
      }
    } else {
      element.skip = true;
    }
  }