001: /*
002:
003: Derby - Class org.apache.derby.impl.tools.ij.utilMain14
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.tools.ij;
023:
024: import org.apache.derby.iapi.reference.JDBC20Translation;
025: import org.apache.derby.iapi.reference.JDBC30Translation;
026:
027: import java.util.Hashtable;
028: import java.sql.Connection;
029: import java.sql.SQLException;
030: import java.sql.Statement;
031:
032: import org.apache.derby.iapi.tools.i18n.LocalizedOutput;
033:
034: /**
035: This class is utilities specific to the two ij Main's.
036: This factoring enables sharing the functionality for
037: single and dual connection ij runs.
038:
039: @author jerry
040: */
041: class utilMain14 extends utilMain {
042: private static final String JDBC_NOTSUPPORTED = "JDBC 3 method called - not yet supported";
043:
044: /**
045: * Set up the test to run with 'numConnections' connections/users.
046: *
047: * @param numConnections The number of connections/users to test.
048: *
049: */
050: utilMain14(int numConnections, LocalizedOutput out)
051: throws ijFatalException {
052: super (numConnections, out, (Hashtable) null);
053: }
054:
055: /**
056: * Set up the test to run with 'numConnections' connections/users.
057: *
058: * @param numConnections The number of connections/users to test.
059: * @param ignoreErrors A list of errors to ignore. If null,
060: * all errors are printed out and nothing
061: * is fatal. If non-null, if an error is
062: * hit and it is in this list, it is silently
063: * ignore. Otherwise, an ijFatalException is
064: * thrown. ignoreErrors is used for stress
065: * tests.
066: *
067: */
068: utilMain14(int numConnections, LocalizedOutput out,
069: Hashtable ignoreErrors) throws ijFatalException {
070: super (numConnections, out, ignoreErrors);
071: }
072:
073: /**
074: * Connections by default create ResultSet objects with holdability true. This method can be used
075: * to change the holdability of the connection by passing one of ResultSet.HOLD_CURSORS_OVER_COMMIT
076: * or ResultSet.CLOSE_CURSORS_AT_COMMIT
077: *
078: * @param conn The connection.
079: * @param holdType The new holdability for the Connection object.
080: *
081: * @return The connection object with holdability set to passed value.
082: */
083: Connection setHoldability(Connection conn, int holdType)
084: throws SQLException {
085: conn.setHoldability(holdType);
086: return conn;
087: }
088:
089: /**
090: JDBC 3.0
091: * Retrieves the current holdability of ResultSet objects created using this
092: * Connection object.
093: *
094: *
095: * @return The holdability, one of ResultSet.HOLD_CURSORS_OVER_COMMIT
096: * or ResultSet.CLOSE_CURSORS_AT_COMMIT
097: *
098: */
099: int getHoldability(Connection conn) throws SQLException {
100: return conn.getHoldability();
101: }
102:
103: /**
104: * Create the right kind of statement (scrolling or not)
105: * off of the specified connection.
106: *
107: * @param conn The connection.
108: * @param scrollType The scroll type of the cursor.
109: *
110: * @return The statement.
111: */
112: Statement createStatement(Connection conn, int scrollType,
113: int holdType) throws SQLException {
114: Statement stmt;
115: try {
116: stmt = conn.createStatement(scrollType,
117: JDBC20Translation.CONCUR_READ_ONLY, holdType);
118: } catch (SQLException se) {
119: //since jcc doesn't yet support JDBC3.0 we have to go back to JDBC2.0
120: if (isJCC && se.getMessage().equals(JDBC_NOTSUPPORTED))
121: stmt = conn.createStatement(scrollType,
122: JDBC20Translation.CONCUR_READ_ONLY);
123: else
124: throw se;
125: } catch (AbstractMethodError ame) {
126: //because weblogic 4.5 doesn't yet implement jdbc 2.0 interfaces, need
127: //to go back to jdbc 1.x functionality
128: //The jcc obfuscated jar gets this error
129: if (isJCC)
130: stmt = conn.createStatement(scrollType,
131: JDBC20Translation.CONCUR_READ_ONLY);
132: else
133: stmt = conn.createStatement();
134: }
135: return stmt;
136: }
137:
138: }
|