KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > client > am > Configuration


1 /*
2
3    Derby - Class org.apache.derby.client.am.Configuration
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.client.am;
23
24 import java.io.IOException JavaDoc;
25 import java.io.InputStream JavaDoc;
26 import java.security.AccessController JavaDoc;
27 import java.security.PrivilegedExceptionAction JavaDoc;
28
29 import org.apache.derby.iapi.services.info.ProductGenusNames;
30 import org.apache.derby.iapi.services.info.ProductVersionHolder;
31 import org.apache.derby.shared.common.reference.SQLState;
32 import org.apache.derby.iapi.services.info.JVMInfo;
33
34 public class Configuration {
35
36
37     public static int traceFileSuffixIndex__ = 0;
38
39     public static int traceLevel__ = org.apache.derby.jdbc.ClientBaseDataSource.TRACE_ALL;
40
41     public static String JavaDoc traceFile__ = null;
42
43     public static String JavaDoc traceDirectory__ = null;
44
45     public static boolean traceFileAppend__ = false;
46     public static String JavaDoc jreLevel = "1.3.0"; // default level if unable to read
47
public static int jreLevelMajor = 1;
48     public static int jreLevelMinor = 3;
49
50     private Configuration() {
51     }
52
53     public static boolean traceSuspended__;
54
55     public static boolean[] enableConnectivityToTargetServer__;
56     public static boolean jvmSupportsMicrosClock__ = false;
57
58     // -------------------------- versioning -------------------------------------
59

60     public static ProductVersionHolder dncProductVersionHolder__;
61
62     public static ProductVersionHolder getProductVersionHolder() {
63         return dncProductVersionHolder__;
64     }
65
66
67     // for DatabaseMetaData.getDriverName()
68
public final static String JavaDoc dncDriverName = "Apache Derby Network Client JDBC Driver";
69
70
71     // Hard-wired for JDBC
72
//
73
// Currently ASCII hex value of "SYSLVL01".
74
public final static byte[] dncPackageConsistencyToken =
75             {0x53, 0x59, 0x53, 0x4c, 0x56, 0x4c, 0x30, 0x31};
76
77     // We will not set packagge VERSION in the initial release.
78
// If we have to change the package version in the future then we can.
79
public static String JavaDoc dncPackageVersion = null;
80
81     // for Driver.jdbcCompliant()
82
public final static boolean jdbcCompliant = true;
83
84     // for Driver.getCompatibileJREVersions()
85
public final static String JavaDoc[] dncCompatibleJREVersions = new String JavaDoc[]{"1.3", "1.4"};
86
87     //---------------------- database URL protocols ------------------------------
88

89     // For DatabaseMetaData.getURL()
90
public final static String JavaDoc jdbcDerbyNETProtocol = "jdbc:derby://";
91
92     // -------------------------- metrics ----------------------
93
// Not currently used by production builds.
94
// We can't really use this stuff with tracing enabled, the results are not accurate.
95

96     // -------------------------- compiled in properties -------------------------
97

98     public final static boolean enableNetConnectionPooling = true;
99
100     final static boolean rangeCheckCrossConverters = true;
101
102     // Define different levels of bug checking, for now turn all bits on.
103
final static int bugCheckLevel = 0xff;
104
105     // --------------------------- connection defaults ---------------------------
106

107     // This is the DERBY default and maps to DERBY's "Cursor Stability".
108
public final static int defaultIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED;
109
110     // ---------------------------- statement defaults----------------------------
111

112     public static final int defaultFetchSize = 64;
113
114     // Prepare attribute constants
115
public static final String JavaDoc cursorAttribute_SensitiveStatic = "SENSITIVE STATIC SCROLL ";
116     public static final String JavaDoc cursorAttribute_SensitiveStaticRowset = cursorAttribute_SensitiveStatic;
117     public static final String JavaDoc cursorAttribute_SensitiveDynamic = "SENSITIVE DYNAMIC SCROLL ";
118     public static final String JavaDoc cursorAttribute_SensitiveDynamicRowset = "SENSITIVE DYNAMIC SCROLL WITH ROWSET POSITIONING ";
119     public static final String JavaDoc cursorAttribute_Insensitive = "INSENSITIVE SCROLL ";
120     public static final String JavaDoc cursorAttribute_InsensitiveRowset = cursorAttribute_Insensitive;
121
122     // uncomment the following when we want to use multi-row fetch to support sensitive static and
123
// insensitve cursors whenever the server has support for it.
124
//public static final String cursorAttribute_SensitiveStaticRowset = "SENSITIVE STATIC SCROLL WITH ROWSET POSITIONING ";
125
//public static final String cursorAttribute_InsensitiveRowset = "INSENSITIVE SCROLL WITH ROWSET POSITIONING ";
126

127     public static final String JavaDoc cursorAttribute_ForUpdate = "FOR UPDATE ";
128     public static final String JavaDoc cursorAttribute_ForReadOnly = "FOR READ ONLY ";
129
130     public static final String JavaDoc cursorAttribute_WithHold = "WITH HOLD ";
131
132     // -----------------------Load resource bundles for the driver asap-----------
133

134     private static final String JavaDoc packageNameForDNC = "org.apache.derby.client";
135
136     public static SqlException exceptionsOnLoadResources = null; // used by ClientDriver to accumulate load exceptions
137

138     static {
139         try {
140             loadProductVersionHolder();
141         } catch (SqlException e) {
142             exceptionsOnLoadResources = e;
143         }
144         try {
145             jreLevel = System.getProperty("java.version");
146         } catch (SecurityException JavaDoc e) {
147         } // ignore it, assume 1.3.0
148
java.util.StringTokenizer JavaDoc st = new java.util.StringTokenizer JavaDoc(jreLevel, ".");
149         int jreState = 0;
150         while (st.hasMoreTokens()) {
151             int i;
152             try {
153                 i = java.lang.Integer.parseInt(st.nextToken()); // get int value
154
} catch (NumberFormatException JavaDoc e) {
155                 i = 0;
156             }
157             switch (jreState++) {
158             case 0:
159                 jreLevelMajor = i; // state 0, this is the major version
160
break;
161             case 1:
162                 jreLevelMinor = i; // state 1, this is the minor version
163
break;
164             default:
165                 break; // state >1, ignore
166
}
167         }
168     }
169
170     /**
171      * load product version information and accumulate exceptions
172      */

