Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / impl / sql / compile / CharConstantNode.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/sql/compile/CharConstantNode.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/sql/compile/CharConstantNode.java
new file mode 100644 (file)
index 0000000..f112800
--- /dev/null
@@ -0,0 +1,191 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.sql.compile.CharConstantNode\r
+\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to you under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+ */\r
+\r
+package        org.apache.derby.impl.sql.compile;\r
+\r
+import org.apache.derby.iapi.types.StringDataValue;\r
+import org.apache.derby.iapi.types.TypeId;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.services.compiler.MethodBuilder;\r
+\r
+import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;\r
+import org.apache.derby.iapi.reference.SQLState;\r
+\r
+import org.apache.derby.iapi.util.ReuseFactory;\r
+\r
+import java.util.Vector;\r
+\r
+public final class CharConstantNode extends ConstantNode\r
+{\r
+       /**\r
+        * Initializer for a CharConstantNode.\r
+        *\r
+        * @param arg1  A String containing the value of the constant OR The TypeId for the type of the node\r
+        *\r
+        * @exception StandardException\r
+        */\r
+       public void init(\r
+                                       Object arg1)\r
+               throws StandardException\r
+       {\r
+               if (arg1 instanceof TypeId)\r
+               {\r
+                       super.init(\r
+                                               arg1,\r
+                                               Boolean.TRUE,\r
+                                               ReuseFactory.getInteger(0));\r
+               }\r
+               else\r
+               {\r
+                       String val = (String) arg1;\r
+\r
+                       super.init(\r
+                               TypeId.CHAR_ID,\r
+                               (val == null) ? Boolean.TRUE : Boolean.FALSE,\r
+                               (val != null) ?\r
+                                       ReuseFactory.getInteger(val.length()) :\r
+                                       ReuseFactory.getInteger(0));\r
+\r
+                       setValue(getDataValueFactory().getCharDataValue(val));\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Initializer for a CharConstantNode of a specific length.\r
+        *\r
+        * @param newValue      A String containing the value of the constant\r
+        * @param newLength The length of the new value of the constant\r
+        *\r
+        * @exception StandardException\r
+        */\r
+       public void init(\r
+                                       Object newValue, \r
+                                       Object newLength)\r
+               throws StandardException\r
+       {\r
+               String val = (String) newValue;\r
+               int newLen = ((Integer) newLength).intValue();\r
+\r
+               super.init(\r
+                        TypeId.CHAR_ID,\r
+                        (val == null) ? Boolean.TRUE : Boolean.FALSE,\r
+                        newLength);\r
+\r
+               if (val.length() > newLen)\r
+               {\r
+                       throw StandardException.newException(SQLState.LANG_STRING_TRUNCATION, "CHAR", val, String.valueOf(newLen));\r
+               }\r
+\r
+               // Blank pad the string if necessesary\r
+               while (val.length() < newLen)\r
+               {\r
+                       val = val + ' ';\r
+               }\r
+\r
+               setValue(getDataValueFactory().getCharDataValue(val));\r
+       }\r
+\r
+       /**\r
+        * Return the value from this CharConstantNode\r
+        *\r
+        * @return      The value of this CharConstantNode.\r
+        *\r
+        * @exception StandardException         Thrown on error\r
+        */\r
+\r
+       public String   getString() throws StandardException\r
+       {\r
+               return value.getString();\r
+       }\r
+\r
+       /**\r
+        * Return the length\r
+        *\r
+        * @return      The length of the value this node represents\r
+        *\r
+        * @exception StandardException         Thrown on error\r
+        */\r
+\r
+       //public int    getLength() throws StandardException\r
+       //{\r
+       //      return value.getLength();\r
+       //}\r
+\r
+       /**\r
+        * Return an Object representing the bind time value of this\r
+        * expression tree.  If the expression tree does not evaluate to\r
+        * a constant at bind time then we return null.\r
+        * This is useful for bind time resolution of VTIs.\r
+        * RESOLVE: What do we do for primitives?\r
+        *\r
+        * @return      An Object representing the bind time value of this expression tree.\r
+        *                      (null if not a bind time constant.)\r
+        *\r
+        * @exception StandardException         Thrown on error\r
+        */\r
+       Object getConstantValueAsObject() throws StandardException \r
+       {\r
+               return value.getString();\r
+       }\r
+       \r
+       public ValueNode bindExpression(\r
+                       FromList fromList, SubqueryList subqueryList,\r
+                       Vector  aggregateVector)\r
+       throws StandardException\r
+       {\r
+               //The DTD for this character constant should get its collation type\r
+               //from the schema it is getting compiled in.\r
+               setCollationUsingCompilationSchema(\r
+                               StringDataValue.COLLATION_DERIVATION_IMPLICIT);\r
+           //Once we have the collation type, we should check if the value\r
+           //associated with this node should change from \r
+           //SQLChar/SQLVarchar/SQLLongvarchar/SQLClob\r
+           //to\r
+           //CollatorSQLChar/CollatoSQLVarchar/CollatoSQLLongvarchar/CollatoSQLClob.\r
+           //By default, the value associated with char constants are SQLxxx\r
+           //kind because that is what is needed for UCS_BASIC collation. But\r
+           //if at this bind time, we find that the char constant's collation\r
+           //type is territory based, then we should change value from SQLxxx\r
+           //to CollatorSQLxxx. That is what is getting done below.\r
+           value = ((StringDataValue)value).getValue(\r
+                       getLanguageConnectionContext().getDataValueFactory().getCharacterCollator(\r
+                                       getTypeServices().getCollationType()));\r
+               return this;\r
+       }\r
+\r
+       /**\r
+        * This generates the proper constant.  It is implemented\r
+        * by every specific constant node (e.g. IntConstantNode).\r
+        *\r
+        * @param acb   The ExpressionClassBuilder for the class being built\r
+        * @param mb    The method the code to place the code\r
+        *\r
+        * @exception StandardException         Thrown on error\r
+        */\r
+       void generateConstant(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException\r
+       {\r
+               // The generated java is the expression:\r
+               // "#getString()"\r
+               mb.push(getString());\r
+       }\r
+}\r