Package org.compiere.util

Examples of org.compiere.util.Trx


   */
  public String generate(IStatusBar statusBar, KeyNamePair docTypeKNPair, String docActionSelected)
  {
    String info = "";
    String trxName = Trx.createTrxName("IVG");
    Trx trx = Trx.get(trxName, true)//trx needs to be committed too
   
    setSelectionActive(false)//  prevents from being called twice
    statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "InvGenerateGen"));
    statusBar.setStatusDB(String.valueOf(getSelection().size()));

    //  Prepare Process
    int AD_Process_ID = 0;
       
        if (docTypeKNPair.getKey() == MRMA.Table_ID)
        {
            AD_Process_ID = 52002; // C_Invoice_GenerateRMA - org.adempiere.process.InvoiceGenerateRMA
        }
        else
        {
            AD_Process_ID = 134// HARDCODED    C_InvoiceCreate
        }
    MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
    if (!instance.save())
    {
      info = Msg.getMsg(Env.getCtx(), "ProcessNoInstance");
      return info;
    }
   
    //insert selection
    StringBuffer insert = new StringBuffer();
    insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
    int counter = 0;
    for(Integer selectedId : getSelection())
    {
      counter++;
      if (counter > 1)
        insert.append(" UNION ");
      insert.append("SELECT ");
      insert.append(instance.getAD_PInstance_ID());
      insert.append(", ");
      insert.append(selectedId);
      insert.append(" FROM DUAL ");
     
      if (counter == 1000)
      {
        if ( DB.executeUpdate(insert.toString(), trxName) < 0 )
        {
          String msg = "No Invoices";     //  not translated!
          info = msg;
          log.config(msg);
          trx.rollback();
          return info;
        }
        insert = new StringBuffer();
        insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
        counter = 0;
      }
    }
    if (counter > 0)
    {
      if ( DB.executeUpdate(insert.toString(), trxName) < 0 )
      {
        String msg = "No Invoices";     //  not translated!
        info = msg;
        log.config(msg);
        trx.rollback();
        return info;
      }
    }
   
    ProcessInfo pi = new ProcessInfo ("", AD_Process_ID);
View Full Code Here


  public static void create (MClient client)
  {
    MAcctSchema[] ass = MAcctSchema.getClientAcctSchema(client.getCtx(), client.getAD_Client_ID());
    String trxName = client.get_TrxName();
    String trxNameUsed = trxName;
    Trx trx = null;
    if (trxName == null)
    {
      trxNameUsed = Trx.createTrxName("Cost");
      trx = Trx.get(trxNameUsed, true);
    }
    boolean success = true;
    //  For all Products
    String sql = "SELECT * FROM M_Product p "
      + "WHERE AD_Client_ID=?"
      + " AND EXISTS (SELECT * FROM M_CostDetail cd "
        + "WHERE p.M_Product_ID=cd.M_Product_ID AND Processed='N')";
    PreparedStatement pstmt = null;
    try
    {
      pstmt = DB.prepareStatement (sql, trxNameUsed);
      pstmt.setInt (1, client.getAD_Client_ID());
      ResultSet rs = pstmt.executeQuery ();
      while (rs.next ())
      {
        MProduct product = new MProduct (client.getCtx(), rs, trxNameUsed);
        for (int i = 0; i < ass.length; i++)
        {
          BigDecimal cost = getCurrentCost(product, 0, ass[i], 0,
            null, Env.ONE, 0, false, trxNameUsed);    //  create non-zero costs
          s_log.info(product.getName() + " = " + cost);
        }
      }
      rs.close ();
      pstmt.close ();
      pstmt = null;
    }
    catch (Exception e)
    {
      s_log.log (Level.SEVERE, sql, e);
      success = false;
    }
    try
    {
      if (pstmt != null)
        pstmt.close ();
      pstmt = null;
    }
    catch (Exception e)
    {
      pstmt = null;
    }
    //  Transaction
    if (trx != null)
    {
      if (success)
        trx.commit();
      else
        trx.rollback();
      trx.close();
    }
  }  //  create
View Full Code Here

  {
    log.info("Sta=" + status + " DT=" + getDocumentType()
      + " ID=" +  p_po.get_ID());
    p_Status = status;

    Trx trx = Trx.get(getTrxName(), true);
    try
    {
    //  *** Transaction Start       ***
      //  Commit Facts
      if (status.equals(STATUS_Posted))
      {
        for (int i = 0; i < m_fact.size(); i++)
        {
          Fact fact = m_fact.get(i);
          if (fact == null)
            ;
          else if (fact.save(getTrxName()))
            ;
          else
          {
            log.log(Level.SEVERE, "(fact not saved) ... rolling back");
            trx.rollback();
            trx.close();
            unlock();
            return STATUS_Error;
          }
        }
      }
      //  Commit Doc
      if (!save(getTrxName()))     //  contains unlock & document status update
      {
        log.log(Level.SEVERE, "(doc not saved) ... rolling back");
        trx.rollback();
        trx.close();
        unlock();
        return STATUS_Error;
      }
      //  Success
      trx.commit(true);
      trx.close();
      trx = null;
    //  *** Transaction End         ***
    }
    catch (Exception e)
    {
      log.log(Level.SEVERE, "... rolling back", e);
      status = STATUS_Error;
      try {
        if (trx != null)
          trx.rollback();
      } catch (Exception e2) {}
      try {
        if (trx != null)
          trx.close();
        trx = null;
      } catch (Exception e3) {}
      unlock();
    }
    p_Status = status;
View Full Code Here

TOP

Related Classes of org.compiere.util.Trx

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.