MMatchInv: Use new Query API instead of plain JDBC calls
This commit is contained in:
parent
129d61007a
commit
1e0e18f804
|
@ -17,14 +17,11 @@
|
||||||
package org.compiere.model;
|
package org.compiere.model;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import org.compiere.report.MReportTree;
|
|
||||||
import org.compiere.util.CLogger;
|
import org.compiere.util.CLogger;
|
||||||
import org.compiere.util.DB;
|
import org.compiere.util.DB;
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
|
@ -63,37 +60,16 @@ public class MMatchInv extends X_M_MatchInv
|
||||||
* @param trxName transaction
|
* @param trxName transaction
|
||||||
* @return array of matches
|
* @return array of matches
|
||||||
*/
|
*/
|
||||||
public static MMatchInv[] get (Properties ctx,
|
public static MMatchInv[] get (Properties ctx, int M_InOutLine_ID, int C_InvoiceLine_ID, String trxName)
|
||||||
int M_InOutLine_ID, int C_InvoiceLine_ID, String trxName)
|
|
||||||
{
|
{
|
||||||
if (M_InOutLine_ID == 0 || C_InvoiceLine_ID == 0)
|
if (M_InOutLine_ID <= 0 || C_InvoiceLine_ID <= 0)
|
||||||
return new MMatchInv[]{};
|
return new MMatchInv[]{};
|
||||||
//
|
//
|
||||||
String sql = "SELECT * FROM M_MatchInv WHERE M_InOutLine_ID=? AND C_InvoiceLine_ID=?";
|
final String whereClause = "M_InOutLine_ID=? AND C_InvoiceLine_ID=?";
|
||||||
ArrayList<MMatchInv> list = new ArrayList<MMatchInv>();
|
List<MMatchInv> list = new Query(ctx, MMatchInv.Table_Name, whereClause, trxName)
|
||||||
PreparedStatement pstmt = null;
|
.setParameters(new Object[]{M_InOutLine_ID, C_InvoiceLine_ID})
|
||||||
ResultSet rs = null;
|
.list();
|
||||||
try
|
return list.toArray (new MMatchInv[list.size()]);
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement (sql, trxName);
|
|
||||||
pstmt.setInt (1, M_InOutLine_ID);
|
|
||||||
pstmt.setInt (2, C_InvoiceLine_ID);
|
|
||||||
rs = pstmt.executeQuery ();
|
|
||||||
while (rs.next ())
|
|
||||||
list.add (new MMatchInv (ctx, rs, trxName));
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
s_log.log(Level.SEVERE, sql, e);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
DB.close(rs, pstmt);
|
|
||||||
rs = null; pstmt = null;
|
|
||||||
}
|
|
||||||
MMatchInv[] retValue = new MMatchInv[list.size()];
|
|
||||||
list.toArray (retValue);
|
|
||||||
return retValue;
|
|
||||||
} // get
|
} // get
|
||||||
|
|
||||||
// MZ Goodwill
|
// MZ Goodwill
|
||||||
|
@ -106,33 +82,14 @@ public class MMatchInv extends X_M_MatchInv
|
||||||
*/
|
*/
|
||||||
public static MMatchInv[] getInvoiceLine (Properties ctx, int C_InvoiceLine_ID, String trxName)
|
public static MMatchInv[] getInvoiceLine (Properties ctx, int C_InvoiceLine_ID, String trxName)
|
||||||
{
|
{
|
||||||
if (C_InvoiceLine_ID == 0)
|
if (C_InvoiceLine_ID <= 0)
|
||||||
return new MMatchInv[]{};
|
return new MMatchInv[]{};
|
||||||
//
|
//
|
||||||
String sql = "SELECT * FROM M_MatchInv WHERE C_InvoiceLine_ID=?";
|
String whereClause = "C_InvoiceLine_ID=?";
|
||||||
ArrayList<MMatchInv> list = new ArrayList<MMatchInv>();
|
List<MMatchInv> list = new Query(ctx, MMatchInv.Table_Name, whereClause, trxName)
|
||||||
PreparedStatement pstmt = null;
|
.setParameters(new Object[]{C_InvoiceLine_ID})
|
||||||
ResultSet rs = null;
|
.list();
|
||||||
try
|
return list.toArray (new MMatchInv[list.size()]);
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement (sql, trxName);
|
|
||||||
pstmt.setInt (1, C_InvoiceLine_ID);
|
|
||||||
rs = pstmt.executeQuery ();
|
|
||||||
while (rs.next ())
|
|
||||||
list.add (new MMatchInv (ctx, rs, trxName));
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
s_log.log(Level.SEVERE, sql, e);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
DB.close(rs, pstmt);
|
|
||||||
rs = null; pstmt = null;
|
|
||||||
}
|
|
||||||
MMatchInv[] retValue = new MMatchInv[list.size()];
|
|
||||||
list.toArray (retValue);
|
|
||||||
return retValue;
|
|
||||||
} // getInvoiceLine
|
} // getInvoiceLine
|
||||||
// end MZ
|
// end MZ
|
||||||
|
|
||||||
|
@ -143,38 +100,17 @@ public class MMatchInv extends X_M_MatchInv
|
||||||
* @param trxName transaction
|
* @param trxName transaction
|
||||||
* @return array of matches
|
* @return array of matches
|
||||||
*/
|
*/
|
||||||
public static MMatchInv[] getInOut (Properties ctx,
|
public static MMatchInv[] getInOut (Properties ctx, int M_InOut_ID, String trxName)
|
||||||
int M_InOut_ID, String trxName)
|
|
||||||
{
|
{
|
||||||
if (M_InOut_ID == 0)
|
if (M_InOut_ID <= 0)
|
||||||
return new MMatchInv[]{};
|
return new MMatchInv[]{};
|
||||||
//
|
//
|
||||||
String sql = "SELECT * FROM M_MatchInv m"
|
final String whereClause = "EXISTS (SELECT 1 FROM M_InOutLine l"
|
||||||
+ " INNER JOIN M_InOutLine l ON (m.M_InOutLine_ID=l.M_InOutLine_ID) "
|
+" WHERE M_MatchInv.M_InOutLine_ID=l.M_InOutLine_ID AND l.M_InOut_ID=?)";
|
||||||
+ "WHERE l.M_InOut_ID=?";
|
List<MMatchInv> list = new Query(ctx, MMatchInv.Table_Name, whereClause, trxName)
|
||||||
ArrayList<MMatchInv> list = new ArrayList<MMatchInv>();
|
.setParameters(new Object[]{M_InOut_ID})
|
||||||
PreparedStatement pstmt = null;
|
.list();
|
||||||
ResultSet rs = null;
|
return list.toArray (new MMatchInv[list.size()]);
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement (sql, trxName);
|
|
||||||
pstmt.setInt (1, M_InOut_ID);
|
|
||||||
rs = pstmt.executeQuery ();
|
|
||||||
while (rs.next ())
|
|
||||||
list.add (new MMatchInv (ctx, rs, trxName));
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
s_log.log(Level.SEVERE, sql, e);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
DB.close(rs, pstmt);
|
|
||||||
rs = null; pstmt = null;
|
|
||||||
}
|
|
||||||
MMatchInv[] retValue = new MMatchInv[list.size()];
|
|
||||||
list.toArray (retValue);
|
|
||||||
return retValue;
|
|
||||||
} // getInOut
|
} // getInOut
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -190,32 +126,12 @@ public class MMatchInv extends X_M_MatchInv
|
||||||
if (C_Invoice_ID == 0)
|
if (C_Invoice_ID == 0)
|
||||||
return new MMatchInv[]{};
|
return new MMatchInv[]{};
|
||||||
//
|
//
|
||||||
String sql = "SELECT * FROM M_MatchInv mi"
|
final String whereClause = " EXISTS (SELECT 1 FROM C_InvoiceLine il"
|
||||||
+ " INNER JOIN C_InvoiceLine il ON (mi.C_InvoiceLine_ID=il.C_InvoiceLine_ID) "
|
+" WHERE M_MatchInv.C_InvoiceLine_ID=il.C_InvoiceLine_ID AND il.C_Invoice_ID=?)";
|
||||||
+ "WHERE il.C_Invoice_ID=?";
|
List<MMatchInv> list = new Query(ctx, MMatchInv.Table_Name, whereClause, trxName)
|
||||||
ArrayList<MMatchInv> list = new ArrayList<MMatchInv>();
|
.setParameters(new Object[]{C_Invoice_ID})
|
||||||
PreparedStatement pstmt = null;
|
.list();
|
||||||
ResultSet rs = null;
|
return list.toArray (new MMatchInv[list.size()]);
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement (sql, trxName);
|
|
||||||
pstmt.setInt (1, C_Invoice_ID);
|
|
||||||
rs = pstmt.executeQuery ();
|
|
||||||
while (rs.next ())
|
|
||||||
list.add (new MMatchInv (ctx, rs, trxName));
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
s_log.log(Level.SEVERE, sql, e);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
DB.close(rs, pstmt);
|
|
||||||
rs = null; pstmt = null;
|
|
||||||
}
|
|
||||||
MMatchInv[] retValue = new MMatchInv[list.size()];
|
|
||||||
list.toArray (retValue);
|
|
||||||
return retValue;
|
|
||||||
} // getInvoice
|
} // getInvoice
|
||||||
|
|
||||||
|
|
||||||
|
@ -548,34 +464,16 @@ public class MMatchInv extends X_M_MatchInv
|
||||||
public static MMatchInv[] getInOutLine (Properties ctx,
|
public static MMatchInv[] getInOutLine (Properties ctx,
|
||||||
int M_InOutLine_ID, String trxName)
|
int M_InOutLine_ID, String trxName)
|
||||||
{
|
{
|
||||||
if (M_InOutLine_ID == 0)
|
if (M_InOutLine_ID <= 0)
|
||||||
|
{
|
||||||
return new MMatchInv[]{};
|
return new MMatchInv[]{};
|
||||||
|
}
|
||||||
//
|
//
|
||||||
String sql = "SELECT * FROM M_MatchInv m "
|
final String whereClause = MMatchInv.COLUMNNAME_M_InOutLine_ID+"=?";
|
||||||
+ "WHERE m.M_InOutLine_ID=?";
|
List<MMatchInv> list = new Query(ctx, MMatchInv.Table_Name, whereClause, trxName)
|
||||||
ArrayList<MMatchInv> list = new ArrayList<MMatchInv>();
|
.setParameters(new Object[]{M_InOutLine_ID})
|
||||||
PreparedStatement pstmt = null;
|
.list();
|
||||||
ResultSet rs = null;
|
return list.toArray (new MMatchInv[list.size()]);
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement (sql, trxName);
|
|
||||||
pstmt.setInt (1, M_InOutLine_ID);
|
|
||||||
rs = pstmt.executeQuery ();
|
|
||||||
while (rs.next ())
|
|
||||||
list.add (new MMatchInv (ctx, rs, trxName));
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
s_log.log(Level.SEVERE, sql, e);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
DB.close(rs, pstmt);
|
|
||||||
rs = null; pstmt = null;
|
|
||||||
}
|
|
||||||
MMatchInv[] retValue = new MMatchInv[list.size()];
|
|
||||||
list.toArray (retValue);
|
|
||||||
return retValue;
|
|
||||||
} // getInOutLine
|
} // getInOutLine
|
||||||
// end Bayu
|
// end Bayu
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package test.functional;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.compiere.model.MMatchInv;
|
||||||
|
|
||||||
|
import test.AdempiereTestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Teo Sarca
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MMatchInvTest extends AdempiereTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Only check if new API was correctly introduced
|
||||||
|
*/
|
||||||
|
public void testNewQueryAPI() throws Exception
|
||||||
|
{
|
||||||
|
Properties ctx = getCtx();
|
||||||
|
String trxName = getTrxName();
|
||||||
|
int C_Invoice_ID = 100;
|
||||||
|
int C_InvoiceLine_ID = 100;
|
||||||
|
int M_InOut_ID = 100;
|
||||||
|
int M_InOutLine_ID = 100;
|
||||||
|
//
|
||||||
|
MMatchInv.get(ctx, M_InOutLine_ID, C_InvoiceLine_ID, trxName);
|
||||||
|
MMatchInv.getInvoice(ctx, C_Invoice_ID, trxName);
|
||||||
|
MMatchInv.getInvoiceLine(ctx, C_InvoiceLine_ID, trxName);
|
||||||
|
MMatchInv.getInOut(ctx, M_InOut_ID, trxName);
|
||||||
|
MMatchInv.getInOutLine(ctx, M_InOutLine_ID, trxName);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue