Red1, please review them.
This commit is contained in:
teo_sarca 2009-07-13 08:18:52 +00:00
parent 89be929138
commit 23adb686f4
2 changed files with 34 additions and 85 deletions

View File

@ -16,14 +16,11 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
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 org.compiere.util.CLogger;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Msg; import org.compiere.util.Msg;
@ -32,7 +29,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 * FR: [ 2214883 ] Remove SQL code and Replace for Query - red1, teo_sarca
*/ */
public class M_Element extends X_AD_Element public class M_Element extends X_AD_Element
{ {
@ -52,31 +49,26 @@ public class M_Element extends X_AD_Element
} }
/** /**
* Get case sensitive Column Name * Get case sensitive Column Name
* @param columnName case insentitive column name * @param columnName case insensitive column name
* @param trxName optional transaction name * @param trxName optional transaction name
* @return case sensitive column name * @return case sensitive column name
*/ */
public static String getColumnName (String columnName, String trxName) public static String getColumnName (String columnName, String trxName)
{ {
if (columnName == null || columnName.length() == 0) if (columnName == null || columnName.length() == 0)
return columnName; return columnName;
//FR: [ 2214883 ] Remove SQL code and Replace for Query - red1 M_Element element = get(Env.getCtx(), columnName, trxName);
String whereClause = "UPPER(ColumnName)=?"; if (element == null)
List <M_Element> list = new Query(null, M_Element.Table_Name, whereClause, trxName) return columnName;
.setParameters(new Object[]{columnName.toUpperCase()}) return element.getColumnName();
.list(); //to detect > 1 condition
if (list.size() > 1)
s_log.warning("Not unique: " + columnName + " -> " + list.size() + " of same columnName");
M_Element retValue = list.get(0); //red1 - now getting the first only occurrence
return retValue.toString();
} // getColumnName } // getColumnName
/** /**
* Get Element * Get Element
* @param ctx context * @param ctx context
* @param columnName case insentitive column name * @param columnName case insensitive column name
* @return case sensitive column name * @return case sensitive column name
*/ */
public static M_Element get (Properties ctx, String columnName) public static M_Element get (Properties ctx, String columnName)
@ -87,40 +79,20 @@ public class M_Element extends X_AD_Element
/** /**
* Get Element * Get Element
* @param ctx context * @param ctx context
* @param columnName case insentitive column name * @param columnName case insensitive column name
* @param trxName optional transaction name * @param trxName optional transaction name
* @return case sensitive column name * @return case sensitive column name
*/ */
public static M_Element get (Properties ctx, String columnName, String trxName) public static M_Element get (Properties ctx, String columnName, String trxName)
{ {
if (columnName == null || columnName.length() == 0) if (columnName == null || columnName.length() == 0)
return null; return null;
M_Element retValue = null; //
String sql = "SELECT * FROM AD_Element WHERE UPPER(ColumnName)=?"; // TODO: caching if trxName == null
PreparedStatement pstmt = null; final String whereClause = "UPPER(ColumnName)=?";
ResultSet rs = null; M_Element retValue = new Query(ctx, M_Element.Table_Name, whereClause, trxName)
try .setParameters(new Object[]{columnName.toUpperCase()})
{ .firstOnly();
pstmt = DB.prepareStatement (sql, trxName);
pstmt.setString (1, columnName.toUpperCase());
rs = pstmt.executeQuery ();
if (rs.next ())
{
retValue = new M_Element (ctx, rs, trxName);
if (rs.next())
s_log.warning("Not unique: " + columnName
+ " -> " + retValue + " - " + rs.getString("ColumnName"));
}
}
catch (Exception e)
{
s_log.log (Level.SEVERE, sql, e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return retValue; return retValue;
} // get } // get
@ -136,30 +108,11 @@ public class M_Element extends X_AD_Element
{ {
if (AD_Column_ID ==0) if (AD_Column_ID ==0)
return null; return null;
M_Element retValue = null; String whereClause = "EXISTS (SELECT 1 FROM AD_Column c "
String sql = "SELECT * FROM AD_Element e " + "WHERE c.AD_Element_ID=AD_Element.AD_Element_ID AND c.AD_Column_ID=?)";
+ "WHERE EXISTS (SELECT * FROM AD_Column c " M_Element retValue = new Query(ctx, Table_Name, whereClause, trxName)
+ "WHERE c.AD_Element_ID=e.AD_Element_ID AND c.AD_Column_ID=?)"; .setParameters(new Object[]{AD_Column_ID})
PreparedStatement pstmt = null; .firstOnly();
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement (sql, trxName);
pstmt.setInt (1, AD_Column_ID);
rs = pstmt.executeQuery ();
if (rs.next ())
retValue = new M_Element (ctx, rs, trxName);
}
catch (Exception e)
{
s_log.log (Level.SEVERE, sql, e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return retValue; return retValue;
} // get } // get
@ -174,9 +127,6 @@ public class M_Element extends X_AD_Element
return getOfColumn(ctx, AD_Column_ID, null); return getOfColumn(ctx, AD_Column_ID, null);
} // get } // get
/** Logger */
private static CLogger s_log = CLogger.getCLogger (M_Element.class);
/************************************************************************** /**************************************************************************
* Standard Constructor * Standard Constructor
* @param ctx context * @param ctx context

View File

@ -17,9 +17,7 @@
package org.compiere.process; package org.compiere.process;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.PreparedStatement; import java.util.Iterator;
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;
@ -27,7 +25,6 @@ import org.compiere.model.MInvoice;
import org.compiere.model.MPayment; import org.compiere.model.MPayment;
import org.compiere.model.Query; import org.compiere.model.Query;
import org.compiere.util.AdempiereUserError; import org.compiere.util.AdempiereUserError;
import org.compiere.util.DB;
import org.compiere.util.Msg; import org.compiere.util.Msg;
@ -36,7 +33,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 * FR: [ 2214883 ] Remove SQL code and Replace for Query - red1, teo_sarca
*/ */
public class BPartnerValidate extends SvrProcess public class BPartnerValidate extends SvrProcess
{ {
@ -86,13 +83,15 @@ public class BPartnerValidate extends SvrProcess
} }
else else
{ {
//FR: [ 2214883 ] Remove SQL code and Replace for Query
String whereClause = "C_BP_Group_ID=?"; String whereClause = "C_BP_Group_ID=?";
List <MBPartner> list = new Query(getCtx(), MBPartner.Table_Name, whereClause, get_TrxName()) Iterator<MBPartner> it = new Query(getCtx(), MBPartner.Table_Name, whereClause, get_TrxName())
.setParameters(new Object[]{p_C_BP_Group_ID}) .setParameters(new Object[]{p_C_BP_Group_ID})
.setOnlyActiveRecords(true) .setOnlyActiveRecords(true)
.list(); .iterate();
//FR: [ 2214883 ] Remove SQL code and Replace for Query while(it.hasNext())
{
checkBP(it.next());
}
} }
// //
return "OK"; return "OK";
@ -111,7 +110,7 @@ public class BPartnerValidate extends SvrProcess
// //
bp.setTotalOpenBalance(); bp.setTotalOpenBalance();
bp.setActualLifeTimeValue(); bp.setActualLifeTimeValue();
bp.save(); bp.saveEx();
// //
// if (bp.getSO_CreditUsed().signum() != 0) // if (bp.getSO_CreditUsed().signum() != 0)
addLog(0, null, bp.getSO_CreditUsed(), Msg.getElement(getCtx(), "SO_CreditUsed")); addLog(0, null, bp.getSO_CreditUsed(), Msg.getElement(getCtx(), "SO_CreditUsed"));