Пример #1
0
 /**
  * ************************************************************************ Receive notification
  * of the start of an element.
  *
  * @param uri namespace
  * @param localName simple name
  * @param qName qualified name
  * @param attributes attributes
  * @throws org.xml.sax.SAXException
  */
 public void startElement(String uri, String localName, String qName, Attributes attributes)
     throws org.xml.sax.SAXException {
   //	log.fine( "TranslationHandler.startElement", qName);	// + " - " + uri + " - " + localName);
   if (qName.equals(Translation.XML_TAG)
       || qName.equals(Translation.XML_TAG2)
       || qName.equals(Translation.XML_TAG3)) {
     m_AD_Language = attributes.getValue(Translation.XML_ATTRIBUTE_LANGUAGE);
     m_isBaseLanguage = Language.isBaseLanguage(m_AD_Language);
     m_TableName = attributes.getValue(Translation.XML_ATTRIBUTE_TABLE);
     m_updateSQL = "UPDATE " + m_TableName;
     if (!m_isBaseLanguage) m_updateSQL += "_Trl";
     m_updateSQL += " SET ";
     if (log.isLoggable(Level.FINE))
       log.fine(
           "AD_Language="
               + m_AD_Language
               + ", Base="
               + m_isBaseLanguage
               + ", TableName="
               + m_TableName);
   } else if (qName.equals(Translation.XML_ROW_TAG)) {
     m_curID = attributes.getValue(Translation.XML_ROW_ATTRIBUTE_ID);
     m_curUUID = attributes.getValue(Translation.XML_ROW_ATTRIBUTE_UUID);
     m_trl = attributes.getValue(Translation.XML_ROW_ATTRIBUTE_TRANSLATED);
     //	log.finest( "ID=" + m_curID);
     m_sql = new StringBuffer();
   } else if (qName.equals(Translation.XML_VALUE_TAG)) {
     m_curColumnName = attributes.getValue(Translation.XML_VALUE_ATTRIBUTE_COLUMN);
     //	log.finest( "ColumnName=" + m_curColName);
   } else log.severe("UNKNOWN TAG: " + qName);
   m_curValue = new StringBuffer();
 } //	startElement
Пример #2
0
  private static ElementBean getTrl(String sql) {
    PreparedStatement pstmt = DB.prepareStatement(sql, null);

    ElementBean retElementBean = null;
    try {
      ResultSet rs = pstmt.executeQuery();
      if (rs.next()) {
        retElementBean = new ElementBean();
        retElementBean.setColumnName(rs.getString(1));
        retElementBean.setName(rs.getString(2));
        retElementBean.setPrintName(rs.getString(3));
        retElementBean.setDescription(rs.getString(4));
        retElementBean.setHelp(rs.getString(5));
      } else {
        return null;
      }
      rs.close();
    } catch (Exception ex) {
      log.severe("Could retrieve element translation with sql: " + sql);
    } finally {
      try {
        pstmt.close();
      } catch (Exception ex) {
      }
    }

    return retElementBean;
  }
Пример #3
0
 /**
  * Get Calendar of Period
  *
  * @return calendar
  */
 public int getC_Calendar_ID() {
   if (m_C_Calendar_ID == 0) {
     MYear year = MYear.get(getCtx(), getC_Year_ID());
     if (year != null) m_C_Calendar_ID = year.getC_Calendar_ID();
     else log.severe("@NotFound@ C_Year_ID=" + getC_Year_ID());
   }
   return m_C_Calendar_ID;
 } //	getC_Calendar_ID
