KickJava   Java API By Example, From Geeks To Geeks.

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


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 Lot
23  *
24  * @author Jorg Janke
25  * @version $Id: MLot.java,v 1.3 2003/10/21 05:31:40 jjanke Exp $
26  */

27 public class MLot extends X_M_Lot
28 {
29     /** Logger */
30     private static Logger s_log = Logger.getCLogger(MLot.class);
31
32     /**
33      * Get Lots for Product
34      * @param ctx context
35      * @param M_Product_ID product
36      * @return Array of Lots for Product
37      */

38     public static MLot[] getProductLots (Properties ctx, int M_Product_ID)
39     {
40         String JavaDoc sql = "SELECT * FROM M_Lot WHERE M_Product_ID=?";
41         ArrayList list = new ArrayList();
42         PreparedStatement pstmt = null;
43         try
44         {
45             pstmt = DB.prepareStatement (sql);
46             pstmt.setInt (1, M_Product_ID);
47             ResultSet rs = pstmt.executeQuery ();
48             while (rs.next ())
49                 list.add (new MLot (ctx, rs));
50             rs.close ();
51             pstmt.close ();
52             pstmt = null;
53         }
54         catch (SQLException ex)
55         {
56             s_log.error ("getProductLots (MLot)", ex);
57         }
58         try
59         {
60             if (pstmt != null)
61                 pstmt.close ();
62         }
63         catch (SQLException ex1)
64         {
65         }
66         pstmt = null;
67         //
68
MLot[] retValue = new MLot[list.size()];
69         list.toArray(retValue);
70         return retValue;
71     } // getProductLots
72

73     /**
74      * Get Lot Key Name Pairs for Product
75      * @param M_Product_ID product
76      * @return Array of Lot Key Name Pairs for Product
77      */

78     public static KeyNamePair[] getProductLots (int M_Product_ID)
79     {
80         String JavaDoc sql = "SELECT M_Lot_ID, Name FROM M_Lot WHERE M_Product_ID=?";
81         ArrayList list = new ArrayList();
82         PreparedStatement pstmt = null;
83         try
84         {
85             pstmt = DB.prepareStatement (sql);
86             pstmt.setInt (1, M_Product_ID);
87             ResultSet rs = pstmt.executeQuery ();
88             while (rs.next ())
89                 list.add (new KeyNamePair (rs.getInt(1), rs.getString(2)));
90             rs.close ();
91             pstmt.close ();
92             pstmt = null;
93         }
94         catch (SQLException ex)
95         {
96             s_log.error ("getProductLots (KeyNamePair)", ex);
97         }
98         try
99         {
100             if (pstmt != null)
101                 pstmt.close ();
102         }
103         catch (SQLException ex1)
104         {
105         }
106         pstmt = null;
107         //
108
KeyNamePair[] retValue = new KeyNamePair[list.size()];
109         list.toArray(retValue);
110         return retValue;
111     } // getProductLots
112

113     /*************************************************************************/
114
115     /**
116      * Standard Constructor
117      * @param ctx context
118      * @param M_Lot_ID ID
119      */

120     public MLot (Properties ctx, int M_Lot_ID)
121     {
122         super (ctx, M_Lot_ID);
123         /** if (M_Lot_ID == 0)
124         {
125             setM_Lot_ID (0);
126             setM_Product_ID (0);
127             setName (null);
128         }
129         **/

130     } // MLot
131

132     /**
133      * Load Constructor
134      * @param ctx context
135      * @param rs result set
136      */

137     public MLot (Properties ctx, ResultSet rs)
138     {
139         super (ctx, rs);
140     } // MLot
141

142     /**
143      * Full New Constructor
144      * @param ctx context
145      * @param M_Product_ID product
146      * @param Name name
147      */

148     public MLot (Properties ctx, int M_Product_ID, String JavaDoc Name)
149     {
150         this (ctx, 0);
151         setM_Product_ID (M_Product_ID);
152         setName (Name);
153     } // MLot
154

155     /**
156      * String Representation
157      * @return info
158      */

159     public String JavaDoc toString()
160     {
161         return getName();
162     } // toString
163

164 } // MLot
165
Popular Tags