KickJava   Java API By Example, From Geeks To Geeks.

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


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-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 import java.math.*;
19 import java.io.Serializable JavaDoc;
20
21 import org.compiere.util.*;
22
23 /**
24  * Reference List Value
25  *
26  * @author Jorg Janke
27  * @version $Id: MRef_List.java,v 1.2 2003/10/04 03:51:50 jjanke Exp $
28  */

29 public class MRef_List extends X_AD_Ref_List
30 {
31     /**
32      * Get Reference List
33      * @param ctx context
34      * @param AD_Reference_ID reference
35      * @param Value value
36      * @return List or null
37      */

38     public static MRef_List get (Properties ctx, int AD_Reference_ID, String JavaDoc Value)
39     {
40         MRef_List retValue = null;
41         String JavaDoc sql = "SELECT * FROM AD_Ref_List "
42             + "WHERE AD_Reference_ID=? AND Value=?";
43         PreparedStatement pstmt = null;
44         try
45         {
46             pstmt = DB.prepareStatement (sql);
47             pstmt.setInt (1, AD_Reference_ID);
48             pstmt.setString (2, Value);
49             ResultSet rs = pstmt.executeQuery ();
50             if (rs.next ())
51                 retValue = new MRef_List (ctx, rs);
52             rs.close ();
53             pstmt.close ();
54             pstmt = null;
55         }
56         catch (SQLException ex)
57         {
58             s_log.error ("get", ex);
59         }
60         try
61         {
62             if (pstmt != null)
63                 pstmt.close ();
64         }
65         catch (SQLException ex1)
66         {
67         }
68         pstmt = null;
69
70         return retValue;
71     } // get
72

73     /**
74      * Get List Name
75      * @param ctx context
76      * @param AD_Reference_ID reference
77      * @param Value value
78      * @return List or null
79      */

80     public static String JavaDoc getListName (Properties ctx, int AD_Reference_ID, String JavaDoc Value)
81     {
82         String JavaDoc AD_Language = Env.getAD_Language(ctx);
83         String JavaDoc key = AD_Language + "_" + AD_Reference_ID + "_" + Value;
84         String JavaDoc retValue = (String JavaDoc)s_cache.get(key);
85         if (retValue != null)
86             return retValue;
87
88         boolean isBaseLanguage = Env.isBaseLanguage(AD_Language, "AD_Ref_List");
89         String JavaDoc sql = isBaseLanguage ?
90             "SELECT Name FROM AD_Ref_List "
91             + "WHERE AD_Reference_ID=? AND Value=?" :
92             "SELECT t.Name FROM AD_Ref_List_Trl t"
93             + " INNER JOIN AD_Ref_List r ON (r.AD_Ref_List_ID=t.AD_Ref_List_ID) "
94             + "WHERE r.AD_Reference_ID=? AND r.Value=? AND t.AD_Language=?";
95         PreparedStatement pstmt = null;
96         try
97         {
98             pstmt = DB.prepareStatement (sql);
99             pstmt.setInt (1, AD_Reference_ID);
100             pstmt.setString(2, Value);
101             if (!isBaseLanguage)
102                 pstmt.setString(3, AD_Language);
103             ResultSet rs = pstmt.executeQuery ();
104             if (rs.next ())
105                 retValue = rs.getString(1);
106             rs.close ();
107             pstmt.close ();
108             pstmt = null;
109         }
110         catch (SQLException ex)
111         {
112             s_log.error ("getListName - " + sql + " - " + key, ex);
113         }
114         try
115         {
116             if (pstmt != null)
117                pstmt.close ();
118         }
119         catch (SQLException ex1)
120         {
121         }
122         pstmt = null;
123
124         // Save into Cache
125
if (retValue == null)
126         {
127             retValue = "";
128             s_log.warn("getListName - Not found " + key);
129         }
130         s_cache.put(key, retValue);
131         //
132
return retValue;
133     } // getListName
134

135
136     /** Logger */
137     private static Logger s_log = Logger.getCLogger (MRef_List.class);
138     /** Value Cache */
139     private static CCache s_cache = new CCache("MRef_List", 20);
140
141     /*************************************************************************/
142
143     /**
144      * Load Contructor
145      * @param ctx context
146      * @param rs result
147      */

148     public MRef_List (Properties ctx, ResultSet rs)
149     {
150         super (ctx, rs);
151     } // MRef_List
152

153     /**
154      * String Representation
155      * @return Name
156      */

157     public String JavaDoc toString()
158     {
159         return getName();
160     } // toString
161

162
163 } // MRef_List
164
Popular Tags