Пример #4
0
  /**
   * 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
Пример #5
0
  @Override
  public String getSQLDataType(int displayType, String columnName, int fieldLength) {
    if (columnName.equals("EntityType") || columnName.equals("AD_Language"))
      return "VARCHAR2(" + fieldLength + ")";
    //	ID
    if (DisplayType.isID(displayType)) {
      if (displayType == DisplayType.Image // 	FIXTHIS
          && columnName.equals("BinaryData")) return "BLOB";
      //	ID, CreatedBy/UpdatedBy, Acct
      else if (columnName.endsWith("_ID")
          || columnName.endsWith("tedBy")
          || columnName.endsWith("_Acct")
          || "AD_Key".equals(columnName) // HARDCODED for AD_Ref_Table.AD_Key
          || "AD_Display".equals(columnName) // HARDCODED for AD_Ref_Table.AD_Display
      ) return "NUMBER(10)";
      else if (fieldLength < 4) return "CHAR(" + fieldLength + ")";
      else //	EntityType, AD_Language	fallback
      return "VARCHAR2(" + fieldLength + ")";
    }
    //
    if (displayType == DisplayType.Integer) return "NUMBER(10)";
    if (displayType == DisplayType.DateTime) return "TIMESTAMP WITH TIME ZONE";
    if (DisplayType.isDate(displayType)) return "DATE";
    if (DisplayType.isNumeric(displayType)) return "NUMBER";
    if (displayType == DisplayType.Binary) return "BLOB";
    if (displayType == DisplayType.TextLong
        || (displayType == DisplayType.Text && fieldLength >= 4000)) return "CLOB";
    if (displayType == DisplayType.YesNo) return "CHAR(1)";
    if (displayType == DisplayType.List) {
      if (fieldLength == 1) return "CHAR(" + fieldLength + ")";
      else return "NVARCHAR2(" + fieldLength + ")";
    }
    if (displayType
        == DisplayType.Color) // this condition is never reached - filtered above in isID
    {
      if (columnName.endsWith("_ID")) return "NUMBER(10)";
      else return "CHAR(" + fieldLength + ")";
    }
    if (displayType == DisplayType.Button) {
      if (columnName.endsWith("_ID")) return "NUMBER(10)";
      else return "CHAR(" + fieldLength + ")";
    }
    if (!DisplayType.isText(displayType)) log.severe("Unhandled Data Type = " + displayType);

    return "NVARCHAR2(" + fieldLength + ")";
  } //	getSQLDataType
Пример #6
0
  /**
   * Field Changed
   *
   * @param windowNo relative window
   * @param AD_Field_ID field
   * @param AD_Tab_ID tab
   * @param oldValue old field value
   * @param newValue new field value
   * @param context record context
   * @return Field Change VO
   */
  public ChangeVO fieldChanged(
      int windowNo,
      int AD_Field_ID,
      int AD_Tab_ID,
      String oldValue,
      String newValue,
      Map<String, String> context) {
    // Same Values
    if (oldValue == null || oldValue.equals(Null.NULLString)) oldValue = "";
    if (newValue == null || newValue.equals(Null.NULLString)) newValue = "";
    if (oldValue.equals(newValue)) return null;
    //
    UITab tab = getTab(AD_Tab_ID);
    if (tab == null) {
      log.config("Not found AD_Tab_ID=" + AD_Tab_ID);
      return null;
    }
    UIField field = getField(AD_Field_ID, windowNo);
    if (field == null) {
      log.warning("Cannot find AD_Field_ID=" + AD_Field_ID);
      return null;
    }

    CContext ctx = new CContext(m_context.entrySet());
    ctx.addWindow(windowNo, context);
    CContext origCtx = new CContext(m_context.entrySet());
    origCtx.addWindow(windowNo, context);
    ChangeVO change = null;
    try {
      // reset the thread active flag, in case the thread is reused later on
      CThreadUtil.setCalloutActive(false);
      change =
          tab.fieldChanged(
              origCtx, ctx, new ArrayList<UIField>(5), windowNo, field, oldValue, newValue);
      CThreadUtil.setCalloutActive(false);
      ctx.setContext(windowNo, field.getColumnName(), change.newConfirmedFieldValue);
    } catch (Exception e) {
      log.severe("fieldChange error:" + field.getColumnName() + e.getMessage());
    } finally {
      CThreadUtil.setCalloutActive(false);
    }

    return change;
  } // fieldChanged
 /** @param success */
 protected boolean afterDelete(boolean success) {
   if (success) {
     try {
       MPayment[] pays = getPayments(get_TrxName());
       for (int i = 0; i < pays.length; i++) {
         if (!pays[i].delete(false, get_TrxName())) {
           String msg =
               "No se pudo eliminar alguno de los pagos vinculados al documento que"
                   + "se está eliminando. Se cancelará la operación";
           s_log.severe(msg);
           ADialog.error(0, null, msg);
           return false;
         }
       }
     } catch (SQLException e) {
       s_log.log(Level.SEVERE, e.getLocalizedMessage(), e);
       return false;
     }
   }
   return success;
 }
