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

-- JUnit test pending
Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2214883
This commit is contained in:
Redhuan D. Oon 2010-03-07 16:25:43 +00:00
parent f95f2f2f6d
commit 14046997c8
3 changed files with 19 additions and 120 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.ArrayList; 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.CLogger;
import org.compiere.util.DB;
/** /**
* BP Bank Account Model * BP Bank Account Model
@ -47,34 +44,11 @@ public class MBPBankAccount extends X_C_BP_BankAccount
*/ */
public static MBPBankAccount[] getOfBPartner (Properties ctx, int C_BPartner_ID) public static MBPBankAccount[] getOfBPartner (Properties ctx, int C_BPartner_ID)
{ {
String sql = "SELECT * FROM C_BP_BankAccount WHERE C_BPartner_ID=? AND IsActive='Y'"; final String whereClause = MBPBankAccount.COLUMNNAME_C_BPartner_ID+"=?";
ArrayList<MBPBankAccount> list = new ArrayList<MBPBankAccount>(); List<MBPBankAccount>list = new Query(ctx,MBPBankAccount.COLUMNNAME_C_BPartner_ID,whereClause,null)
PreparedStatement pstmt = null; .setParameters(C_BPartner_ID)
try .setOnlyActiveRecords(true)
{ .list();
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, C_BPartner_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
list.add(new MBPBankAccount(ctx, rs, null));
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
s_log.log(Level.SEVERE, sql, e);
}
try {
if (pstmt != null)
pstmt.close();
pstmt = null;
} catch (Exception e) {
pstmt = null;
}
MBPBankAccount[] retValue = new MBPBankAccount[list.size()]; MBPBankAccount[] retValue = new MBPBankAccount[list.size()];
list.toArray(retValue); list.toArray(retValue);

View File

@ -97,34 +97,10 @@ public class MTable extends X_AD_Table
} }
} }
// //
MTable retValue = null; final String whereClause = I_AD_Table.COLUMNNAME_AD_Table_ID.toUpperCase()+"=?";
String sql = "SELECT * FROM AD_Table WHERE UPPER(TableName)=?"; MTable retValue = new Query(ctx,I_AD_Table.Table_Name,whereClause,null)
PreparedStatement pstmt = null; .setParameters(tableName.toUpperCase())
try .first();
{
pstmt = DB.prepareStatement (sql, null);
pstmt.setString(1, tableName.toUpperCase());
ResultSet rs = pstmt.executeQuery ();
if (rs.next ())
retValue = new MTable (ctx, rs, null);
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
s_log.log(Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
if (retValue != null) if (retValue != null)
{ {

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.ArrayList; 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.CLogger;
import org.compiere.util.DB;
/** /**
* User Roles Model * User Roles Model
@ -47,34 +44,10 @@ public class MUserRoles extends X_AD_User_Roles
*/ */
public static MUserRoles[] getOfRole (Properties ctx, int AD_Role_ID) public static MUserRoles[] getOfRole (Properties ctx, int AD_Role_ID)
{ {
String sql = "SELECT * FROM AD_User_Roles WHERE AD_Role_ID=?"; final String whereClause = I_AD_User_Roles.COLUMNNAME_AD_Role_ID+"=?";
ArrayList<MUserRoles> list = new ArrayList<MUserRoles>(); List<MUserRoles> list = new Query(ctx,I_AD_User_Roles.Table_Name,whereClause,null)
PreparedStatement pstmt = null; .setParameters(AD_Role_ID)
try .list();
{
pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, AD_Role_ID);
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())
list.add (new MUserRoles (ctx, rs, null));
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
s_log.log(Level.SEVERE, "getOfRole", e);
}
try
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
MUserRoles[] retValue = new MUserRoles[list.size ()]; MUserRoles[] retValue = new MUserRoles[list.size ()];
list.toArray (retValue); list.toArray (retValue);
return retValue; return retValue;
@ -88,34 +61,10 @@ public class MUserRoles extends X_AD_User_Roles
*/ */
public static MUserRoles[] getOfUser (Properties ctx, int AD_User_ID) public static MUserRoles[] getOfUser (Properties ctx, int AD_User_ID)
{ {
String sql = "SELECT * FROM AD_User_Roles WHERE AD_User_ID=?"; final String whereClause = I_AD_User_Roles.COLUMNNAME_AD_User_ID+"=?";
ArrayList<MUserRoles> list = new ArrayList<MUserRoles>(); List<MUserRoles> list = new Query(ctx,I_AD_User_Roles.Table_Name,whereClause,null)
PreparedStatement pstmt = null; .setParameters(AD_User_ID)
try .list();
{
pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, AD_User_ID);
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())
list.add (new MUserRoles (ctx, rs, null));
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
s_log.log(Level.SEVERE, "getOfUser", e);
}
try
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
MUserRoles[] retValue = new MUserRoles[list.size ()]; MUserRoles[] retValue = new MUserRoles[list.size ()];
list.toArray (retValue); list.toArray (retValue);
return retValue; return retValue;