Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / iapi / types / SQLNationalChar.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/iapi/types/SQLNationalChar.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/iapi/types/SQLNationalChar.java
new file mode 100644 (file)
index 0000000..936bf6f
--- /dev/null
@@ -0,0 +1,292 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.iapi.types.SQLNationalChar\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.iapi.types;\r
+\r
+import org.apache.derby.iapi.types.DataTypeDescriptor;\r
+import org.apache.derby.iapi.types.DataValueDescriptor;\r
+import org.apache.derby.iapi.types.TypeId;\r
+import org.apache.derby.iapi.types.StringDataValue;\r
+import org.apache.derby.iapi.types.DataValueDescriptor;\r
+import org.apache.derby.iapi.types.BooleanDataValue;\r
+import org.apache.derby.iapi.reference.SQLState;\r
+\r
+import org.apache.derby.iapi.types.Orderable;\r
+\r
+import org.apache.derby.iapi.services.io.Storable;\r
+import org.apache.derby.iapi.services.io.FormatIdUtil;\r
+import org.apache.derby.iapi.services.io.StoredFormatIds;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+import org.apache.derby.iapi.util.StringUtil;\r
+\r
+import org.apache.derby.iapi.services.i18n.LocaleFinder;\r
+\r
+import java.io.ObjectOutput;\r
+import java.io.ObjectInput;\r
+import java.io.IOException;\r
+import java.io.UTFDataFormatException;\r
+import java.io.EOFException;\r
+import java.sql.Date;\r
+import java.sql.ResultSet;\r
+import java.sql.SQLException;\r
+import java.sql.Time;\r
+import java.sql.Timestamp;\r
+import java.util.Locale;\r
+import java.util.Calendar;\r
+\r
+/**\r
+ * SQLNationalChar satisfies the DataValueDescriptor\r
+ * interfaces (i.e., OrderableDataType). It implements an String holder,\r
+ * e.g. for storing a column value; it can be specified\r
+ * when constructed to not allow nulls. Nullability cannot be changed\r
+ * after construction.\r
+ * <p>\r
+ * Because OrderableDataType is a subclass of DataType,\r
+ * SQLNationalChar can play a role in either a DataType/ValueRow\r
+ * or a OrderableDataType/KeyRow, interchangeably.\r
+ */\r
+public class SQLNationalChar\r
+       extends SQLChar\r
+{\r
+\r
+       /*\r
+        * DataValueDescriptor interface.\r
+        *\r
+        * These are actually all implemented in the super-class, but we need\r
+        * to duplicate some of them here so they can be called by byte-code\r
+        * generation, which needs to know the class the method appears in.\r
+        */\r
+\r
+       public String getTypeName()\r
+       {\r
+               return TypeId.NATIONAL_CHAR_NAME;\r
+       }\r
+\r
+       /*\r
+        * Storable interface, implies Externalizable, TypedFormat\r
+        */\r
+\r
+       /**\r
+               Return my format identifier.\r
+\r
+               @see org.apache.derby.iapi.services.io.TypedFormat#getTypeFormatId\r
+       */\r
+       public int getTypeFormatId() {\r
+               return StoredFormatIds.SQL_NATIONAL_CHAR_ID;\r
+       }\r
+\r
+       /*\r
+        * DataValueDescriptor interface\r
+        */\r
+\r
+       /** @see DataValueDescriptor#getClone */\r
+       public DataValueDescriptor getClone()\r
+       {\r
+               try\r
+               {\r
+                       /* NOTE: We pass instance variables for locale info \r
+                        * because we only call methods when we know that we\r
+                        * will need locale info.\r
+                        */\r
+                       return new SQLNationalChar(getString(), getLocaleFinder());\r
+               }\r
+               catch (StandardException se)\r
+               {\r
+                       if (SanityManager.DEBUG)\r
+                               SanityManager.THROWASSERT("Unexpected exception", se);\r
+                       return null;\r
+               }\r
+       }\r
+\r
+       /**\r
+        * @see DataValueDescriptor#getNewNull\r
+        *\r
+        */\r
+       public DataValueDescriptor getNewNull()\r
+       {\r
+               /* NOTE: We pass instance variables for locale info \r
+                * because we only call methods when we know that we\r
+                * will need locale info.\r
+                */\r
+               SQLNationalChar result = new SQLNationalChar();\r
+               result.setLocaleFinder(getLocaleFinder());\r
+               return result;\r
+       }\r
+\r
+       /*\r
+        * class interface\r
+        */\r
+\r
+       /*\r
+        * constructors\r
+        */\r
+\r
+       /**\r
+               no-arg constructor, required by Formattable.\r
+       */\r
+       public SQLNationalChar()\r
+       {\r
+       }\r
+\r
+       public SQLNationalChar(String val, LocaleFinder localeFinder)\r
+       {\r
+               super(val);\r
+               setLocaleFinder(localeFinder);\r
+       }\r
+\r
+       /**\r
+        * @see DataValueDescriptor#getDate\r
+        * @exception StandardException thrown on failure to convert\r
+        */\r
+       public Date     getDate( Calendar cal) throws StandardException\r
+       {\r
+               return nationalGetDate(cal);\r
+       }\r
+\r
+       /**\r
+        * @see DataValueDescriptor#getTime\r
+        * @exception StandardException thrown on failure to convert\r
+        */\r
+       public Time getTime( Calendar cal) throws StandardException\r
+       {\r
+               return nationalGetTime(cal);\r
+       }\r
+\r
+       /**\r
+        * @see DataValueDescriptor#getTimestamp\r
+        * @exception StandardException thrown on failure to convert\r
+        */\r
+       public Timestamp getTimestamp( Calendar cal) throws StandardException\r
+       {\r
+               return nationalGetTimestamp(cal);\r
+       }\r
+\r
+       /**\r
+        * @see DataValueDescriptor#setValue\r
+        *\r
+        * @exception StandardException         Thrown on error\r
+        */\r
+       public void setValue(Date theValue, Calendar cal) throws StandardException\r
+       {\r
+               setValue(getDateFormat( cal).format(theValue));\r
+       }\r
+\r
+       /**\r
+        * @see DataValueDescriptor#setValue\r
+        *\r
+        * @exception StandardException         Thrown on error\r
+        */\r
+       public void setValue(Time theValue, Calendar cal) throws StandardException\r
+       {\r
+               setValue(getTimeFormat( cal).format(theValue));\r
+       }\r
+\r
+       /**\r
+        * @see DataValueDescriptor#setValue\r
+        *\r
+        * @exception StandardException         Thrown on error\r
+        */\r
+       public void setValue(Timestamp theValue, Calendar cal) throws StandardException\r
+       {\r
+               setValue(getTimestampFormat(cal).format(theValue));\r
+       }\r
+\r
+       /*\r
+        * DataValueDescriptor interface\r
+        */\r
+\r
+       /** @see DataValueDescriptor#typePrecedence */\r
+       public int typePrecedence()\r
+       {\r
+               return TypeId.CHAR_PRECEDENCE;\r
+       }\r
+\r
+\r
+       /** \r
+        * Compare two SQLChars.  This method will be overriden in the\r
+        * National char wrappers so that the appropriate comparison\r
+        * is done.\r
+        *\r
+        * @exception StandardException         Thrown on error\r
+        */\r
+        protected int stringCompare(SQLChar char1, SQLChar char2)\r
+                throws StandardException\r
+        {\r
+                return char1.stringCollatorCompare(char2);\r
+        }\r
+\r
+       /**\r
+        * Get a SQLVarchar for a built-in string function.  \r
+        * (Could be either a SQLVarchar or SQLNationalVarchar.)\r
+        *\r
+        * @return a SQLVarchar or SQLNationalVarchar.\r
+        */\r
+       protected StringDataValue getNewVarchar() throws StandardException\r
+       {\r
+               SQLNationalVarchar result = new SQLNationalVarchar();\r
+               result.setLocaleFinder(getLocaleFinder());\r
+               return result;\r
+       }\r
+\r
+       /**\r
+        * Normalization method - this method may be called when putting\r
+        * a value into a SQLChar, for example, when inserting into a SQLChar\r
+        * column.  See NormalizeResultSet in execution.\r
+        *\r
+        * @param desiredType   The type to normalize the source column to\r
+        * @param source                The value to normalize\r
+        *\r
+        * @exception StandardException                         Thrown for null into\r
+        *                                                                                      non-nullable column, and for\r
+        *                                                                                      truncation error\r
+        */\r
+\r
+       public void normalize(\r
+                               DataTypeDescriptor desiredType,\r
+                               DataValueDescriptor source)\r
+                                       throws StandardException\r
+       {\r
+\r
+               normalize(desiredType, ((DataType) source).getNationalString(getLocaleFinder()));\r
+\r
+       }\r
+       protected void setFrom(DataValueDescriptor theValue) throws StandardException {\r
+\r
+               setValue(((DataType) theValue).getNationalString(getLocaleFinder()));\r
+       }\r
+\r
+       /** \r
+        * Return whether or not this is a national character datatype.\r
+        */\r
+       protected boolean isNationalString()\r
+       {\r
+               return true;\r
+       }\r
+\r
+       /** @see java.lang.Object#hashCode */\r
+       public int hashCode()\r
+       {\r
+               return nationalHashCode();\r
+       }\r
+}\r