예제 #1
0
  private final PO retrievePO(
      final Properties ctx,
      final String tableName,
      final String whereClause,
      final Object[] params,
      final String trxName) {
    if (whereClause == null || whereClause.length() == 0) {
      return null;
    }

    //
    PO po = null;
    final POInfo info = POInfo.getPOInfo(tableName);
    if (info == null) {
      return null;
    }

    final StringBuilder sqlBuffer = info.buildSelect();
    sqlBuffer.append(" WHERE ").append(whereClause);
    final String sql = sqlBuffer.toString();

    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(sql, trxName);
      DB.setParameters(pstmt, params);

      rs = pstmt.executeQuery();
      if (rs.next()) {
        po = getPO(ctx, tableName, rs, trxName);
      }
    } catch (Exception e) {
      log.error(sql, e);
      MetasfreshLastError.saveError(log, "Error", e);
    } finally {
      DB.close(rs, pstmt);
    }

    return po;
  }
예제 #2
0
  /**
   * Loads the PO from database. In case some errors were encountered, they will be logged and
   * <code>null</code> will be returned.
   *
   * @param ctx
   * @param tableName
   * @param Record_ID
   * @param trxName
   * @return PO or null
   */
  private final PO retrievePO(
      final Properties ctx, final String tableName, int Record_ID, String trxName) {
    final POInfo poInfo = POInfo.getPOInfo(tableName);
    if (Record_ID > 0 && poInfo.getKeyColumnName() == null) {
      log.warn("(id) - Multi-Key " + tableName);
      return null;
    }

    final Class<?> clazz = tableModelClassLoader.getClass(tableName);
    if (clazz == null) {
      log.info("Using GenericPO for {}", tableName);
      final GenericPO po = new GenericPO(tableName, ctx, Record_ID, trxName);
      return po;
    }

    boolean errorLogged = false;
    try {
      final Constructor<?> constructor = tableModelClassLoader.getIDConstructor(clazz);
      final PO po = (PO) constructor.newInstance(ctx, Record_ID, trxName);
      if (po != null && po.get_ID() != Record_ID && Record_ID > 0) {
        return null;
      }
      return po;
    } catch (Exception e) {
      final Throwable cause = e.getCause() == null ? e : e.getCause();
      log.error("(id) - Table=" + tableName + ",Class=" + clazz, cause);
      MetasfreshLastError.saveError(log, "Error", cause);
      errorLogged = true;
    }

    if (!errorLogged) {
      log.error("(id) - Not found - Table=" + tableName + ", Record_ID=" + Record_ID);
    }

    return null;
  } // getPO
예제 #3
0
 /** Load Meta Data */
 protected POInfo initPO(Properties ctx) {
   POInfo poi = POInfo.getPOInfo(ctx, Table_ID, get_TrxName());
   return poi;
 }
 /** Load Meta Data */
 @Override
 protected org.compiere.model.POInfo initPO(Properties ctx) {
   org.compiere.model.POInfo poi =
       org.compiere.model.POInfo.getPOInfo(ctx, Table_Name, get_TrxName());
   return poi;
 }