📄 clientbasedatasource.java
字号:
/* Derby - Class org.apache.derby.jdbc.ClientBaseDataSource Copyright (c) 2001, 2005 The Apache Software Foundation or its licensors, where applicable. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.*/package org.apache.derby.jdbc;import java.io.Serializable;import java.io.PrintWriter;import java.util.Properties;import java.util.StringTokenizer;import java.util.NoSuchElementException;import java.lang.reflect.Field;import java.lang.reflect.Modifier;import java.security.AccessController;import java.security.PrivilegedActionException;import java.sql.SQLException;import javax.naming.Referenceable;import javax.naming.Reference;import javax.naming.NamingException;import javax.naming.StringRefAddr;import javax.naming.RefAddr;import org.apache.derby.client.am.Configuration;import org.apache.derby.client.am.LogWriter;import org.apache.derby.client.am.SqlException;import org.apache.derby.client.am.SetAccessibleAction;import org.apache.derby.client.am.Connection;import org.apache.derby.client.net.NetConfiguration;import org.apache.derby.client.net.NetLogWriter;import org.apache.derby.client.ClientDataSourceFactory;/** * Base class for client-side DataSource implementations. */public abstract class ClientBaseDataSource implements Serializable, Referenceable { private static final long serialVersionUID = -7660172643035173692L; // The loginTimeout jdbc 2 data source property is not supported as a jdbc 1 connection property, // because loginTimeout is set by the jdbc 1 api via java.sql.DriverManager.setLoginTimeout(). // The databaseName, serverName, and portNumber data source properties are also not supported as connection properties // because they are extracted from the jdbc 1 database url passed on the connection request. // However, all other data source properties should probably also be supported as connection properties. //---------------------contructors/finalizers--------------------------------- // This class is abstract, hide the default constructor protected ClientBaseDataSource() { } // ---------------------------- loginTimeout ----------------------------------- // // was serialized in 1.0 release /** * The time in seconds to wait for a connection request on this data source. The default value of zero indicates * that either the system time out be used or no timeout limit. * * @serial */ protected int loginTimeout = propertyDefault_loginTimeout; public final static String propertyKey_loginTimeout = "loginTimeout"; public static final int propertyDefault_loginTimeout = 0; public synchronized void setLoginTimeout(int seconds) { this.loginTimeout = seconds; } public int getLoginTimeout() { return this.loginTimeout; } // ---------------------------- logWriter ----------------------------------- // /** * The log writer is declared transient, and is not serialized or stored under JNDI. * * @see #traceLevel */ protected transient PrintWriter logWriter = null; public synchronized void setLogWriter(PrintWriter logWriter) { this.logWriter = logWriter; } public PrintWriter getLogWriter() { return this.logWriter; } // ---------------------------- databaseName ----------------------------------- // // Stores the relational database name, RDBNAME. // The length of the database name may be limited to 18 bytes // and therefore may throw an SQLException. // // protected String databaseName = null; public final static String propertyKey_databaseName = "databaseName"; // databaseName is not permitted in a properties object // ---------------------------- description ------------------------------ // A description of this data source. protected String description = null; public final static String propertyKey_description = "description"; // ---------------------------- dataSourceName ----------------------------------- // // A data source name; // used to name an underlying XADataSource, // or ConnectionPoolDataSource when pooling of connections is done. // protected String dataSourceName = null; public final static String propertyKey_dataSourceName = "dataSourceName"; // ---------------------------- portNumber ----------------------------------- // protected int portNumber = propertyDefault_portNumber; public final static int propertyDefault_portNumber = 1527; public final static String propertyKey_portNumber = "portNumber"; // ---------------------------- serverName ----------------------------------- // // Derby-410 fix. protected String serverName = propertyDefault_serverName; public final static String propertyDefault_serverName = "localhost"; public final static String propertyKey_serverName = "serverName"; // serverName is not permitted in a properties object // ---------------------------- user ----------------------------------- // // This property can be overwritten by specifing the // username parameter on the DataSource.getConnection() method // call. If user is specified, then password must also be // specified, either in the data source object or provided on // the DataSource.getConnection() call. // // Each data source implementation subclass will maintain it's own <code>password</code> property. // This password property may or may not be declared transient, and therefore may be serialized // to a file in clear-text, care must taken by the user to prevent security breaches. // Derby-406 fix protected String user = propertyDefault_user; public final static String propertyKey_user = "user"; public final static String propertyDefault_user = "APP"; public static String getUser(Properties properties) { String userString = properties.getProperty(propertyKey_user); return parseString(userString, propertyDefault_user); } public final static int HOLD_CURSORS_OVER_COMMIT = 1; // this matches jdbc 3 ResultSet.HOLD_CURSORS_OVER_COMMIT public final static int CLOSE_CURSORS_AT_COMMIT = 2; // this matches jdbc 3 ResultSet.CLOSE_CURSORS_AT_COMMIT public final static int NOT_SET = 0; // 0 means not set. public final static int YES = 1; // ="yes" as property string public final static int NO = 2; // ="no" as property string // ---------------------------- securityMechanism ----------------------------------- // // The source security mechanism to use when connecting to this data source. // <p> // Security mechanism options are: // <ul> // <li> USER_ONLY_SECURITY // <li> CLEAR_TEXT_PASSWORD_SECURITY // <li> ENCRYPTED_PASSWORD_SECURITY // <li> ENCRYPTED_USER_AND_PASSWORD_SECURITY - both password and user are encrypted // </ul> // The default security mechanism is USER_ONLY_SECURITY. // <p> // If the application specifies a security // mechanism then it will be the only one attempted. // If the specified security mechanism is not supported by the conversation // then an exception will be thrown and there will be no additional retries. // <p> // This property is currently only available for the DNC driver. // <p> // Both user and password need to be set for all security mechanism except USER_ONLY_SECURITY // When using USER_ONLY_SECURITY, only the user property needs to be specified. // protected short securityMechanism = propertyDefault_securityMechanism; // TODO default should be USER_ONLY_SECURITY. Change when working on // Network Server // public final static short propertyDefault_securityMechanism = (short) // org.apache.derby.client.net.NetConfiguration.SECMEC_USRIDONL; public final static short propertyDefault_securityMechanism = (short) NetConfiguration.SECMEC_USRIDONL; public final static String propertyKey_securityMechanism = "securityMechanism"; // We use the NET layer constants to avoid a mapping for the NET driver. public static short getSecurityMechanism(Properties properties) { String securityMechanismString = properties.getProperty(propertyKey_securityMechanism); String passwordString = properties.getProperty(propertyKey_password); short setSecurityMechanism = parseShort(securityMechanismString, propertyDefault_securityMechanism); return getUpgradedSecurityMechanism(setSecurityMechanism, passwordString); } /** * Upgrade the security mechansim to USRIDPWD if it is set to USRIDONL but we have a password. */ public static short getUpgradedSecurityMechanism(short securityMechanism, String password) { // if securityMechanism is USER_ONLY (the default) we may need // to change it to CLEAR_TEXT_PASSWORD in order to send the password. if ((password != null) && (securityMechanism == NetConfiguration.SECMEC_USRIDONL)) { return (short) NetConfiguration.SECMEC_USRIDPWD; } else { return securityMechanism; } } // ---------------------------- getServerMessageTextOnGetMessage ----------------------------------- // protected boolean retrieveMessageText = propertyDefault_retrieveMessageText; public final static boolean propertyDefault_retrieveMessageText = true; public final static String propertyKey_retrieveMessageText = "retrieveMessageText"; public static boolean getRetrieveMessageText(Properties properties) { String retrieveMessageTextString = properties.getProperty(propertyKey_retrieveMessageText); return parseBoolean(retrieveMessageTextString, propertyDefault_retrieveMessageText); } // ---------------------------- traceFile ----------------------------------- // protected String traceFile = null; public final static String propertyKey_traceFile = "traceFile"; public static String getTraceFile(Properties properties) { return properties.getProperty(propertyKey_traceFile); } // ---------------------------- traceDirectory ----------------------------------- // For the suffix of the trace file when traceDirectory is enabled. private transient int traceFileSuffixIndex_ = 0; // protected String traceDirectory = null; public final static String propertyKey_traceDirectory = "traceDirectory"; public static String getTraceDirectory(Properties properties) { return properties.getProperty(propertyKey_traceDirectory); } // ---------------------------- traceFileAppend ----------------------------------- // protected boolean traceFileAppend = propertyDefault_traceFileAppend; public final static boolean propertyDefault_traceFileAppend = false; public final static String propertyKey_traceFileAppend = "traceFileAppend"; public static boolean getTraceFileAppend(Properties properties) { String traceFileAppendString = properties.getProperty(propertyKey_traceFileAppend); return parseBoolean(traceFileAppendString, propertyDefault_traceFileAppend); } // ---------------------------- password ----------------------------------- // // The password property is defined in subclasses, but the method // getPassword (java.util.Properties properties) is in this class to eliminate // dependencies on j2ee for connections that go thru the driver manager. public final static String propertyKey_password = "password"; public static String getPassword(Properties properties) { return properties.getProperty("password"); } protected String password = null; synchronized public void setPassword(String password) { this.password = password; } //------------------------ interface methods --------------------------------- public Reference getReference() throws NamingException { // This method creates a new Reference object to represent this data source. // The class name of the data source object is saved in the Reference, // so that an object factory will know that it should create an instance // of that class when a lookup operation is performed. The class // name of the object factory, org.apache.derby.client.ClientBaseDataSourceFactory, // is also stored in the reference. // This is not required by JNDI, but is recommend in practice. // JNDI will always use the object factory class specified in the reference when // reconstructing an object, if a class name has been specified. // See the JNDI SPI documentation // for further details on this topic, and for a complete description of the Reference // and StringRefAddr classes.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -