Example #1
0
  /**
   * @param args
   * @throws Exception
   */
  public static void main(String[] args) throws Exception {
    if (Check.isEmpty(System.getProperty("PropertyFile"), true)) {
      throw new AdempiereException("Please set the PropertyFile");
    }

    final String outputFolder = System.getProperty("OutputFolder");
    if (Check.isEmpty(outputFolder, true)) {
      throw new AdempiereException("Please set the OutputFolder");
    }

    final String entityType = System.getProperty("EntityType");
    if (Check.isEmpty(entityType, true)) {
      throw new AdempiereException("Please set the EntityType");
    }

    CLogMgt.initialize(true); // just to make sure we are using the client side settings

    AdempiereToolsHelper.getInstance().startupMinimal();

    final ProcessInfo pi = new ProcessInfo("GenerateCanonicalXSD", -1, 0, 0);
    pi.setParameter(
        new ProcessInfoParameter[] {
          new ProcessInfoParameter("Target_Directory", outputFolder, null, null, null),
          new ProcessInfoParameter("EntityType", entityType, null, null, null),
        });
    pi.setAD_Client_ID(Env.getAD_Client_ID(Env.getCtx()));

    final GenerateCanonicalXSD process = new GenerateCanonicalXSD();
    process.p_FilterBy_AD_Client_ID = false;

    CLogMgt.setLevel(Level.INFO);
    process.startProcess(Env.getCtx(), pi, ITrx.TRX_None);

    //
    // CanonicalXSDGenerator.validateXML(new File("d:/tmp/C_BPartner.xml"), proc.getSchemaFile());
    // CanonicalXSDGenerator.validateXML(new File("d:/tmp/clientPartners.xml"),
    // proc.getSchemaFile());
  }
