001: /*
002:
003: Derby - Class org.apache.derby.client.am.Configuration
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.client.am;
023:
024: import java.io.IOException;
025: import java.io.InputStream;
026: import java.security.AccessController;
027: import java.security.PrivilegedExceptionAction;
028:
029: import org.apache.derby.iapi.services.info.ProductGenusNames;
030: import org.apache.derby.iapi.services.info.ProductVersionHolder;
031: import org.apache.derby.shared.common.reference.SQLState;
032: import org.apache.derby.iapi.services.info.JVMInfo;
033:
034: public class Configuration {
035:
036: public static int traceFileSuffixIndex__ = 0;
037:
038: public static int traceLevel__ = org.apache.derby.jdbc.ClientBaseDataSource.TRACE_ALL;
039:
040: public static String traceFile__ = null;
041:
042: public static String traceDirectory__ = null;
043:
044: public static boolean traceFileAppend__ = false;
045: public static String jreLevel = "1.3.0"; // default level if unable to read
046: public static int jreLevelMajor = 1;
047: public static int jreLevelMinor = 3;
048:
049: private Configuration() {
050: }
051:
052: public static boolean traceSuspended__;
053:
054: public static boolean[] enableConnectivityToTargetServer__;
055: public static boolean jvmSupportsMicrosClock__ = false;
056:
057: // -------------------------- versioning -------------------------------------
058:
059: public static ProductVersionHolder dncProductVersionHolder__;
060:
061: public static ProductVersionHolder getProductVersionHolder() {
062: return dncProductVersionHolder__;
063: }
064:
065: // for DatabaseMetaData.getDriverName()
066: public final static String dncDriverName = "Apache Derby Network Client JDBC Driver";
067:
068: // Hard-wired for JDBC
069: //
070: // Currently ASCII hex value of "SYSLVL01".
071: public final static byte[] dncPackageConsistencyToken = { 0x53,
072: 0x59, 0x53, 0x4c, 0x56, 0x4c, 0x30, 0x31 };
073:
074: // We will not set packagge VERSION in the initial release.
075: // If we have to change the package version in the future then we can.
076: public static String dncPackageVersion = null;
077:
078: // for Driver.jdbcCompliant()
079: public final static boolean jdbcCompliant = true;
080:
081: // for Driver.getCompatibileJREVersions()
082: public final static String[] dncCompatibleJREVersions = new String[] {
083: "1.3", "1.4" };
084:
085: //---------------------- database URL protocols ------------------------------
086:
087: // For DatabaseMetaData.getURL()
088: public final static String jdbcDerbyNETProtocol = "jdbc:derby://";
089:
090: // -------------------------- metrics ----------------------
091: // Not currently used by production builds.
092: // We can't really use this stuff with tracing enabled, the results are not accurate.
093:
094: // -------------------------- compiled in properties -------------------------
095:
096: public final static boolean enableNetConnectionPooling = true;
097:
098: final static boolean rangeCheckCrossConverters = true;
099:
100: // Define different levels of bug checking, for now turn all bits on.
101: final static int bugCheckLevel = 0xff;
102:
103: // --------------------------- connection defaults ---------------------------
104:
105: // This is the DERBY default and maps to DERBY's "Cursor Stability".
106: public final static int defaultIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED;
107:
108: // ---------------------------- statement defaults----------------------------
109:
110: public static final int defaultFetchSize = 64;
111:
112: // Prepare attribute constants
113: public static final String cursorAttribute_SensitiveStatic = "SENSITIVE STATIC SCROLL ";
114: public static final String cursorAttribute_SensitiveStaticRowset = cursorAttribute_SensitiveStatic;
115: public static final String cursorAttribute_SensitiveDynamic = "SENSITIVE DYNAMIC SCROLL ";
116: public static final String cursorAttribute_SensitiveDynamicRowset = "SENSITIVE DYNAMIC SCROLL WITH ROWSET POSITIONING ";
117: public static final String cursorAttribute_Insensitive = "INSENSITIVE SCROLL ";
118: public static final String cursorAttribute_InsensitiveRowset = cursorAttribute_Insensitive;
119:
120: // uncomment the following when we want to use multi-row fetch to support sensitive static and
121: // insensitve cursors whenever the server has support for it.
122: //public static final String cursorAttribute_SensitiveStaticRowset = "SENSITIVE STATIC SCROLL WITH ROWSET POSITIONING ";
123: //public static final String cursorAttribute_InsensitiveRowset = "INSENSITIVE SCROLL WITH ROWSET POSITIONING ";
124:
125: public static final String cursorAttribute_ForUpdate = "FOR UPDATE ";
126: public static final String cursorAttribute_ForReadOnly = "FOR READ ONLY ";
127:
128: public static final String cursorAttribute_WithHold = "WITH HOLD ";
129:
130: // -----------------------Load resource bundles for the driver asap-----------
131:
132: private static final String packageNameForDNC = "org.apache.derby.client";
133:
134: public static SqlException exceptionsOnLoadResources = null; // used by ClientDriver to accumulate load exceptions
135:
136: static {
137: try {
138: loadProductVersionHolder();
139: } catch (SqlException e) {
140: exceptionsOnLoadResources = e;
141: }
142: try {
143: jreLevel = System.getProperty("java.version");
144: } catch (SecurityException e) {
145: } // ignore it, assume 1.3.0
146: java.util.StringTokenizer st = new java.util.StringTokenizer(
147: jreLevel, ".");
148: int jreState = 0;
149: while (st.hasMoreTokens()) {
150: int i;
151: try {
152: i = java.lang.Integer.parseInt(st.nextToken()); // get int value
153: } catch (NumberFormatException e) {
154: i = 0;
155: }
156: switch (jreState++) {
157: case 0:
158: jreLevelMajor = i; // state 0, this is the major version
159: break;
160: case 1:
161: jreLevelMinor = i; // state 1, this is the minor version
162: break;
163: default:
164: break; // state >1, ignore
165: }
166: }
167: }
168:
169: /**
170: * load product version information and accumulate exceptions
171: */
172: private static void loadProductVersionHolder() throws SqlException {
173: try {
174: dncProductVersionHolder__ = buildProductVersionHolder();
175: } catch (java.security.PrivilegedActionException e) {
176: throw new SqlException(null, new ClientMessageId(
177: SQLState.ERROR_PRIVILEGED_ACTION), e.getException());
178: } catch (java.io.IOException ioe) {
179: throw SqlException.javaException(null, ioe);
180: }
181: }
182:
183: // Create ProductVersionHolder in security block for Java 2 security.
184: private static ProductVersionHolder buildProductVersionHolder()
185: throws java.security.PrivilegedActionException, IOException {
186: ProductVersionHolder myPVH = null;
187: myPVH = (ProductVersionHolder) AccessController
188: .doPrivileged(new PrivilegedExceptionAction() {
189:
190: public Object run() throws IOException {
191: InputStream versionStream = getClass()
192: .getResourceAsStream(
193: ProductGenusNames.DNC_INFO);
194:
195: return ProductVersionHolder
196: .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: }
|