BF [ 2007837 ] VCreateFrom.save() should run in trx

https://sourceforge.net/tracker/?func=detail&atid=879332&aid=2007837&group_id=176962
This commit is contained in:
teo_sarca 2009-02-10 21:07:42 +00:00
parent 997bf660dc
commit 2e60e57aa4
5 changed files with 147 additions and 101 deletions

View File

@ -42,6 +42,7 @@ import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel; import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel; import javax.swing.table.TableModel;
import org.compiere.apps.ADialog;
import org.compiere.apps.AEnv; import org.compiere.apps.AEnv;
import org.compiere.apps.AppsAction; import org.compiere.apps.AppsAction;
import org.compiere.apps.ConfirmPanel; import org.compiere.apps.ConfirmPanel;
@ -71,6 +72,8 @@ import org.compiere.util.DisplayType;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.KeyNamePair; import org.compiere.util.KeyNamePair;
import org.compiere.util.Msg; import org.compiere.util.Msg;
import org.compiere.util.Trx;
import org.compiere.util.TrxRunnable;
/** /**
* CreateFrom (Called from GridController.startProcess) * CreateFrom (Called from GridController.startProcess)
@ -81,6 +84,7 @@ import org.compiere.util.Msg;
* @author Teo Sarca, SC ARHIPAC SERVICE SRL * @author Teo Sarca, SC ARHIPAC SERVICE SRL
* <li>FR [ 1794050 ] Usability: VCreateFrom OK button always enabled * <li>FR [ 1794050 ] Usability: VCreateFrom OK button always enabled
* <li>FR [ 1974354 ] VCreateFrom.create should be more flexible * <li>FR [ 1974354 ] VCreateFrom.create should be more flexible
* <li>BF [ 2007837 ] VCreateFrom.save() should run in trx
* @author Victor Perez, e-Evolucion * @author Victor Perez, e-Evolucion
* <li> RF [1811114] http://sourceforge.net/tracker/index.php?func=detail&aid=1811114&group_id=176962&atid=879335 * <li> RF [1811114] http://sourceforge.net/tracker/index.php?func=detail&aid=1811114&group_id=176962&atid=879335
* @author Karsten Thiemann, Schaeffer AG * @author Karsten Thiemann, Schaeffer AG
@ -89,6 +93,11 @@ import org.compiere.util.Msg;
public abstract class VCreateFrom extends CDialog public abstract class VCreateFrom extends CDialog
implements ActionListener, TableModelListener implements ActionListener, TableModelListener
{ {
/**
*
*/
private static final long serialVersionUID = 7749087067953806144L;
/** /**
* Register custom VCreateFrom* class * Register custom VCreateFrom* class
* @param ad_table_id * @param ad_table_id
@ -192,7 +201,7 @@ public abstract class VCreateFrom extends CDialog
private static CLogger s_log = CLogger.getCLogger (VCreateFrom.class); private static CLogger s_log = CLogger.getCLogger (VCreateFrom.class);
// //
private CPanel parameterPanel = new CPanel(); protected CPanel parameterPanel = new CPanel();
protected CPanel parameterBankPanel = new CPanel(); protected CPanel parameterBankPanel = new CPanel();
private BorderLayout parameterLayout = new BorderLayout(); private BorderLayout parameterLayout = new BorderLayout();
private JLabel bankAccountLabel = new JLabel(); private JLabel bankAccountLabel = new JLabel();
@ -458,7 +467,7 @@ public abstract class VCreateFrom extends CDialog
* Save & Insert Data * Save & Insert Data
* @return true if saved * @return true if saved
*/ */
abstract boolean save(); abstract boolean save(String trxName);
/*************************************************************************/ /*************************************************************************/
@ -476,9 +485,24 @@ public abstract class VCreateFrom extends CDialog
// OK - Save // OK - Save
if (e.getActionCommand().equals(ConfirmPanel.A_OK)) if (e.getActionCommand().equals(ConfirmPanel.A_OK))
{ {
if (save()) try
{
Trx.run(new TrxRunnable()
{
public void run(String trxName)
{
if (save(trxName))
{
dispose(); dispose();
} }
}
});
}
catch (Exception ex)
{
ADialog.error(p_WindowNo, this, "Error", ex.getLocalizedMessage());
}
}
// Cancel // Cancel
else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL))
{ {
@ -615,9 +639,9 @@ public abstract class VCreateFrom extends CDialog
* InvoiceLine - 7 * InvoiceLine - 7
*/ */
log.config("C_Order_ID=" + C_Order_ID); log.config("C_Order_ID=" + C_Order_ID);
p_order = new MOrder (Env.getCtx(), C_Order_ID, null); // save p_order = new MOrder (Env.getCtx(), C_Order_ID, null);
Vector<Vector> data = new Vector<Vector>(); Vector<Vector<Object>> data = new Vector<Vector<Object>>();
StringBuffer sql = new StringBuffer("SELECT " StringBuffer sql = new StringBuffer("SELECT "
+ "l.QtyOrdered-SUM(COALESCE(m.Qty,0))," // 1 + "l.QtyOrdered-SUM(COALESCE(m.Qty,0))," // 1
+ "CASE WHEN l.QtyOrdered=0 THEN 0 ELSE l.QtyEntered/l.QtyOrdered END," // 2 + "CASE WHEN l.QtyOrdered=0 THEN 0 ELSE l.QtyEntered/l.QtyOrdered END," // 2
@ -644,11 +668,13 @@ public abstract class VCreateFrom extends CDialog
+ "ORDER BY l.Line"); + "ORDER BY l.Line");
// //
log.finer(sql.toString()); log.finer(sql.toString());
PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, C_Order_ID); pstmt.setInt(1, C_Order_ID);
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
{ {
Vector<Object> line = new Vector<Object>(); Vector<Object> line = new Vector<Object>();
@ -668,13 +694,17 @@ public abstract class VCreateFrom extends CDialog
line.add(null); // 7-Invoice line.add(null); // 7-Invoice
data.add(line); data.add(line);
} }
rs.close();
pstmt.close();
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, sql.toString(), e); log.log(Level.SEVERE, sql.toString(), e);
} }
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
loadTableOIS (data); loadTableOIS (data);
} // LoadOrder } // LoadOrder
@ -683,7 +713,7 @@ public abstract class VCreateFrom extends CDialog
* Load Order/Invoice/Shipment data into Table * Load Order/Invoice/Shipment data into Table
* @param data data * @param data data
*/ */
protected void loadTableOIS (Vector data) protected void loadTableOIS (Vector<?> data)
{ {
// Header Info // Header Info
Vector<String> columnNames = new Vector<String>(7); Vector<String> columnNames = new Vector<String>(7);
@ -730,5 +760,4 @@ public abstract class VCreateFrom extends CDialog
// //
confirmPanel.getOKButton().setEnabled(selectedRowCount > 0); confirmPanel.getOKButton().setEnabled(selectedRowCount > 0);
} }
} // VCreateFrom } // VCreateFrom