Example #2
0
  /**
   * Test
   *
   * @param args ignored
   */
  public static void main(String[] args) {

    Adempiere.startupEnvironment(false);
    CLogMgt.setLevel(Level.CONFIG);

    ColumnEncryption columnEncryption = new ColumnEncryption();

    int processId = 328; // AD_ColumnEncryption
    int columnId = 417; // AD_User - Password
    Env.setContext(Env.getCtx(), I_AD_Column.COLUMNNAME_AD_Column_ID, columnId);

    MPInstance instance;
    MPInstancePara instanceParameters;

    instance = new MPInstance(Env.getCtx(), processId, columnId);
    instance.saveEx();

    instanceParameters = new MPInstancePara(instance, 10);
    instanceParameters.setParameter(I_AD_Column.COLUMNNAME_IsEncrypted, true);
    instanceParameters.saveEx();

    instanceParameters = new MPInstancePara(instance, 20);
    instanceParameters.setParameter("ChangeSetting", true);
    instanceParameters.saveEx();

    ProcessInfo pi = new ProcessInfo("AD_ColumnEncryption", processId);
    pi.setRecord_ID(instance.getRecord_ID());
    pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
    pi.setAD_Client_ID(0);
    pi.setAD_User_ID(100);

    columnEncryption.startProcess(Env.getCtx(), pi, null);

    /*List<MUser> users = new Query(Env.getCtx(), I_AD_User.Table_Name , "Password IS NOT NULL", null).list();
    for (MUser user : users)
    {
        user.setPassword(user.getPassword());
        user.saveEx();
    }*/

    processId = 53259; // Convert password to hashed

    pi = new ProcessInfo("AD_User_HashPassword", processId);
    pi.setAD_Client_ID(0);
    pi.setAD_User_ID(100);

    HashPasswords process = new HashPasswords();
    process.startProcess(Env.getCtx(), pi, null);
  }
  // add main method, preparing for nightly build
  public static void main(String[] args) {
    Adempiere.startupEnvironment(false);
    CLogMgt.setLevel(Level.FINE);
    s_log.info("Synchronize Terminology");
    s_log.info("-----------------------");
    ProcessInfo pi = new ProcessInfo("Synchronize Terminology", 172);
    pi.setAD_Client_ID(0);
    pi.setAD_User_ID(100);

    SynchronizeTerminology sc = new SynchronizeTerminology();
    sc.startProcess(Env.getCtx(), pi, null);

    System.out.println(
        "Process=" + pi.getTitle() + " Error=" + pi.isError() + " Summary=" + pi.getSummary());
  }
 /**
  * Parse Original SQL. Called from setSql or Constructor.
  *
  * @return true if pased
  */
 public boolean parse() {
   if (m_sqlOriginal == null || m_sqlOriginal.length() == 0)
     throw new IllegalArgumentException("No SQL");
   //
   //	if (CLogMgt.isLevelFinest())
   //		log.fine(m_sqlOriginal);
   getSelectStatements();
   //	analyse each select
   for (int i = 0; i < m_sql.length; i++) {
     TableInfo[] info = getTableInfo(m_sql[i].trim());
     m_tableInfo.add(info);
   }
   //
   if (CLogMgt.isLevelFinest()) log.fine(toString());
   return m_tableInfo.size() > 0;
 } //	parse
  /**
   * Main test
   *
   * @param args
   * @throws Exception
   */
  public static void main(String[] args) {
    Adempiere.startupEnvironment(true);
    CLogMgt.setLevel(Level.INFO);

    Properties ctx = Env.getCtx();
    int AD_Process_ID = 53156; // HARDCODED

    MPInstance pinstance = new MPInstance(ctx, AD_Process_ID, -1);
    pinstance.saveEx();

    ProcessInfo pi = new ProcessInfo("", AD_Process_ID, 0, 0);
    pi.setAD_Client_ID(Env.getAD_Client_ID(ctx));
    pi.setAD_User_ID(Env.getAD_User_ID(ctx));
    pi.setAD_PInstance_ID(pinstance.getAD_PInstance_ID());
    //
    EnableNativeSequence proc = new EnableNativeSequence();
    proc.startProcess(ctx, pi, null);
    if (pi.isError()) {
      throw new AdempiereException(pi.getSummary());
    }
  }
  /**
   * ************************************************************************ 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
Example #7
0
  /** Query ATP */
  private void initAtpTab(int m_M_Warehouse_ID) {

    //	Header
    Vector<String> columnNames = new Vector<String>();
    columnNames.add(Msg.translate(Env.getCtx(), "Date"));
    columnNames.add(Msg.translate(Env.getCtx(), "QtyOnHand"));
    columnNames.add(Msg.translate(Env.getCtx(), "C_BPartner_ID"));
    columnNames.add(Msg.translate(Env.getCtx(), "QtyOrdered"));
    columnNames.add(Msg.translate(Env.getCtx(), "QtyReserved"));
    columnNames.add(Msg.translate(Env.getCtx(), "M_Locator_ID"));
    columnNames.add(Msg.translate(Env.getCtx(), "M_AttributeSetInstance_ID"));
    columnNames.add(Msg.translate(Env.getCtx(), "DocumentNo"));
    columnNames.add(Msg.translate(Env.getCtx(), "M_Warehouse_ID"));

    //	Fill Storage Data
    boolean showDetail = CLogMgt.isLevelFine();
    String sql =
        "SELECT s.QtyOnHand, s.QtyReserved, s.QtyOrdered,"
            + " productAttribute(s.M_AttributeSetInstance_ID), s.M_AttributeSetInstance_ID,";
    if (!showDetail)
      sql =
          "SELECT SUM(s.QtyOnHand), SUM(s.QtyReserved), SUM(s.QtyOrdered),"
              + " productAttribute(s.M_AttributeSetInstance_ID), 0,";
    sql +=
        " w.Name, l.Value "
            + "FROM M_Storage s"
            + " INNER JOIN M_Locator l ON (s.M_Locator_ID=l.M_Locator_ID)"
            + " INNER JOIN M_Warehouse w ON (l.M_Warehouse_ID=w.M_Warehouse_ID) "
            + "WHERE M_Product_ID=?";
    if (m_M_Warehouse_ID != 0) sql += " AND l.M_Warehouse_ID=?";
    if (m_M_AttributeSetInstance_ID > 0) sql += " AND s.M_AttributeSetInstance_ID=?";
    sql += " AND (s.QtyOnHand<>0 OR s.QtyReserved<>0 OR s.QtyOrdered<>0)";
    if (!showDetail)
      sql += " GROUP BY productAttribute(s.M_AttributeSetInstance_ID), w.Name, l.Value";
    sql += " ORDER BY l.Value";

    Vector<Vector<Object>> data = new Vector<Vector<Object>>();
    double qty = 0;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(sql, null);
      pstmt.setInt(1, m_M_Product_ID);
      if (m_M_Warehouse_ID != 0) pstmt.setInt(2, m_M_Warehouse_ID);
      if (m_M_AttributeSetInstance_ID > 0) pstmt.setInt(3, m_M_AttributeSetInstance_ID);
      rs = pstmt.executeQuery();
      while (rs.next()) {
        Vector<Object> line = new Vector<Object>(9);
        line.add(null); //  Date
        double qtyOnHand = rs.getDouble(1);
        qty += qtyOnHand;
        line.add(new Double(qtyOnHand)); //  Qty
        line.add(null); //  BPartner
        line.add(new Double(rs.getDouble(3))); //  QtyOrdered
        line.add(new Double(rs.getDouble(2))); //  QtyReserved
        line.add(rs.getString(7)); //  Locator
        String asi = rs.getString(4);
        if (showDetail && (asi == null || asi.length() == 0)) asi = "{" + rs.getInt(5) + "}";
        line.add(asi); //  ASI
        line.add(null); //  DocumentNo
        line.add(rs.getString(6)); // 	Warehouse
        data.add(line);
      }
    } catch (SQLException e) {
      log.log(Level.SEVERE, sql, e);
    } finally {
      DB.close(rs, pstmt);
      rs = null;
      pstmt = null;
    }

    //	Orders
    sql =
        "SELECT ol.DatePromised, ol.QtyReserved,"
            + " productAttribute(ol.M_AttributeSetInstance_ID), ol.M_AttributeSetInstance_ID,"
            + " dt.DocBaseType, bp.Name,"
            + " dt.PrintName || ' ' || o.DocumentNo As DocumentNo, w.Name "
            + "FROM C_Order o"
            + " INNER JOIN C_OrderLine ol ON (o.C_Order_ID=ol.C_Order_ID)"
            + " INNER JOIN C_DocType dt ON (o.C_DocType_ID=dt.C_DocType_ID)"
            + " INNER JOIN M_Warehouse w ON (ol.M_Warehouse_ID=w.M_Warehouse_ID)"
            + " INNER JOIN C_BPartner bp  ON (o.C_BPartner_ID=bp.C_BPartner_ID) "
            + "WHERE ol.QtyReserved<>0"
            + " AND ol.M_Product_ID=?";
    if (m_M_Warehouse_ID != 0) sql += " AND ol.M_Warehouse_ID=?";
    if (m_M_AttributeSetInstance_ID > 0) sql += " AND ol.M_AttributeSetInstance_ID=?";
    sql += " ORDER BY o.DatePromised";
    try {
      pstmt = DB.prepareStatement(sql, null);
      pstmt.setInt(1, m_M_Product_ID);
      if (m_M_Warehouse_ID != 0) pstmt.setInt(2, m_M_Warehouse_ID);
      if (m_M_AttributeSetInstance_ID > 0) pstmt.setInt(3, m_M_AttributeSetInstance_ID);
      rs = pstmt.executeQuery();
      while (rs.next()) {
        Vector<Object> line = new Vector<Object>(9);
        line.add(rs.getTimestamp(1)); //  Date
        double oq = rs.getDouble(2);
        String DocBaseType = rs.getString(5);
        Double qtyReserved = null;
        Double qtyOrdered = null;
        if (MDocType.DOCBASETYPE_PurchaseOrder.equals(DocBaseType)) {
          qtyOrdered = new Double(oq);
          qty += oq;
        } else {
          qtyReserved = new Double(oq);
          qty -= oq;
        }
        line.add(new Double(qty)); //  Qty
        line.add(rs.getString(6)); //  BPartner
        line.add(qtyOrdered); //  QtyOrdered
        line.add(qtyReserved); //  QtyReserved
        line.add(null); //  Locator
        String asi = rs.getString(3);
        if (showDetail && (asi == null || asi.length() == 0)) asi = "{" + rs.getInt(4) + "}";
        line.add(asi); //  ASI
        line.add(rs.getString(7)); //  DocumentNo
        line.add(rs.getString(8)); // 	Warehouse
        data.add(line);
      }
    } catch (SQLException e) {
      log.log(Level.SEVERE, sql, e);
    } finally {
      DB.close(rs, pstmt);
      rs = null;
      pstmt = null;
    }

    //  Table
    MiniTable table = null;
    m_modelAtp = new DefaultTableModel(data, columnNames);
    m_tableAtp.setModel(m_modelAtp);
    table = m_tableAtp;
    //
    table.setColumnClass(0, Timestamp.class, true); //  Date
    table.setColumnClass(1, Double.class, true); //  Quantity
    table.setColumnClass(2, String.class, true); //  Partner
    table.setColumnClass(3, Double.class, true); //  Quantity
    table.setColumnClass(4, Double.class, true); //  Quantity
    table.setColumnClass(5, String.class, true); //  Locator
    table.setColumnClass(6, String.class, true); //  ASI
    table.setColumnClass(7, String.class, true); //  DocNo
    table.setColumnClass(8, String.class, true); //  Warehouse
    //
    table.autoSize();
  } //	initAtpTab
  /**
   * Process
   *
   * @return info
   * @throws Exception
   */
  protected String doIt() throws Exception {
    if (p_IsAllCurrencies) p_C_Currency_ID = 0;
    log.info(
        "C_AcctSchema_ID="
            + p_C_AcctSchema_ID
            + ",C_ConversionTypeReval_ID="
            + p_C_ConversionTypeReval_ID
            + ",DateReval="
            + p_DateReval
            + ", APAR="
            + p_APAR
            + ", IsAllCurrencies="
            + p_IsAllCurrencies
            + ",C_Currency_ID="
            + p_C_Currency_ID
            + ", C_DocType_ID="
            + p_C_DocTypeReval_ID);

    //	Parameter
    if (p_DateReval == null) p_DateReval = new Timestamp(System.currentTimeMillis());

    //	Delete - just to be sure
    String sql = "DELETE FROM T_InvoiceGL WHERE AD_PInstance_ID=" + getAD_PInstance_ID();
    int no = DB.executeUpdate(sql, get_TrxName());
    if (no > 0) log.info("Deleted #" + no);

    //	Insert Trx
    String dateStr = DB.TO_DATE(p_DateReval, true);
    sql =
        "INSERT INTO T_InvoiceGL (AD_Client_ID, AD_Org_ID, IsActive, Created,CreatedBy, Updated,UpdatedBy,"
            + " AD_PInstance_ID, C_Invoice_ID, GrandTotal, OpenAmt, "
            + " Fact_Acct_ID, AmtSourceBalance, AmtAcctBalance, "
            + " AmtRevalDr, AmtRevalCr, C_DocTypeReval_ID, IsAllCurrencies, "
            + " DateReval, C_ConversionTypeReval_ID, AmtRevalDrDiff, AmtRevalCrDiff, APAR) "
            //	--
            + "SELECT i.AD_Client_ID, i.AD_Org_ID, i.IsActive, i.Created,i.CreatedBy, i.Updated,i.UpdatedBy,"
            + getAD_PInstance_ID()
            + ", i.C_Invoice_ID, i.GrandTotal, invoiceOpen(i.C_Invoice_ID, 0), "
            + " fa.Fact_Acct_ID, fa.AmtSourceDr-fa.AmtSourceCr, fa.AmtAcctDr-fa.AmtAcctCr, "
            //	AmtRevalDr, AmtRevalCr,
            + " currencyConvert(fa.AmtSourceDr, i.C_Currency_ID, a.C_Currency_ID, "
            + dateStr
            + ", "
            + p_C_ConversionTypeReval_ID
            + ", i.AD_Client_ID, i.AD_Org_ID),"
            + " currencyConvert(fa.AmtSourceCr, i.C_Currency_ID, a.C_Currency_ID, "
            + dateStr
            + ", "
            + p_C_ConversionTypeReval_ID
            + ", i.AD_Client_ID, i.AD_Org_ID),"
            + (p_C_DocTypeReval_ID == 0 ? "NULL" : String.valueOf(p_C_DocTypeReval_ID))
            + ", "
            + (p_IsAllCurrencies ? "'Y'," : "'N',")
            + dateStr
            + ", "
            + p_C_ConversionTypeReval_ID
            + ", 0, 0, '"
            + p_APAR
            + "' "
            //
            + "FROM C_Invoice_v i"
            + " INNER JOIN Fact_Acct fa ON (fa.AD_Table_ID=318 AND fa.Record_ID=i.C_Invoice_ID"
            + " AND (i.GrandTotal=fa.AmtSourceDr OR i.GrandTotal=fa.AmtSourceCr))"
            + " INNER JOIN C_AcctSchema a ON (fa.C_AcctSchema_ID=a.C_AcctSchema_ID) "
            + "WHERE i.IsPaid='N'"
            + " AND EXISTS (SELECT * FROM C_ElementValue ev "
            + "WHERE ev.C_ElementValue_ID=fa.Account_ID AND (ev.AccountType='A' OR ev.AccountType='L'))"
            + " AND fa.C_AcctSchema_ID="
            + p_C_AcctSchema_ID;
    if (!p_IsAllCurrencies) sql += " AND i.C_Currency_ID<>a.C_Currency_ID";
    if (ONLY_AR.equals(p_APAR)) sql += " AND i.IsSOTrx='Y'";
    else if (ONLY_AP.equals(p_APAR)) sql += " AND i.IsSOTrx='N'";
    if (!p_IsAllCurrencies && p_C_Currency_ID != 0)
      sql += " AND i.C_Currency_ID=" + p_C_Currency_ID;

    no = DB.executeUpdate(sql, get_TrxName());
    if (no != 0) log.info("Inserted #" + no);
    else if (CLogMgt.isLevelFiner()) log.warning("Inserted #" + no + " - " + sql);
    else log.warning("Inserted #" + no);

    //	Calculate Difference
    sql =
        DB.convertSqlToNative(
            "UPDATE T_InvoiceGL gl "
                + "SET (AmtRevalDrDiff,AmtRevalCrDiff)="
                + "(SELECT gl.AmtRevalDr-fa.AmtAcctDr, gl.AmtRevalCr-fa.AmtAcctCr "
                + "FROM Fact_Acct fa "
                + "WHERE gl.Fact_Acct_ID=fa.Fact_Acct_ID) "
                + "WHERE AD_PInstance_ID="
                + getAD_PInstance_ID());
    int noT = DB.executeUpdate(sql, get_TrxName());
    if (noT > 0) log.config("Difference #" + noT);

    //	Percentage
    sql =
        "UPDATE T_InvoiceGL SET Percent = 100 "
            + "WHERE GrandTotal=OpenAmt AND AD_PInstance_ID="
            + getAD_PInstance_ID();
    no = DB.executeUpdate(sql, get_TrxName());
    if (no > 0) log.info("Not Paid #" + no);

    sql =
        "UPDATE T_InvoiceGL SET Percent = ROUND(OpenAmt*100/GrandTotal,6) "
            + "WHERE GrandTotal<>OpenAmt AND GrandTotal <> 0 AND AD_PInstance_ID="
            + getAD_PInstance_ID();
    no = DB.executeUpdate(sql, get_TrxName());
    if (no > 0) log.info("Partial Paid #" + no);

    sql =
        "UPDATE T_InvoiceGL SET AmtRevalDr = AmtRevalDr * Percent/100,"
            + " AmtRevalCr = AmtRevalCr * Percent/100,"
            + " AmtRevalDrDiff = AmtRevalDrDiff * Percent/100,"
            + " AmtRevalCrDiff = AmtRevalCrDiff * Percent/100 "
            + "WHERE Percent <> 100 AND AD_PInstance_ID="
            + getAD_PInstance_ID();
    no = DB.executeUpdate(sql, get_TrxName());
    if (no > 0) log.config("Partial Calc #" + no);

    //	Create Document
    String info = "";
    if (p_C_DocTypeReval_ID != 0) {
      if (p_C_Currency_ID != 0) log.warning("Can create Journal only for all currencies");
      else info = createGLJournal();
    }
    return "#" + noT + info;
  } //	doIt
  /**
   * ************************************************************************* Generate Interface.
   *
   * <pre>
   *  	Example: java GenerateInterafce.class mydirectory myPackage 'U','A'
   *  	would generate entity type User and Application classes into mydirectory.
   *  	Without parameters, the default is used:
   *  	C:\extend\src\compiere\model\ compiere.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) {
    Adempiere.startupEnvironment(true);
    CLogMgt.setLevel(Level.FINE);
    log.info("Generate Interface   $Revision: 1.0 $");
    log.info("----------------------------------");
    // first parameter
    String directory = "C:\\Adempiere\\adempiere-all\\extend\\src\\compiere\\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 = "compiere.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'"; // 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("----------------------------------");

    // Table name like
    String tableLike = "'%'"; // 	All tables
    // tableLike = "'AD_OrgInfo', 'AD_Role', 'C_CashLine', 'C_Currency', 'C_Invoice', 'C_Order',
    // 'C_Payment', 'M_InventoryLine', 'M_PriceList', 'M_Product', 'U_POSTerminal'"; // only
    // specific tables
    if (args.length > 3) tableLike = args[3];
    log.info("Table Like: " + tableLike);

    // 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 IsActive = 'Y' AND TableName NOT LIKE '%_Trl' AND ");
    sql.append(" AND TableName LIKE ").append(tableLike);
    // sql.append(" AND TableName IN (").append( tableLike ).append(")");
    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 ModelInterfaceGenerator(rs.getInt(1), directory, packageName);
        count++;
      }
    } catch (SQLException e) {
      throw new DBException(e, sql.toString());
    } finally {
      DB.close(rs, pstmt);
      rs = null;
      pstmt = null;
    }
    log.info("Generated = " + count);
  }
Example #10
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:\Compiere\compiere-all\extend\src\compiere\model\ compiere.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) {
    Adempiere.startupEnvironment((args.length > 4 && args[4].equals("Client")));
    CLogMgt.setLevel(Level.FINE);
    log.info("Generate Model   $Revision: 1.42 $");
    log.info("----------------------------------");
    //	first parameter
    // mgrigioni 13/07/2010
    String directory = "dbPort/src/";
    // String directory = "C:\\Compiere\\compiere-all\\extend\\src\\compiere\\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 = "org.adempierelbr.wrapper"; // ORIGINAL WAS compiere.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'";	//	User, Application
    String entityType = "'A', 'D'";
    String entityTypeColumn = "'LBRA'";
    String preffix = "W_";

    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("----------------------------------");

    String tableLike = null;
    tableLike = "'%'"; // 	All tables
    // tableLike = "'AD_OrgInfo', 'AD_Role', 'C_CashLine', 'C_Currency', 'C_Invoice', 'C_Order',
    // 'C_Payment', 'M_InventoryLine', 'M_PriceList', 'M_Product', 'U_POSTerminal'";	//	Only
    // specific tables
    if (args.length > 3) tableLike = args[3];
    log.info("Table Like: " + tableLike);

    //	complete sql
    sql.insert(
        0,
        "SELECT AD_Table_ID, EntityType "
            + "FROM AD_Table "
            + "WHERE (TableName IN ('RV_WarehousePrice','RV_BPartner')" //	special views
            + " OR IsView='N')"
            + " AND IsActive = 'Y' AND TableName NOT LIKE '%_Trl' AND TableName NOT LIKE '%AAAA%'"
            + " AND EXISTS (SELECT '1' FROM AD_Column c WHERE c.AD_Table_ID=AD_Table.AD_Table_ID AND c.EntityType IN ("
            + entityTypeColumn
            + ")) AND ");
    sql.append(" AND TableName LIKE ").append(tableLike);
    // sql.append(" AND TableName IN (").append(tableLike).append(")"); // only specific tables

    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()) {
        String etmodelpackage = packageName;
        String classDirectory = directory;
        if (etmodelpackage != null) {
          packageName = etmodelpackage;
          String packages[] = packageName.split("\\.");
          for (String pack : packages) {
            classDirectory += pack + "/";
          }
        } else {
          classDirectory += "org/compiere/model/";
        }

        new ModelWrapperGenerator(
            rs.getInt(1), classDirectory, packageName, entityTypeColumn, preffix);
        count++;
      }
    } catch (Exception e) {
      log.log(Level.SEVERE, sql.toString(), e);
    } finally {
      DB.close(rs, pstmt);
      rs = null;
      pstmt = null;
    }
    log.info("Generated = " + count);
  }