KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > extractor > algebra > SqlTypeAtom


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.algebra;
24
25 import java.sql.Types JavaDoc;
26
27 import org.xquark.extractor.common.Debug;
28 import org.xquark.jdbc.typing.DbType;
29
30
31 public final class SqlTypeAtom extends SqlType
32 {
33    private static final String JavaDoc RCSRevision = "$Revision: 1.9 $";
34     private static final String JavaDoc RCSName = "$Name: $";
35
36     private DbType _type = null;
37     private String JavaDoc _name = null;
38     private String JavaDoc _relationName = null;
39
40     /**
41     @param type
42     @param name
43     @roseuid 3BD145850305
44      */

45
46     public SqlTypeAtom(DbType type, String JavaDoc name)
47     {
48         setType(type);
49         setName(name);
50     }
51
52     public SqlTypeAtom(DbType type, String JavaDoc name, int multiplicity )
53     {
54         setType(type);
55         setName(name);
56         setMultiplicity(multiplicity);
57     }
58
59     public Object JavaDoc clone()
60     {
61         //Trace.enter(this, "clone()");
62
try {
63             SqlTypeAtom retVal = (SqlTypeAtom)super.clone();
64             retVal.setName((getName() == null) ? null : new String JavaDoc(getName()) );
65             retVal.setType(getType() ==null ? null : (DbType)getType().clone());
66             //Trace.exit(this, "clone()");
67
return retVal;
68         }
69         catch (CloneNotSupportedException JavaDoc ex) {
70             Debug.assertTrue(false, "error in implementation of clone");
71             //Trace.exit(this, "clone()");
72
return null;
73         }
74     }
75
76     /**
77     Access method for the _type property.
78
79     @return the current value of the _type property
80      */

81     public DbType getType()
82     {
83         return _type;
84     }
85
86     /**
87     Sets the value of the _type property.
88
89     @param aType the new value of the _type property
90      */

91     public void setType(DbType aType)
92     {
93         _type = aType;
94     }
95
96     /**
97     Access method for the _name property.
98
99     @return the current value of the _name property
100      */

101     public String JavaDoc getName()
102     {
103         return _name;
104     }
105
106     /**
107     Sets the value of the _name property.
108
109     @param aName the new value of the _name property
110      */

111     public void setName(String JavaDoc aName)
112     {
113         _name = aName;
114     }
115
116     public void setRelationName(String JavaDoc relationName)
117     {
118         _relationName = relationName;
119     }
120
121     public String JavaDoc getRelationName()
122     {
123         return _relationName;
124     }
125
126     public boolean isRelation()
127     {
128         return false;
129     }
130
131     public boolean isTuple()
132     {
133         return false;
134     }
135
136     public boolean isColumn()
137     {
138         return MANY == _multiplicity;
139     }
140
141     public boolean isAtom()
142     {
143         return ONE == _multiplicity;
144     }
145
146
147
148     public boolean isBoolean()
149     {
150         int typeCode = _type.getPrimitiveTypeCode();
151         return Types.BIT == typeCode;
152     }
153
154     public boolean isNumeric() { return _type.isNumeric();}
155
156     public boolean isInteger() { return _type.isInteger();}
157
158     public boolean isString() { return _type.isString();};
159
160     public boolean isDataTime() { return _type.isDataTime();}
161
162     public boolean isNull() { return _type.isNull();}
163
164     public boolean isOracleRowid()
165     {
166         return _type.getJDBCType() == DbType.ORACLE_ROWID;
167     }
168
169     public String JavaDoc pprint ()
170     {
171         String JavaDoc retVal = null;
172         retVal = MANY == _multiplicity ? "Column" : "Value";
173         retVal += "(" + ppprint()+")";
174
175         return retVal;
176     }
177
178     String JavaDoc ppprint()
179     {
180         return _name + ":" + _type.getName();
181     }
182
183     public boolean isCompatibleTo(SqlType type)
184     {
185         boolean retVal;
186         if ( type instanceof SqlTypeAtom ) {
187             SqlTypeAtom tmpType = (SqlTypeAtom)type;
188             retVal = _type.isCompatibleTo(tmpType.getType());
189         }
190         else
191             retVal = false;
192
193         return retVal;
194     }
195 }
196
Popular Tags