KickJava   Java API By Example, From Geeks To Geeks.

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


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.Serializable JavaDoc;
19
20 import org.compiere.util.*;
21
22 /**
23  * Info Class for Lookup SQL (ValueObject)
24  *
25  * @author Jorg Janke
26  * @version $Id: MLookupInfo.java,v 1.10 2003/11/06 07:09:09 jjanke Exp $
27  */

28 public final class MLookupInfo implements Serializable JavaDoc
29 {
30     /**
31      * Constructor.
32      * (called from MLookupFactory)
33      * @param sqlQuery SQL query
34      * @param keyColumn key column
35      * @param zoomWindow zoom window
36      * @param zoomWindowPO PO zoom window
37      * @param zoomQuery zoom query
38      */

39     public MLookupInfo (String JavaDoc sqlQuery, String JavaDoc tableName, String JavaDoc keyColumn, int zoomWindow, int zoomWindowPO,
40         MQuery zoomQuery)
41     {
42         if (sqlQuery == null)
43             throw new IllegalArgumentException JavaDoc("MLookupInfo - sqlQuery is null");
44         Query = sqlQuery;
45         if (keyColumn == null)
46             throw new IllegalArgumentException JavaDoc("MLookupInfo - keyColumn is null");
47         TableName = tableName;
48         KeyColumn = keyColumn;
49         ZoomWindow = zoomWindow;
50         ZoomWindowPO = zoomWindowPO;
51         ZoomQuery = zoomQuery;
52     } // MLookupInfo
53

54     /** SQL Query */
55     public String JavaDoc Query = null;
56     /** Table Name */
57     public String JavaDoc TableName = "";
58     /** Key Column */
59     public String JavaDoc KeyColumn = "";
60     /** Zoom Window */
61     public int ZoomWindow;
62     /** Zoom Window */
63     public int ZoomWindowPO;
64     /** Zoom Query */
65     public MQuery ZoomQuery = null;
66
67     /** Direct Access Query */
68     public String JavaDoc QueryDirect = "";
69     /** Parent Flag */
70     public boolean IsParent = false;
71     /** Validation code */
72     public String JavaDoc ValidationCode = "";
73     /** Validation flag */
74     public boolean IsValidated = true;
75
76     public Properties ctx = null;
77     public int WindowNo;
78
79     /** AD_Column_Info or AD_Process_Para */
80     public int Column_ID;
81     /** AD_Reference_ID */
82     public int DisplayType;
83     /** Real AD_Reference_ID */
84     public int AD_Reference_Value_ID;
85
86     /**
87      * String representation
88      * @return info
89      */

90     public String JavaDoc toString()
91     {
92         StringBuffer JavaDoc sb = new StringBuffer JavaDoc ("MLookupInfo[")
93             .append(KeyColumn).append(" - Direct=").append(QueryDirect)
94             .append("]");
95         return sb.toString();
96     } // toString
97

98     /*************************************************************************/
99
100     /**
101      * Get first AD_Reference_ID of a matching Reference Name.
102      * Can have SQL LIKE placeholders.
103      * (This is more a development tool than used for production)
104      * @param referenceName reference name
105      * @return AD_Reference_ID
106      */

107     public static int getAD_Reference_ID (String JavaDoc referenceName)
108     {
109         int retValue = 0;
110         String JavaDoc sql = "SELECT AD_Reference_ID,Name,ValidationType,IsActive "
111             + "FROM AD_Reference WHERE Name LIKE ?";
112         try
113         {
114             PreparedStatement pstmt = DB.prepareStatement(sql);
115             pstmt.setString(1, referenceName);
116             ResultSet rs = pstmt.executeQuery();
117             //
118
int i = 0;
119             int id = 0;
120             String JavaDoc refName = "";
121             String JavaDoc validationType = "";
122             boolean isActive = false;
123             while (rs.next())
124             {
125                 id = rs.getInt(1);
126                 if (i == 0)
127                     retValue = id;
128                 refName = rs.getString(2);
129                 validationType = rs.getString(3);
130                 isActive = rs.getString(4).equals("Y");
131                 Log.trace(Log.l3_Util, "AD_Reference Name=" + refName + ", ID=" + id + ", Type=" + validationType + ", Active=" + isActive);
132             }
133             rs.close();
134             pstmt.close();
135         }
136         catch (SQLException e)
137         {
138             Log.error("MLookupInfo.getAD_Reference_ID", e);
139         }
140         return retValue;
141     } // getAD_Reference_ID
142

143     /**
144      * Get first AD_Column_ID of matching ColumnName.
145      * Can have SQL LIKE placeholders.
146      * (This is more a development tool than used for production)
147      * @param columnName column name
148      * @return AD_Column_ID
149      */

150     public static int getAD_Column_ID (String JavaDoc columnName)
151     {
152         int retValue = 0;
153         String JavaDoc sql = "SELECT c.AD_Column_ID,c.ColumnName,t.TableName "
154             + "FROM AD_Column c, AD_Table t "
155             + "WHERE c.ColumnName LIKE ? AND c.AD_Table_ID=t.AD_Table_ID";
156         try
157         {
158             PreparedStatement pstmt = DB.prepareStatement(sql);
159             pstmt.setString(1, columnName);
160             ResultSet rs = pstmt.executeQuery();
161             //
162
int i = 0;
163             int id = 0;
164             String JavaDoc colName = "";
165             String JavaDoc tabName = "";
166             while (rs.next())
167             {
168                 id = rs.getInt(1);
169                 if (i == 0)
170                     retValue = id;
171                 colName = rs.getString(2);
172                 tabName = rs.getString(3);
173                 Log.trace(Log.l3_Util, "AD_Column Name=" + colName + ", ID=" + id + ", Table=" + tabName);
174             }
175             rs.close();
176             pstmt.close();
177         }
178         catch (SQLException e)
179         {
180             Log.error("MLookupInfo.getAD_Column_ID", e);
181         }
182         return retValue;
183     } // getAD_Reference_ID
184

185 } // MLookupInfo
186
Popular Tags