Example #1
0
 /**
  * After Save
  *
  * @param newRecord new
  * @param success success
  * @return success
  */
 @Override
 protected boolean afterSave(boolean newRecord, boolean success) {
   // Update Fields
   if (!newRecord) {
     if (is_ValueChanged(MColumn.COLUMNNAME_Name)
         || is_ValueChanged(MColumn.COLUMNNAME_Description)
         || is_ValueChanged(MColumn.COLUMNNAME_Help)) {
       StringBuffer sql =
           new StringBuffer("UPDATE AD_Field SET Name=")
               .append(DB.TO_STRING(getName()))
               .append(", Description=")
               .append(DB.TO_STRING(getDescription()))
               .append(", Help=")
               .append(DB.TO_STRING(getHelp()))
               .append(" WHERE AD_Column_ID=")
               .append(get_ID())
               .append(" AND IsCentrallyMaintained='Y'");
       int no = DB.executeUpdate(sql.toString(), get_TrxName());
       log.debug("afterSave - Fields updated #" + no);
     }
   }
   return success;
 } // afterSave
  /**
   * Receive notification of the end of an element.
   *
   * @param uri namespace
   * @param localName simple name
   * @param qName qualified name
   * @throws SAXException
   */
  public void endElement(String uri, String localName, String qName) throws SAXException {
    //	Log.trace(Log.l6_Database+1, "TranslationHandler.endElement", qName);
    if (qName.equals(Translation.XML_TAG)
        || qName.equals(Translation.XML_TAG2)
        || qName.equals(Translation.XML_TAG3)) {

    } else if (qName.equals(Translation.XML_ROW_TAG)) {
      //	Set section
      if (m_sql.length() > 0) m_sql.append(",");
      m_sql.append("Updated=").append(DB.TO_DATE(m_time, false));
      if (!m_isBaseLanguage) {
        if (m_trl != null && ("Y".equals(m_trl) || "N".equals(m_trl)))
          m_sql.append(",IsTranslated='").append(m_trl).append("'");
        else m_sql.append(",IsTranslated='Y'");
      }
      //	Where section
      m_sql.append(" WHERE ");
      if (m_curUUID != null) {
        StringBuilder sql =
            new StringBuilder("SELECT ")
                .append(m_TableName)
                .append("_ID")
                .append(" FROM ")
                .append(m_TableName)
                .append(" WHERE ")
                .append(m_TableName)
                .append("_UU =?");
        int ID = DB.getSQLValueEx(null, sql.toString(), m_curUUID);
        m_sql.append(m_TableName).append("_ID=").append(ID);
      } else {
        m_sql.append(m_TableName).append("_ID=").append(m_curID);
      }
      if (!m_isBaseLanguage) m_sql.append(" AND AD_Language='").append(m_AD_Language).append("'");
      if (m_AD_Client_ID >= 0) m_sql.append(" AND AD_Client_ID=").append(m_AD_Client_ID);
      //	Update section
      m_sql.insert(0, m_updateSQL);

      //	Execute
      int no = DB.executeUpdate(m_sql.toString(), null);
      if (no == 1) {
        if (log.isLoggable(Level.FINE)) log.fine(m_sql.toString());
        m_updateCount++;
      } else if (no == 0) log.warning("Not Found - " + m_sql.toString());
      else log.severe("Update Rows=" + no + " (Should be 1) - " + m_sql.toString());
    } else if (qName.equals(Translation.XML_VALUE_TAG)) {
      if (m_sql.length() > 0) m_sql.append(",");
      m_sql.append(m_curColumnName).append("=").append(DB.TO_STRING(m_curValue.toString()));
    }
  } //	endElement
