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

-- JUnit test in next commit (no failures)
Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2214883
This commit is contained in:
Redhuan D. Oon 2010-02-27 14:05:19 +00:00
parent 9aa3c31c35
commit bb3a54da57
1 changed files with 16 additions and 69 deletions

View File

@ -16,12 +16,10 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
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.util.CCache; import org.compiere.util.CCache;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
@ -50,26 +48,9 @@ public class MAlertProcessor extends X_AD_AlertProcessor
*/ */
public static MAlertProcessor[] getActive (Properties ctx) public static MAlertProcessor[] getActive (Properties ctx)
{ {
ArrayList<MAlertProcessor> list = new ArrayList<MAlertProcessor>(); List <MAlertProcessor> list = new Query(ctx,I_AD_AlertProcessor.Table_Name, null, null)
String sql = "SELECT * FROM AD_AlertProcessor WHERE IsActive='Y'"; .setOnlyActiveRecords(true)
PreparedStatement pstmt = null; .list();
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement (sql, null);
rs = pstmt.executeQuery ();
while (rs.next ())
list.add (new MAlertProcessor (ctx, rs, null));
}
catch (Exception e)
{
s_log.log(Level.SEVERE, sql, e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
MAlertProcessor[] retValue = new MAlertProcessor[list.size ()]; MAlertProcessor[] retValue = new MAlertProcessor[list.size ()];
list.toArray (retValue); list.toArray (retValue);
return retValue; return retValue;
@ -131,30 +112,11 @@ public class MAlertProcessor extends X_AD_AlertProcessor
*/ */
public AdempiereProcessorLog[] getLogs () public AdempiereProcessorLog[] getLogs ()
{ {
ArrayList<MAlertProcessorLog> list = new ArrayList<MAlertProcessorLog>(); final String whereClause ="AD_AlertProcessor_ID=?";
String sql = "SELECT * " List <MAlertProcessorLog> list = new Query(getCtx(), I_AD_AlertProcessorLog.Table_Name, whereClause, null)
+ "FROM AD_AlertProcessorLog " .setParameters(getAD_AlertProcessor_ID())
+ "WHERE AD_AlertProcessor_ID=? " .setOrderBy("Created DESC")
+ "ORDER BY Created DESC"; .list();
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, getAD_AlertProcessor_ID());
rs = pstmt.executeQuery ();
while (rs.next ())
list.add (new MAlertProcessorLog (getCtx(), rs, null));
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
MAlertProcessorLog[] retValue = new MAlertProcessorLog[list.size ()]; MAlertProcessorLog[] retValue = new MAlertProcessorLog[list.size ()];
list.toArray (retValue); list.toArray (retValue);
return retValue; return retValue;
@ -186,28 +148,13 @@ public class MAlertProcessor extends X_AD_AlertProcessor
MAlert[] alerts = s_cacheAlerts.get(get_ID()); MAlert[] alerts = s_cacheAlerts.get(get_ID());
if (alerts != null && !reload) if (alerts != null && !reload)
return alerts; return alerts;
String sql = "SELECT * FROM AD_Alert "
+ "WHERE AD_AlertProcessor_ID=? AND IsActive='Y' "; final String whereClause ="AD_AlertProcessor_ID=?";
ArrayList<MAlert> list = new ArrayList<MAlert>(); List <MAlert> list = new Query(getCtx(), I_AD_Alert.Table_Name, whereClause, null)
PreparedStatement pstmt = null; .setParameters(getAD_AlertProcessor_ID())
ResultSet rs = null; .setOnlyActiveRecords(true)
try .list();
{
pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, getAD_AlertProcessor_ID());
rs = pstmt.executeQuery ();
while (rs.next ())
list.add (new MAlert (getCtx(), rs, null));
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// //
alerts = new MAlert[list.size ()]; alerts = new MAlert[list.size ()];
list.toArray (alerts); list.toArray (alerts);