[ 2214883 ] Remove SQL code and Replace for Query

http://sourceforge.net/tracker/index.php?func=detail&aid=2214883&group_id=176962&atid=879335
Test executed

1.- Account View work.
2.- Create new Schema account work.
3.- Copy Default Account from other schema work.
4.- ComboBox for Account report work.
5.- Display Account lookup in BPartner work.

kind regards
Victor Perez
www.e-evolution.com
This commit is contained in:
vpj-cd 2008-11-03 17:35:46 +00:00
parent 0d9edf98d0
commit ea51559332
8 changed files with 127 additions and 212 deletions

View File

@ -16,16 +16,13 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
/** /**
@ -33,8 +30,8 @@ import org.compiere.util.Env;
* C_ValidCombination * C_ValidCombination
* *
* @author Jorg Janke * @author Jorg Janke
* @author victor.perez, www.e-evolution.com * @author victor.perez@e-evolution.com, www.e-evolution.com
* <li>[ 2214883 ] Remove SQL code and Replace for Query http://sourceforge.net/tracker/index.php?func=detail&aid=2214883&group_id=176962&atid=879335 * <li>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 $ * @version $Id: MAccount.java,v 1.4 2006/07/30 00:58:04 jjanke Exp $
*/ */
public class MAccount extends X_C_ValidCombination public class MAccount extends X_C_ValidCombination

View File

@ -16,16 +16,22 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
import java.io.*; import java.io.Serializable;
import java.sql.*; import java.util.ArrayList;
import java.util.*; import java.util.List;
import java.util.logging.*; import java.util.Properties;
import org.compiere.util.*;
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 * Account Model Lookup - Maintains ValidCombination Info for Display & Edit - not cached
* *
* @author Jorg Janke * @author Jorg Janke
* @author victor.perez@e-evolution.com, www.e-evolution.com
* <li>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 $ * @version $Id: MAccountLookup.java,v 1.3 2006/07/30 00:54:54 jjanke Exp $
*/ */
public final class MAccountLookup extends Lookup implements Serializable public final class MAccountLookup extends Lookup implements Serializable
@ -127,34 +133,17 @@ public final class MAccountLookup extends Lookup implements Serializable
if (ID == C_ValidCombination_ID) // already loaded if (ID == C_ValidCombination_ID) // already loaded
return true; return true;
String SQL = "SELECT C_ValidCombination_ID, Combination, Description " String whereClause = "C_ValidCombination_ID=?";
+ "FROM C_ValidCombination WHERE C_ValidCombination_ID=?"; MAccount account = new Query(Env.getCtx(),MAccount.Table_Name,whereClause,null)
.setParameters(new Object[]{ID})
.first();
PreparedStatement pstmt = null; if(account == null)
ResultSet rs = null;
try
{
// Prepare Statement
pstmt = DB.prepareStatement(SQL, null);
pstmt.setInt(1, ID);
rs = pstmt.executeQuery();
if (!rs.next())
{
return false; return false;
}
// C_ValidCombination_ID = account.getC_ValidCombination_ID();
C_ValidCombination_ID = rs.getInt(1); Combination = account.getCombination();
Combination = rs.getString(2); Description = account.getDescription();
Description = rs.getString(3);
}
catch (SQLException e)
{
return false;
}
finally
{
DB.close(rs, pstmt);
}
return true; return true;
} // load } // load
@ -183,30 +172,26 @@ public final class MAccountLookup extends Lookup implements Serializable
if (!mandatory) if (!mandatory)
list.add(new KeyNamePair (-1, "")); list.add(new KeyNamePair (-1, ""));
// //
StringBuffer sql = new StringBuffer ("SELECT C_ValidCombination_ID, Combination, Description " ArrayList<Object> params = new ArrayList<Object>();
+ "FROM C_ValidCombination WHERE AD_Client_ID=?"); String whereClause = "AD_Client_ID=?";
params.add(Env.getAD_Client_ID(m_ctx));
if (onlyActive) 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); whereClause+=" AND IsActive=?";
pstmt.setInt(1, Env.getAD_Client_ID(m_ctx)); params.add("Y");
rs = pstmt.executeQuery();
while (rs.next())
list.add (new KeyNamePair(rs.getInt(1), rs.getString(2) + " - " + rs.getString(3)));
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql.toString(), e);
}
finally
{
DB.close(rs, pstmt);
} }
List<MAccount> accounts = new Query(Env.getCtx(),MAccount.Table_Name,whereClause,null)
.setParameters(params)
.setOrderBy("Combination")
.list();
for(MAccount account :accounts)
{
list.add (new KeyNamePair(account.getC_ValidCombination_ID(),
account.getCombination() + " - " +
account.getDescription()));
}
// Sort & return // Sort & return
return list; return list;
} // getData } // getData

