diff --git a/base/src/org/compiere/model/MAccount.java b/base/src/org/compiere/model/MAccount.java index 22edcbc7ff..25f7e492d8 100644 --- a/base/src/org/compiere/model/MAccount.java +++ b/base/src/org/compiere/model/MAccount.java @@ -16,16 +16,13 @@ *****************************************************************************/ package org.compiere.model; -import java.sql.PreparedStatement; import java.sql.ResultSet; -import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.Properties; import java.util.logging.Level; import org.compiere.util.CLogger; -import org.compiere.util.DB; import org.compiere.util.Env; /** @@ -33,8 +30,8 @@ import org.compiere.util.Env; * C_ValidCombination * * @author Jorg Janke - * @author victor.perez, www.e-evolution.com - *
  • [ 2214883 ] Remove SQL code and Replace for Query http://sourceforge.net/tracker/index.php?func=detail&aid=2214883&group_id=176962&atid=879335 + * @author victor.perez@e-evolution.com, www.e-evolution.com + *
  • RF [ 2214883 ] Remove SQL code and Replace for Query http://sourceforge.net/tracker/index.php?func=detail&aid=2214883&group_id=176962&atid=879335 * @version $Id: MAccount.java,v 1.4 2006/07/30 00:58:04 jjanke Exp $ */ public class MAccount extends X_C_ValidCombination diff --git a/base/src/org/compiere/model/MAccountLookup.java b/base/src/org/compiere/model/MAccountLookup.java index 3b28e08dd6..a979368fc4 100644 --- a/base/src/org/compiere/model/MAccountLookup.java +++ b/base/src/org/compiere/model/MAccountLookup.java @@ -16,16 +16,22 @@ *****************************************************************************/ package org.compiere.model; -import java.io.*; -import java.sql.*; -import java.util.*; -import java.util.logging.*; -import org.compiere.util.*; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.compiere.util.DisplayType; +import org.compiere.util.Env; +import org.compiere.util.KeyNamePair; +import org.compiere.util.NamePair; /** * Account Model Lookup - Maintains ValidCombination Info for Display & Edit - not cached * * @author Jorg Janke + * @author victor.perez@e-evolution.com, www.e-evolution.com + *
  • RF [ 2214883 ] Remove SQL code and Replace for Query http://sourceforge.net/tracker/index.php?func=detail&aid=2214883&group_id=176962&atid=879335 * @version $Id: MAccountLookup.java,v 1.3 2006/07/30 00:54:54 jjanke Exp $ */ public final class MAccountLookup extends Lookup implements Serializable @@ -126,35 +132,18 @@ public final class MAccountLookup extends Lookup implements Serializable } if (ID == C_ValidCombination_ID) // already loaded return true; - - String SQL = "SELECT C_ValidCombination_ID, Combination, Description " - + "FROM C_ValidCombination WHERE C_ValidCombination_ID=?"; - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - // Prepare Statement - pstmt = DB.prepareStatement(SQL, null); - pstmt.setInt(1, ID); - rs = pstmt.executeQuery(); - if (!rs.next()) - { - return false; - } - // - C_ValidCombination_ID = rs.getInt(1); - Combination = rs.getString(2); - Description = rs.getString(3); - } - catch (SQLException e) - { + String whereClause = "C_ValidCombination_ID=?"; + MAccount account = new Query(Env.getCtx(),MAccount.Table_Name,whereClause,null) + .setParameters(new Object[]{ID}) + .first(); + + if(account == null) return false; - } - finally - { - DB.close(rs, pstmt); - } + + C_ValidCombination_ID = account.getC_ValidCombination_ID(); + Combination = account.getCombination(); + Description = account.getDescription(); return true; } // load @@ -183,30 +172,26 @@ public final class MAccountLookup extends Lookup implements Serializable if (!mandatory) list.add(new KeyNamePair (-1, "")); // - StringBuffer sql = new StringBuffer ("SELECT C_ValidCombination_ID, Combination, Description " - + "FROM C_ValidCombination WHERE AD_Client_ID=?"); + ArrayList params = new ArrayList(); + String whereClause = "AD_Client_ID=?"; + params.add(Env.getAD_Client_ID(m_ctx)); if (onlyActive) - sql.append(" AND IsActive='Y'"); - sql.append(" ORDER BY 2"); - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = DB.prepareStatement(sql.toString(), null); - pstmt.setInt(1, Env.getAD_Client_ID(m_ctx)); - rs = pstmt.executeQuery(); - while (rs.next()) - list.add (new KeyNamePair(rs.getInt(1), rs.getString(2) + " - " + rs.getString(3))); + { + whereClause+=" AND IsActive=?"; + params.add("Y"); } - catch (SQLException e) + + List accounts = new Query(Env.getCtx(),MAccount.Table_Name,whereClause,null) + .setParameters(params) + .setOrderBy("Combination") + .list(); + + for(MAccount account :accounts) { - log.log(Level.SEVERE, sql.toString(), e); + list.add (new KeyNamePair(account.getC_ValidCombination_ID(), + account.getCombination() + " - " + + account.getDescription())); } - finally - { - DB.close(rs, pstmt); - } - // Sort & return return list; } // getData diff --git a/base/src/org/compiere/model/MAcctProcessor.java b/base/src/org/compiere/model/MAcctProcessor.java index 30614dd0ca..7d2f0cd4cb 100644 --- a/base/src/org/compiere/model/MAcctProcessor.java +++ b/base/src/org/compiere/model/MAcctProcessor.java @@ -16,12 +16,11 @@ *****************************************************************************/ package org.compiere.model; -import java.sql.PreparedStatement; + import java.sql.ResultSet; import java.sql.Timestamp; -import java.util.ArrayList; +import java.util.List; import java.util.Properties; -import java.util.logging.Level; import org.compiere.util.CLogger; import org.compiere.util.DB; @@ -32,6 +31,8 @@ import org.compiere.util.Msg; * Accounting Processor Model * * @author Jorg Janke + * @author victor.perez@e-evolution.com, www.e-evolution.com + *
  • RF [ 2214883 ] Remove SQL code and Replace for Query http://sourceforge.net/tracker/index.php?func=detail&aid=2214883&group_id=176962&atid=879335 * @version $Id: MAcctProcessor.java,v 1.3 2006/07/30 00:51:02 jjanke Exp $ */ public class MAcctProcessor extends X_C_AcctProcessor @@ -44,29 +45,10 @@ public class MAcctProcessor extends X_C_AcctProcessor */ public static MAcctProcessor[] getActive (Properties ctx) { - ArrayList list = new ArrayList(); - String sql = "SELECT * FROM C_AcctProcessor WHERE IsActive='Y'"; - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = DB.prepareStatement (sql, null); - rs = pstmt.executeQuery (); - while (rs.next ()) - list.add (new MAcctProcessor (ctx, rs, null)); - } - catch (Exception e) - { - s_log.log(Level.SEVERE, "getActive", e); - } - finally - { - DB.close(rs, pstmt); - rs = null; pstmt = null; - } - MAcctProcessor[] retValue = new MAcctProcessor[list.size ()]; - list.toArray (retValue); - return retValue; + String whereClause = "IsActive=?"; + List list = new Query(ctx, MAcctProcessor.Table_Name,whereClause,null) + .setParameters(new Object[]{"Y"}).list(); + return list.toArray(new MAcctProcessor[list.size()]); } // getActive /** Static Logger */ @@ -146,33 +128,12 @@ public class MAcctProcessor extends X_C_AcctProcessor */ public AdempiereProcessorLog[] getLogs () { - ArrayList list = new ArrayList(); - String sql = "SELECT * " - + "FROM C_AcctProcessorLog " - + "WHERE C_AcctProcessor_ID=? " - + "ORDER BY Created DESC"; - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = DB.prepareStatement (sql, get_TrxName()); - pstmt.setInt (1, getC_AcctProcessor_ID()); - rs = pstmt.executeQuery (); - while (rs.next ()) - list.add (new MAcctProcessorLog (getCtx(), rs, get_TrxName())); - } - catch (Exception e) - { - log.log(Level.SEVERE, sql, e); - } - finally - { - DB.close(rs, pstmt); - rs = null; pstmt = null; - } - MAcctProcessorLog[] retValue = new MAcctProcessorLog[list.size ()]; - list.toArray (retValue); - return retValue; + String whereClause = "C_AcctProcessor_ID=? "; + List list = new Query(getCtx(), MAcctProcessorLog.Table_Name,whereClause,get_TrxName()) + .setParameters(new Object[]{getC_AcctProcessor_ID()}) + .setOrderBy("Created DESC") + .list(); + return list.toArray(new MAcctProcessorLog[list.size()]); } // getLogs /** diff --git a/base/src/org/compiere/model/MAcctProcessorLog.java b/base/src/org/compiere/model/MAcctProcessorLog.java index c2b5cc0843..a83dddf5c1 100644 --- a/base/src/org/compiere/model/MAcctProcessorLog.java +++ b/base/src/org/compiere/model/MAcctProcessorLog.java @@ -16,8 +16,8 @@ *****************************************************************************/ package org.compiere.model; -import java.sql.*; -import java.util.*; +import java.sql.ResultSet; +import java.util.Properties; /** diff --git a/base/src/org/compiere/model/MAcctSchema.java b/base/src/org/compiere/model/MAcctSchema.java index 5798bb2213..abcbe5d839 100644 --- a/base/src/org/compiere/model/MAcctSchema.java +++ b/base/src/org/compiere/model/MAcctSchema.java @@ -16,15 +16,21 @@ *****************************************************************************/ package org.compiere.model; -import java.sql.*; -import java.util.*; -import java.util.logging.*; -import org.compiere.util.*; +import java.sql.ResultSet; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.compiere.util.CCache; +import org.compiere.util.CLogger; +import org.compiere.util.KeyNamePair; /** * Accounting Schema Model (base) * * @author Jorg Janke + * @author victor.perez@e-evolution.com, www.e-evolution.com + *
  • RF [ 2214883 ] Remove SQL code and Replace for Query http://sourceforge.net/tracker/index.php?func=detail&aid=2214883&group_id=176962&atid=879335 * @version $Id: MAcctSchema.java,v 1.4 2006/07/30 00:58:04 jjanke Exp $ */ public class MAcctSchema extends X_C_AcctSchema @@ -92,36 +98,29 @@ public class MAcctSchema extends X_C_AcctSchema if (as.get_ID() != 0 && trxName == null) list.add(as); - // Other - String sql = "SELECT C_AcctSchema_ID FROM C_AcctSchema acs " - + "WHERE IsActive='Y'" - + " AND EXISTS (SELECT * FROM C_AcctSchema_GL gl WHERE acs.C_AcctSchema_ID=gl.C_AcctSchema_ID)" - + " AND EXISTS (SELECT * FROM C_AcctSchema_Default d WHERE acs.C_AcctSchema_ID=d.C_AcctSchema_ID)"; + ArrayList params = new ArrayList(); + String whereClause = "IsActive=? " + + " AND EXISTS (SELECT * FROM C_AcctSchema_GL gl WHERE C_AcctSchema.C_AcctSchema_ID=gl.C_AcctSchema_ID)" + + " AND EXISTS (SELECT * FROM C_AcctSchema_Default d WHERE C_AcctSchema.C_AcctSchema_ID=d.C_AcctSchema_ID)"; + params.add("Y"); if (AD_Client_ID != 0) - sql += " AND AD_Client_ID=?"; - sql += " ORDER BY C_AcctSchema_ID"; - try + { + whereClause += " AND AD_Client_ID=?"; + params.add(AD_Client_ID); + } + + List ass = new Query(ctx, MAcctSchema.Table_Name,whereClause,trxName) + .setParameters(params) + .setOrderBy(MAcctSchema.COLUMNNAME_C_AcctSchema_ID) + .list(); + + for(MAcctSchema acctschema : ass) { - PreparedStatement pstmt = DB.prepareStatement(sql, trxName); - if (AD_Client_ID != 0) - pstmt.setInt(1, AD_Client_ID); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) + if (acctschema.get_ID() != info.getC_AcctSchema1_ID()) // already in list { - int id = rs.getInt(1); - if (id != info.getC_AcctSchema1_ID()) // already in list - { - as = MAcctSchema.get (ctx, id, trxName); - if (as.get_ID() != 0 && trxName == null) - list.add(as); - } + if (acctschema.get_ID() != 0 && trxName == null) + list.add(acctschema); } - rs.close(); - pstmt.close(); - } - catch (SQLException e) - { - s_log.log(Level.SEVERE, sql, e); } // Save MAcctSchema[] retValue = new MAcctSchema [list.size()]; diff --git a/base/src/org/compiere/model/MAcctSchemaDefault.java b/base/src/org/compiere/model/MAcctSchemaDefault.java index e39208a4a4..3557982be4 100644 --- a/base/src/org/compiere/model/MAcctSchemaDefault.java +++ b/base/src/org/compiere/model/MAcctSchemaDefault.java @@ -16,16 +16,19 @@ *****************************************************************************/ package org.compiere.model; -import java.sql.*; -import java.util.*; +import java.sql.ResultSet; +import java.util.ArrayList; +import java.util.Properties; -import java.util.logging.*; -import org.compiere.util.*; +import org.compiere.util.CLogger; +import org.compiere.util.KeyNamePair; /** * Default Accounts for MAcctSchema * * @author Jorg Janke + * @author victor.perez@e-evolution.com, www.e-evolution.com + *
  • RF [ 2214883 ] Remove SQL code and Replace for Query http://sourceforge.net/tracker/index.php?func=detail&aid=2214883&group_id=176962&atid=879335 * @version $Id: MAcctSchemaDefault.java,v 1.3 2006/07/30 00:58:37 jjanke Exp $ */ public class MAcctSchemaDefault extends X_C_AcctSchema_Default @@ -38,37 +41,9 @@ public class MAcctSchemaDefault extends X_C_AcctSchema_Default */ public static MAcctSchemaDefault get (Properties ctx, int C_AcctSchema_ID) { - MAcctSchemaDefault retValue = null; - String sql = "SELECT * FROM C_AcctSchema_Default WHERE C_AcctSchema_ID=?"; - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement(sql, null); - pstmt.setInt(1, C_AcctSchema_ID); - ResultSet rs = pstmt.executeQuery(); - if (rs.next()) - { - retValue = new MAcctSchemaDefault (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; - } - return retValue; + String whereClause = "C_AcctSchema_ID=?"; + return new Query(ctx,MAcctSchemaDefault.Table_Name,whereClause,null) + .setParameters(new Object[]{C_AcctSchema_ID}).first(); } // get /** Logger */ diff --git a/base/src/org/compiere/model/MAcctSchemaElement.java b/base/src/org/compiere/model/MAcctSchemaElement.java index f0aa60f648..5b1cd323d3 100644 --- a/base/src/org/compiere/model/MAcctSchemaElement.java +++ b/base/src/org/compiere/model/MAcctSchemaElement.java @@ -16,10 +16,16 @@ *****************************************************************************/ package org.compiere.model; -import java.sql.*; -import java.util.*; -import java.util.logging.*; -import org.compiere.util.*; +import java.sql.ResultSet; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import java.util.logging.Level; + +import org.compiere.util.CCache; +import org.compiere.util.CLogger; +import org.compiere.util.DB; +import org.compiere.util.Msg; /** * Account Schema Element Object @@ -29,6 +35,8 @@ import org.compiere.util.*; * * @author Teo Sarca, SC ARHIPAC SERVICE SRL *
  • BF [ 1795817 ] Acct Schema Elements "Account" and "Org" should be mandatory + * @author victor.perez@e-evolution.com, www.e-evolution.com + *
  • RF [ 2214883 ] Remove SQL code and Replace for Query http://sourceforge.net/tracker/index.php?func=detail&aid=2214883&group_id=176962&atid=879335 */ public final class MAcctSchemaElement extends X_C_AcctSchema_Element { @@ -46,30 +54,18 @@ public final class MAcctSchemaElement extends X_C_AcctSchema_Element s_log.fine("C_AcctSchema_ID=" + as.getC_AcctSchema_ID()); ArrayList list = new ArrayList(); - // - String sql = "SELECT * FROM C_AcctSchema_Element " - + "WHERE C_AcctSchema_ID=? AND IsActive='Y' ORDER BY SeqNo"; - - try + + String whereClause = "C_AcctSchema_ID=? AND IsActive=?"; + List elements= new Query(as.getCtx(), MAcctSchemaElement.Table_Name,whereClause,as.get_TrxName()) + .setParameters(new Object[]{as.getC_AcctSchema_ID(),"Y"}).setOrderBy("SeqNo") + .list(); + + for(MAcctSchemaElement ase : elements) { - PreparedStatement pstmt = DB.prepareStatement(sql, as.get_TrxName()); - pstmt.setInt(1, as.getC_AcctSchema_ID()); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - MAcctSchemaElement ase = new MAcctSchemaElement(as.getCtx(), rs, as.get_TrxName()); - s_log.fine(" - " + ase); - if (ase.isMandatory() && ase.getDefaultValue() == 0) - s_log.log(Level.SEVERE, "No default value for " + ase.getName()); - list.add(ase); - // - } - rs.close(); - pstmt.close(); - } - catch (SQLException e) - { - s_log.log(Level.SEVERE, sql, e); + s_log.fine(" - " + ase); + if (ase.isMandatory() && ase.getDefaultValue() == 0) + s_log.log(Level.SEVERE, "No default value for " + ase.getName()); + list.add(ase); } retValue = new MAcctSchemaElement[list.size()]; diff --git a/base/src/org/compiere/model/MAcctSchemaGL.java b/base/src/org/compiere/model/MAcctSchemaGL.java index a728c649e4..e3037b7204 100644 --- a/base/src/org/compiere/model/MAcctSchemaGL.java +++ b/base/src/org/compiere/model/MAcctSchemaGL.java @@ -15,7 +15,7 @@ * or via info@compiere.org or http://www.compiere.org/license.html * *****************************************************************************/ package org.compiere.model; - + import java.sql.ResultSet; import java.util.ArrayList; import java.util.Properties; @@ -23,11 +23,15 @@ import java.util.Properties; import org.compiere.util.CLogger; import org.compiere.util.KeyNamePair; + + /** * Accounting Schema GL info * * @author Jorg Janke * @version $Id: MAcctSchemaGL.java,v 1.3 2006/07/30 00:58:18 jjanke Exp $ + * @author victor.perez@e-evolution.com, www.e-evolution.com + *
  • RF [ 2214883 ] Remove SQL code and Replace for Query http://sourceforge.net/tracker/index.php?func=detail&aid=2214883&group_id=176962&atid=879335 */ public class MAcctSchemaGL extends X_C_AcctSchema_GL { @@ -44,13 +48,11 @@ public class MAcctSchemaGL extends X_C_AcctSchema_GL * @return defaults */ public static MAcctSchemaGL get (Properties ctx, int C_AcctSchema_ID) - { - String whereClause = "C_AcctSchema_ID=?"; - MAcctSchemaGL retValue = new Query(ctx, MAcctSchemaGL.Table_Name, whereClause, null) - .setParameters(new Object[]{C_AcctSchema_ID}) - .first() - ; - return retValue; + { + String whereClause = "C_AcctSchema_ID=?"; + return new Query(ctx,MAcctSchemaGL.Table_Name,whereClause,null) + .setParameters(new Object[]{C_AcctSchema_ID}) + .first(); } // get /** Logger */