View File

@ -53,9 +53,15 @@ import org.compiere.util.Msg;
* *
* @author Teo Sarca, SC ARHIPAC SERVICE SRL * @author Teo Sarca, SC ARHIPAC SERVICE SRL
* <li>BF [ 1896947 ] Generate invoice from Order error * <li>BF [ 1896947 ] Generate invoice from Order error
* <li>BF [ 2007837 ] VCreateFrom.save() should run in trx
*/ */
public class VCreateFromInvoice extends VCreateFrom implements VetoableChangeListener public class VCreateFromInvoice extends VCreateFrom implements VetoableChangeListener
{ {
/**
*
*/
private static final long serialVersionUID = -7102932507855655539L;
/** /**
* Protected Constructor * Protected Constructor
* @param mTab MTab * @param mTab MTab
@ -67,7 +73,8 @@ public class VCreateFromInvoice extends VCreateFrom implements VetoableChangeLis
} // VCreateFromInvoice } // VCreateFromInvoice
private boolean m_actionActive = false; private boolean m_actionActive = false;
private MInOut m_inout = null; // private MInOut m_inout = null;
private int m_M_InOut_ID = -1;
/** Loaded RMA */ /** Loaded RMA */
private MRMA m_rma = null; private MRMA m_rma = null;
@ -295,10 +302,10 @@ public class VCreateFromInvoice extends VCreateFrom implements VetoableChangeLis
private void loadShipment (int M_InOut_ID) private void loadShipment (int M_InOut_ID)
{ {
log.config("M_InOut_ID=" + M_InOut_ID); log.config("M_InOut_ID=" + M_InOut_ID);
m_inout = new MInOut(Env.getCtx(), M_InOut_ID, null); MInOut inout = new MInOut(Env.getCtx(), M_InOut_ID, null);
p_order = null; p_order = null;
if (m_inout.getC_Order_ID() != 0) if (inout.getC_Order_ID() != 0)
p_order = new MOrder (Env.getCtx(), m_inout.getC_Order_ID(), null); p_order = new MOrder (Env.getCtx(), inout.getC_Order_ID(), null);
// //
Vector<Vector<Object>> data = new Vector<Vector<Object>>(); Vector<Vector<Object>> data = new Vector<Vector<Object>>();
@ -374,7 +381,7 @@ public class VCreateFromInvoice extends VCreateFrom implements VetoableChangeLis
m_rma = new MRMA(Env.getCtx(), M_RMA_ID, null); m_rma = new MRMA(Env.getCtx(), M_RMA_ID, null);
Vector<Vector> data = new Vector<Vector>(); Vector<Vector<?>> data = new Vector<Vector<?>>();
StringBuffer sqlStmt = new StringBuffer(); StringBuffer sqlStmt = new StringBuffer();
sqlStmt.append("SELECT rl.M_RMALine_ID, rl.line, rl.Qty - rl.QtyDelivered, iol.M_Product_ID, p.Name, uom.C_UOM_ID, COALESCE(uom.UOMSymbol,uom.Name) "); sqlStmt.append("SELECT rl.M_RMALine_ID, rl.line, rl.Qty - rl.QtyDelivered, iol.M_Product_ID, p.Name, uom.C_UOM_ID, COALESCE(uom.UOMSymbol,uom.Name) ");
sqlStmt.append("FROM M_RMALine rl INNER JOIN M_InOutLine iol ON rl.M_InOutLine_ID=iol.M_InOutLine_ID "); sqlStmt.append("FROM M_RMALine rl INNER JOIN M_InOutLine iol ON rl.M_InOutLine_ID=iol.M_InOutLine_ID ");
@ -409,13 +416,13 @@ public class VCreateFromInvoice extends VCreateFrom implements VetoableChangeLis
sqlStmt.append("AND rl.C_Charge_ID IS NOT NULL"); sqlStmt.append("AND rl.C_Charge_ID IS NOT NULL");
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement(sqlStmt.toString(), null); pstmt = DB.prepareStatement(sqlStmt.toString(), null);
pstmt.setInt(1, M_RMA_ID); pstmt.setInt(1, M_RMA_ID);
pstmt.setInt(2, M_RMA_ID); pstmt.setInt(2, M_RMA_ID);
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
{ {
@ -441,17 +448,8 @@ public class VCreateFromInvoice extends VCreateFrom implements VetoableChangeLis
} }
finally finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
{ rs = null; pstmt = null;
try
{
pstmt.close();
}
catch (Exception ex)
{
log.severe("Could not close prepared statement");
}
}
} }
loadTableOIS(data); loadTableOIS(data);
} }
@ -476,7 +474,7 @@ public class VCreateFromInvoice extends VCreateFrom implements VetoableChangeLis
* Save - Create Invoice Lines * Save - Create Invoice Lines
* @return true if saved * @return true if saved
*/ */
protected boolean save() protected boolean save(String trxName)
{ {
dataTable.stopEditor(true); dataTable.stopEditor(true);
log.config(""); log.config("");
@ -487,19 +485,25 @@ public class VCreateFromInvoice extends VCreateFrom implements VetoableChangeLis
// Invoice // Invoice
int C_Invoice_ID = ((Integer)p_mTab.getValue("C_Invoice_ID")).intValue(); int C_Invoice_ID = ((Integer)p_mTab.getValue("C_Invoice_ID")).intValue();
MInvoice invoice = new MInvoice (Env.getCtx(), C_Invoice_ID, null); MInvoice invoice = new MInvoice (Env.getCtx(), C_Invoice_ID, trxName);
log.config(invoice.toString()); log.config(invoice.toString());
if (p_order != null) if (p_order != null)
{ {
invoice.setOrder(p_order); // overwrite header values invoice.setOrder(p_order); // overwrite header values
invoice.save(); invoice.saveEx();
} }
if (m_inout != null && m_inout.getM_InOut_ID() != 0
&& m_inout.getC_Invoice_ID() == 0) // only first time MInOut inout = null;
if (m_M_InOut_ID > 0)
{ {
m_inout.setC_Invoice_ID(C_Invoice_ID); inout = new MInOut(Env.getCtx(), m_M_InOut_ID, trxName);
m_inout.save(); }
if (inout != null && inout.getM_InOut_ID() != 0
&& inout.getC_Invoice_ID() == 0) // only first time
{
inout.setC_Invoice_ID(C_Invoice_ID);
inout.saveEx();
} }
@ -518,7 +522,6 @@ public class VCreateFromInvoice extends VCreateFrom implements VetoableChangeLis
int M_Product_ID = 0; int M_Product_ID = 0;
if (pp != null) if (pp != null)
M_Product_ID = pp.getKey(); M_Product_ID = pp.getKey();
int C_Charge_ID = 0;
// //
int C_OrderLine_ID = 0; int C_OrderLine_ID = 0;
pp = (KeyNamePair)model.getValueAt(i, 5); // 5-OrderLine pp = (KeyNamePair)model.getValueAt(i, 5); // 5-OrderLine
@ -549,22 +552,22 @@ public class VCreateFromInvoice extends VCreateFrom implements VetoableChangeLis
// Info // Info
MOrderLine orderLine = null; MOrderLine orderLine = null;
if (C_OrderLine_ID != 0) if (C_OrderLine_ID != 0)
orderLine = new MOrderLine (Env.getCtx(), C_OrderLine_ID, null); orderLine = new MOrderLine (Env.getCtx(), C_OrderLine_ID, trxName);
MInOutLine inoutLine = null; MInOutLine inoutLine = null;
if (M_InOutLine_ID != 0) if (M_InOutLine_ID != 0)
{ {
inoutLine = new MInOutLine (Env.getCtx(), M_InOutLine_ID, null); inoutLine = new MInOutLine (Env.getCtx(), M_InOutLine_ID, trxName);
if (orderLine == null && inoutLine.getC_OrderLine_ID() != 0) if (orderLine == null && inoutLine.getC_OrderLine_ID() != 0)
{ {
C_OrderLine_ID = inoutLine.getC_OrderLine_ID(); C_OrderLine_ID = inoutLine.getC_OrderLine_ID();
orderLine = new MOrderLine (Env.getCtx(), C_OrderLine_ID, null); orderLine = new MOrderLine (Env.getCtx(), C_OrderLine_ID, trxName);
} }
} }
else else
{ {
String whereClause = "EXISTS (SELECT 1 FROM M_InOut io WHERE io.M_InOut_ID=M_InOutLine.M_InOut_ID AND io.DocStatus IN ('CO','CL'))"; String whereClause = "EXISTS (SELECT 1 FROM M_InOut io WHERE io.M_InOut_ID=M_InOutLine.M_InOut_ID AND io.DocStatus IN ('CO','CL'))";
MInOutLine[] lines = MInOutLine.getOfOrderLine(Env.getCtx(), MInOutLine[] lines = MInOutLine.getOfOrderLine(Env.getCtx(),
C_OrderLine_ID, whereClause, null); C_OrderLine_ID, whereClause, trxName);
log.fine ("Receipt Lines with OrderLine = #" + lines.length); log.fine ("Receipt Lines with OrderLine = #" + lines.length);
if (lines.length > 0) if (lines.length > 0)
{ {
@ -613,8 +616,7 @@ public class VCreateFromInvoice extends VCreateFrom implements VetoableChangeLis
invoiceLine.setTax(); invoiceLine.setTax();
} }
} }
if (!invoiceLine.save()) invoiceLine.saveEx();
log.log(Level.SEVERE, "Line NOT created #" + i);
} // if selected } // if selected
} // for all rows } // for all rows
@ -622,7 +624,8 @@ public class VCreateFromInvoice extends VCreateFrom implements VetoableChangeLis
} // saveInvoice } // saveInvoice
@Override @Override
protected void loadTableOIS(Vector data) { protected void loadTableOIS(Vector<?> data)
{
// Header Info // Header Info
Vector<String> columnNames = new Vector<String>(7); Vector<String> columnNames = new Vector<String>(7);
columnNames.add(Msg.getMsg(Env.getCtx(), "Select")); columnNames.add(Msg.getMsg(Env.getCtx(), "Select"));

View File

@ -32,10 +32,18 @@ import org.compiere.util.KeyNamePair;
import org.compiere.util.Msg; import org.compiere.util.Msg;
/** /**
* Create Transactions for RMA
* @author ashley * @author ashley
* @author Teo Sarca, www.arhipac.ro
* <li>BF [ 2007837 ] VCreateFrom.save() should run in trx
*/ */
public class VCreateFromRMA extends VCreateFrom public class VCreateFromRMA extends VCreateFrom
{ {
/**
*
*/
private static final long serialVersionUID = 8621409442057992906L;
/** /**
* *
* @param mTab * @param mTab
@ -81,11 +89,8 @@ public class VCreateFromRMA extends VCreateFrom
return true; return true;
} }
/** @Override
* Load Order/Invoice/Shipment data into Table protected void loadTableOIS (Vector<?> data)
* @param data data
*/
protected void loadTableOIS (Vector data)
{ {
// Header Info // Header Info
Vector<String> columnNames = new Vector<String>(7); Vector<String> columnNames = new Vector<String>(7);
@ -191,7 +196,7 @@ public class VCreateFromRMA extends VCreateFrom
} }
protected boolean save() protected boolean save(String trxName)
{ {
log.config(""); log.config("");
int m_rma_id = Env.getContextAsInt(Env.getCtx(), p_WindowNo, "M_RMA_ID"); int m_rma_id = Env.getContextAsInt(Env.getCtx(), p_WindowNo, "M_RMA_ID");
@ -203,7 +208,7 @@ public class VCreateFromRMA extends VCreateFrom
} }
// Integer bpId = (Integer)bPartnerField.getValue(); // Integer bpId = (Integer)bPartnerField.getValue();
MRMA rma = new MRMA(Env.getCtx(), m_rma_id, null); MRMA rma = new MRMA(Env.getCtx(), m_rma_id, trxName);
//update BP //update BP
// rma.setC_BPartner_ID(bpId); // rma.setC_BPartner_ID(bpId);
@ -216,7 +221,7 @@ public class VCreateFromRMA extends VCreateFrom
int inOutLineId = pp.getKey(); int inOutLineId = pp.getKey();
MRMALine rmaLine = new MRMALine(Env.getCtx(), 0, null); MRMALine rmaLine = new MRMALine(rma.getCtx(), 0, rma.get_TrxName());
rmaLine.setM_RMA_ID(m_rma_id); rmaLine.setM_RMA_ID(m_rma_id);
rmaLine.setM_InOutLine_ID(inOutLineId); rmaLine.setM_InOutLine_ID(inOutLineId);
rmaLine.setQty(d); rmaLine.setQty(d);
@ -227,12 +232,7 @@ public class VCreateFromRMA extends VCreateFrom
} }
} }
} }
rma.saveEx();
if (!rma.save())
{
throw new IllegalStateException("Could not update RMA");
}
return true; return true;
} }