View File

@ -16,12 +16,11 @@
*****************************************************************************/ *****************************************************************************/
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.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DB; import org.compiere.util.DB;
@ -32,6 +31,8 @@ import org.compiere.util.Msg;
* Accounting Processor Model * Accounting Processor Model
* *
* @author Jorg Janke * @author Jorg Janke
* @author victor.perez@e-evolution.com, www.e-evolution.com
* <li>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 $ * @version $Id: MAcctProcessor.java,v 1.3 2006/07/30 00:51:02 jjanke Exp $
*/ */
public class MAcctProcessor extends X_C_AcctProcessor public class MAcctProcessor extends X_C_AcctProcessor
@ -44,29 +45,10 @@ public class MAcctProcessor extends X_C_AcctProcessor
*/ */
public static MAcctProcessor[] getActive (Properties ctx) public static MAcctProcessor[] getActive (Properties ctx)
{ {
ArrayList<MAcctProcessor> list = new ArrayList<MAcctProcessor>(); String whereClause = "IsActive=?";
String sql = "SELECT * FROM C_AcctProcessor WHERE IsActive='Y'"; List<MAcctProcessor> list = new Query(ctx, MAcctProcessor.Table_Name,whereClause,null)
PreparedStatement pstmt = null; .setParameters(new Object[]{"Y"}).list();
ResultSet rs = null; return list.toArray(new MAcctProcessor[list.size()]);
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;
} // getActive } // getActive
/** Static Logger */ /** Static Logger */
@ -146,33 +128,12 @@ public class MAcctProcessor extends X_C_AcctProcessor
*/ */
public AdempiereProcessorLog[] getLogs () public AdempiereProcessorLog[] getLogs ()
{ {
ArrayList<MAcctProcessorLog> list = new ArrayList<MAcctProcessorLog>(); String whereClause = "C_AcctProcessor_ID=? ";
String sql = "SELECT * " List<MAcctProcessor> list = new Query(getCtx(), MAcctProcessorLog.Table_Name,whereClause,get_TrxName())
+ "FROM C_AcctProcessorLog " .setParameters(new Object[]{getC_AcctProcessor_ID()})
+ "WHERE C_AcctProcessor_ID=? " .setOrderBy("Created DESC")
+ "ORDER BY Created DESC"; .list();
PreparedStatement pstmt = null; return list.toArray(new MAcctProcessorLog[list.size()]);
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;
} // getLogs } // getLogs
/** /**

View File

@ -16,8 +16,8 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
import java.sql.*; import java.sql.ResultSet;
import java.util.*; import java.util.Properties;
/** /**

View File

@ -16,15 +16,21 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
import java.sql.*; import java.sql.ResultSet;
import java.util.*; import java.util.ArrayList;
import java.util.logging.*; import java.util.List;
import org.compiere.util.*; import java.util.Properties;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.KeyNamePair;
/** /**
* Accounting Schema Model (base) * Accounting Schema Model (base)
* *
* @author Jorg Janke * @author Jorg Janke
* @author victor.perez@e-evolution.com, www.e-evolution.com
* <li>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 $ * @version $Id: MAcctSchema.java,v 1.4 2006/07/30 00:58:04 jjanke Exp $
*/ */
public class MAcctSchema extends X_C_AcctSchema 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) if (as.get_ID() != 0 && trxName == null)
list.add(as); list.add(as);
// Other ArrayList<Object> params = new ArrayList<Object>();
String sql = "SELECT C_AcctSchema_ID FROM C_AcctSchema acs " String whereClause = "IsActive=? "
+ "WHERE IsActive='Y'" + " AND EXISTS (SELECT * FROM C_AcctSchema_GL gl WHERE C_AcctSchema.C_AcctSchema_ID=gl.C_AcctSchema_ID)"
+ " 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 C_AcctSchema.C_AcctSchema_ID=d.C_AcctSchema_ID)";
+ " AND EXISTS (SELECT * FROM C_AcctSchema_Default d WHERE acs.C_AcctSchema_ID=d.C_AcctSchema_ID)"; params.add("Y");
if (AD_Client_ID != 0) if (AD_Client_ID != 0)
sql += " AND AD_Client_ID=?";
sql += " ORDER BY C_AcctSchema_ID";
try
{ {
PreparedStatement pstmt = DB.prepareStatement(sql, trxName); whereClause += " AND AD_Client_ID=?";
if (AD_Client_ID != 0) params.add(AD_Client_ID);
pstmt.setInt(1, AD_Client_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
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);
} }
}
rs.close(); List <MAcctSchema> ass = new Query(ctx, MAcctSchema.Table_Name,whereClause,trxName)
pstmt.close(); .setParameters(params)
} .setOrderBy(MAcctSchema.COLUMNNAME_C_AcctSchema_ID)
catch (SQLException e) .list();
for(MAcctSchema acctschema : ass)
{ {
s_log.log(Level.SEVERE, sql, e); if (acctschema.get_ID() != info.getC_AcctSchema1_ID()) // already in list
{
if (acctschema.get_ID() != 0 && trxName == null)
list.add(acctschema);
}
} }
// Save // Save
MAcctSchema[] retValue = new MAcctSchema [list.size()]; MAcctSchema[] retValue = new MAcctSchema [list.size()];

