KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > compile > LOBConstantNode


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.LOBConstantNode
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.sql.compile;
23
24 import org.apache.derby.iapi.types.StringDataValue;
25 import org.apache.derby.iapi.types.TypeId;
26
27
28 import org.apache.derby.iapi.error.StandardException;
29
30 import org.apache.derby.iapi.services.compiler.MethodBuilder;
31
32 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;
33 import org.apache.derby.iapi.reference.SQLState;
34
35 import org.apache.derby.iapi.util.ReuseFactory;
36
37 import java.sql.Types JavaDoc;
38
39 public final class LOBConstantNode extends ConstantNode
40 {
41     /**
42      * Initializer for a LOBConstantNode. Parameters are:
43      *
44      * <ul>
45      * <li>arg1 The TypeId for the type of the node, or a string?</li>
46      * </ul>
47      *
48      * <p>
49      * - OR -
50      * </p>
51      *
52      * <ul>
53      * <li>arg1 A String containing the value of the constant</li>
54      * <li>arg2 The factory to get the TypeId and DataTypeServices factories from.</li>
55      * </ul>
56      *
57      * @exception StandardException
58      */

59     public void init(Object JavaDoc arg1)
60         throws StandardException
61     {
62         if (arg1 instanceof TypeId)
63         {
64             super.init(
65                         arg1,
66                         Boolean.TRUE,
67                         ReuseFactory.getInteger(0));
68         }
69         else
70         {
71             String JavaDoc val = (String JavaDoc) arg1;
72
73             super.init(
74                 TypeId.CHAR_ID,
75                 (val == null) ? Boolean.TRUE : Boolean.FALSE,
76                 (val != null) ?
77                     ReuseFactory.getInteger(val.length()) :
78                     ReuseFactory.getInteger(0));
79
80             setValue(getDataValueFactory().getCharDataValue(val));
81         }
82     }
83
84     public void init(
85                     Object JavaDoc newValue,
86                     Object JavaDoc newLength)
87         throws StandardException
88     {
89         String JavaDoc val = (String JavaDoc) newValue;
90         int newLen = ((Integer JavaDoc) newLength).intValue();
91
92         super.init(
93              TypeId.CHAR_ID,
94              (val == null) ? Boolean.TRUE : Boolean.FALSE,
95              newLength);
96
97         if (val.length() > newLen)
98         {
99             throw StandardException.newException(SQLState.LANG_STRING_TRUNCATION, "CHAR", val, String.valueOf(newLen));
100         }
101
102         // Blank pad the string if necessesary
103
while (val.length() < newLen)
104         {
105             val = val + ' ';
106         }
107
108         setValue(getDataValueFactory().getCharDataValue(val));
109     }
110
111     /**
112      * Return the value from this LOBConstantNode
113      *
114      * @return The value of this LOBConstantNode.
115      *
116      * @exception StandardException Thrown on error
117      */

118
119     public String JavaDoc getString() throws StandardException
120     {
121         return value.getString();
122     }
123
124     /**
125      * Return the length
126      *
127      * @return The length of the value this node represents
128      *
129      * @exception StandardException Thrown on error
130      */

131
132     //public int getLength() throws StandardException
133
//{
134
// return value.getLength();
135
//}
136

137     /**
138      * Return an Object representing the bind time value of this
139      * expression tree. If the expression tree does not evaluate to
140      * a constant at bind time then we return null.
141      * This is useful for bind time resolution of VTIs.
142      * RESOLVE: What do we do for primitives?
143      *
144      * @return An Object representing the bind time value of this expression tree.
145      * (null if not a bind time constant.)
146      *
147      * @exception StandardException Thrown on error
148      */

149     Object JavaDoc getConstantValueAsObject() throws StandardException
150     {
151         return value.getString();
152     }
153
154     /**
155      * This generates the proper constant. It is implemented
156      * by every specific constant node (e.g. IntConstantNode).
157      *
158      * @param acb The ExpressionClassBuilder for the class being built
159      * @param mb The method the code to place the code
160      *
161      * @exception StandardException Thrown on error
162      */

163     void generateConstant(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException
164     {
165         // The generated java is the expression:
166
// "#getString()"
167
mb.push(getString());
168     }
169 }
170
Popular Tags