Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / engine / org / apache / derby / impl / load / ImportResultSetMetaData.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/load/ImportResultSetMetaData.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/load/ImportResultSetMetaData.java
new file mode 100644 (file)
index 0000000..51a29f2
--- /dev/null
@@ -0,0 +1,131 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.load.ImportResultSetMetaData\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.load;\r
+\r
+import java.sql.SQLException;\r
+import org.apache.derby.vti.VTIMetaDataTemplate;\r
+\r
+import org.apache.derby.iapi.reference.Limits;\r
+\r
+class ImportResultSetMetaData extends VTIMetaDataTemplate {\r
+\r
+  private final int numberOfColumns;\r
+  private final String[] columnNames;\r
+  private final int[] columnWidths;\r
+  // types of the table columns that the data is imported. \r
+  private final int[] tableColumnTypes ; \r
+\r
+  public ImportResultSetMetaData(int numberOfColumns, \r
+                                 String[] columnNames,\r
+                                 int[] columnWidths, \r
+                                 int[] tableColumnTypes) {\r
+    this.numberOfColumns = numberOfColumns;\r
+    this.columnNames = columnNames;\r
+    this.columnWidths = columnWidths;\r
+    this.tableColumnTypes = tableColumnTypes;\r
+  }\r
+\r
+       public int getColumnCount() {\r
+    return numberOfColumns;\r
+  }\r
+\r
+       public String getColumnName(int column) {\r
+        return columnNames[column-1];\r
+  }\r
+\r
+       public int getColumnType(int column) {\r
+\r
+        /* By default all the data in the import file is assumed\r
+         * to be in varchar format. Appropriate casting is applied \r
+         * while executing the select on the import VTI. Using this \r
+         * approach import vti does not have to do the data conversion, \r
+         * casting will do that. \r
+         *\r
+         * But for some types like binary types there is no casting \r
+         * support from varchar or the data in the file is hex format, \r
+         * so data  needs to be converted to binary format first. And \r
+         * incase of blobs/clobs stored in an exteranl file memory usage \r
+         * will  be less if data is supplied as stream, instead of \r
+         * materializing the column data as one string. For these\r
+         * types import vti result set will return resultset column\r
+         * type is same as the column type of the import table. Data \r
+         * for the blob, clob or binary type columns is returned by \r
+         * the getXXX() calls used by the VTI Resultset to read the \r
+         * data for that particular type. For example, Blob data \r
+         * is read using getBlob() method, which will return a \r
+         * Blob object that contains the data in the import file \r
+         * for a column. \r
+         */\r
+\r
+        int colType;\r
+        switch (tableColumnTypes[column -1])\r
+        {\r
+        case java.sql.Types.BLOB: \r
+            // blob \r
+            colType = java.sql.Types.BLOB;\r
+            break;\r
+        case java.sql.Types.CLOB: \r
+            // clob \r
+            colType = java.sql.Types.CLOB;\r
+            break;\r
+        case java.sql.Types.LONGVARBINARY: \r
+            // LONG VARCHAR FOR BIT DATA\r
+            colType = java.sql.Types.LONGVARBINARY; \r
+            break;\r
+        case java.sql.Types.VARBINARY: \r
+            // VARCHAR FOR BIT DATA\r
+            colType = java.sql.Types.VARBINARY;\r
+            break;\r
+        case java.sql.Types.BINARY: \r
+            // CHAR FOR BIT DATA \r
+            colType = java.sql.Types.BINARY;\r
+            break;\r
+        default: \r
+            // all other data in the import file is \r
+            // assumed to be in varchar format.\r
+            colType = java.sql.Types.VARCHAR;\r
+        }\r
+\r
+        return colType;\r
+    }\r
+\r
+       public int isNullable(int column) {\r
+    return columnNullableUnknown;\r
+  }\r
+       public int getColumnDisplaySize(int column) {\r
+    if (columnWidths == null)\r
+       return Limits.DB2_VARCHAR_MAXWIDTH;\r
+    else\r
+       return columnWidths[column-1];\r
+  }\r
+\r
+       public boolean isWrapperFor(Class<?> iface) throws SQLException {\r
+               // TODO Auto-generated method stub\r
+               return false;\r
+       }\r
+\r
+       public <T> T unwrap(Class<T> iface) throws SQLException {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+}\r