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:
parent
4b73c696ba
commit
fe3a1ef173
|
@ -17,12 +17,10 @@
|
||||||
package org.compiere.model;
|
package org.compiere.model;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
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.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;
|
||||||
|
@ -52,45 +50,30 @@ public class MAttribute extends X_M_Attribute
|
||||||
public static MAttribute[] getOfClient(Properties ctx,
|
public static MAttribute[] getOfClient(Properties ctx,
|
||||||
boolean onlyProductAttributes, boolean onlyListAttributes)
|
boolean onlyProductAttributes, boolean onlyListAttributes)
|
||||||
{
|
{
|
||||||
ArrayList<MAttribute> list = new ArrayList<MAttribute>();
|
|
||||||
int AD_Client_ID = Env.getAD_Client_ID(ctx);
|
int AD_Client_ID = Env.getAD_Client_ID(ctx);
|
||||||
String sql = "SELECT * FROM M_Attribute "
|
String sql = "";
|
||||||
+ "WHERE AD_Client_ID=? AND IsActive='Y'";
|
ArrayList<Object> params = new ArrayList<Object>();
|
||||||
|
params.add(AD_Client_ID);
|
||||||
if (onlyProductAttributes)
|
if (onlyProductAttributes)
|
||||||
sql += " AND IsInstanceAttribute='N'";
|
{
|
||||||
|
sql += " AND IsInstanceAttribute=?";
|
||||||
|
params.add("N");
|
||||||
|
}
|
||||||
if (onlyListAttributes)
|
if (onlyListAttributes)
|
||||||
sql += " AND AttributeValueType='L'";
|
{
|
||||||
sql += " ORDER BY Name";
|
sql += " AND AttributeValueType=?";
|
||||||
PreparedStatement pstmt = null;
|
params.add("L");
|
||||||
try
|
}
|
||||||
{
|
final String whereClause = "AD_Client_ID=?"+sql;
|
||||||
pstmt = DB.prepareStatement (sql, null);
|
|
||||||
pstmt.setInt (1, AD_Client_ID);
|
|
||||||
ResultSet rs = pstmt.executeQuery ();
|
|
||||||
while (rs.next ())
|
|
||||||
list.add (new MAttribute (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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
List<MAttribute>list = new Query(ctx,I_M_Attribute.Table_Name,whereClause,null)
|
||||||
|
.setParameters(params.toArray())
|
||||||
|
.setOnlyActiveRecords(true)
|
||||||
|
.list();
|
||||||
|
|
||||||
MAttribute[] retValue = new MAttribute[list.size ()];
|
MAttribute[] retValue = new MAttribute[list.size ()];
|
||||||
list.toArray (retValue);
|
list.toArray (retValue);
|
||||||
s_log.fine("AD_Client_ID=" + AD_Client_ID + " - #" + retValue.length);
|
s_log.fine("AD_Client_ID=" + AD_Client_ID + " - #" + list.size());
|
||||||
return retValue;
|
return retValue;
|
||||||
} // getOfClient
|
} // getOfClient
|
||||||
|
|
||||||
|
@ -137,38 +120,10 @@ public class MAttribute extends X_M_Attribute
|
||||||
{
|
{
|
||||||
if (m_values == null && ATTRIBUTEVALUETYPE_List.equals(getAttributeValueType()))
|
if (m_values == null && ATTRIBUTEVALUETYPE_List.equals(getAttributeValueType()))
|
||||||
{
|
{
|
||||||
ArrayList<MAttributeValue> list = new ArrayList<MAttributeValue>();
|
final String whereClause = I_M_AttributeValue.COLUMNNAME_M_Attribute_ID+"=?";
|
||||||
if (!isMandatory())
|
List<MAttributeValue>list = new Query(getCtx(),I_M_AttributeValue.Table_Name,whereClause,null)
|
||||||
list.add (null);
|
.setParameters(getM_Attribute_ID())
|
||||||
//
|
.list();
|
||||||
String sql = "SELECT * FROM M_AttributeValue "
|
|
||||||
+ "WHERE M_Attribute_ID=? "
|
|
||||||
+ "ORDER BY Value";
|
|
||||||
PreparedStatement pstmt = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement(sql, null);
|
|
||||||
pstmt.setInt(1, getM_Attribute_ID());
|
|
||||||
ResultSet rs = pstmt.executeQuery();
|
|
||||||
while (rs.next())
|
|
||||||
list.add(new MAttributeValue (getCtx(), rs, null));
|
|
||||||
rs.close();
|
|
||||||
pstmt.close();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (SQLException ex)
|
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, sql, ex);
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (pstmt != null)
|
|
||||||
pstmt.close();
|
|
||||||
}
|
|
||||||
catch (SQLException ex1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
pstmt = null;
|
|
||||||
m_values = new MAttributeValue[list.size()];
|
m_values = new MAttributeValue[list.size()];
|
||||||
list.toArray(m_values);
|
list.toArray(m_values);
|
||||||
}
|
}
|
||||||
|
@ -183,36 +138,10 @@ public class MAttribute extends X_M_Attribute
|
||||||
*/
|
*/
|
||||||
public MAttributeInstance getMAttributeInstance (int M_AttributeSetInstance_ID)
|
public MAttributeInstance getMAttributeInstance (int M_AttributeSetInstance_ID)
|
||||||
{
|
{
|
||||||
MAttributeInstance retValue = null;
|
final String whereClause = I_M_AttributeInstance.COLUMNNAME_M_Attribute_ID+"=? AND "+I_M_AttributeInstance.COLUMNNAME_M_AttributeSetInstance_ID+"=?";
|
||||||
String sql = "SELECT * "
|
MAttributeInstance retValue = new Query(getCtx(),I_M_AttributeInstance.Table_Name,whereClause,get_TrxName())
|
||||||
+ "FROM M_AttributeInstance "
|
.setParameters(getM_Attribute_ID(),M_AttributeSetInstance_ID)
|
||||||
+ "WHERE M_Attribute_ID=? AND M_AttributeSetInstance_ID=?";
|
.firstOnly();
|
||||||
PreparedStatement pstmt = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement (sql, get_TrxName());
|
|
||||||
pstmt.setInt (1, getM_Attribute_ID());
|
|
||||||
pstmt.setInt(2, M_AttributeSetInstance_ID);
|
|
||||||
ResultSet rs = pstmt.executeQuery ();
|
|
||||||
if (rs.next ())
|
|
||||||
retValue = new MAttributeInstance (getCtx(), rs, get_TrxName());
|
|
||||||
rs.close ();
|
|
||||||
pstmt.close ();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (SQLException ex)
|
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, sql, ex);
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (pstmt != null)
|
|
||||||
pstmt.close ();
|
|
||||||
}
|
|
||||||
catch (SQLException ex1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
pstmt = null;
|
|
||||||
|
|
||||||
return retValue;
|
return retValue;
|
||||||
} // getAttributeInstance
|
} // getAttributeInstance
|
||||||
|
|
Loading…
Reference in New Issue