001: /*
002:
003: Derby - Class org.apache.derby.impl.tools.ij.ijResultSetResult
004:
005: Licensed to the Apache Software Foundation (ASF) under one
006: or more contributor license agreements. See the NOTICE file
007: distributed with this work for additional information
008: regarding copyright ownership. The ASF licenses this file
009: to you under the Apache License, Version 2.0 (the
010: "License"); you may not use this file except in compliance
011: with the License. You may obtain a copy of the License at
012:
013: http://www.apache.org/licenses/LICENSE-2.0
014:
015: Unless required by applicable law or agreed to in writing, software
016: distributed under the License is distributed on an "AS IS" BASIS,
017: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: See the License for the specific language governing permissions and
019: limitations under the License.
020:
021: */
022:
023: package org.apache.derby.impl.tools.ij;
024:
025: import java.sql.Connection;
026: import java.sql.ResultSet;
027: import java.sql.Statement;
028: import java.sql.SQLException;
029: import java.sql.SQLWarning;
030:
031: /**
032: * This impl is intended to be used with a resultset,
033: * where the execution of the statement is already complete.
034: */
035: public class ijResultSetResult extends ijResultImpl {
036:
037: ResultSet resultSet;
038: Statement statement;
039:
040: int[] displayColumns = null;
041: int[] columnWidths = null;
042:
043: /**
044: * Create a ijResultImpl that represents a result set.
045: */
046: public ijResultSetResult(ResultSet r) throws SQLException {
047: resultSet = r;
048: statement = resultSet.getStatement();
049: }
050:
051: /**
052: * Create a ijResultImpl that represents a result set, only
053: * displaying a subset of the columns, using specified column widths.
054: *
055: * @param r The result set to display
056: * @param display Which column numbers to display, or null to display
057: * all columns.
058: * @param widths The widths of the columns specified in 'display', or
059: * null to display using default column sizes.
060: */
061: public ijResultSetResult(ResultSet r, int[] display, int[] widths)
062: throws SQLException {
063: resultSet = r;
064: statement = resultSet.getStatement();
065:
066: displayColumns = display;
067: columnWidths = widths;
068: }
069:
070: public boolean isResultSet() throws SQLException {
071: return statement == null || statement.getUpdateCount() == -1;
072: }
073:
074: public ResultSet getResultSet() throws SQLException {
075: return resultSet;
076: }
077:
078: public void closeStatement() throws SQLException {
079: if (statement != null)
080: statement.close();
081: else
082: resultSet.close();
083: }
084:
085: public int[] getColumnDisplayList() {
086: return displayColumns;
087: }
088:
089: public int[] getColumnWidthList() {
090: return columnWidths;
091: }
092:
093: public SQLWarning getSQLWarnings() throws SQLException {
094: return resultSet.getWarnings();
095: }
096:
097: public void clearSQLWarnings() throws SQLException {
098: resultSet.clearWarnings();
099: }
100: }
|