IDEMPIERE-308 Performance: Replace use of StringBuffer and String concatenation with StringBuilder - thanks to David Peñuela

This commit is contained in:
Carlos Ruiz 2012-09-17 16:30:08 -05:00
parent d561f2b556
commit 7f4c2934c0
21 changed files with 285 additions and 283 deletions

View File

@ -63,32 +63,32 @@ public class MRelationType extends X_AD_RelationType implements IZoomProvider {
* <b>Warning:</b> Doesn't support POs with more or less than one key
* column.
*/
final static String SQL = //
" SELECT " //
+ " rt.AD_RelationType_ID AS " + COLUMNNAME_AD_RelationType_ID //
+ ", rt.Name AS " + COLUMNNAME_Name //
+ ", rt.IsDirected AS " + COLUMNNAME_IsDirected //
+ ", ref.AD_Reference_ID AS " + COLUMNNAME_AD_Reference_ID //
+ ", tab.WhereClause AS " + COLUMNNAME_WhereClause //
+ ", tab.OrderByClause AS " + COLUMNNAME_OrderByClause //
+ " FROM" //
+ " AD_RelationType rt, AD_Reference ref, AD_Ref_Table tab" //
+ " WHERE " //
+ " rt.IsActive='Y'" //
+ " AND ref.IsActive='Y'" //
+ " AND ref.ValidationType='T'" // must have table validation
+ " AND (" // join the source AD_Reference
+ " rt.AD_Reference_Source_ID=ref.AD_Reference_ID" //
+ " OR (" // not directed? -> also join the target AD_Reference
+ " rt.IsDirected='N' " //
+ " AND rt.AD_Reference_Target_ID=ref.AD_Reference_ID" //
+ " )" //
+ " )" //
+ " AND tab.IsActive='Y'" // Join the AD_Reference's AD_Ref_Table
+ " AND tab.AD_Reference_ID=ref.AD_Reference_ID" //
+ " AND tab.AD_Table_ID=?" //
+ " AND tab.AD_Key=?" //
+ " ORDER BY rt.Name";
final static StringBuffer SQL = //
new StringBuffer(" SELECT " )//
.append(" rt.AD_RelationType_ID AS ").append(COLUMNNAME_AD_RelationType_ID) //
.append(", rt.Name AS ").append(COLUMNNAME_Name )//
.append(", rt.IsDirected AS ").append(COLUMNNAME_IsDirected) //
.append(", ref.AD_Reference_ID AS ").append(COLUMNNAME_AD_Reference_ID) //
.append(", tab.WhereClause AS ").append(COLUMNNAME_WhereClause) //
.append(", tab.OrderByClause AS ").append(COLUMNNAME_OrderByClause) //
.append(" FROM") //
.append(" AD_RelationType rt, AD_Reference ref, AD_Ref_Table tab") //
.append(" WHERE ") //
.append(" rt.IsActive='Y'") //
.append(" AND ref.IsActive='Y'") //
.append(" AND ref.ValidationType='T'") // must have table validation
.append(" AND (") // join the source AD_Reference
.append(" rt.AD_Reference_Source_ID=ref.AD_Reference_ID") //
.append(" OR (") // not directed? -> also join the target AD_Reference
.append(" rt.IsDirected='N' ") //
.append(" AND rt.AD_Reference_Target_ID=ref.AD_Reference_ID") //
.append(" )") //
.append(" )") //
.append(" AND tab.IsActive='Y'") // Join the AD_Reference's AD_Ref_Table
.append(" AND tab.AD_Reference_ID=ref.AD_Reference_ID") //
.append(" AND tab.AD_Table_ID=?") //
.append(" AND tab.AD_Key=?") //
.append(" ORDER BY rt.Name");
final static String SQL_WINDOW_NAME = "SELECT Name FROM AD_Window WHERE AD_WINDOW_ID=?";
@ -131,7 +131,7 @@ public class MRelationType extends X_AD_RelationType implements IZoomProvider {
final int colId = MColumn.getColumn_ID(po.get_TableName(), keyColumn);
final PreparedStatement pstmt = DB.prepareStatement(SQL, po
final PreparedStatement pstmt = DB.prepareStatement(SQL.toString(), po
.get_TrxName());
ResultSet rs = null;

View File

@ -326,8 +326,8 @@ public class PromotionRule {
* @throws Exception
*/
private static Map<Integer, List<Integer>> findM_Promotion_ID(MOrder order) throws Exception {
String select = "SELECT M_Promotion.M_Promotion_ID From M_Promotion Inner Join M_PromotionPreCondition "
+ " ON (M_Promotion.M_Promotion_ID = M_PromotionPreCondition.M_Promotion_ID)";
StringBuffer select = new StringBuffer("SELECT M_Promotion.M_Promotion_ID From M_Promotion Inner Join M_PromotionPreCondition ")
.append(" ON (M_Promotion.M_Promotion_ID = M_PromotionPreCondition.M_Promotion_ID)");
String bpFilter = "M_PromotionPreCondition.C_BPartner_ID = ? OR M_PromotionPreCondition.C_BP_Group_ID = ? OR (M_PromotionPreCondition.C_BPartner_ID IS NULL AND M_PromotionPreCondition.C_BP_Group_ID IS NULL)";
String priceListFilter = "M_PromotionPreCondition.M_PriceList_ID IS NULL OR M_PromotionPreCondition.M_PriceList_ID = ?";
@ -414,12 +414,12 @@ public class PromotionRule {
private static DistributionSet calculateDistributionQty(MPromotionDistribution distribution,
DistributionSet prevSet, List<Integer> validPromotionLineIDs, Map<Integer, BigDecimal> orderLineQty, List<Integer> orderLineIdList, String trxName) throws Exception {
String sql = "SELECT C_OrderLine.C_OrderLine_ID FROM M_PromotionLine"
+ " INNER JOIN M_PromotionGroup ON (M_PromotionLine.M_PromotionGroup_ID = M_PromotionGroup.M_PromotionGroup_ID AND M_PromotionGroup.IsActive = 'Y')"
+ " INNER JOIN M_PromotionGroupLine ON (M_PromotionGroup.M_PromotionGroup_ID = M_PromotionGroupLine.M_PromotionGroup_ID AND M_PromotionGroupLine.IsActive = 'Y')"
+ " INNER JOIN C_OrderLine ON (M_PromotionGroupLine.M_Product_ID = C_OrderLine.M_Product_ID)"
+ " WHERE M_PromotionLine.M_PromotionLine_ID = ? AND C_OrderLine.C_OrderLine_ID = ?"
+ " AND M_PromotionLine.IsActive = 'Y'";
StringBuilder sql = new StringBuilder("SELECT C_OrderLine.C_OrderLine_ID FROM M_PromotionLine")
.append(" INNER JOIN M_PromotionGroup ON (M_PromotionLine.M_PromotionGroup_ID = M_PromotionGroup.M_PromotionGroup_ID AND M_PromotionGroup.IsActive = 'Y')")
.append(" INNER JOIN M_PromotionGroupLine ON (M_PromotionGroup.M_PromotionGroup_ID = M_PromotionGroupLine.M_PromotionGroup_ID AND M_PromotionGroupLine.IsActive = 'Y')")
.append(" INNER JOIN C_OrderLine ON (M_PromotionGroupLine.M_Product_ID = C_OrderLine.M_Product_ID)")
.append(" WHERE M_PromotionLine.M_PromotionLine_ID = ? AND C_OrderLine.C_OrderLine_ID = ?")
.append(" AND M_PromotionLine.IsActive = 'Y'");
DistributionSet distributionSet = new DistributionSet();
List<Integer>eligibleOrderLineIDs = new ArrayList<Integer>();
@ -434,7 +434,7 @@ public class PromotionRule {
PreparedStatement stmt = null;
ResultSet rs = null;
try {
stmt = DB.prepareStatement(sql, trxName);
stmt = DB.prepareStatement(sql.toString(), trxName);
stmt.setInt(1, distribution.getM_PromotionLine_ID());
stmt.setInt(2, C_OrderLine_ID);
rs = stmt.executeQuery();
@ -547,17 +547,17 @@ public class PromotionRule {
for (MPromotionLine pl : plist) {
boolean match = false;
if (pl.getM_PromotionGroup_ID() > 0) {
String sql = "SELECT DISTINCT C_OrderLine.C_OrderLine_ID FROM M_PromotionGroup INNER JOIN M_PromotionGroupLine"
+ " ON (M_PromotionGroup.M_PromotionGroup_ID = M_PromotionGroupLine.M_PromotionGroup_ID AND M_PromotionGroupLine.IsActive = 'Y')"
+ " INNER JOIN C_OrderLine ON (M_PromotionGroupLine.M_Product_ID = C_OrderLine.M_Product_ID)"
+ " INNER JOIN M_PromotionLine ON (M_PromotionLine.M_PromotionGroup_ID = M_PromotionGroup.M_PromotionGroup_ID)"
+ " WHERE M_PromotionLine.M_PromotionLine_ID = ? AND C_OrderLine.C_Order_ID = ?"
+ " AND M_PromotionLine.IsActive = 'Y'"
+ " AND M_PromotionGroup.IsActive = 'Y'";
StringBuilder sql = new StringBuilder("SELECT DISTINCT C_OrderLine.C_OrderLine_ID FROM M_PromotionGroup INNER JOIN M_PromotionGroupLine")
.append(" ON (M_PromotionGroup.M_PromotionGroup_ID = M_PromotionGroupLine.M_PromotionGroup_ID AND M_PromotionGroupLine.IsActive = 'Y')")
.append(" INNER JOIN C_OrderLine ON (M_PromotionGroupLine.M_Product_ID = C_OrderLine.M_Product_ID)")
.append(" INNER JOIN M_PromotionLine ON (M_PromotionLine.M_PromotionGroup_ID = M_PromotionGroup.M_PromotionGroup_ID)")
.append(" WHERE M_PromotionLine.M_PromotionLine_ID = ? AND C_OrderLine.C_Order_ID = ?")
.append(" AND M_PromotionLine.IsActive = 'Y'")
.append(" AND M_PromotionGroup.IsActive = 'Y'");
PreparedStatement stmt = null;
ResultSet rs = null;
try {
stmt = DB.prepareStatement(sql, order.get_TrxName());
stmt = DB.prepareStatement(sql.toString(), order.get_TrxName());
stmt.setInt(1, pl.getM_PromotionLine_ID());
stmt.setInt(2, order.getC_Order_ID());
rs = stmt.executeQuery();

View File

@ -47,11 +47,11 @@ public class ResetLockedAccount extends SvrProcess {
if (!user.isLocked())
throw new AdempiereException("User " + user.getName() + " is not locked");
String sql = "UPDATE AD_User SET IsLocked = 'N', DateAccountLocked=NULL, FailedLoginCount=0, DateLastLogin=NULL, Updated=SysDate "
+ " WHERE IsLocked='Y' AND AD_Client_ID = ? "
+ " AND DateAccountLocked IS NOT NULL "
+ " AND AD_User_ID = " + user.getAD_User_ID();
int no = DB.executeUpdate(sql, new Object[] { p_AD_Client_ID }, false, get_TrxName());
StringBuffer sql = new StringBuffer ("UPDATE AD_User SET IsLocked = 'N', DateAccountLocked=NULL, FailedLoginCount=0, DateLastLogin=NULL, Updated=SysDate ")
.append(" WHERE IsLocked='Y' AND AD_Client_ID = ? ")
.append(" AND DateAccountLocked IS NOT NULL ")
.append(" AND AD_User_ID = " + user.getAD_User_ID());
int no = DB.executeUpdate(sql.toString(), new Object[] { p_AD_Client_ID }, false, get_TrxName());
if (no < 0)
throw new AdempiereException("Could not unlock user account" + user.toString());
@ -62,26 +62,26 @@ public class ResetLockedAccount extends SvrProcess {
int MAX_ACCOUNT_LOCK_MINUTES = MSysConfig.getIntValue(MSysConfig.USER_LOCKING_MAX_ACCOUNT_LOCK_MINUTES, 0);
int MAX_INACTIVE_PERIOD = MSysConfig.getIntValue(MSysConfig.USER_LOCKING_MAX_INACTIVE_PERIOD_DAY, 0);
String sql = "UPDATE AD_User SET IsLocked = 'N', DateAccountLocked=NULL, FailedLoginCount=0, DateLastLogin=NULL, Updated=SysDate "
+ " WHERE IsLocked='Y' AND AD_Client_ID IN (0, ?) "
+ " AND DateAccountLocked IS NOT NULL";
StringBuffer sql = new StringBuffer("UPDATE AD_User SET IsLocked = 'N', DateAccountLocked=NULL, FailedLoginCount=0, DateLastLogin=NULL, Updated=SysDate ")
.append(" WHERE IsLocked='Y' AND AD_Client_ID IN (0, ?) ")
.append(" AND DateAccountLocked IS NOT NULL");
if (DB.isPostgreSQL())
{
if (MAX_ACCOUNT_LOCK_MINUTES > 0)
sql += " AND EXTRACT(MINUTE FROM (now()-DateAccountLocked)) * 24 * 60 > " + MAX_ACCOUNT_LOCK_MINUTES;
sql.append( " AND EXTRACT(MINUTE FROM (now()-DateAccountLocked)) * 24 * 60 > ").append(MAX_ACCOUNT_LOCK_MINUTES);
if (MAX_INACTIVE_PERIOD > 0)
sql += " AND EXTRACT(DAY FROM (now()-DateLastLogin)) * 24 <= " + MAX_INACTIVE_PERIOD;
sql.append(" AND EXTRACT(DAY FROM (now()-DateLastLogin)) * 24 <= ").append(MAX_INACTIVE_PERIOD);
}
else
{
if (MAX_ACCOUNT_LOCK_MINUTES > 0)
sql += " AND (SysDate-DateAccountLocked) * 24 * 60 > " + MAX_ACCOUNT_LOCK_MINUTES;
sql.append(" AND (SysDate-DateAccountLocked) * 24 * 60 > ").append(MAX_ACCOUNT_LOCK_MINUTES);
if (MAX_INACTIVE_PERIOD > 0)
sql += " AND (SysDate-DateLastLogin) * 24 <= " + MAX_INACTIVE_PERIOD;
sql.append(" AND (SysDate-DateLastLogin) * 24 <= ").append(MAX_INACTIVE_PERIOD);
}
int no = DB.executeUpdate(sql, p_AD_Client_ID, get_TrxName());
int no = DB.executeUpdate(sql.toString(), p_AD_Client_ID, get_TrxName());
if (no < 0)
throw new AdempiereException("Could not unlock user account");
return no + " locked account has been reset";

View File

@ -233,23 +233,23 @@ public class ModelInterfaceGenerator
*/
private StringBuffer createColumns(int AD_Table_ID, StringBuffer mandatory) {
StringBuffer sb = new StringBuffer();
String sql = "SELECT c.ColumnName, c.IsUpdateable, c.IsMandatory," // 1..3
+ " c.AD_Reference_ID, c.AD_Reference_Value_ID, DefaultValue, SeqNo, " // 4..7
+ " c.FieldLength, c.ValueMin, c.ValueMax, c.VFormat, c.Callout, " // 8..12
+ " c.Name, c.Description, c.ColumnSQL, c.IsEncrypted, c.IsKey " // 13..17
+ "FROM AD_Column c "
+ "WHERE c.AD_Table_ID=?"
StringBuffer sql = new StringBuffer("SELECT c.ColumnName, c.IsUpdateable, c.IsMandatory,") // 1..3
.append(" c.AD_Reference_ID, c.AD_Reference_Value_ID, DefaultValue, SeqNo, ") // 4..7
.append(" c.FieldLength, c.ValueMin, c.ValueMax, c.VFormat, c.Callout, ") // 8..12
.append(" c.Name, c.Description, c.ColumnSQL, c.IsEncrypted, c.IsKey ") // 13..17
.append("FROM AD_Column c ")
.append("WHERE c.AD_Table_ID=?")
// + " AND c.ColumnName <> 'AD_Client_ID'"
// + " AND c.ColumnName <> 'AD_Org_ID'"
// + " AND c.ColumnName <> 'IsActive'"
// + " AND c.ColumnName NOT LIKE 'Created%'"
// + " AND c.ColumnName NOT LIKE 'Updated%' "
+ " AND c.IsActive='Y'"
+ " ORDER BY c.ColumnName";
.append(" AND c.IsActive='Y'")
.append(" ORDER BY c.ColumnName");
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, AD_Table_ID);
rs = pstmt.executeQuery();
while (rs.next()) {
@ -289,7 +289,7 @@ public class ModelInterfaceGenerator
}
catch (SQLException e)
{
throw new DBException(e, sql);
throw new DBException(e, sql.toString());
}
finally
{
@ -495,15 +495,15 @@ public class ModelInterfaceGenerator
else if ((DisplayType.Table == displayType || DisplayType.Search == displayType)
&& AD_Reference_ID > 0)
{
String sql = "SELECT c.AD_Reference_ID, c.AD_Reference_Value_ID"
+" FROM AD_Ref_Table rt"
+" INNER JOIN AD_Column c ON (c.AD_Column_ID=rt.AD_Key)"
+" WHERE rt.AD_Reference_ID=?";
StringBuffer sql = new StringBuffer("SELECT c.AD_Reference_ID, c.AD_Reference_Value_ID")
.append(" FROM AD_Ref_Table rt")
.append(" INNER JOIN AD_Column c ON (c.AD_Column_ID=rt.AD_Key)")
.append(" WHERE rt.AD_Reference_ID=?");
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, AD_Reference_ID);
rs = pstmt.executeQuery();
if (rs.next())
@ -518,7 +518,7 @@ public class ModelInterfaceGenerator
}
catch (SQLException e)
{
throw new DBException(e, sql);
throw new DBException(e, sql.toString());
}
finally
{
@ -670,17 +670,17 @@ public class ModelInterfaceGenerator
if (AD_Table_ID == 707 && columnName.equals("Account_ID"))
return null;
//
final String sql = "SELECT t.TableName, t.EntityType, ck.AD_Reference_ID"
+" FROM AD_Ref_Table rt"
+" INNER JOIN AD_Table t ON (t.AD_Table_ID=rt.AD_Table_ID)"
+" INNER JOIN AD_Column ck ON (ck.AD_Table_ID=rt.AD_Table_ID AND ck.AD_Column_ID=rt.AD_Key)"
+" WHERE rt.AD_Reference_ID=?"
final StringBuffer sql = new StringBuffer("SELECT t.TableName, t.EntityType, ck.AD_Reference_ID")
.append(" FROM AD_Ref_Table rt")
.append(" INNER JOIN AD_Table t ON (t.AD_Table_ID=rt.AD_Table_ID)")
.append(" INNER JOIN AD_Column ck ON (ck.AD_Table_ID=rt.AD_Table_ID AND ck.AD_Column_ID=rt.AD_Key)")
.append(" WHERE rt.AD_Reference_ID=?")
;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, AD_Reference_ID);
rs = pstmt.executeQuery();
if (rs.next())
@ -705,7 +705,7 @@ public class ModelInterfaceGenerator
}
catch (SQLException e)
{
throw new DBException(e, sql);
throw new DBException(e, sql.toString());
}
finally
{

View File

@ -841,11 +841,11 @@ public abstract class Doc
// We have a document Type, but no GL info - search for DocType
if (m_GL_Category_ID == 0)
{
String sql = "SELECT GL_Category_ID FROM C_DocType "
+ "WHERE AD_Client_ID=? AND DocBaseType=?";
StringBuilder sql = new StringBuilder("SELECT GL_Category_ID FROM C_DocType ")
.append("WHERE AD_Client_ID=? AND DocBaseType=?");
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, getAD_Client_ID());
pstmt.setString(2, m_DocumentType);
ResultSet rsDT = pstmt.executeQuery();
@ -856,19 +856,19 @@ public abstract class Doc
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
log.log(Level.SEVERE, sql.toString(), e);
}
}
// Still no GL_Category - get Default GL Category
if (m_GL_Category_ID == 0)
{
String sql = "SELECT GL_Category_ID FROM GL_Category "
+ "WHERE AD_Client_ID=? "
+ "ORDER BY IsDefault DESC";
StringBuilder sql = new StringBuilder("SELECT GL_Category_ID FROM GL_Category ")
.append("WHERE AD_Client_ID=? ")
.append("ORDER BY IsDefault DESC");
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, getAD_Client_ID());
ResultSet rsDT = pstmt.executeQuery();
if (rsDT.next())
@ -878,7 +878,7 @@ public abstract class Doc
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
log.log(Level.SEVERE, sql.toString(), e);
}
}
//

View File

@ -71,10 +71,10 @@ public class DocLine_Allocation extends DocLine
{
if (m_C_Invoice_ID == 0)
return 0;
String sql = "SELECT C_Currency_ID "
+ "FROM C_Invoice "
+ "WHERE C_Invoice_ID=?";
return DB.getSQLValue(null, sql, m_C_Invoice_ID);
StringBuilder sql = new StringBuilder("SELECT C_Currency_ID ")
.append("FROM C_Invoice ")
.append("WHERE C_Invoice_ID=?");
return DB.getSQLValue(null, sql.toString(), m_C_Invoice_ID);
} // getInvoiceC_Currency_ID
/**

View File

@ -68,19 +68,19 @@ public class DocManager {
private static void fillDocumentsTableArrays() {
if (documentsTableID == null) {
String sql = "SELECT t.AD_Table_ID, t.TableName " +
"FROM AD_Table t, AD_Column c " +
"WHERE t.AD_Table_ID=c.AD_Table_ID AND " +
"c.ColumnName='Posted' AND " +
"IsView='N' " +
"ORDER BY t.AD_Table_ID";
StringBuilder sql = new StringBuilder("SELECT t.AD_Table_ID, t.TableName ")
.append("FROM AD_Table t, AD_Column c ")
.append("WHERE t.AD_Table_ID=c.AD_Table_ID AND ")
.append("c.ColumnName='Posted' AND ")
.append("IsView='N' ")
.append("ORDER BY t.AD_Table_ID");
ArrayList<Integer> tableIDs = new ArrayList<Integer>();
ArrayList<String> tableNames = new ArrayList<String>();
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt = DB.prepareStatement(sql.toString(), null);
rs = pstmt.executeQuery();
while (rs.next())
{
@ -90,7 +90,7 @@ public class DocManager {
}
catch (SQLException e)
{
throw new DBException(e, sql);
throw new DBException(e, sql.toString());
}
finally
{

View File

@ -96,14 +96,14 @@ public final class DocTax
if (AcctType < 0 || AcctType > 4)
return null;
//
String sql = "SELECT T_Due_Acct, T_Liability_Acct, T_Credit_Acct, T_Receivables_Acct, T_Expense_Acct "
+ "FROM C_Tax_Acct WHERE C_Tax_ID=? AND C_AcctSchema_ID=?";
StringBuilder sql = new StringBuilder("SELECT T_Due_Acct, T_Liability_Acct, T_Credit_Acct, T_Receivables_Acct, T_Expense_Acct ")
.append("FROM C_Tax_Acct WHERE C_Tax_ID=? AND C_AcctSchema_ID=?");
int validCombination_ID = 0;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, m_C_Tax_ID);
pstmt.setInt(2, as.getC_AcctSchema_ID());
rs = pstmt.executeQuery();
@ -112,7 +112,7 @@ public final class DocTax
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
log.log(Level.SEVERE, sql.toString(), e);
}
finally {
DB.close(rs, pstmt);

View File

@ -628,14 +628,14 @@ public class Doc_AllocationHdr extends Doc
// or Doc.ACCTTYPE_PaymentSelect (AP) or V_Prepayment
int accountType = Doc.ACCTTYPE_UnallocatedCash;
//
String sql = "SELECT p.C_BankAccount_ID, d.DocBaseType, p.IsReceipt, p.IsPrepayment "
+ "FROM C_Payment p INNER JOIN C_DocType d ON (p.C_DocType_ID=d.C_DocType_ID) "
+ "WHERE C_Payment_ID=?";
StringBuilder sql = new StringBuilder("SELECT p.C_BankAccount_ID, d.DocBaseType, p.IsReceipt, p.IsPrepayment ")
.append("FROM C_Payment p INNER JOIN C_DocType d ON (p.C_DocType_ID=d.C_DocType_ID) ")
.append("WHERE C_Payment_ID=?");
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement (sql, getTrxName());
pstmt = DB.prepareStatement (sql.toString(), getTrxName());
pstmt.setInt (1, C_Payment_ID);
rs = pstmt.executeQuery ();
if (rs.next ())
@ -655,7 +655,7 @@ public class Doc_AllocationHdr extends Doc
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
log.log(Level.SEVERE, sql.toString(), e);
}
finally
{
@ -680,10 +680,10 @@ public class Doc_AllocationHdr extends Doc
*/
private MAccount getCashAcct (MAcctSchema as, int C_CashLine_ID)
{
String sql = "SELECT c.C_CashBook_ID "
+ "FROM C_Cash c, C_CashLine cl "
+ "WHERE c.C_Cash_ID=cl.C_Cash_ID AND cl.C_CashLine_ID=?";
setC_CashBook_ID(DB.getSQLValue(null, sql, C_CashLine_ID));
StringBuilder sql = new StringBuilder("SELECT c.C_CashBook_ID ")
.append("FROM C_Cash c, C_CashLine cl ")
.append("WHERE c.C_Cash_ID=cl.C_Cash_ID AND cl.C_CashLine_ID=?");
setC_CashBook_ID(DB.getSQLValue(null, sql.toString(), C_CashLine_ID));
if (getC_CashBook_ID() <= 0)
{
log.log(Level.SEVERE, "NONE for C_CashLine_ID=" + C_CashLine_ID);
@ -711,20 +711,20 @@ public class Doc_AllocationHdr extends Doc
BigDecimal invoiceSource = null;
BigDecimal invoiceAccounted = null;
//
String sql = "SELECT "
+ (invoice.isSOTrx()
StringBuffer sql = new StringBuffer("SELECT ")
.append((invoice.isSOTrx()
? "SUM(AmtSourceDr), SUM(AmtAcctDr)" // so
: "SUM(AmtSourceCr), SUM(AmtAcctCr)") // po
+ " FROM Fact_Acct "
+ "WHERE AD_Table_ID=318 AND Record_ID=?" // Invoice
+ " AND C_AcctSchema_ID=?"
+ " AND PostingType='A'";
: "SUM(AmtSourceCr), SUM(AmtAcctCr)")) // po
.append(" FROM Fact_Acct ")
.append("WHERE AD_Table_ID=318 AND Record_ID=?") // Invoice
.append(" AND C_AcctSchema_ID=?")
.append(" AND PostingType='A'");
//AND C_Currency_ID=102
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, getTrxName());
pstmt = DB.prepareStatement(sql.toString(), getTrxName());
pstmt.setInt(1, invoice.getC_Invoice_ID());
pstmt.setInt(2, as.getC_AcctSchema_ID());
rs = pstmt.executeQuery();
@ -736,7 +736,7 @@ public class Doc_AllocationHdr extends Doc
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
log.log(Level.SEVERE, sql.toString(), e);
}
finally {
DB.close(rs, pstmt);
@ -856,16 +856,16 @@ public class Doc_AllocationHdr extends Doc
DiscountAccount, discount, WriteOffAccoint, writeOff, isSOTrx);
// Get Source Amounts with account
String sql = "SELECT * "
+ "FROM Fact_Acct "
+ "WHERE AD_Table_ID=318 AND Record_ID=?" // Invoice
+ " AND C_AcctSchema_ID=?"
+ " AND Line_ID IS NULL"; // header lines like tax or total
StringBuilder sql = new StringBuilder("SELECT * ")
.append("FROM Fact_Acct ")
.append("WHERE AD_Table_ID=318 AND Record_ID=?") // Invoice
.append(" AND C_AcctSchema_ID=?")
.append(" AND Line_ID IS NULL"); // header lines like tax or total
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, getTrxName());
pstmt = DB.prepareStatement(sql.toString(), getTrxName());
pstmt.setInt(1, line.getC_Invoice_ID());
pstmt.setInt(2, as.getC_AcctSchema_ID());
rs = pstmt.executeQuery();
@ -874,7 +874,7 @@ public class Doc_AllocationHdr extends Doc
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
log.log(Level.SEVERE, sql.toString(), e);
}
finally {
DB.close(rs, pstmt);

View File

@ -99,14 +99,14 @@ public class Doc_Invoice extends Doc
private DocTax[] loadTaxes()
{
ArrayList<DocTax> list = new ArrayList<DocTax>();
String sql = "SELECT it.C_Tax_ID, t.Name, t.Rate, it.TaxBaseAmt, it.TaxAmt, t.IsSalesTax "
+ "FROM C_Tax t, C_InvoiceTax it "
+ "WHERE t.C_Tax_ID=it.C_Tax_ID AND it.C_Invoice_ID=?";
StringBuilder sql = new StringBuilder("SELECT it.C_Tax_ID, t.Name, t.Rate, it.TaxBaseAmt, it.TaxAmt, t.IsSalesTax ")
.append("FROM C_Tax t, C_InvoiceTax it ")
.append("WHERE t.C_Tax_ID=it.C_Tax_ID AND it.C_Invoice_ID=?");
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, getTrxName());
pstmt = DB.prepareStatement(sql.toString(), getTrxName());
pstmt.setInt(1, get_ID());
rs = pstmt.executeQuery();
//
@ -127,7 +127,7 @@ public class Doc_Invoice extends Doc
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
log.log(Level.SEVERE, sql.toString(), e);
return null;
}
finally {
@ -886,13 +886,13 @@ public class Doc_Invoice extends Doc
return;
StringBuffer sql = new StringBuffer (
"UPDATE M_Product_PO po "
+ "SET PriceLastInv = "
"UPDATE M_Product_PO po ")
.append("SET PriceLastInv = ")
// select
+ "(SELECT currencyConvert(il.PriceActual,i.C_Currency_ID,po.C_Currency_ID,i.DateInvoiced,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID) "
+ "FROM C_Invoice i, C_InvoiceLine il "
+ "WHERE i.C_Invoice_ID=il.C_Invoice_ID"
+ " AND po.M_Product_ID=il.M_Product_ID AND po.C_BPartner_ID=i.C_BPartner_ID");
.append("(SELECT currencyConvert(il.PriceActual,i.C_Currency_ID,po.C_Currency_ID,i.DateInvoiced,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID) ")
.append("FROM C_Invoice i, C_InvoiceLine il ")
.append("WHERE i.C_Invoice_ID=il.C_Invoice_ID")
.append(" AND po.M_Product_ID=il.M_Product_ID AND po.C_BPartner_ID=i.C_BPartner_ID");
//jz + " AND ROWNUM=1 AND i.C_Invoice_ID=").append(get_ID()).append(") ")
if (DB.isOracle()) //jz
{

View File

@ -164,17 +164,17 @@ public class Doc_Order extends Doc
}
//
ArrayList<DocLine> list = new ArrayList<DocLine>();
String sql = "SELECT * FROM M_RequisitionLine rl "
+ "WHERE EXISTS (SELECT * FROM C_Order o "
+ " INNER JOIN C_OrderLine ol ON (o.C_Order_ID=ol.C_Order_ID) "
+ "WHERE ol.C_OrderLine_ID=rl.C_OrderLine_ID"
+ " AND o.C_Order_ID=?) "
+ "ORDER BY rl.C_OrderLine_ID";
StringBuilder sql = new StringBuilder("SELECT * FROM M_RequisitionLine rl ")
.append("WHERE EXISTS (SELECT * FROM C_Order o ")
.append(" INNER JOIN C_OrderLine ol ON (o.C_Order_ID=ol.C_Order_ID) ")
.append("WHERE ol.C_OrderLine_ID=rl.C_OrderLine_ID")
.append(" AND o.C_Order_ID=?) ")
.append("ORDER BY rl.C_OrderLine_ID");
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement (sql, null);
pstmt = DB.prepareStatement (sql.toString(), null);
pstmt.setInt (1, order.getC_Order_ID());
rs = pstmt.executeQuery ();
while (rs.next ())
@ -201,7 +201,7 @@ public class Doc_Order extends Doc
}
catch (Exception e)
{
log.log (Level.SEVERE, sql, e);
log.log (Level.SEVERE, sql.toString(), e);
}
finally
{
@ -234,14 +234,14 @@ public class Doc_Order extends Doc
private DocTax[] loadTaxes()
{
ArrayList<DocTax> list = new ArrayList<DocTax>();
String sql = "SELECT it.C_Tax_ID, t.Name, t.Rate, it.TaxBaseAmt, it.TaxAmt, t.IsSalesTax "
+ "FROM C_Tax t, C_OrderTax it "
+ "WHERE t.C_Tax_ID=it.C_Tax_ID AND it.C_Order_ID=?";
StringBuilder sql = new StringBuilder("SELECT it.C_Tax_ID, t.Name, t.Rate, it.TaxBaseAmt, it.TaxAmt, t.IsSalesTax ")
.append("FROM C_Tax t, C_OrderTax it ")
.append("WHERE t.C_Tax_ID=it.C_Tax_ID AND it.C_Order_ID=?");
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, getTrxName());
pstmt = DB.prepareStatement(sql.toString(), getTrxName());
pstmt.setInt(1, get_ID());
rs = pstmt.executeQuery();
//
@ -261,7 +261,7 @@ public class Doc_Order extends Doc
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
log.log(Level.SEVERE, sql.toString(), e);
}
finally {
DB.close(rs, pstmt);
@ -462,21 +462,21 @@ public class Doc_Order extends Doc
return;
StringBuffer sql = new StringBuffer (
"UPDATE M_Product_PO po "
+ "SET PriceLastPO = (SELECT currencyConvert(ol.PriceActual,ol.C_Currency_ID,po.C_Currency_ID,o.DateOrdered,o.C_ConversionType_ID,o.AD_Client_ID,o.AD_Org_ID) "
+ "FROM C_Order o, C_OrderLine ol "
+ "WHERE o.C_Order_ID=ol.C_Order_ID"
+ " AND po.M_Product_ID=ol.M_Product_ID AND po.C_BPartner_ID=o.C_BPartner_ID ");
"UPDATE M_Product_PO po ")
.append("SET PriceLastPO = (SELECT currencyConvert(ol.PriceActual,ol.C_Currency_ID,po.C_Currency_ID,o.DateOrdered,o.C_ConversionType_ID,o.AD_Client_ID,o.AD_Org_ID) ")
.append("FROM C_Order o, C_OrderLine ol ")
.append("WHERE o.C_Order_ID=ol.C_Order_ID")
.append(" AND po.M_Product_ID=ol.M_Product_ID AND po.C_BPartner_ID=o.C_BPartner_ID ");
//jz + " AND ROWNUM=1 AND o.C_Order_ID=").append(get_ID()).append(") ")
if (DB.isOracle()) //jz
{
sql.append(" AND ROWNUM=1 ");
}
else
sql.append(" AND ol.C_OrderLine_ID = (SELECT MIN(ol1.C_OrderLine_ID) "
+ "FROM C_Order o1, C_OrderLine ol1 "
+ "WHERE o1.C_Order_ID=ol1.C_Order_ID"
+ " AND po.M_Product_ID=ol1.M_Product_ID AND po.C_BPartner_ID=o1.C_BPartner_ID")
sql.append(" AND ol.C_OrderLine_ID = (SELECT MIN(ol1.C_OrderLine_ID) ")
.append("FROM C_Order o1, C_OrderLine ol1 ")
.append("WHERE o1.C_Order_ID=ol1.C_Order_ID")
.append(" AND po.M_Product_ID=ol1.M_Product_ID AND po.C_BPartner_ID=o1.C_BPartner_ID")
.append(" AND o1.C_Order_ID=").append(get_ID()).append(") ");
sql.append(" AND o.C_Order_ID=").append(get_ID()).append(") ")
.append("WHERE EXISTS (SELECT * "
@ -501,20 +501,20 @@ public class Doc_Order extends Doc
int precision = -1;
//
ArrayList<DocLine> list = new ArrayList<DocLine>();
String sql = "SELECT * FROM C_OrderLine ol "
+ "WHERE EXISTS "
+ "(SELECT * FROM C_InvoiceLine il "
+ "WHERE il.C_OrderLine_ID=ol.C_OrderLine_ID"
+ " AND il.C_InvoiceLine_ID=?)"
+ " OR EXISTS "
+ "(SELECT * FROM M_MatchPO po "
+ "WHERE po.C_OrderLine_ID=ol.C_OrderLine_ID"
+ " AND po.C_InvoiceLine_ID=?)";
StringBuilder sql = new StringBuilder("SELECT * FROM C_OrderLine ol ")
.append("WHERE EXISTS ")
.append("(SELECT * FROM C_InvoiceLine il ")
.append("WHERE il.C_OrderLine_ID=ol.C_OrderLine_ID")
.append(" AND il.C_InvoiceLine_ID=?)")
.append(" OR EXISTS ")
.append("(SELECT * FROM M_MatchPO po ")
.append("WHERE po.C_OrderLine_ID=ol.C_OrderLine_ID")
.append(" AND po.C_InvoiceLine_ID=?)");
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement (sql, null);
pstmt = DB.prepareStatement (sql.toString(), null);
pstmt.setInt (1, C_InvoiceLine_ID);
pstmt.setInt (2, C_InvoiceLine_ID);
rs = pstmt.executeQuery ();
@ -568,7 +568,7 @@ public class Doc_Order extends Doc
}
catch (Exception e)
{
s_log.log (Level.SEVERE, sql, e);
s_log.log (Level.SEVERE, sql.toString(), e);
}
finally
{
@ -646,16 +646,16 @@ public class Doc_Order extends Doc
int precision = -1;
//
ArrayList<DocLine> list = new ArrayList<DocLine>();
String sql = "SELECT * FROM C_OrderLine ol "
+ "WHERE EXISTS "
+ "(SELECT * FROM M_InOutLine il "
+ "WHERE il.C_OrderLine_ID=ol.C_OrderLine_ID"
+ " AND il.M_InOutLine_ID=?)";
StringBuilder sql = new StringBuilder("SELECT * FROM C_OrderLine ol ")
.append("WHERE EXISTS ")
.append("(SELECT * FROM M_InOutLine il ")
.append("WHERE il.C_OrderLine_ID=ol.C_OrderLine_ID")
.append(" AND il.M_InOutLine_ID=?)");
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement (sql, null);
pstmt = DB.prepareStatement (sql.toString(), null);
pstmt.setInt (1, M_InOutLine_ID);
rs = pstmt.executeQuery ();
while (rs.next ())
@ -708,7 +708,7 @@ public class Doc_Order extends Doc
}
catch (Exception e)
{
s_log.log (Level.SEVERE, sql, e);
s_log.log (Level.SEVERE, sql.toString(), e);
}
finally
{

View File

@ -82,14 +82,14 @@ public class Doc_Production extends Doc
ArrayList<DocLine> list = new ArrayList<DocLine>();
// Production
// -- ProductionLine - the real level
String sqlPL = "SELECT * FROM M_ProductionLine pl "
+ "WHERE pl.M_Production_ID=? "
+ "ORDER BY pl.Line";
StringBuilder sqlPL = new StringBuilder("SELECT * FROM M_ProductionLine pl ")
.append("WHERE pl.M_Production_ID=? ")
.append("ORDER BY pl.Line");
try
{
PreparedStatement pstmtPL = DB.prepareStatement(sqlPL, getTrxName());
PreparedStatement pstmtPL = DB.prepareStatement(sqlPL.toString(), getTrxName());
pstmtPL.setInt(1,get_ID());
ResultSet rsPL = pstmtPL.executeQuery();
while (rsPL.next())
@ -113,7 +113,7 @@ public class Doc_Production extends Doc
}
catch (Exception ee)
{
log.log(Level.SEVERE, sqlPL, ee);
log.log(Level.SEVERE, sqlPL.toString(), ee);
}
DocLine[] dl = new DocLine[list.size()];

View File

@ -168,16 +168,16 @@ public class Doc_ProjectIssue extends Doc
{
BigDecimal retValue = null;
// Uses PO Date
String sql = "SELECT currencyConvert(ol.PriceActual, o.C_Currency_ID, ?, o.DateOrdered, o.C_ConversionType_ID, ?, ?) "
+ "FROM C_OrderLine ol"
+ " INNER JOIN M_InOutLine iol ON (iol.C_OrderLine_ID=ol.C_OrderLine_ID)"
+ " INNER JOIN C_Order o ON (o.C_Order_ID=ol.C_Order_ID) "
+ "WHERE iol.M_InOutLine_ID=?";
StringBuilder sql = new StringBuilder("SELECT currencyConvert(ol.PriceActual, o.C_Currency_ID, ?, o.DateOrdered, o.C_ConversionType_ID, ?, ?) ")
.append("FROM C_OrderLine ol")
.append(" INNER JOIN M_InOutLine iol ON (iol.C_OrderLine_ID=ol.C_OrderLine_ID)")
.append(" INNER JOIN C_Order o ON (o.C_Order_ID=ol.C_Order_ID) ")
.append("WHERE iol.M_InOutLine_ID=?");
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, getTrxName());
pstmt = DB.prepareStatement(sql.toString(), getTrxName());
pstmt.setInt(1, as.getC_Currency_ID());
pstmt.setInt(2, getAD_Client_ID());
pstmt.setInt(3, getAD_Org_ID());
@ -193,7 +193,7 @@ public class Doc_ProjectIssue extends Doc
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
log.log(Level.SEVERE, sql.toString(), e);
}
finally
{
@ -215,8 +215,8 @@ public class Doc_ProjectIssue extends Doc
BigDecimal retValue = Env.ZERO;
BigDecimal qty = Env.ZERO;
String sql = "SELECT ConvertedAmt, Qty FROM S_TimeExpenseLine " +
" WHERE S_TimeExpenseLine.S_TimeExpenseLine_ID = ?";
StringBuilder sql = new StringBuilder("SELECT ConvertedAmt, Qty FROM S_TimeExpenseLine ")
.append(" WHERE S_TimeExpenseLine.S_TimeExpenseLine_ID = ?");
PreparedStatement pstmt = null;
ResultSet rs = null;
try

View File

@ -497,13 +497,13 @@ public final class FactLine extends X_Fact_Acct
if (M_Locator_ID == 0)
return;
int C_Location_ID = 0;
String sql = "SELECT w.C_Location_ID FROM M_Warehouse w, M_Locator l "
+ "WHERE w.M_Warehouse_ID=l.M_Warehouse_ID AND l.M_Locator_ID=?";
StringBuilder sql = new StringBuilder("SELECT w.C_Location_ID FROM M_Warehouse w, M_Locator l ")
.append("WHERE w.M_Warehouse_ID=l.M_Warehouse_ID AND l.M_Locator_ID=?");
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
pstmt.setInt(1, M_Locator_ID);
rs = pstmt.executeQuery();
if (rs.next())
@ -511,7 +511,7 @@ public final class FactLine extends X_Fact_Acct
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
log.log(Level.SEVERE, sql.toString(), e);
return;
}
finally {
@ -994,16 +994,16 @@ public final class FactLine extends X_Fact_Acct
// get Unearned Revenue Acct from BPartner Group
int UnearnedRevenue_Acct = 0;
int new_Account_ID = 0;
String sql = "SELECT ga.UnearnedRevenue_Acct, vc.Account_ID "
+ "FROM C_BP_Group_Acct ga, C_BPartner p, C_ValidCombination vc "
+ "WHERE ga.C_BP_Group_ID=p.C_BP_Group_ID"
+ " AND ga.UnearnedRevenue_Acct=vc.C_ValidCombination_ID"
+ " AND ga.C_AcctSchema_ID=? AND p.C_BPartner_ID=?";
StringBuilder sql = new StringBuilder("SELECT ga.UnearnedRevenue_Acct, vc.Account_ID ")
.append("FROM C_BP_Group_Acct ga, C_BPartner p, C_ValidCombination vc ")
.append("WHERE ga.C_BP_Group_ID=p.C_BP_Group_ID")
.append(" AND ga.UnearnedRevenue_Acct=vc.C_ValidCombination_ID")
.append(" AND ga.C_AcctSchema_ID=? AND p.C_BPartner_ID=?");
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
pstmt.setInt(1, getC_AcctSchema_ID());
pstmt.setInt(2, C_BPartner_ID);
rs = pstmt.executeQuery();
@ -1015,7 +1015,7 @@ public final class FactLine extends X_Fact_Acct
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
log.log(Level.SEVERE, sql.toString(), e);
}
finally {
DB.close(rs, pstmt);
@ -1061,20 +1061,20 @@ public final class FactLine extends X_Fact_Acct
{
boolean success = false;
String sql = "SELECT * "
+ "FROM Fact_Acct "
+ "WHERE C_AcctSchema_ID=? AND AD_Table_ID=? AND Record_ID=?"
+ " AND Line_ID=? AND Account_ID=?";
StringBuffer sql = new StringBuffer("SELECT * ")
.append("FROM Fact_Acct ")
.append("WHERE C_AcctSchema_ID=? AND AD_Table_ID=? AND Record_ID=?")
.append(" AND Line_ID=? AND Account_ID=?");
// MZ Goodwill
// for Inventory Move
if (MMovement.Table_ID == AD_Table_ID)
sql += " AND M_Locator_ID=?";
sql.append(" AND M_Locator_ID=?");
// end MZ
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
pstmt.setInt(1, getC_AcctSchema_ID());
pstmt.setInt(2, AD_Table_ID);
pstmt.setInt(3, Record_ID);
@ -1141,7 +1141,7 @@ public final class FactLine extends X_Fact_Acct
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
log.log(Level.SEVERE, sql.toString(), e);
}
finally {
DB.close(rs, pstmt);

View File

@ -80,23 +80,23 @@ public class Matcher
{
int counter = 0;
// (a) Direct Matches
String sql = "SELECT m1.AD_Client_ID,m2.AD_Org_ID, " // 1..2
+ "m1.C_InvoiceLine_ID,m2.M_InOutLine_ID,m1.M_Product_ID, " // 3..5
+ "m1.DateTrx,m2.DateTrx, m1.Qty, m2.Qty " // 6..9
+ "FROM M_MatchPO m1, M_MatchPO m2 "
+ "WHERE m1.C_OrderLine_ID=m2.C_OrderLine_ID"
+ " AND m1.M_InOutLine_ID IS NULL"
+ " AND m2.C_InvoiceLine_ID IS NULL"
+ " AND m1.M_Product_ID=m2.M_Product_ID"
+ " AND m1.AD_Client_ID=?" // #1
StringBuilder sql = new StringBuilder("SELECT m1.AD_Client_ID,m2.AD_Org_ID, ") // 1..2
.append("m1.C_InvoiceLine_ID,m2.M_InOutLine_ID,m1.M_Product_ID, ") // 3..5
.append("m1.DateTrx,m2.DateTrx, m1.Qty, m2.Qty ") // 6..9
.append("FROM M_MatchPO m1, M_MatchPO m2 ")
.append("WHERE m1.C_OrderLine_ID=m2.C_OrderLine_ID")
.append(" AND m1.M_InOutLine_ID IS NULL")
.append(" AND m2.C_InvoiceLine_ID IS NULL")
.append(" AND m1.M_Product_ID=m2.M_Product_ID")
.append(" AND m1.AD_Client_ID=?") // #1
// Not existing Inv Matches
+ " AND NOT EXISTS (SELECT * FROM M_MatchInv mi "
+ "WHERE mi.C_InvoiceLine_ID=m1.C_InvoiceLine_ID AND mi.M_InOutLine_ID=m2.M_InOutLine_ID)";
.append(" AND NOT EXISTS (SELECT * FROM M_MatchInv mi ")
.append("WHERE mi.C_InvoiceLine_ID=m1.C_InvoiceLine_ID AND mi.M_InOutLine_ID=m2.M_InOutLine_ID)");
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, m_AD_Client_ID);
rs = pstmt.executeQuery();
while (rs.next())

View File

@ -83,18 +83,18 @@ public class ProductInfo
if (m_M_Product_ID == 0)
return;
String sql = "SELECT p.ProductType, pc.Value, " // 1..2
+ "p.C_RevenueRecognition_ID,p.C_UOM_ID, " // 3..4
+ "p.AD_Client_ID,p.AD_Org_ID, " // 5..6
+ "p.IsBOM, p.IsStocked " // 7..8
+ "FROM M_Product_Category pc"
+ " INNER JOIN M_Product p ON (pc.M_Product_Category_ID=p.M_Product_Category_ID) "
+ "WHERE p.M_Product_ID=?"; // #1
StringBuilder sql = new StringBuilder("SELECT p.ProductType, pc.Value, ") // 1..2
.append("p.C_RevenueRecognition_ID,p.C_UOM_ID, ") // 3..4
.append("p.AD_Client_ID,p.AD_Org_ID, ") // 5..6
.append("p.IsBOM, p.IsStocked ") // 7..8
.append("FROM M_Product_Category pc")
.append(" INNER JOIN M_Product p ON (pc.M_Product_Category_ID=p.M_Product_Category_ID) ")
.append("WHERE p.M_Product_ID=?"); // #1
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, m_M_Product_ID);
rs = pstmt.executeQuery();
if (rs.next())
@ -113,7 +113,7 @@ public class ProductInfo
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
log.log(Level.SEVERE, sql.toString(), e);
}
finally {
DB.close(rs, pstmt);
@ -296,9 +296,9 @@ public class ProductInfo
*/
private BigDecimal getPOCost (MAcctSchema as)
{
String sql = "SELECT C_Currency_ID, PriceList,PricePO,PriceLastPO "
+ "FROM M_Product_PO WHERE M_Product_ID=? "
+ "ORDER BY IsCurrentVendor DESC";
StringBuilder sql = new StringBuilder("SELECT C_Currency_ID, PriceList,PricePO,PriceLastPO ")
.append("FROM M_Product_PO WHERE M_Product_ID=? ")
.append("ORDER BY IsCurrentVendor DESC");
int C_Currency_ID = 0;
BigDecimal PriceList = null;
@ -308,7 +308,7 @@ public class ProductInfo
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, m_M_Product_ID);
rs = pstmt.executeQuery();
if (rs.next())
@ -321,7 +321,7 @@ public class ProductInfo
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
log.log(Level.SEVERE, sql.toString(), e);
}
finally {
DB.close(rs, pstmt);

View File

@ -115,12 +115,12 @@ public final class ImpFormat
m_AD_Table_ID = AD_Table_ID;
m_tableName = null;
m_tablePK = null;
String sql = "SELECT t.TableName,c.ColumnName "
+ "FROM AD_Table t INNER JOIN AD_Column c ON (t.AD_Table_ID=c.AD_Table_ID AND c.IsKey='Y') "
+ "WHERE t.AD_Table_ID=?";
StringBuilder sql = new StringBuilder("SELECT t.TableName,c.ColumnName ")
.append("FROM AD_Table t INNER JOIN AD_Column c ON (t.AD_Table_ID=c.AD_Table_ID AND c.IsKey='Y') ")
.append("WHERE t.AD_Table_ID=?");
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, AD_Table_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
@ -301,14 +301,14 @@ public final class ImpFormat
*/
private static void loadRows (ImpFormat format, int ID)
{
String sql = "SELECT f.SeqNo,c.ColumnName,f.StartNo,f.EndNo,f.DataType,c.FieldLength," // 1..6
+ "f.DataFormat,f.DecimalPoint,f.DivideBy100,f.ConstantValue,f.Callout " // 7..11
+ "FROM AD_ImpFormat_Row f,AD_Column c "
+ "WHERE f.AD_ImpFormat_ID=? AND f.AD_Column_ID=c.AD_Column_ID AND f.IsActive='Y'"
+ "ORDER BY f.SeqNo";
StringBuilder sql = new StringBuilder("SELECT f.SeqNo,c.ColumnName,f.StartNo,f.EndNo,f.DataType,c.FieldLength,") // 1..6
.append("f.DataFormat,f.DecimalPoint,f.DivideBy100,f.ConstantValue,f.Callout ") // 7..11
.append("FROM AD_ImpFormat_Row f,AD_Column c ")
.append("WHERE f.AD_ImpFormat_ID=? AND f.AD_Column_ID=c.AD_Column_ID AND f.IsActive='Y'")
.append("ORDER BY f.SeqNo");
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt (1, ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
@ -327,7 +327,7 @@ public final class ImpFormat
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
log.log(Level.SEVERE, sql.toString(), e);
}
} // loadLines

View File

@ -69,13 +69,13 @@ public class MImpFormat extends X_AD_ImpFormat
public MImpFormatRow[] getRows()
{
ArrayList<MImpFormatRow> list = new ArrayList<MImpFormatRow>();
String sql = "SELECT * FROM AD_ImpFormat_Row "
+ "WHERE AD_ImpFormat_ID=? "
+ "ORDER BY SeqNo";
StringBuilder sql = new StringBuilder("SELECT * FROM AD_ImpFormat_Row ")
.append("WHERE AD_ImpFormat_ID=? ")
.append("ORDER BY SeqNo");
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, get_TrxName());
pstmt = DB.prepareStatement (sql.toString(), get_TrxName());
pstmt.setInt (1, getAD_ImpFormat_ID());
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())

View File

@ -57,13 +57,15 @@ public class GridFieldVO implements Serializable
public static String getSQL (Properties ctx)
{
// IsActive is part of View
String sql = "SELECT * FROM AD_Field_v WHERE AD_Tab_ID=?"
+ " ORDER BY IsDisplayed DESC, SeqNo";
StringBuffer sql;
if (!Env.isBaseLanguage(ctx, "AD_Tab"))
sql = "SELECT * FROM AD_Field_vt WHERE AD_Tab_ID=?"
+ " AND AD_Language='" + Env.getAD_Language(ctx) + "'"
+ " ORDER BY IsDisplayed DESC, SeqNo";
return sql;
sql = new StringBuffer("SELECT * FROM AD_Field_vt WHERE AD_Tab_ID=?")
.append(" AND AD_Language='" + Env.getAD_Language(ctx) + "'")
.append(" ORDER BY IsDisplayed DESC, SeqNo");
else
sql = new StringBuffer("SELECT * FROM AD_Field_v WHERE AD_Tab_ID=?")
.append(" ORDER BY IsDisplayed DESC, SeqNo");
return sql.toString();
} // getSQL
public String InfoFactoryClass = null;

View File

@ -559,18 +559,18 @@ public class GridWindow implements Serializable
{
if (recalc || m_modelUpdated == null)
{
String sql = "SELECT MAX(w.Updated), MAX(t.Updated), MAX(tt.Updated), MAX(f.Updated), MAX(c.Updated) "
+ "FROM AD_Window w"
+ " INNER JOIN AD_Tab t ON (w.AD_Window_ID=t.AD_Window_ID)"
+ " INNER JOIN AD_Table tt ON (t.AD_Table_ID=tt.AD_Table_ID)"
+ " INNER JOIN AD_Field f ON (t.AD_Tab_ID=f.AD_Tab_ID)"
+ " INNER JOIN AD_Column c ON (f.AD_Column_ID=c.AD_Column_ID) "
+ "WHERE w.AD_Window_ID=?";
StringBuilder sql = new StringBuilder("SELECT MAX(w.Updated), MAX(t.Updated), MAX(tt.Updated), MAX(f.Updated), MAX(c.Updated) ")
.append("FROM AD_Window w")
.append(" INNER JOIN AD_Tab t ON (w.AD_Window_ID=t.AD_Window_ID)")
.append(" INNER JOIN AD_Table tt ON (t.AD_Table_ID=tt.AD_Table_ID)")
.append(" INNER JOIN AD_Field f ON (t.AD_Tab_ID=f.AD_Tab_ID)")
.append(" INNER JOIN AD_Column c ON (f.AD_Column_ID=c.AD_Column_ID) ")
.append("WHERE w.AD_Window_ID=?");
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement (sql, null);
pstmt = DB.prepareStatement (sql.toString(), null);
pstmt.setInt (1, getAD_Window_ID());
rs = pstmt.executeQuery ();
if (rs.next ())
@ -592,7 +592,7 @@ public class GridWindow implements Serializable
}
catch (Exception e)
{
log.log (Level.SEVERE, sql, e);
log.log (Level.SEVERE, sql.toString(), e);
}
finally
{

View File

@ -77,21 +77,21 @@ public class CalloutUser extends CalloutEngine
if (C_BPartner_ID == null || C_BPartner_ID.intValue() == 0)
return "";
String sql = "SELECT p.AD_Language,p.C_PaymentTerm_ID,"
+ " COALESCE(p.M_PriceList_ID,g.M_PriceList_ID) AS M_PriceList_ID, p.PaymentRule,p.POReference,"
+ " p.SO_Description,p.IsDiscountPrinted,"
+ " p.SO_CreditLimit, p.SO_CreditLimit-p.SO_CreditUsed AS CreditAvailable,"
+ " l.C_BPartner_Location_ID,c.AD_User_ID,"
+ " COALESCE(p.PO_PriceList_ID,g.PO_PriceList_ID) AS PO_PriceList_ID, p.PaymentRulePO,p.PO_PaymentTerm_ID "
+ "FROM C_BPartner p"
+ " INNER JOIN C_BP_Group g ON (p.C_BP_Group_ID=g.C_BP_Group_ID)"
+ " LEFT OUTER JOIN C_BPartner_Location l ON (p.C_BPartner_ID=l.C_BPartner_ID AND l.IsBillTo='Y' AND l.IsActive='Y')"
+ " LEFT OUTER JOIN AD_User c ON (p.C_BPartner_ID=c.C_BPartner_ID) "
+ "WHERE p.C_BPartner_ID=? AND p.IsActive='Y'"; // #1
StringBuilder sql = new StringBuilder("SELECT p.AD_Language,p.C_PaymentTerm_ID,")
.append (" COALESCE(p.M_PriceList_ID,g.M_PriceList_ID) AS M_PriceList_ID, p.PaymentRule,p.POReference,")
.append (" p.SO_Description,p.IsDiscountPrinted,")
.append (" p.SO_CreditLimit, p.SO_CreditLimit-p.SO_CreditUsed AS CreditAvailable,")
.append (" l.C_BPartner_Location_ID,c.AD_User_ID,")
.append (" COALESCE(p.PO_PriceList_ID,g.PO_PriceList_ID) AS PO_PriceList_ID, p.PaymentRulePO,p.PO_PaymentTerm_ID ")
.append ("FROM C_BPartner p")
.append (" INNER JOIN C_BP_Group g ON (p.C_BP_Group_ID=g.C_BP_Group_ID)")
.append (" LEFT OUTER JOIN C_BPartner_Location l ON (p.C_BPartner_ID=l.C_BPartner_ID AND l.IsBillTo='Y' AND l.IsActive='Y')")
.append (" LEFT OUTER JOIN AD_User c ON (p.C_BPartner_ID=c.C_BPartner_ID) ")
.append ("WHERE p.C_BPartner_ID=? AND p.IsActive='Y'"); // #1
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, C_BPartner_ID.intValue());
ResultSet rs = pstmt.executeQuery();
//
@ -130,7 +130,7 @@ public class CalloutUser extends CalloutEngine
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
log.log(Level.SEVERE, sql.toString(), e);
return e.getLocalizedMessage();
}