Пример #8
0
  public static MRequestAction[] getActions(MRequest request) {
    ArrayList<MRequestAction> retVal = new ArrayList<MRequestAction>();
    String sql = "SELECT * FROM R_RequestAction WHERE R_Request_ID = ? ";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(sql, request.get_Trx());
      pstmt.setInt(1, request.getR_Request_ID());
      rs = pstmt.executeQuery();
      while (rs.next()) retVal.add(new MRequestAction(request.getCtx(), rs, request.get_Trx()));
    } catch (Exception e) {
      log.severe(e.toString());
    } finally {
      DB.closeResultSet(rs);
      DB.closeStatement(pstmt);
    }

    MRequestAction[] actions = new MRequestAction[retVal.size()];
    retVal.toArray(actions);
    return actions;
  }
Пример #9
0
  /**
   * ************************************************************************ Generate PO Model
   * Class.
   *
   * <pre>
   * 	Example: java GenerateModel.class mydirectory myPackage 'U','A'
   * 	would generate entity type User and Application classes into mydirectory.
   * 	Without parameters, the default is used:
   * 	C:\Adempiere\adempiere-all\extend\src\adempiere\model\ adempiere.model 'U','A'
   * 	</pre>
   *
   * @param args directory package entityType - directory where to save the generated file - package
   *     of the classes to be generated - entityType to be generated
   */
  public static void main(String[] args) {
    org.compiere.Adempiere.startupEnvironment(true);
    CLogMgt.setLevel(Level.FINE);
    //	CLogMgt.setLevel(Level.ALL);
    log.info("Generate Model   $Revision: 1.5 $");
    log.info("----------------------------------");
    //	first parameter
    String directory = "/app/adempiere/adempiere_branch_3.1.1/dbPort/src/org/adempiere/model/";
    if (args.length > 0) directory = args[0];
    if (directory == null || directory.length() == 0) {
      System.err.println("No Directory");
      System.exit(1);
    }
    log.info("Directory: " + directory);

    //	second parameter
    String packageName = "adempiere.model";
    if (args.length > 1) packageName = args[1];
    if (packageName == null || packageName.length() == 0) {
      System.err.println("No package");
      System.exit(1);
    }
    log.info("Package:   " + packageName);

    //	third parameter
    String entityType = "'U','A','D'"; // 	User, Application
    if (args.length > 2) entityType = args[2];
    if (entityType == null || entityType.length() == 0) {
      System.err.println("No EntityType");
      System.exit(1);
    }
    StringBuffer sql = new StringBuffer("EntityType IN (").append(entityType).append(")");
    log.info(sql.toString());
    log.info("----------------------------------");

    //	complete sql
    sql.insert(
        0,
        "SELECT AD_Table_ID "
            + "FROM AD_Table "
            + "WHERE (TableName IN ('RV_WarehousePrice','RV_BPartner')" //	special views
            + " OR IsView='N')"
            + " AND TableName NOT LIKE '%_Trl' AND ");
    sql.append(" ORDER BY TableName");

    //
    int count = 0;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(sql.toString(), null);
      rs = pstmt.executeQuery();
      while (rs.next()) {
        new GenerateModelJPA(rs.getInt(1), directory, packageName);
        count++;
      }
    } catch (Exception e) {
      log.severe("main - " + e);
    } finally {
      DB.close(rs, pstmt);
      rs = null;
      pstmt = null;
    }

    log.info("Generated = " + count);
  } //	main
