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

Compiled and run server. Alert processor works on new alert record. Not sure if any other tests for this MAlert class.
Anyone please review
This commit is contained in:
Redhuan D. Oon 2008-11-03 14:50:31 +00:00
parent 4cb8bb0064
commit 28440a550c
1 changed files with 11 additions and 55 deletions

View File

@ -16,15 +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.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.logging.Level;
import org.compiere.util.DB;
/** /**
* Alert Model * Alert Model
@ -34,6 +30,8 @@ import org.compiere.util.DB;
* *
* @author Teo Sarca, SC ARHIPAC SERVICE SRL * @author Teo Sarca, SC ARHIPAC SERVICE SRL
* <li>FR [ 1894573 ] Alert Processor Improvements * <li>FR [ 1894573 ] Alert Processor Improvements
* Victor Perez, Trifon, red1
* <li>FR: [ 2214883 ] Remove SQL code and Replace for Query
*/ */
public class MAlert extends X_AD_Alert public class MAlert extends X_AD_Alert
{ {
@ -84,34 +82,10 @@ public class MAlert extends X_AD_Alert
{ {
if (m_rules != null && !reload) if (m_rules != null && !reload)
return m_rules; return m_rules;
String sql = "SELECT * FROM AD_AlertRule " //FR: [ 2214883 ] Remove SQL code and Replace for Query - red1
+ "WHERE AD_Alert_ID=?" String whereClause = "AD_Alert_ID=?";
+ " ORDER BY Name, AD_AlertRule_ID"; List <MAchievement> list = new Query(getCtx(),MBPartner.Table_Name,whereClause.toString(),null)
ArrayList<MAlertRule> list = new ArrayList<MAlertRule>(); .setParameters(new Object[]{getAD_Alert_ID()}).setOrderBy("Name, AD_AlertRule_ID").list();
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, getAD_Alert_ID());
rs = pstmt.executeQuery ();
while (rs.next ())
{
MAlertRule rule = new MAlertRule (getCtx(), rs, null);
rule.setParent(this);
list.add (rule);
}
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// //
m_rules = new MAlertRule[list.size ()]; m_rules = new MAlertRule[list.size ()];
list.toArray (m_rules); list.toArray (m_rules);
@ -127,28 +101,10 @@ public class MAlert extends X_AD_Alert
{ {
if (m_recipients != null && !reload) if (m_recipients != null && !reload)
return m_recipients; return m_recipients;
String sql = "SELECT * FROM AD_AlertRecipient " //FR: [ 2214883 ] Remove SQL code and Replace for Query - red1
+ "WHERE AD_Alert_ID=?"; String whereClause = "AD_Alert_ID=?";
ArrayList<MAlertRecipient> list = new ArrayList<MAlertRecipient>(); List <MAlertRecipient> list = new Query(getCtx(),MBPartner.Table_Name,whereClause.toString(),null)
PreparedStatement pstmt = null; .setParameters(new Object[]{getAD_Alert_ID()}).list();
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, getAD_Alert_ID());
rs = pstmt.executeQuery ();
while (rs.next ())
list.add (new MAlertRecipient (getCtx(), rs, null));
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// //
m_recipients = new MAlertRecipient[list.size ()]; m_recipients = new MAlertRecipient[list.size ()];
list.toArray (m_recipients); list.toArray (m_recipients);