Source Code Cross Referenced for BooleanConstantNode.java in  » Database-DBMS » db-derby-10.2 » org » apache » derby » impl » sql » compile » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » db derby 10.2 » org.apache.derby.impl.sql.compile 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Derby - Class org.apache.derby.impl.sql.compile.BooleanConstantNode
004:
005:           Licensed to the Apache Software Foundation (ASF) under one or more
006:           contributor license agreements.  See the NOTICE file distributed with
007:           this work for additional information regarding copyright ownership.
008:           The ASF licenses this file to you under the Apache License, Version 2.0
009:           (the "License"); you may not use this file except in compliance with
010:           the License.  You may obtain a copy of the License at
011:
012:              http://www.apache.org/licenses/LICENSE-2.0
013:
014:           Unless required by applicable law or agreed to in writing, software
015:           distributed under the License is distributed on an "AS IS" BASIS,
016:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:           See the License for the specific language governing permissions and
018:           limitations under the License.
019:
020:         */
021:
022:        package org.apache.derby.impl.sql.compile;
023:
024:        import org.apache.derby.iapi.services.compiler.MethodBuilder;
025:
026:        import org.apache.derby.iapi.error.StandardException;
027:
028:        import org.apache.derby.iapi.sql.compile.Optimizable;
029:
030:        import org.apache.derby.iapi.types.BooleanDataValue;
031:        import org.apache.derby.iapi.types.DataValueDescriptor;
032:        import org.apache.derby.iapi.types.TypeId;
033:
034:        import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;
035:
036:        import org.apache.derby.iapi.util.ReuseFactory;
037:        import java.sql.Types;
038:
039:        public final class BooleanConstantNode extends ConstantNode {
040:            /* Cache actual value to save overhead and
041:             * throws clauses.
042:             */
043:            boolean booleanValue;
044:            boolean unknownValue;
045:
046:            /**
047:             * Initializer for a BooleanConstantNode.
048:             *
049:             * @param arg1	A boolean containing the value of the constant OR The TypeId for the type of the node
050:             *
051:             * @exception StandardException
052:             */
053:            public void init(Object arg1) throws StandardException {
054:                /*
055:                 ** RESOLVE: The length is fixed at 1, even for nulls.
056:                 ** Is that OK?
057:                 */
058:
059:                if (arg1 instanceof  Boolean) {
060:                    /* Fill in the type information in the parent ValueNode */
061:                    super .init(TypeId.BOOLEAN_ID, Boolean.FALSE, ReuseFactory
062:                            .getInteger(1));
063:
064:                    booleanValue = ((Boolean) arg1).booleanValue();
065:                    super .setValue(getDataValueFactory().getDataValue(
066:                            booleanValue));
067:                } else {
068:                    super .init(arg1, Boolean.TRUE, ReuseFactory.getInteger(0));
069:                    unknownValue = true;
070:                }
071:            }
072:
073:            /**
074:             * Return the value from this BooleanConstantNode
075:             *
076:             * @return	The value of this BooleanConstantNode.
077:             *
078:             */
079:
080:            //public boolean	getBoolean()
081:            //{
082:            //	return booleanValue;
083:            //}
084:            /**
085:             * Return the length
086:             *
087:             * @return	The length of the value this node represents
088:             *
089:             * @exception StandardException		Thrown on error
090:             */
091:
092:            //public int	getLength() throws StandardException
093:            //{
094:            //	return value.getLength();
095:            //}
096:            /**
097:             * Return an Object representing the bind time value of this
098:             * expression tree.  If the expression tree does not evaluate to
099:             * a constant at bind time then we return null.
100:             * This is useful for bind time resolution of VTIs.
101:             * RESOLVE: What do we do for primitives?
102:             *
103:             * @return	An Object representing the bind time value of this expression tree.
104:             *			(null if not a bind time constant.)
105:             *
106:             */
107:            Object getConstantValueAsObject() {
108:                return booleanValue ? Boolean.TRUE : Boolean.FALSE;
109:            }
110:
111:            /**
112:             * Return the value as a string.
113:             *
114:             * @return The value as a string.
115:             *
116:             */
117:            String getValueAsString() {
118:                if (booleanValue) {
119:                    return "true";
120:                } else {
121:                    return "false";
122:                }
123:            }
124:
125:            /**
126:             * Does this represent a true constant.
127:             *
128:             * @return Whether or not this node represents a true constant.
129:             */
130:            boolean isBooleanTrue() {
131:                return (booleanValue && !unknownValue);
132:            }
133:
134:            /**
135:             * Does this represent a false constant.
136:             *
137:             * @return Whether or not this node represents a false constant.
138:             */
139:            boolean isBooleanFalse() {
140:                return (!booleanValue && !unknownValue);
141:            }
142:
143:            /**
144:             * The default selectivity for value nodes is 50%.  This is overridden
145:             * in specific cases, such as the RelationalOperators.
146:             */
147:            public double selectivity(Optimizable optTable) {
148:                if (isBooleanTrue()) {
149:                    return 1.0;
150:                } else {
151:                    return 0.0;
152:                }
153:            }
154:
155:            /**
156:             * Eliminate NotNodes in the current query block.  We traverse the tree, 
157:             * inverting ANDs and ORs and eliminating NOTs as we go.  We stop at 
158:             * ComparisonOperators and boolean expressions.  We invert 
159:             * ComparisonOperators and replace boolean expressions with 
160:             * boolean expression = false.
161:             * NOTE: Since we do not recurse under ComparisonOperators, there
162:             * still could be NotNodes left in the tree.
163:             *
164:             * @param	underNotNode		Whether or not we are under a NotNode.
165:             *							
166:             *
167:             * @return		The modified expression
168:             *
169:             */
170:            ValueNode eliminateNots(boolean underNotNode) {
171:                if (!underNotNode) {
172:                    return this ;
173:                }
174:
175:                booleanValue = !booleanValue;
176:                super 
177:                        .setValue(getDataValueFactory().getDataValue(
178:                                booleanValue));
179:
180:                return this ;
181:            }
182:
183:            /**
184:             * This generates the proper constant.  It is implemented
185:             * by every specific constant node (e.g. IntConstantNode).
186:             *
187:             * @param acb	The ExpressionClassBuilder for the class being built
188:             * @param mb	The method the code to place the code
189:             *
190:             */
191:            void generateConstant(ExpressionClassBuilder acb, MethodBuilder mb) {
192:                mb.push(booleanValue);
193:            }
194:
195:            /**
196:             * Set the value in this ConstantNode.
197:             */
198:            public void setValue(DataValueDescriptor value) {
199:                super .setValue(value);
200:                unknownValue = true;
201:                try {
202:                    if (value != null && value.isNotNull().getBoolean()) {
203:                        booleanValue = value.getBoolean();
204:                        unknownValue = false;
205:                    }
206:                } catch (StandardException se) {
207:                }
208:            } // end of setValue
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.