Пример #10
0
  /** @param e */
  public void valueChange(ValueChangeEvent e) {
    if (gridTab.isProcessed()) //  only active records
    {
      Object source = e.getSource();
      if (source instanceof WEditor) {
        // Elaine 2009/05/06
        WEditor editor = (WEditor) source;
        GridField gridField = editor.getGridField();

        if (gridField != null) {
          if (!gridField.isEditable(true)) {
            logger.config("(" + gridTab.toString() + ") " + e.getPropertyName());
            return;
          }
        } else if (!editor.isReadWrite()) {
          logger.config("(" + gridTab.toString() + ") " + e.getPropertyName());
          return;
        }
      } else {
        logger.config("(" + gridTab.toString() + ") " + e.getPropertyName());
        return;
      }
    } //  processed
    logger.config(
        "("
            + gridTab.toString()
            + ") "
            + e.getPropertyName()
            + "="
            + e.getNewValue()
            + " ("
            + e.getOldValue()
            + ") "
            + (e.getOldValue() == null ? "" : e.getOldValue().getClass().getName()));

    //  Get Row/Col Info
    GridTable mTable = gridTab.getTableModel();
    int row = gridTab.getCurrentRow();
    int col = mTable.findColumn(e.getPropertyName());
    //
    if (e.getNewValue() == null
        && e.getOldValue() != null
        && e.getOldValue().toString().length() > 0) //  some editors return "" instead of null
      //        	  this is the original code from GridController, don't know what it does there but
      // it breaks ignore button for web ui
      //            mTable.setChanged (true);
      mTable.setValueAt(e.getNewValue(), row, col);
    else {

      Object newValue = e.getNewValue();
      Integer newValues[] = null;

      if (newValue instanceof Integer[]) {
        newValues = ((Integer[]) newValue);
        newValue = newValues[0];

        if (newValues.length > 1) {
          Integer valuesCopy[] = new Integer[newValues.length - 1];
          System.arraycopy(newValues, 1, valuesCopy, 0, valuesCopy.length);
          newValues = valuesCopy;
        } else {
          newValues = null;
        }
      } else if (newValue instanceof Object[]) {
        logger.severe("Multiple values can only be processed for IDs (Integer)");
        throw new IllegalArgumentException(
            "Multiple Selection values not available for this field. " + e.getPropertyName());
      }

      mTable.setValueAt(newValue, row, col);
      //  Force Callout
      if (e.getPropertyName().equals("S_ResourceAssignment_ID")) {
        GridField mField = gridTab.getField(col);
        if (mField != null && mField.getCallout().length() > 0) {
          gridTab.processFieldChange(mField); //  Dependencies & Callout
        }
      }

      if (newValues != null && newValues.length > 0) {
        // Save data, since record need to be used for generating clones.
        if (!gridTab.dataSave(false)) {
          throw new AdempiereException("SaveError");
        }

        // Retrieve the current record ID
        int recordId = gridTab.getKeyID(gridTab.getCurrentRow());

        Trx trx = Trx.get(Trx.createTrxName(), true);
        trx.start();
        try {
          saveMultipleRecords(
              Env.getCtx(),
              gridTab.getTableName(),
              e.getPropertyName(),
              recordId,
              newValues,
              trx.getTrxName());
          trx.commit();
          gridTab.dataRefreshAll();
        } catch (Exception ex) {
          trx.rollback();
          logger.severe(ex.getMessage());
          throw new AdempiereException("SaveError");
        } finally {
          trx.close();
        }
      }
    }
  } // ValueChange
Пример #11
0
  /**
   * Save LOB. see also org.compiere.session.ServerBean#updateLOB
   *
   * @param trxName trx name
   * @return true if saved
   */
  public boolean save(String trxName) {
    if (m_value == null
        || (!(m_value instanceof String || m_value instanceof byte[]))
        || (m_value instanceof String && m_value.toString().length() == 0)
        || (m_value instanceof byte[] && ((byte[]) m_value).length == 0)) {
      StringBuffer sql =
          new StringBuffer("UPDATE ")
              .append(m_tableName)
              .append(" SET ")
              .append(m_columnName)
              .append("=null WHERE ")
              .append(m_whereClause);
      int no = DB.executeUpdate(sql.toString(), trxName);
      log.fine("save [" + trxName + "] #" + no + " - no data - set to null - " + m_value);
      if (no == 0) log.warning("[" + trxName + "] - not updated - " + sql);
      return true;
    }

    StringBuffer sql =
        new StringBuffer("UPDATE ")
            .append(m_tableName)
            .append(" SET ")
            .append(m_columnName)
            .append("=? WHERE ")
            .append(m_whereClause);
    //

    log.fine("[" + trxName + "] - Local - " + m_value);
    //	Connection
    Trx trx = null;
    if (trxName != null) trx = Trx.get(trxName, false);
    Connection con = null;
    //	Create Connection
    if (trx != null) con = trx.getConnection();
    if (con == null) con = DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED);
    if (con == null) {
      log.log(Level.SEVERE, "Could not get Connection");
      return false;
    }

    PreparedStatement pstmt = null;
    boolean success = true;
    try {
      pstmt = con.prepareStatement(sql.toString());
      if (DisplayType.isText(m_displayType)) pstmt.setString(1, (String) m_value);
      else pstmt.setBytes(1, (byte[]) m_value);
      int no = pstmt.executeUpdate();
      if (no != 1) {
        log.warning("[" + trxName + "] - Not updated #" + no + " - " + sql);
        success = false;
      }
    } catch (Throwable e) {
      log.log(Level.SEVERE, "[" + trxName + "] - " + sql, e);
      success = false;
    } finally {
      DB.close(pstmt);
      pstmt = null;
    }

    //	Success - commit local trx
    if (success) {
      if (trx != null) {
        trx = null;
        con = null;
      } else {
        try {
          con.commit();
        } catch (Exception e) {
          log.log(Level.SEVERE, "[" + trxName + "] - commit ", e);
          success = false;
        } finally {
          try {
            con.close();
          } catch (SQLException e) {
          }
          con = null;
        }
      }
    }
    //	Error - roll back
    if (!success) {
      log.severe("[" + trxName + "] - rollback");
      if (trx != null) {
        trx.rollback();
        trx = null;
        con = null;
      } else {
        try {
          con.rollback();
        } catch (Exception ee) {
          log.log(Level.SEVERE, "[" + trxName + "] - rollback", ee);
        } finally {
          try {
            con.close();
          } catch (SQLException e) {
          }
          con = null;
        }
      }
    }

    return success;
  } //	save
