1 | /* |
2 | |
3 | Derby - Class org.apache.derby.impl.tools.ij.utilMain14 |
4 | |
5 | Copyright 2002, 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.impl.tools.ij; |
22 | |
23 | import org.apache.derby.iapi.reference.JDBC20Translation; |
24 | import org.apache.derby.iapi.reference.JDBC30Translation; |
25 | |
26 | import java.util.Hashtable; |
27 | import java.sql.Connection; |
28 | import java.sql.SQLException; |
29 | import java.sql.Statement; |
30 | |
31 | import org.apache.derby.iapi.tools.i18n.LocalizedOutput; |
32 | /** |
33 | This class is utilities specific to the two ij Main's. |
34 | This factoring enables sharing the functionality for |
35 | single and dual connection ij runs. |
36 | |
37 | @author jerry |
38 | */ |
39 | public class utilMain14 extends utilMain |
40 | { |
41 | private static final String JDBC_NOTSUPPORTED = "JDBC 3 method called - not yet supported"; |
42 | /** |
43 | * Set up the test to run with 'numConnections' connections/users. |
44 | * |
45 | * @param numConnections The number of connections/users to test. |
46 | * |
47 | */ |
48 | public utilMain14(int numConnections, LocalizedOutput out) |
49 | throws ijFatalException |
50 | { |
51 | super(numConnections, out, (Hashtable)null); |
52 | } |
53 | |
54 | /** |
55 | * Set up the test to run with 'numConnections' connections/users. |
56 | * |
57 | * @param numConnections The number of connections/users to test. |
58 | * @param ignoreErrors A list of errors to ignore. If null, |
59 | * all errors are printed out and nothing |
60 | * is fatal. If non-null, if an error is |
61 | * hit and it is in this list, it is silently |
62 | * ignore. Otherwise, an ijFatalException is |
63 | * thrown. ignoreErrors is used for stress |
64 | * tests. |
65 | * |
66 | */ |
67 | public utilMain14(int numConnections, LocalizedOutput out, Hashtable ignoreErrors) |
68 | throws ijFatalException |
69 | { |
70 | super(numConnections, out, ignoreErrors); |
71 | } |
72 | |
73 | /** |
74 | * Return the right utilMain to use. (JDBC 1.1 or 2.0 or 3.0) |
75 | * |
76 | */ |
77 | public utilMain getUtilMain() |
78 | { |
79 | return this; |
80 | } |
81 | |
82 | /** |
83 | * Connections by default create ResultSet objects with holdability true. This method can be used |
84 | * to change the holdability of the connection by passing one of ResultSet.HOLD_CURSORS_OVER_COMMIT |
85 | * or ResultSet.CLOSE_CURSORS_AT_COMMIT |
86 | * |
87 | * @param conn The connection. |
88 | * @param holdType The new holdability for the Connection object. |
89 | * |
90 | * @return The connection object with holdability set to passed value. |
91 | */ |
92 | public Connection setHoldability(Connection conn, int holdType) |
93 | throws SQLException |
94 | { |
95 | conn.setHoldability(holdType); |
96 | return conn; |
97 | } |
98 | |
99 | /** |
100 | JDBC 3.0 |
101 | * Retrieves the current holdability of ResultSet objects created using this |
102 | * Connection object. |
103 | * |
104 | * |
105 | * @return The holdability, one of ResultSet.HOLD_CURSORS_OVER_COMMIT |
106 | * or ResultSet.CLOSE_CURSORS_AT_COMMIT |
107 | * |
108 | */ |
109 | public int getHoldability(Connection conn) |
110 | throws SQLException |
111 | { |
112 | return conn.getHoldability(); |
113 | } |
114 | |
115 | /** |
116 | * Create the right kind of statement (scrolling or not) |
117 | * off of the specified connection. |
118 | * |
119 | * @param conn The connection. |
120 | * @param scrollType The scroll type of the cursor. |
121 | * |
122 | * @return The statement. |
123 | */ |
124 | public Statement createStatement(Connection conn, int scrollType, int holdType) |
125 | throws SQLException |
126 | { |
127 | Statement stmt; |
128 | try { |
129 | stmt = conn.createStatement(scrollType, JDBC20Translation.CONCUR_READ_ONLY, holdType); |
130 | }catch(SQLException se) { |
131 | //since jcc doesn't yet support JDBC3.0 we have to go back to JDBC2.0 |
132 | if (isJCC && se.getMessage().equals(JDBC_NOTSUPPORTED)) |
133 | stmt = conn.createStatement(scrollType, JDBC20Translation.CONCUR_READ_ONLY); |
134 | else |
135 | throw se; |
136 | } |
137 | catch(AbstractMethodError ame) { |
138 | //because weblogic 4.5 doesn't yet implement jdbc 2.0 interfaces, need |
139 | //to go back to jdbc 1.x functionality |
140 | //The jcc obfuscated jar gets this error |
141 | if (isJCC) |
142 | stmt = conn.createStatement(scrollType, JDBC20Translation.CONCUR_READ_ONLY); |
143 | else |
144 | stmt = conn.createStatement(); |
145 | } |
146 | return stmt; |
147 | } |
148 | |
149 | } |