KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.SQLBooleanConstantNode
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.TypeId;
25
26 import org.apache.derby.iapi.error.StandardException;
27
28 import org.apache.derby.iapi.services.compiler.MethodBuilder;
29
30 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;
31 import org.apache.derby.iapi.types.BooleanDataValue;
32
33 import org.apache.derby.iapi.services.sanity.SanityManager;
34
35 import org.apache.derby.iapi.util.ReuseFactory;
36 import org.apache.derby.iapi.util.StringUtil;
37 import java.sql.Types JavaDoc;
38
39 public class SQLBooleanConstantNode extends ConstantNode
40 {
41     /**
42      * Initializer for a SQLBooleanConstantNode.
43      *
44      * @param newValue A String containing the value of the constant: true, false, unknown
45      *
46      * @exception StandardException
47      */

48
49     public void init(
50                     Object JavaDoc newValue)
51         throws StandardException
52     {
53         String JavaDoc strVal = (String JavaDoc) newValue;
54         Boolean JavaDoc val = null;
55
56         if (SanityManager.DEBUG)
57         {
58             SanityManager.ASSERT((StringUtil.SQLEqualsIgnoreCase(strVal,"true")) ||
59                                 (StringUtil.SQLEqualsIgnoreCase(strVal,"false")) ||
60                                 (StringUtil.SQLEqualsIgnoreCase(strVal,"unknown")),
61                                 "String \"" + strVal +
62                                 "\" cannot be converted to a SQLBoolean");
63         }
64
65         if (StringUtil.SQLEqualsIgnoreCase(strVal,"true"))
66             val = Boolean.TRUE;
67         else if (StringUtil.SQLEqualsIgnoreCase(strVal,"false"))
68             val = Boolean.FALSE;
69
70         /*
71         ** RESOLVE: The length is fixed at 1, even for nulls.
72         ** Is that OK?
73         */

74
75         /* Fill in the type information in the parent ValueNode */
76         super.init(
77              TypeId.BOOLEAN_ID,
78              Boolean.TRUE,
79              ReuseFactory.getInteger(1));
80
81         if ( val == null )
82         {
83             setValue(getTypeServices().getNull() );
84         }
85         else
86         {
87             setValue(getDataValueFactory().getDataValue(val.booleanValue()));
88         }
89     }
90
91     /**
92      * This generates the proper constant. It is implemented
93      * by every specific constant node (e.g. IntConstantNode).
94      *
95      * @param acb The ExpressionClassBuilder for the class being built
96      * @param mb The method the expression will go into
97      *
98      *
99      * @exception StandardException Thrown on error
100      */

101     void generateConstant(ExpressionClassBuilder acb, MethodBuilder mb)
102         throws StandardException
103     {
104         mb.push(value.getBoolean());
105     }
106 }
107
Popular Tags