Пример #12
0
  public void sortResults(
      int WindowNo, int AD_Tab_ID, int AD_Field_ID, int queryResultID, final boolean ascending) {
    class SortCell {

      String[] row;

      String sort;
    }
    ArrayList<String[]> results = m_results.get(queryResultID);
    if (results == null)
      log.severe("cannot sort. results non-existent for queryResultID:" + queryResultID);
    UITab tab = getTab(AD_Tab_ID);
    final UIField field = getField(AD_Field_ID, WindowNo);
    final int displayType = field.getAD_Reference_ID();
    final int idx = tab.getFieldIndex(AD_Field_ID);
    // if not a lookup, directly sort
    if (!field.isLookup()) {
      if (FieldType.isNumeric(displayType)) {
        Collections.sort(
            results,
            new Comparator<String[]>() {

              @Override
              public int compare(String[] o1, String[] o2) {
                if (o1[idx] == null) o1[idx] = "";
                if (o2[idx] == null) o2[idx] = "";
                BigDecimal s1 = new BigDecimal(o1[idx].equals("") ? "-1e-10" : o1[idx]);
                BigDecimal s2 = new BigDecimal(o2[idx].equals("") ? "-1e-10" : o2[idx]);
                return ascending ? s1.compareTo(s2) : s2.compareTo(s1);
              }
            });
      } else if (FieldType.isDate(displayType)) {
        Collections.sort(
            results,
            new Comparator<String[]>() {

              @Override
              public int compare(String[] o1, String[] o2) {
                if (o1[idx] == null) o1[idx] = "";
                if (o2[idx] == null) o2[idx] = "";
                Long s1 = new Long(o1[idx].equals("") ? "-1000000" : o1[idx]);
                Long s2 = new Long(o2[idx].equals("") ? "-1000000" : o2[idx]);
                return ascending ? s1.compareTo(s2) : s2.compareTo(s1);
              }
            });
      } else {
        Collections.sort(
            results,
            new Comparator<String[]>() {

              @Override
              public int compare(String[] o1, String[] o2) {
                if (o1[idx] == null) o1[idx] = "";
                if (o2[idx] == null) o2[idx] = "";
                String s1 = o1[idx];
                String s2 = o2[idx];
                return ascending ? s1.compareTo(s2) : s2.compareTo(s1);
              }
            });
      }
      return;
    }
    Comparator<SortCell> c =
        new Comparator<SortCell>() {

          public int compare(SortCell o1, SortCell o2) {
            if (ascending) return o1.sort.compareTo(o2.sort);
            else return o2.sort.compareTo(o1.sort);
          }
        };
    // for look up, first get id values
    ArrayList<String> fieldValues = new ArrayList<String>(results.size());
    for (String[] row : results) {
      fieldValues.add(row[idx]);
    }
    // then translate into real values
    ArrayList<String> sorts = getLookupValueOnlyDirect(AD_Field_ID, fieldValues, true);
    ArrayList<SortCell> toBeSorteds = new ArrayList<SortCell>(sorts.size());
    for (int i = 0; i < sorts.size(); i++) {
      SortCell toBeSorted = new SortCell();
      toBeSorted.row = results.get(i);
      toBeSorted.sort = sorts.get(i);
      toBeSorteds.add(toBeSorted);
    }
    // sort
    Collections.sort(toBeSorteds, c);
    // after sorting, replace col with original values
    int i = 0;
    for (SortCell toBeSorted : toBeSorteds) {
      results.set(i, toBeSorted.row);
      i++;
    }
  }
Пример #13
0
 /**
  * Get JDBC Schema
  *
  * @return user name
  */
 @Override
 public String getSchema() {
   if (m_userName != null) return m_userName.toUpperCase();
   log.severe("User Name not set (yet) - call getConnectionURL first");
   return null;
 } //  getSchema