View File

@ -16,16 +16,19 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
import java.sql.*; import java.sql.ResultSet;
import java.util.*; import java.util.ArrayList;
import java.util.Properties;
import java.util.logging.*; import org.compiere.util.CLogger;
import org.compiere.util.*; import org.compiere.util.KeyNamePair;
/** /**
* Default Accounts for MAcctSchema * Default Accounts for MAcctSchema
* *
* @author Jorg Janke * @author Jorg Janke
* @author victor.perez@e-evolution.com, www.e-evolution.com
* <li>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 $ * @version $Id: MAcctSchemaDefault.java,v 1.3 2006/07/30 00:58:37 jjanke Exp $
*/ */
public class MAcctSchemaDefault extends X_C_AcctSchema_Default 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) public static MAcctSchemaDefault get (Properties ctx, int C_AcctSchema_ID)
{ {
MAcctSchemaDefault retValue = null; String whereClause = "C_AcctSchema_ID=?";
String sql = "SELECT * FROM C_AcctSchema_Default WHERE C_AcctSchema_ID=?"; return new Query(ctx,MAcctSchemaDefault.Table_Name,whereClause,null)
PreparedStatement pstmt = null; .setParameters(new Object[]{C_AcctSchema_ID}).first();
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;
} // get } // get
/** Logger */ /** Logger */

View File

@ -16,10 +16,16 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
import java.sql.*; import java.sql.ResultSet;
import java.util.*; import java.util.ArrayList;
import java.util.logging.*; import java.util.List;
import org.compiere.util.*; 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 * Account Schema Element Object
@ -29,6 +35,8 @@ import org.compiere.util.*;
* *
* @author Teo Sarca, SC ARHIPAC SERVICE SRL * @author Teo Sarca, SC ARHIPAC SERVICE SRL
* <li>BF [ 1795817 ] Acct Schema Elements "Account" and "Org" should be mandatory * <li>BF [ 1795817 ] Acct Schema Elements "Account" and "Org" should be mandatory
* @author victor.perez@e-evolution.com, www.e-evolution.com
* <li>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 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()); s_log.fine("C_AcctSchema_ID=" + as.getC_AcctSchema_ID());
ArrayList<MAcctSchemaElement> list = new ArrayList<MAcctSchemaElement>(); ArrayList<MAcctSchemaElement> list = new ArrayList<MAcctSchemaElement>();
//
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<MAcctSchemaElement> 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); s_log.fine(" - " + ase);
if (ase.isMandatory() && ase.getDefaultValue() == 0) if (ase.isMandatory() && ase.getDefaultValue() == 0)
s_log.log(Level.SEVERE, "No default value for " + ase.getName()); s_log.log(Level.SEVERE, "No default value for " + ase.getName());
list.add(ase); list.add(ase);
//
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
s_log.log(Level.SEVERE, sql, e);
} }
retValue = new MAcctSchemaElement[list.size()]; retValue = new MAcctSchemaElement[list.size()];

View File

@ -23,11 +23,15 @@ import java.util.Properties;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.KeyNamePair; import org.compiere.util.KeyNamePair;
/** /**
* Accounting Schema GL info * Accounting Schema GL info
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: MAcctSchemaGL.java,v 1.3 2006/07/30 00:58:18 jjanke Exp $ * @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
* <li>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 public class MAcctSchemaGL extends X_C_AcctSchema_GL
{ {
@ -46,11 +50,9 @@ public class MAcctSchemaGL extends X_C_AcctSchema_GL
public static MAcctSchemaGL get (Properties ctx, int C_AcctSchema_ID) public static MAcctSchemaGL get (Properties ctx, int C_AcctSchema_ID)
{ {
String whereClause = "C_AcctSchema_ID=?"; String whereClause = "C_AcctSchema_ID=?";
MAcctSchemaGL retValue = new Query(ctx, MAcctSchemaGL.Table_Name, whereClause, null) return new Query(ctx,MAcctSchemaGL.Table_Name,whereClause,null)
.setParameters(new Object[]{C_AcctSchema_ID}) .setParameters(new Object[]{C_AcctSchema_ID})
.first() .first();
;
return retValue;
} // get } // get
/** Logger */ /** Logger */