KickJava   Java API By Example, From Geeks To Geeks.

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


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.sql.*;
17 import java.util.*;
18
19 import org.compiere.util.*;
20
21 /**
22  * Column Access Model
23  *
24  * @author Jorg Janke
25  * @version $Id: MColumnAccess.java,v 1.2 2003/11/02 07:49:56 jjanke Exp $
26  */

27 public class MColumnAccess extends X_AD_Column_Access
28 {
29     /**
30      * Load Constructor
31      * @param ctx context
32      * @param rs result set
33      */

34     public MColumnAccess(Properties ctx, ResultSet rs)
35     {
36         super(ctx, rs);
37     } // MColumnAccess
38

39     /**
40      * String Representation
41      * @return info
42      */

43     public String JavaDoc toString()
44     {
45         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("MColumnAccess[");
46         sb.append("AD_Role_ID=").append(getAD_Role_ID())
47             .append(",AD_Table_ID=").append(getAD_Table_ID())
48             .append(",AD_Column_ID=").append(getAD_Column_ID())
49             .append(",Exclude=").append(isExclude());
50         sb.append("]");
51         return sb.toString();
52     } // toString
53

54     /**
55      * Extended String Representation
56      * @return extended info
57      */

58     public String JavaDoc toStringX (Properties ctx)
59     {
60         String JavaDoc in = Msg.getMsg(ctx, "Include");
61         String JavaDoc ex = Msg.getMsg(ctx, "Exclude");
62         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
63         sb.append(Msg.translate(ctx, "AD_Table_ID"))
64             .append("=").append(getTableName(ctx)).append(", ")
65             .append(Msg.translate(ctx, "AD_Column_ID"))
66             .append("=").append(getColumnName(ctx))
67             .append(" (").append(Msg.translate(ctx, "IsReadOnly")).append("=").append(isReadOnly())
68             .append(") - ").append(isExclude() ? ex : in);
69         return sb.toString();
70     } // toStringX
71

72     /** TableName */
73     private String JavaDoc m_tableName;
74     /** ColumnName */
75     private String JavaDoc m_columnName;
76
77     /**
78      * Get Table Name
79      * @param AD_Table_ID id
80      * @param ctx context
81      * @return table name
82      */

83     public String JavaDoc getTableName (Properties ctx)
84     {
85         if (m_tableName == null)
86             getColumnName(ctx);
87         return m_tableName;
88     } // getTableName
89

90     /**
91      * Get Column Name
92      * @param ctx context
93      * @return column name
94      */

95     public String JavaDoc getColumnName (Properties ctx)
96     {
97         if (m_columnName == null)
98         {
99             String JavaDoc sql = "SELECT t.TableName,c.ColumnName, t.AD_Table_ID "
100                 + "FROM AD_Table t INNER JOIN AD_Column c ON (t.AD_Table_ID=c.AD_Table_ID) "
101                 + "WHERE AD_Column_ID=?";
102             PreparedStatement pstmt = null;
103             try
104             {
105                 pstmt = DB.prepareCall(sql);
106                 pstmt.setInt(1, getAD_Column_ID());
107                 ResultSet rs = pstmt.executeQuery();
108                 if (rs.next())
109                 {
110                     m_tableName = rs.getString(1);
111                     m_columnName = rs.getString(2);
112                     if (rs.getInt(3) != getAD_Table_ID())
113                         log.error("getColumnName - AD_Table_ID inconsistent - Access=" + getAD_Table_ID() + " - Table=" + rs.getInt(3));
114                 }
115                 rs.close();
116                 pstmt.close();
117                 pstmt = null;
118             }
119             catch (Exception JavaDoc e)
120             {
121                 log.error("getColumnName", e);
122             }
123             try
124             {
125                 if (pstmt != null)
126                     pstmt.close();
127                 pstmt = null;
128             }
129             catch (Exception JavaDoc e)
130             {
131                 pstmt = null;
132             }
133             // Get Clear Text
134
String JavaDoc realName = Msg.translate(ctx, m_tableName + "_ID");
135             if (!realName.equals(m_tableName + "_ID"))
136                 m_tableName = realName;
137             m_columnName = Msg.translate(ctx, m_columnName);
138         }
139         return m_columnName;
140     } // getColumnName
141

142 } // MColumnAccess
143
Popular Tags