FR: [ 2214883 ] Remove SQL code and Replace for Query

-- hi, i am starting to slowly go thru the codes to do the above. any comments or advice?
This commit is contained in:
Redhuan D. Oon 2009-07-12 23:45:22 +00:00
parent c19a5a7915
commit 30616a0000
3 changed files with 32 additions and 83 deletions

View File

@ -18,6 +18,7 @@ package org.compiere.model;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
@ -31,6 +32,7 @@ import org.compiere.util.Msg;
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: M_Element.java,v 1.3 2006/07/30 00:58:37 jjanke Exp $ * @version $Id: M_Element.java,v 1.3 2006/07/30 00:58:37 jjanke Exp $
* FR: [ 2214883 ] Remove SQL code and Replace for Query - red1
*/ */
public class M_Element extends X_AD_Element public class M_Element extends X_AD_Element
{ {
@ -59,36 +61,16 @@ public class M_Element extends X_AD_Element
{ {
if (columnName == null || columnName.length() == 0) if (columnName == null || columnName.length() == 0)
return columnName; return columnName;
String retValue = columnName; //FR: [ 2214883 ] Remove SQL code and Replace for Query - red1
String sql = "SELECT ColumnName FROM AD_Element WHERE UPPER(ColumnName)=?"; String whereClause = "UPPER(ColumnName)=?";
PreparedStatement pstmt = null; List <M_Element> list = new Query(null, M_Element.Table_Name, whereClause, trxName)
ResultSet rs = null; .setParameters(new Object[]{columnName.toUpperCase()})
try .list(); //to detect > 1 condition
{ if (list.size() > 1)
pstmt = DB.prepareStatement (sql, trxName); s_log.warning("Not unique: " + columnName + " -> " + list.size() + " of same columnName");
pstmt.setString (1, columnName.toUpperCase()); M_Element retValue = list.get(0); //red1 - now getting the first only occurrence
rs = pstmt.executeQuery (); return retValue.toString();
if (rs.next ())
{
retValue = rs.getString(1);
if (rs.next())
s_log.warning("Not unique: " + columnName
+ " -> " + retValue + " - " + rs.getString(1));
}
else
s_log.warning("No found: " + columnName);
}
catch (Exception e)
{
s_log.log (Level.SEVERE, columnName, e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return retValue;
} // getColumnName } // getColumnName
/** /**

View File

@ -19,11 +19,13 @@ package org.compiere.process;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import org.compiere.model.MBPartner; import org.compiere.model.MBPartner;
import org.compiere.model.MInvoice; import org.compiere.model.MInvoice;
import org.compiere.model.MPayment; import org.compiere.model.MPayment;
import org.compiere.model.Query;
import org.compiere.util.AdempiereUserError; import org.compiere.util.AdempiereUserError;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.Msg; import org.compiere.util.Msg;
@ -34,6 +36,7 @@ import org.compiere.util.Msg;
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: BPartnerValidate.java,v 1.2 2006/07/30 00:51:02 jjanke Exp $ * @version $Id: BPartnerValidate.java,v 1.2 2006/07/30 00:51:02 jjanke Exp $
* FR: [ 2214883 ] Remove SQL code and Replace for Query - red1
*/ */
public class BPartnerValidate extends SvrProcess public class BPartnerValidate extends SvrProcess
{ {
@ -83,29 +86,13 @@ public class BPartnerValidate extends SvrProcess
} }
else else
{ {
String sql = "SELECT * FROM C_BPartner WHERE C_BP_Group_ID=? AND IsActive='Y'"; //FR: [ 2214883 ] Remove SQL code and Replace for Query
PreparedStatement pstmt = null; String whereClause = "C_BP_Group_ID=?";
ResultSet rs = null; List <MBPartner> list = new Query(getCtx(), MBPartner.Table_Name, whereClause, get_TrxName())
try .setParameters(new Object[]{p_C_BP_Group_ID})
{ .setOnlyActiveRecords(true)
pstmt = DB.prepareStatement (sql, get_TrxName()); .list();
pstmt.setInt (1, p_C_BP_Group_ID); //FR: [ 2214883 ] Remove SQL code and Replace for Query
rs = pstmt.executeQuery ();
while (rs.next ())
{
MBPartner bp = new MBPartner (getCtx(), rs, get_TrxName());
checkBP (bp);
}
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
} }
// //
return "OK"; return "OK";

View File

@ -21,6 +21,7 @@ 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.ArrayList;
import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import org.compiere.model.MAccount; import org.compiere.model.MAccount;
@ -34,6 +35,7 @@ import org.compiere.model.MJournal;
import org.compiere.model.MJournalBatch; import org.compiere.model.MJournalBatch;
import org.compiere.model.MJournalLine; import org.compiere.model.MJournalLine;
import org.compiere.model.MOrg; import org.compiere.model.MOrg;
import org.compiere.model.Query;
import org.compiere.model.X_T_InvoiceGL; import org.compiere.model.X_T_InvoiceGL;
import org.compiere.util.CLogMgt; import org.compiere.util.CLogMgt;
import org.compiere.util.DB; import org.compiere.util.DB;
@ -45,6 +47,7 @@ import org.compiere.util.Msg;
* The actual data shown is T_InvoiceGL_v * The actual data shown is T_InvoiceGL_v
* @author Jorg Janke * @author Jorg Janke
* @version $Id: InvoiceNGL.java,v 1.3 2006/08/04 03:53:59 jjanke Exp $ * @version $Id: InvoiceNGL.java,v 1.3 2006/08/04 03:53:59 jjanke Exp $
* FR: [ 2214883 ] Remove SQL code and Replace for Query - red1
*/ */
public class InvoiceNGL extends SvrProcess public class InvoiceNGL extends SvrProcess
{ {
@ -216,37 +219,14 @@ public class InvoiceNGL extends SvrProcess
*/ */
private String createGLJournal() private String createGLJournal()
{ {
ArrayList<X_T_InvoiceGL> list = new ArrayList<X_T_InvoiceGL>(); //FR: [ 2214883 ] Remove SQL code and Replace for Query
String sql = "SELECT * FROM T_InvoiceGL " String whereClause = "AD_PInstance_ID=?";
+ "WHERE AD_PInstance_ID=" + getAD_PInstance_ID() List <X_T_InvoiceGL> list = new Query(getCtx(), X_T_InvoiceGL.Table_Name, whereClause, get_TrxName())
+ " ORDER BY AD_Org_ID"; .setParameters(new Object[]{getAD_PInstance_ID()})
PreparedStatement pstmt = null; .setOrderBy("AD_Org_ID")
try .list();
{ //FR: [ 2214883 ] Remove SQL code and Replace for Query
pstmt = DB.prepareStatement (sql, get_TrxName());
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())
{
list.add (new X_T_InvoiceGL (getCtx(), rs, get_TrxName()));
}
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
log.log (Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
if (list.size() == 0) if (list.size() == 0)
return " - No Records found"; return " - No Records found";