Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / tools / org / apache / derby / impl / tools / ij / ijMultipleResultSetResult.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/tools/org/apache/derby/impl/tools/ij/ijMultipleResultSetResult.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/tools/org/apache/derby/impl/tools/ij/ijMultipleResultSetResult.java
new file mode 100644 (file)
index 0000000..d231495
--- /dev/null
@@ -0,0 +1,123 @@
+/*\r
+\r
+Derby - Class org.apache.derby.impl.tools.ij.ijResultSetResult\r
+\r
+Licensed to the Apache Software Foundation (ASF) under one\r
+or more contributor license agreements.  See the NOTICE file\r
+distributed with this work for additional information\r
+regarding copyright ownership.  The ASF licenses this file\r
+to you under the Apache License, Version 2.0 (the\r
+"License"); you may not use this file except in compliance\r
+with 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.tools.ij;\r
+\r
+import java.sql.Connection;\r
+import java.sql.ResultSet;\r
+import java.sql.Statement;\r
+import java.sql.SQLException;\r
+import java.sql.SQLWarning;\r
+\r
+import java.util.List;\r
+import java.util.ArrayList;\r
+\r
+/**\r
+ * This impl is intended to be used with multiple resultsets, where\r
+ * the execution of the statement is already complete.\r
+ */\r
+public class ijMultipleResultSetResult extends ijResultImpl {\r
+\r
+    List resultSets = null;\r
+\r
+    int[] displayColumns = null;\r
+    int[] columnWidths = null;\r
+\r
+    /**\r
+     * Create a ijResultImpl that represents multiple result set.\r
+     */\r
+    public ijMultipleResultSetResult(List resultSets) throws SQLException {\r
+        resultSets = new ArrayList();\r
+        resultSets.addAll(resultSets);\r
+    }\r
+\r
+    /**\r
+     * Create a ijResultImpl that represents multiple result sets, only\r
+     * displaying a subset of the columns, using specified column widths.\r
+     * \r
+     * @param resultSets The result sets to display\r
+     * @param display Which column numbers to display, or null to display\r
+     *                all columns.\r
+     * @param widths  The widths of the columns specified in 'display', or\r
+     *                null to display using default column sizes.\r
+     */\r
+    public ijMultipleResultSetResult(List resultSets, int[] display,\r
+                                     int[] widths) throws SQLException {\r
+        this.resultSets = new ArrayList();\r
+        this.resultSets.addAll(resultSets);\r
+\r
+        displayColumns = display;\r
+        columnWidths   = widths;\r
+    }\r
+\r
+\r
+    public void addResultSet(ResultSet rs){\r
+        resultSets.add(rs);\r
+    }\r
+\r
+    public boolean isMultipleResultSetResult(){\r
+        return true;\r
+    }\r
+\r
+    public List getMultipleResultSets() {\r
+        return resultSets;\r
+    }\r
+\r
+    public void closeStatement() throws SQLException {\r
+        if (resultSets != null) {\r
+            ResultSet rs = null;\r
+            for (int i = 0; i<resultSets.size(); i++){\r
+                rs = (ResultSet)resultSets.get(i);\r
+                if(rs.getStatement() != null) rs.getStatement().close();\r
+                else rs.close(); \r
+            }\r
+        }\r
+    }\r
+\r
+    public int[] getColumnDisplayList() { return displayColumns; }\r
+    public int[] getColumnWidthList() { return columnWidths; }\r
+\r
+    /**\r
+     * @return the warnings from all resultsets as one SQLWarning chain\r
+     */\r
+    public SQLWarning getSQLWarnings() throws SQLException { \r
+        SQLWarning warning = null;\r
+        ResultSet rs = null;\r
+        for (int i=0; i<resultSets.size(); i++){\r
+            rs = (ResultSet)resultSets.get(i);\r
+            if (rs.getWarnings() != null) {\r
+                if (warning == null) warning = rs.getWarnings();\r
+                else                 warning.setNextWarning(rs.getWarnings());\r
+            }\r
+        }\r
+        return warning;\r
+    }\r
+    \r
+    /**\r
+     * Clears the warnings in all resultsets\r
+     */\r
+    public void clearSQLWarnings() throws SQLException {\r
+        for (int i=0; i<resultSets.size(); i++){\r
+            ((ResultSet)resultSets.get(i)).clearWarnings();\r
+        }\r
+    }\r
+}\r