Example #3
0
  /**
   * Perform process.
   *
   * @return Message
   * @throws Exception if not successful
   */
  protected String doIt() throws Exception {
    String where = " Password IS NOT NULL AND Salt IS NULL ";

    int count = 0;
    boolean isEncrypted = MColumn.isEncrypted(417);

    List<MUser> users =
        MTable.get(getCtx(), MUser.Table_ID).createQuery(where, get_TrxName()).list();
    for (MUser user : users) {
      if (user.getAD_User_ID() == 0) {
        String password =
            DB.getSQLValueString(
                get_TrxName(), "SELECT Password FROM AD_User WHERE AD_User_ID=?", 0);
        if (isEncrypted) password = SecureEngine.decrypt(password);

        user.setPassword(password);
        String sql = "UPDATE AD_User SET Updated=SysDate, UpdatedBy=" + getAD_User_ID();
        if (!Util.isEmpty(password)) {
          sql +=
              ", Password="******", Salt=" + DB.TO_STRING(user.getSalt());
        }
        sql += " WHERE AD_User_ID=0";
        DB.executeUpdateEx(sql, get_TrxName());
        count++;
      } else {
        user.setPassword(user.getPassword());
        count++;
        user.saveEx();
      }
    }

    return "@Updated@ " + count;
  } //	doIt
  private Vector<Vector> getBExceptionData() {
    Vector<Vector> data = new Vector<Vector>();

    final String whereClause =
        MBExceptionDetail.COLUMNNAME_Record_ID
            + " = "
            + m_mTab.getRecord_ID()
            + " AND "
            + MBExceptionDetail.COLUMNNAME_Status
            + "<>"
            + DB.TO_STRING(MBExceptionDetail.STATUS_Completed);
    MBExceptionDetail[] bExceptionDetails =
        MBExceptionDetail.getBExceptionDetail(Env.getCtx(), whereClause);
    for (MBExceptionDetail ex : bExceptionDetails) {

      Vector<String> row = new Vector<String>();
      row.add(ex.getWT_BExceptionType().getName());
      row.add(ex.getValue());
      data.add(row);
    }

    return data;
  }
Example #5
0
  /**
   * Get SQL DDL
   *
   * @return columnName datataype ..
   */
  public String getSQLDDL() {
    if (isVirtualColumn()) return null;

    StringBuffer sql = new StringBuffer(getColumnName()).append(" ").append(getSQLDataType());

    // Default
    String defaultValue = getDefaultValue();
    if (defaultValue != null
        && defaultValue.length() > 0
        && defaultValue.indexOf('@') == -1 // no variables
        && (!(DisplayType.isID(getAD_Reference_ID())
            && defaultValue.equals("-1")))) // not for ID's with default -1
    {
      if (DisplayType.isText(getAD_Reference_ID())
          || getAD_Reference_ID() == DisplayType.List
          || getAD_Reference_ID() == DisplayType.YesNo
          // Two special columns: Defined as Table but DB Type is String
          || getColumnName().equals("EntityType")
          || getColumnName().equals("AD_Language")
          || (getAD_Reference_ID() == DisplayType.Button && !(getColumnName().endsWith("_ID")))) {
        if (!defaultValue.startsWith("'") && !defaultValue.endsWith("'"))
          defaultValue = DB.TO_STRING(defaultValue);
      }
      sql.append(" DEFAULT ").append(defaultValue);
    } else {
      if (!isMandatory()) sql.append(" DEFAULT NULL ");
      defaultValue = null;
    }

    // Inline Constraint
    if (getAD_Reference_ID() == DisplayType.YesNo)
      sql.append(" CHECK (").append(getColumnName()).append(" IN ('Y','N'))");

    // Null
    if (isMandatory()) sql.append(" NOT NULL");
    return sql.toString();
  } // getSQLDDL