173     private static void loadProductVersionHolder() throws SqlException {
174         try {
175             dncProductVersionHolder__ = buildProductVersionHolder();
176         } catch (java.security.PrivilegedActionException JavaDoc e) {
177             throw new SqlException(null,
178                     new ClientMessageId (SQLState.ERROR_PRIVILEGED_ACTION),
179                     e.getException());
180         } catch (java.io.IOException JavaDoc ioe) {
181             throw SqlException.javaException(null, ioe);
182         }
183     }
184
185
186     // Create ProductVersionHolder in security block for Java 2 security.
187
private static ProductVersionHolder buildProductVersionHolder() throws
188             java.security.PrivilegedActionException JavaDoc, IOException JavaDoc {
189         ProductVersionHolder myPVH = null;
190         myPVH = (ProductVersionHolder)
191                 AccessController.doPrivileged(new PrivilegedExceptionAction JavaDoc() {
192
193                     public Object JavaDoc run() throws IOException JavaDoc {
194                         InputStream JavaDoc versionStream = getClass().getResourceAsStream(ProductGenusNames.DNC_INFO);
195
196                         return ProductVersionHolder.getProductVersionHolderFromMyEnv(versionStream);
197                     }
198                 });
199
200         return myPVH;
201     }
202     
203     /**
204      * Check to see if the jvm version is such that JDBC 4.0 is supported
205      */

206     
207     public static boolean supportsJDBC40() {
208         if (JVMInfo.JDK_ID >= JVMInfo.J2SE_16) {
209             return true;
210         }
211         return false;
212     }
213
214
215
216 }
217
Popular Tags