KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > tools > ij > utilMain14


1 /*
2
3    Derby - Class org.apache.derby.impl.tools.ij.utilMain14
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.tools.ij;
23                 
24 import org.apache.derby.iapi.reference.JDBC20Translation;
25 import org.apache.derby.iapi.reference.JDBC30Translation;
26
27 import java.util.Hashtable JavaDoc;
28 import java.sql.Connection JavaDoc;
29 import java.sql.SQLException JavaDoc;
30 import java.sql.Statement JavaDoc;
31
32 import org.apache.derby.iapi.tools.i18n.LocalizedOutput;
33 /**
34     This class is utilities specific to the two ij Main's.
35     This factoring enables sharing the functionality for
36     single and dual connection ij runs.
37
38     @author jerry
39  */

40 class utilMain14 extends utilMain
41 {
42     private static final String JavaDoc JDBC_NOTSUPPORTED = "JDBC 3 method called - not yet supported";
43     /**
44      * Set up the test to run with 'numConnections' connections/users.
45      *
46      * @param numConnections The number of connections/users to test.
47      *
48      */

49     utilMain14(int numConnections, LocalizedOutput out)
50         throws ijFatalException
51     {
52         super(numConnections, out, (Hashtable JavaDoc)null);
53     }
54
55     /**
56      * Set up the test to run with 'numConnections' connections/users.
57      *
58      * @param numConnections The number of connections/users to test.
59      * @param ignoreErrors A list of errors to ignore. If null,
60      * all errors are printed out and nothing
61      * is fatal. If non-null, if an error is
62      * hit and it is in this list, it is silently
63      * ignore. Otherwise, an ijFatalException is
64      * thrown. ignoreErrors is used for stress
65      * tests.
66      *
67      */

68     utilMain14(int numConnections, LocalizedOutput out, Hashtable JavaDoc ignoreErrors)
69         throws ijFatalException
70     {
71         super(numConnections, out, ignoreErrors);
72     }
73
74     /**
75      * Connections by default create ResultSet objects with holdability true. This method can be used
76      * to change the holdability of the connection by passing one of ResultSet.HOLD_CURSORS_OVER_COMMIT
77      * or ResultSet.CLOSE_CURSORS_AT_COMMIT
78      *
79      * @param conn The connection.
80      * @param holdType The new holdability for the Connection object.
81      *
82      * @return The connection object with holdability set to passed value.
83      */

84     Connection JavaDoc setHoldability(Connection JavaDoc conn, int holdType)
85         throws SQLException JavaDoc
86     {
87         conn.setHoldability(holdType);
88         return conn;
89     }
90
91     /**
92         JDBC 3.0
93      * Retrieves the current holdability of ResultSet objects created using this
94      * Connection object.
95      *
96      *
97      * @return The holdability, one of ResultSet.HOLD_CURSORS_OVER_COMMIT
98      * or ResultSet.CLOSE_CURSORS_AT_COMMIT
99      *
100      */

101     int getHoldability(Connection JavaDoc conn)
102         throws SQLException JavaDoc
103     {
104         return conn.getHoldability();
105     }
106
107     /**
108      * Create the right kind of statement (scrolling or not)
109      * off of the specified connection.
110      *
111      * @param conn The connection.
112      * @param scrollType The scroll type of the cursor.
113      *
114      * @return The statement.
115      */

116     Statement JavaDoc createStatement(Connection JavaDoc conn, int scrollType, int holdType)
117         throws SQLException JavaDoc
118     {
119         Statement JavaDoc stmt;
120         try {
121             stmt = conn.createStatement(scrollType, JDBC20Translation.CONCUR_READ_ONLY, holdType);
122         }catch(SQLException JavaDoc se) {
123             //since jcc doesn't yet support JDBC3.0 we have to go back to JDBC2.0
124
if (isJCC && se.getMessage().equals(JDBC_NOTSUPPORTED))
125                 stmt = conn.createStatement(scrollType, JDBC20Translation.CONCUR_READ_ONLY);
126             else
127                 throw se;
128         }
129         catch(AbstractMethodError JavaDoc ame) {
130             //because weblogic 4.5 doesn't yet implement jdbc 2.0 interfaces, need
131
//to go back to jdbc 1.x functionality
132
//The jcc obfuscated jar gets this error
133
if (isJCC)
134                 stmt = conn.createStatement(scrollType, JDBC20Translation.CONCUR_READ_ONLY);
135             else
136                 stmt = conn.createStatement();
137         }
138         return stmt;
139     }
140
141 }
142
Popular Tags