View File

@ -66,10 +66,16 @@ import org.compiere.util.Msg;
* <li> BF 2530254 It is wrong locator in material receipt for outsourced PO's * <li> BF 2530254 It is wrong locator in material receipt for outsourced PO's
* @see http://sourceforge.net/tracker2/?func=detail&atid=879332&aid=2530254&group_id=176962 * @see http://sourceforge.net/tracker2/?func=detail&atid=879332&aid=2530254&group_id=176962
* @version $Id: VCreateFromShipment.java,v 1.4 2006/07/30 00:51:28 jjanke Exp $ * @version $Id: VCreateFromShipment.java,v 1.4 2006/07/30 00:51:28 jjanke Exp $
*
* @author Teo Sarca, www.arhipac.ro
* <li>BF [ 2007837 ] VCreateFrom.save() should run in trx
*/ */
public class VCreateFromShipment extends VCreateFrom implements VetoableChangeListener public class VCreateFromShipment extends VCreateFrom implements VetoableChangeListener
{ {
private static final long serialVersionUID = 1L; /**
*
*/
private static final long serialVersionUID = -6317997004973385619L;
/** /**
* Cell editor specific for the MLocator in this form's table. * Cell editor specific for the MLocator in this form's table.
@ -194,7 +200,7 @@ public class VCreateFromShipment extends VCreateFrom implements VetoableChangeLi
* @param data data * @param data data
*/ */
@Override @Override
protected void loadTableOIS (Vector data) protected void loadTableOIS (Vector<?> data)
{ {
// Header Info // Header Info
Vector<String> columnNames = new Vector<String>(colNames.length); Vector<String> columnNames = new Vector<String>(colNames.length);
@ -291,24 +297,29 @@ public class VCreateFromShipment extends VCreateFrom implements VetoableChangeLi
+ " OR mi.C_InvoiceLine_ID IS NULL) " + " OR mi.C_InvoiceLine_ID IS NULL) "
+ "ORDER BY i.DateInvoiced"); + "ORDER BY i.DateInvoiced");
PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, C_BPartner_ID); pstmt.setInt(1, C_BPartner_ID);
pstmt.setInt(2, C_BPartner_ID); pstmt.setInt(2, C_BPartner_ID);
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
{ {
pp = new KeyNamePair(rs.getInt(1), rs.getString(2)); pp = new KeyNamePair(rs.getInt(1), rs.getString(2));
invoiceField.addItem(pp); invoiceField.addItem(pp);
} }
rs.close();
pstmt.close();
} }
catch (SQLException e) catch (SQLException e)
{ {
log.log(Level.SEVERE, sql.toString(), e); log.log(Level.SEVERE, sql.toString(), e);
} }
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
invoiceField.setSelectedIndex(0); invoiceField.setSelectedIndex(0);
invoiceField.addActionListener(this); invoiceField.addActionListener(this);
upcField.addActionListener(this); upcField.addActionListener(this);
@ -334,17 +345,17 @@ public class VCreateFromShipment extends VCreateFrom implements VetoableChangeLi
+ "AND rl.M_InOutLine_ID IS NOT NULL)"; + "AND rl.M_InOutLine_ID IS NOT NULL)";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement(sqlStmt, null); pstmt = DB.prepareStatement(sqlStmt, null);
pstmt.setInt(1, C_BPartner_ID); pstmt.setInt(1, C_BPartner_ID);
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
{ {
pp = new KeyNamePair(rs.getInt(1), rs.getString(2)); pp = new KeyNamePair(rs.getInt(1), rs.getString(2));
rmaField.addItem(pp); rmaField.addItem(pp);
} }
rs.close();
} }
catch (SQLException e) catch (SQLException e)
{ {
@ -352,17 +363,8 @@ public class VCreateFromShipment extends VCreateFrom implements VetoableChangeLi
} }
finally finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
{ rs = null; pstmt = null;
try
{
pstmt.close();
}
catch (Exception ex)
{
log.severe("Could not close prepared statement");
}
}
} }
rmaField.setSelectedIndex(0); rmaField.setSelectedIndex(0);
rmaField.addActionListener(this); rmaField.addActionListener(this);
@ -794,7 +796,7 @@ public class VCreateFromShipment extends VCreateFrom implements VetoableChangeLi
* *
* @return true if saved * @return true if saved
*/ */
protected boolean save() protected boolean save(String trxName)
{ {
dataTable.stopEditor(true); dataTable.stopEditor(true);
log.config(""); log.config("");
@ -811,7 +813,7 @@ public class VCreateFromShipment extends VCreateFrom implements VetoableChangeLi
int M_Locator_ID = defaultLoc.intValue(); int M_Locator_ID = defaultLoc.intValue();
// Get Shipment // Get Shipment
int M_InOut_ID = ((Integer) p_mTab.getValue("M_InOut_ID")).intValue(); int M_InOut_ID = ((Integer) p_mTab.getValue("M_InOut_ID")).intValue();
MInOut inout = new MInOut(Env.getCtx(), M_InOut_ID, null); MInOut inout = new MInOut(Env.getCtx(), M_InOut_ID, trxName);
log.config(inout + ", C_Locator_ID=" + M_Locator_ID); log.config(inout + ", C_Locator_ID=" + M_Locator_ID);
// Lines // Lines
@ -843,7 +845,7 @@ public class VCreateFromShipment extends VCreateFrom implements VetoableChangeLi
if (pp != null) if (pp != null)
C_InvoiceLine_ID = pp.getKey(); C_InvoiceLine_ID = pp.getKey();
if (C_InvoiceLine_ID != 0) if (C_InvoiceLine_ID != 0)
il = new MInvoiceLine (Env.getCtx(), C_InvoiceLine_ID, null); il = new MInvoiceLine (Env.getCtx(), C_InvoiceLine_ID, trxName);
//boolean isInvoiced = (C_InvoiceLine_ID != 0); //boolean isInvoiced = (C_InvoiceLine_ID != 0);
// Precision of Qty UOM // Precision of Qty UOM
int precision = 2; int precision = 2;
@ -872,7 +874,7 @@ public class VCreateFromShipment extends VCreateFrom implements VetoableChangeLi
if (C_OrderLine_ID != 0) if (C_OrderLine_ID != 0)
{ {
iol.setC_OrderLine_ID(C_OrderLine_ID); iol.setC_OrderLine_ID(C_OrderLine_ID);
ol = new MOrderLine (Env.getCtx(), C_OrderLine_ID, null); ol = new MOrderLine (Env.getCtx(), C_OrderLine_ID, trxName);
if (ol.getQtyEntered().compareTo(ol.getQtyOrdered()) != 0) if (ol.getQtyEntered().compareTo(ol.getQtyOrdered()) != 0)
{ {
iol.setMovementQty(QtyEntered iol.setMovementQty(QtyEntered
@ -913,7 +915,7 @@ public class VCreateFromShipment extends VCreateFrom implements VetoableChangeLi
} }
else if (M_RMALine_ID != 0) else if (M_RMALine_ID != 0)
{ {
rmal = new MRMALine(Env.getCtx(), M_RMALine_ID, null); rmal = new MRMALine(Env.getCtx(), M_RMALine_ID, trxName);
iol.setM_RMALine_ID(M_RMALine_ID); iol.setM_RMALine_ID(M_RMALine_ID);
iol.setQtyEntered(QtyEntered); iol.setQtyEntered(QtyEntered);
iol.setDescription(rmal.getDescription()); iol.setDescription(rmal.getDescription());
@ -945,7 +947,7 @@ public class VCreateFromShipment extends VCreateFrom implements VetoableChangeLi
else if (il != null) else if (il != null)
{ {
il.setM_InOutLine_ID(iol.getM_InOutLine_ID()); il.setM_InOutLine_ID(iol.getM_InOutLine_ID());
il.save(); il.saveEx();
} }
} // if selected } // if selected
} // for all rows } // for all rows
@ -1000,7 +1002,7 @@ public class VCreateFromShipment extends VCreateFrom implements VetoableChangeLi
inout.setUser1_ID(originalIO.getUser1_ID()); inout.setUser1_ID(originalIO.getUser1_ID());
inout.setUser2_ID(originalIO.getUser2_ID()); inout.setUser2_ID(originalIO.getUser2_ID());
} }
inout.save(); inout.saveEx();
return true; return true;
} // save } // save

View File

@ -58,9 +58,15 @@ import org.compiere.util.Msg;
* @version $Id: VCreateFromStatement.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $ * @version $Id: VCreateFromStatement.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $
* @author Victor Perez, e-Evolucion * @author Victor Perez, e-Evolucion
* <li> RF [1811114] http://sourceforge.net/tracker/index.php?func=detail&aid=1811114&group_id=176962&atid=879335 * <li> RF [1811114] http://sourceforge.net/tracker/index.php?func=detail&aid=1811114&group_id=176962&atid=879335
* @author Teo Sarca, www.arhipac.ro
* <li>BF [ 2007837 ] VCreateFrom.save() should run in trx
*/ */
public class VCreateFromStatement extends VCreateFrom implements ActionListener public class VCreateFromStatement extends VCreateFrom implements ActionListener
{ {
/**
*
*/
private static final long serialVersionUID = 5544131841459717303L;
private MBankAccount bankAccount; private MBankAccount bankAccount;
/** /**
@ -298,13 +304,13 @@ public class VCreateFromStatement extends VCreateFrom implements ActionListener
sql = sql + getSQLWhere() + " ORDER BY p.DateTrx"; sql = sql + getSQLWhere() + " ORDER BY p.DateTrx";
PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); pstmt = DB.prepareStatement(sql.toString(), null);
setParameters( pstmt, false); setParameters( pstmt, false);
rs = pstmt.executeQuery();
ResultSet rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
{ {
Vector<Object> line = new Vector<Object>(6); Vector<Object> line = new Vector<Object>(6);
@ -319,13 +325,16 @@ public class VCreateFromStatement extends VCreateFrom implements ActionListener
line.add(rs.getString(8)); // 6-BParner line.add(rs.getString(8)); // 6-BParner
data.add(line); data.add(line);
} }
rs.close();
pstmt.close();
} }
catch (SQLException e) catch (SQLException e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// Header Info // Header Info
Vector<String> columnNames = new Vector<String>(6); Vector<String> columnNames = new Vector<String>(6);
columnNames.add(Msg.getMsg(Env.getCtx(), "Select")); columnNames.add(Msg.getMsg(Env.getCtx(), "Select"));
@ -380,7 +389,7 @@ public class VCreateFromStatement extends VCreateFrom implements ActionListener
* Save Statement - Insert Data * Save Statement - Insert Data
* @return true if saved * @return true if saved
*/ */
protected boolean save() protected boolean save(String trxName)
{ {
log.config(""); log.config("");
TableModel model = dataTable.getModel(); TableModel model = dataTable.getModel();
@ -390,7 +399,7 @@ public class VCreateFromStatement extends VCreateFrom implements ActionListener
// fixed values // fixed values
int C_BankStatement_ID = ((Integer)p_mTab.getValue("C_BankStatement_ID")).intValue(); int C_BankStatement_ID = ((Integer)p_mTab.getValue("C_BankStatement_ID")).intValue();
MBankStatement bs = new MBankStatement (Env.getCtx(), C_BankStatement_ID, null); MBankStatement bs = new MBankStatement (Env.getCtx(), C_BankStatement_ID, trxName);
log.config(bs.toString()); log.config(bs.toString());
// Lines // Lines
@ -410,7 +419,7 @@ public class VCreateFromStatement extends VCreateFrom implements ActionListener
// //
MBankStatementLine bsl = new MBankStatementLine (bs); MBankStatementLine bsl = new MBankStatementLine (bs);
bsl.setStatementLineDate(trxDate); bsl.setStatementLineDate(trxDate);
bsl.setPayment(new MPayment(Env.getCtx(), C_Payment_ID, null)); bsl.setPayment(new MPayment(Env.getCtx(), C_Payment_ID, trxName));
bsl.setTrxAmt(TrxAmt); bsl.setTrxAmt(TrxAmt);
bsl.setStmtAmt(TrxAmt); bsl.setStmtAmt(TrxAmt);
@ -430,15 +439,18 @@ public class VCreateFromStatement extends VCreateFrom implements ActionListener
public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e)
{ {
log.config("Action=" + e.getActionCommand()); log.config("Action=" + e.getActionCommand());
Object source = e.getSource(); // Object source = e.getSource();
if ( e.getActionCommand().equals(confirmPanel.A_REFRESH) ) { if ( e.getActionCommand().equals(ConfirmPanel.A_REFRESH) )
{
Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR); Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
loadBankAccount(); loadBankAccount();
tableChanged(null); tableChanged(null);
Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
} }
else else
{
super.actionPerformed(e); super.actionPerformed(e);
} }
}
} // VCreateFromStatement } // VCreateFromStatement