KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > model > MAttributeSet


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Smart Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.model;
15
16 import java.util.*;
17 import java.sql.*;
18
19 import org.compiere.util.*;
20
21 /**
22  * Product Attribute Set
23  *
24  * @author Jorg Janke
25  * @version $Id: MAttributeSet.java,v 1.1 2003/08/26 17:30:35 jjanke Exp $
26  */

27 public class MAttributeSet extends X_M_AttributeSet
28 {
29     /**
30      * Standard constructor
31      * @param ctx context
32      * @param M_AttributeSet_ID id
33      */

34     public MAttributeSet (Properties ctx, int M_AttributeSet_ID)
35     {
36         super (ctx, M_AttributeSet_ID);
37         if (M_AttributeSet_ID == 0)
38         {
39             setIsGuaranteeDate (false);
40             setIsLot (false);
41             setIsSerNo (false);
42             setM_AttributeSet_ID (0);
43             setName (null);
44         }
45     } // MAttributeSet
46

47     /**
48      * Load constructor
49      * @param ctx context
50      * @param rs result set
51      */

52     public MAttributeSet (Properties ctx, ResultSet rs)
53     {
54         super (ctx, rs);
55     } // MAttributeSet
56

57     /** Instance Attributes */
58     private MAttribute[] m_instanceAttributes = null;
59     /** Instance Attributes */
60     private MAttribute[] m_productAttributes = null;
61
62
63     /**
64      * Get Attribute Array
65      * @param instanceAttributes true if for instance
66      * @return instance or product attribute array
67      */

68     public MAttribute[] getMAttributes (boolean instanceAttributes)
69     {
70         if ((m_instanceAttributes == null && instanceAttributes)
71             || m_productAttributes == null && !instanceAttributes)
72         {
73             String JavaDoc sql = "SELECT mau.M_Attribute_ID "
74                 + "FROM M_AttributeUse mau"
75                 + " INNER JOIN M_Attribute ma ON (mau.M_Attribute_ID=ma.M_Attribute_ID) "
76                 + "WHERE mau.IsActive='Y' AND ma.IsActive='Y'"
77                 + " AND mau.M_AttributeSet_ID=? AND ma.IsInstanceAttribute=? " // #1,2
78
+ "ORDER BY mau.SeqNo";
79             ArrayList list = new ArrayList();
80             PreparedStatement pstmt = null;
81             try
82             {
83                 pstmt = DB.prepareStatement(sql);
84                 pstmt.setInt(1, getM_AttributeSet_ID());
85                 pstmt.setString(2, instanceAttributes ? "Y" : "N");
86                 ResultSet rs = pstmt.executeQuery();
87                 while (rs.next())
88                     list.add (new MAttribute (getCtx(), rs.getInt(1)));
89                 rs.close();
90                 pstmt.close();
91                 pstmt = null;
92             }
93             catch (SQLException ex)
94             {
95                 log.error("getMAttributes", ex);
96             }
97             try
98             {
99                 if (pstmt != null)
100                     pstmt.close();
101             }
102             catch (SQLException ex1)
103             {
104             }
105             pstmt = null;
106             //
107
if (instanceAttributes)
108             {
109                 m_instanceAttributes = new MAttribute[list.size()];
110                 list.toArray (m_instanceAttributes);
111             }
112             else
113             {
114                 m_productAttributes = new MAttribute[list.size()];
115                 list.toArray (m_productAttributes);
116             }
117         }
118         //
119
if (instanceAttributes)
120             return m_instanceAttributes;
121         return m_productAttributes;
122     } // getMAttributes
123

124
125 } // MAttributeSet
126
Popular Tags