KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > extractor > sql > SqlAttributeExpression


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.extractor.sql;
24
25
26 public class SqlAttributeExpression extends SqlExpression
27 {
28
29     private static final String JavaDoc RCSRevision = "$Revision: 1.5 $";
30     private static final String JavaDoc RCSName = "$Name: $";
31
32     private String JavaDoc _attribute;
33     private String JavaDoc _tableInstance;
34
35     /**
36     @param tableInstance
37     @param attribute
38     @roseuid 3BD177CE00F9
39      */

40     public SqlAttributeExpression(String JavaDoc tableInstance, String JavaDoc attribute)
41     {
42         setTableInstance (tableInstance);
43         setAttribute(attribute);
44     }
45
46     /**
47     @roseuid 3BD177CE00C7
48      */

49     public SqlAttributeExpression()
50     {
51
52     }
53
54     /**
55     Access method for the _attribute property.
56     @return the current value of the _attribute property
57     @roseuid 3BD177CE01FE
58      */

59     public String JavaDoc getAttribute()
60     {
61         return _attribute;
62     }
63
64     /**
65     Sets the value of the _attribute property.
66     @param aAttribute the new value of the _attribute property
67     @roseuid 3BD177CE0230
68      */

69     public void setAttribute(String JavaDoc aAttribute)
70     {
71         _attribute = aAttribute;
72     }
73
74     /**
75     Access method for the _tableInstance property.
76     @return the current value of the _tableInstance property
77     @roseuid 3BD177CE02BC
78      */

79     public String JavaDoc getTableInstance()
80     {
81         return _tableInstance;
82     }
83
84     /**
85     Sets the value of the _tableInstance property.
86     @param aTableInstance the new value of the _tableInstance property
87     @roseuid 3BD177CE02F8
88      */

89     public void setTableInstance(String JavaDoc aTableInstance)
90     {
91         _tableInstance = aTableInstance;
92     }
93
94     public String JavaDoc getName()
95     {
96         return getAttribute();
97     }
98
99     public String JavaDoc toSql(Context context) {
100         return toSql(context,true);
101     }
102     
103     public String JavaDoc toSql(Context context, boolean putQuotes)
104     {
105         //Trace.enter(this,"toSql(Context context)");
106

107         StringBuffer JavaDoc retVal = new StringBuffer JavaDoc();
108
109         if (getAttribute().equals("*"))
110             retVal.append(_attribute);
111         else {
112             if (getTableInstance() != null) {
113                 if (putQuotes)
114                     retVal.append('"');
115                 retVal.append(_tableInstance);
116                 if (putQuotes)
117                     retVal.append('"');
118                 retVal.append(".");
119             }
120
121             if (putQuotes)
122                 retVal.append('"');
123             retVal.append(_attribute);
124             if (putQuotes)
125                 retVal.append('"');
126                 
127             if (context.outerJoinPredicate) {
128                 if (getTableInstance()
129                     .equalsIgnoreCase(context.innerTable.getName())) {
130                     retVal.append("(+)");
131                 }
132             }
133         }
134
135         //Trace.exit(this,"toSql(Context context)", retVal);
136
return retVal.toString() ;
137     }
138 }
139
Popular Tags