KickJava   Java API By Example, From Geeks To Geeks.

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


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 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-2001 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 import java.io.*;
19
20 import org.compiere.util.*;
21
22 /**
23  * Warehouse Locator Object
24  *
25  * @author Jorg Janke
26  * @version $Id: MLocator.java,v 1.11 2003/10/04 03:51:50 jjanke Exp $
27  */

28 public final class MLocator extends X_M_Locator implements Serializable
29 {
30     /**
31      * Standard Locator Constructor
32      * @param ctx Context
33      * @param M_Locator_ID id
34      */

35     public MLocator (Properties ctx, int M_Locator_ID)
36     {
37         super (ctx, M_Locator_ID);
38         if (M_Locator_ID == 0)
39         {
40         // setM_Locator_ID (0); // PK
41
// setM_Warehouse_ID (0); // Parent
42
setIsDefault (false);
43             setPriorityNo (50);
44         // setValue (null);
45
// setX (null);
46
// setY (null);
47
// setZ (null);
48
}
49     } // MLocator
50

51     /**
52      * Detailed New Locator Constructor
53      * @param ctx Context
54      * @param M_Warehouse_ID warehouse
55      * @param Value value
56      * @param X x
57      * @param Y y
58      * @param Z z
59      */

60     public MLocator (Properties ctx, int M_Warehouse_ID, String JavaDoc Value,
61         String JavaDoc X, String JavaDoc Y, String JavaDoc Z)
62     {
63         this (ctx, 0);
64         setM_Warehouse_ID (M_Warehouse_ID); // Parent
65
setValue (Value);
66         setX (X);
67         setY (Y);
68         setZ (Z);
69     } // MLocator
70

71     /**
72      * Load Constructor
73      * @param ctx context
74      * @param rs result set
75      */

76     public MLocator (Properties ctx, ResultSet rs)
77     {
78         super (ctx, rs);
79     } // MLocator
80

81     private static Logger s_log = Logger.getCLogger (MLocator.class);
82
83
84     /**
85      * Get the Locator with the combination or create new one
86      * @param ctx Context
87      * @param M_Warehouse_ID warehouse
88      * @param Value value
89      * @param X x
90      * @param Y y
91      * @param Z z
92      * @return locator
93      */

94      public static MLocator get (Properties ctx, int M_Warehouse_ID, String JavaDoc Value,
95          String JavaDoc X, String JavaDoc Y, String JavaDoc Z)
96      {
97         MLocator retValue = null;
98         String JavaDoc sql = "SELECT * FROM M_Locator WHERE M_Warehouse_ID=? AND X=? AND Y=? AND Z=?";
99         PreparedStatement pstmt = null;
100         try
101         {
102             pstmt = DB.prepareStatement(sql);
103             pstmt.setInt(1, M_Warehouse_ID);
104             pstmt.setString(2, X);
105             pstmt.setString(3, Y);
106             pstmt.setString(4, Z);
107             ResultSet rs = pstmt.executeQuery();
108             if (rs.next())
109                 retValue = new MLocator (ctx, rs);
110             rs.close();
111             pstmt.close();
112             pstmt = null;
113         }
114         catch (SQLException ex)
115         {
116             s_log.error("get", ex);
117         }
118         try
119         {
120             if (pstmt != null)
121                 pstmt.close();
122         }
123         catch (SQLException ex1)
124         {
125         }
126         pstmt = null;
127         //
128
if (retValue == null)
129         {
130             retValue = new MLocator (ctx, M_Warehouse_ID, Value, X, Y, Z);
131             retValue.save();
132         }
133         return retValue;
134      } // get
135

136     /**
137      * Get String Representation
138      * @return Value
139      */

140     public String JavaDoc toString()
141     {
142         return getValue();
143     } // getValue
144

145     /*************************************************************************/
146
147     private static CCache s_warehouseName = new CCache("MLocatorWarehouseName", 5);
148
149     /**
150      * Get Warehouse Name
151      * @return name
152      */

153     public String JavaDoc getWarehouseName()
154     {
155         int M_Warehouse_ID = getM_Warehouse_ID();
156         if (M_Warehouse_ID == 0)
157             return "";
158         Integer JavaDoc key = new Integer JavaDoc (M_Warehouse_ID);
159         String JavaDoc Name = (String JavaDoc)s_warehouseName.get(key);
160         if (Name == null)
161         {
162             String JavaDoc sql = "SELECT Value, Name FROM M_Warehouse WHERE M_Warehouse_ID=?";
163             PreparedStatement pstmt = null;
164             try
165             {
166                 pstmt = DB.prepareStatement(sql);
167                 pstmt.setInt(1, M_Warehouse_ID);
168                 ResultSet rs = pstmt.executeQuery();
169                 if (rs.next())
170                     Name = rs.getString(2);
171                 rs.close();
172                 pstmt.close();
173                 pstmt = null;
174             }
175             catch (SQLException ex)
176             {
177                 log.error("getWarehouseName", ex);
178             }
179             try
180             {
181                 if (pstmt != null)
182                     pstmt.close();
183             }
184             catch (SQLException ex1)
185             {
186             }
187             pstmt = null;
188             if (Name != null)
189                 s_warehouseName.put(key, Name);
190         }
191         if (Name == null)
192             return "<" + M_Warehouse_ID + ">";
193         return Name;
194     } // getWarehouseName
195

196 } // MLocator
197
Popular Tags