Example #6
0
  /**
   * Get SQL Modify command
   *
   * @param table table
   * @param setNullOption generate null / not null statement
   * @return sql separated by ;
   */
  public String getSQLModify(final I_AD_Table table, final boolean setNullOption) {
    final String tableName = table.getTableName();
    final String columnName = getColumnName();
    final int displayType = getAD_Reference_ID();
    String defaultValue = getDefaultValue();
    final boolean mandatory = isMandatory();
    final String sqlDataType = getSQLDataType();

    final StringBuilder sql = new StringBuilder();
    final StringBuilder sqlBase =
        new StringBuilder("ALTER TABLE ").append(tableName).append(" MODIFY ").append(columnName);

    // Default
    final StringBuilder sqlDefault = new StringBuilder(sqlBase).append(" ").append(sqlDataType);
    if (defaultValue != null
        && defaultValue.length() > 0
        && defaultValue.indexOf('@') == -1 // no variables
        && (!(DisplayType.isID(displayType)
            && defaultValue.equals("-1")))) // not for ID's with default -1
    {
      if (DisplayType.isText(displayType)
          || displayType == DisplayType.List
          || displayType == DisplayType.YesNo
          // Two special columns: Defined as Table but DB Type is String
          || columnName.equals("EntityType")
          || columnName.equals("AD_Language")
          || (displayType == DisplayType.Button && !(columnName.endsWith("_ID")))) {
        if (!defaultValue.startsWith("'") && !defaultValue.endsWith("'"))
          defaultValue = DB.TO_STRING(defaultValue);
      }
      sqlDefault.append(" DEFAULT ").append(defaultValue);
    } else {
      if (!mandatory) sqlDefault.append(" DEFAULT NULL ");
      defaultValue = null;
    }
    sql.append(DB.convertSqlToNative(sqlDefault.toString()));

    // Constraint

    // Null Values
    if (mandatory && defaultValue != null && defaultValue.length() > 0) {
      StringBuffer sqlSet =
          new StringBuffer("UPDATE ")
              .append(tableName)
              .append(" SET ")
              .append(columnName)
              .append("=")
              .append(defaultValue)
              .append(" WHERE ")
              .append(columnName)
              .append(" IS NULL");
      sql.append(DB.SQLSTATEMENT_SEPARATOR).append(sqlSet);
    }

    // Null
    if (setNullOption) {
      StringBuffer sqlNull = new StringBuffer(sqlBase);
      if (mandatory) sqlNull.append(" NOT NULL");
      else sqlNull.append(" NULL");
      sql.append(DB.SQLSTATEMENT_SEPARATOR).append(DB.convertSqlToNative(sqlNull.toString()));
    }
    //
    return sql.toString();
  } // getSQLModify
Example #7
0
  /**
   * Hit Enter in Text Field
   *
   * @param only_Warehouse_ID if not 0 restrict warehouse
   * @param only_Product_ID of not 0 restricted product
   * @return true if found
   */
  private boolean actionText(int only_Warehouse_ID, int only_Product_ID) {
    String text = m_text.getText();
    log.debug(text);
    //	Null
    if (text == null || text.length() == 0) {
      if (isMandatory()) return false;
      else {
        setValue(null, true);
        return true;
      }
    }
    if (text.endsWith("%")) text = text.toUpperCase();
    else text = text.toUpperCase() + "%";

    //	Look up - see MLocatorLookup.run
    StringBuffer sql =
        new StringBuffer("SELECT M_Locator_ID FROM M_Locator ")
            .append(" WHERE IsActive='Y' AND UPPER(Value) LIKE ")
            .append(DB.TO_STRING(text));
    if (getOnly_Warehouse_ID() != 0) sql.append(" AND M_Warehouse_ID=?");
    if (getOnly_Product_ID() != 0)
      sql.append(" AND (IsDefault='Y' ") // 	Default Locator
          .append("OR EXISTS (SELECT * FROM M_Product p ") // 	Product Locator
          .append("WHERE p.M_Locator_ID=M_Locator.M_Locator_ID AND p.M_Product_ID=?)")
          .append("OR EXISTS (SELECT * FROM M_Storage s ") // 	Storage Locator
          .append("WHERE s.M_Locator_ID=M_Locator.M_Locator_ID AND s.M_Product_ID=?))");
    String finalSql =
        Env.getUserRolePermissions()
            .addAccessSQL(
                sql.toString(),
                "M_Locator",
                IUserRolePermissions.SQL_NOTQUALIFIED,
                IUserRolePermissions.SQL_RO);
    //
    int M_Locator_ID = 0;
    PreparedStatement pstmt = null;
    try {
      pstmt = DB.prepareStatement(finalSql, null);
      int index = 1;
      if (only_Warehouse_ID != 0) pstmt.setInt(index++, only_Warehouse_ID);
      if (only_Product_ID != 0) {
        pstmt.setInt(index++, only_Product_ID);
        pstmt.setInt(index++, only_Product_ID);
      }
      ResultSet rs = pstmt.executeQuery();
      if (rs.next()) {
        M_Locator_ID = rs.getInt(1);
        if (rs.next()) M_Locator_ID = 0; // 	more than one
      }
      rs.close();
      pstmt.close();
      pstmt = null;
    } catch (SQLException ex) {
      log.error(finalSql, ex);
    }
    try {
      if (pstmt != null) pstmt.close();
    } catch (SQLException ex1) {
    }
    pstmt = null;
    if (M_Locator_ID == 0) return false;

    setValue(new Integer(M_Locator_ID), true);
    return true;
  } //	actionText