Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / engine / org / apache / derby / iapi / types / SQLNClob.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/iapi/types/SQLNClob.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/iapi/types/SQLNClob.java
new file mode 100644 (file)
index 0000000..e767e35
--- /dev/null
@@ -0,0 +1,249 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.iapi.types.SQLNClob\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.reference.SQLState;\r
+import org.apache.derby.iapi.error.StandardException;\r
+\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.services.sanity.SanityManager;\r
+\r
+import org.apache.derby.iapi.services.i18n.LocaleFinder;\r
+\r
+import java.util.Locale;\r
+\r
+import java.sql.Date;\r
+import java.sql.Time;\r
+import java.sql.Timestamp;\r
+import java.util.Calendar;\r
+\r
+/**\r
+ * SQLNClob satisfies the DataValueDescriptor interfaces (i.e., OrderableDataType). It implements a String\r
+ * holder, 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
+ *** ----- TODO: fix for NCLOB\r
+ * Because OrderableDataType is a subclass of DataType,\r
+ * SQLNationalLongvarchar can play a role in either a DataType/ValueRow\r
+ * or a OrderableDataType/KeyRow, interchangeably.\r
+ *** ----- TODO: fix for NCLOB\r
+ * SQLNationalLongvarchar is mostly the same as SQLLongvarchar, so it is implemented as a\r
+ * subclass of SQLLongvarchar.  Only those methods with different behavior are\r
+ * implemented here.\r
+ */\r
+public class SQLNClob\r
+        extends SQLNationalVarchar\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.NCLOB_NAME;\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 SQLNClob(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
+                SQLNClob result = new SQLNClob();\r
+                result.setLocaleFinder(getLocaleFinder());\r
+                return result;\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_NCLOB_ID;\r
+        }\r
+\r
+        /*\r
+         * constructors\r
+         */\r
+\r
+        public SQLNClob()\r
+        {\r
+        }\r
+\r
+        public SQLNClob(String val, LocaleFinder localeFinder)\r
+        {\r
+                super(val, 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
+         * DataValueDescriptor interface\r
+         */\r
+\r
+        /* @see DataValueDescriptor#typePrecedence */\r
+        public int typePrecedence()\r
+        {\r
+                return TypeId.CLOB_PRECEDENCE;\r
+        }\r
+\r
+        /** \r
+     ****  ---- TODO: Disable?\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()\r
+        {\r
+                return new SQLNationalVarchar();\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
+        /**\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
+        protected void setFrom(DataValueDescriptor theValue) throws StandardException {\r
+\r
+                setValue(((DataType) theValue).getNationalString(getLocaleFinder()));\r
+        }\r
+\r
+        /** @see java.lang.Object#hashCode */\r
+        public int hashCode()\r
+        {\r
+                return nationalHashCode();\r
+        }\r
+}\r