01: /*
02:
03: Derby - Class org.apache.derby.impl.sql.compile.SQLBooleanConstantNode
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (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;
38:
39: public class SQLBooleanConstantNode extends ConstantNode {
40: /**
41: * Initializer for a SQLBooleanConstantNode.
42: *
43: * @param newValue A String containing the value of the constant: true, false, unknown
44: *
45: * @exception StandardException
46: */
47:
48: public void init(Object newValue) throws StandardException {
49: String strVal = (String) newValue;
50: Boolean val = null;
51:
52: if (SanityManager.DEBUG) {
53: SanityManager.ASSERT(
54: (StringUtil.SQLEqualsIgnoreCase(strVal, "true"))
55: || (StringUtil.SQLEqualsIgnoreCase(strVal,
56: "false"))
57: || (StringUtil.SQLEqualsIgnoreCase(strVal,
58: "unknown")), "String \"" + strVal
59: + "\" cannot be converted to a SQLBoolean");
60: }
61:
62: if (StringUtil.SQLEqualsIgnoreCase(strVal, "true"))
63: val = Boolean.TRUE;
64: else if (StringUtil.SQLEqualsIgnoreCase(strVal, "false"))
65: val = Boolean.FALSE;
66:
67: /*
68: ** RESOLVE: The length is fixed at 1, even for nulls.
69: ** Is that OK?
70: */
71:
72: /* Fill in the type information in the parent ValueNode */
73: super .init(TypeId.BOOLEAN_ID, Boolean.TRUE, ReuseFactory
74: .getInteger(1));
75:
76: if (val == null) {
77: setValue(getTypeServices().getNull());
78: } else {
79: setValue(getDataValueFactory().getDataValue(
80: val.booleanValue()));
81: }
82: }
83:
84: /**
85: * This generates the proper constant. It is implemented
86: * by every specific constant node (e.g. IntConstantNode).
87: *
88: * @param acb The ExpressionClassBuilder for the class being built
89: * @param mb The method the expression will go into
90: *
91: *
92: * @exception StandardException Thrown on error
93: */
94: void generateConstant(ExpressionClassBuilder acb, MethodBuilder mb)
95: throws StandardException {
96: mb.push(value.getBoolean());
97: }
98: }
|