📄 netconnection.java
字号:
/* Derby - Class org.apache.derby.client.net.NetConnection 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.client.net;import org.apache.derby.jdbc.ClientBaseDataSource;import org.apache.derby.client.am.CallableStatement;import org.apache.derby.client.am.DatabaseMetaData;import org.apache.derby.client.am.DisconnectException;import org.apache.derby.client.am.EncryptionManager;import org.apache.derby.client.am.PreparedStatement;import org.apache.derby.client.am.ProductLevel;import org.apache.derby.client.am.SqlException;import org.apache.derby.client.am.Statement;import org.apache.derby.client.am.Utils;import org.apache.derby.jdbc.ClientDataSource;public class NetConnection extends org.apache.derby.client.am.Connection { protected NetAgent netAgent_; // For XA Transaction protected int pendingEndXACallinfoOffset_ = -1; // byte[] to save the connect flows for connection reset protected byte[] cachedConnectBytes_ = null; protected boolean wroteConnectFromCache_ = false; //-----------------------------state------------------------------------------ // these variables store the manager levels for the connection. // they are initialized to the highest value which this driver supports // at the current time. theses intial values should be increased when // new manager level support is added to this driver. these initial values // are sent to the server in the excsat command. the server will return a // set of values and these will be parsed out by parseExcsatrd and parseMgrlvlls. // during this parsing, these instance variable values will be reset to the negotiated // levels for the connection. these values may be less than the // values origionally set here at constructor time. it is these new values // (following the parse) which are the levels for the connection. after // a successful excsat command, these values can be checked to see // what protocol is supported by this particular connection. // if support for a new manager class is added, the buildExcsat and parseMgrlvlls // methods will need to be changed to accomodate sending and receiving the new class. protected int targetAgent_ = NetConfiguration.MGRLVL_7; //01292003jev monitoring protected int targetCmntcpip_ = NetConfiguration.MGRLVL_5; protected int targetRdb_ = NetConfiguration.MGRLVL_7; public int targetSecmgr_ = NetConfiguration.MGRLVL_7; protected int targetCmnappc_ = NetConfiguration.MGRLVL_NA; //NA since currently not used by net protected int targetXamgr_ = NetConfiguration.MGRLVL_7; protected int targetSyncptmgr_ = NetConfiguration.MGRLVL_NA; protected int targetRsyncmgr_ = NetConfiguration.MGRLVL_NA; // this is the external name of the target server. // it is set by the parseExcsatrd method but not really used for much at this // time. one possible use is for logging purposes and in the future it // may be placed in the trace. String targetExtnam_; String extnam_; // Server Class Name of the target server returned in excsatrd. // Again this is something which the driver is not currently using // to make any decions. Right now it is just stored for future logging. // It does contain some useful information however and possibly // the database meta data object will make use of this // for example, the product id (prdid) would give this driver an idea of // what type of sevrer it is connected to. public String targetSrvclsnm_; // Server Name of the target server returned in excsatrd. // Again this is something which we don't currently use but // keep it in case we want to log it in some problem determination // trace/dump later. protected String targetSrvnam_; // Server Product Release Level of the target server returned in excsatrd. // specifies the procuct release level of a ddm server. // Again this is something which we don't currently use but // keep it in case we want to log it in some problem determination // trace/dump later. public String targetSrvrlslv_; // Keys used for encryption. transient byte[] publicKey_; transient byte[] targetPublicKey_; // Product-Specific Data (prddta) sent to the server in the accrdb command. // The prddta has a specified format. It is saved in case it is needed again // since it takes a little effort to compute. Saving this information is // useful for when the connect flows need to be resent (right now the connect // flow is resent when this driver disconnects and reconnects with // non unicode ccsids. this is done when the server doesn't recoginze the // unicode ccsids). // byte[] prddta_; // Correlation Token of the source sent to the server in the accrdb. // It is saved like the prddta in case it is needed for a connect reflow. public byte[] crrtkn_; // The Secmec used by the target. // It contains the negotiated security mechanism for the connection. // Initially the value of this is 0. It is set only when the server and // the target successfully negotiate a security mechanism. int targetSecmec_; // the security mechanism requested by the application protected int securityMechanism_; // stored the password for deferred reset only. private transient char[] deferredResetPassword_ = null; //If Network Server gets null connection from the embedded driver, //it sends RDBAFLRM followed by SQLCARD with null SQLException. //Client will parse the SQLCARD and set connectionNull to true if the //SQLCARD is empty. If connectionNull=true, connect method in //ClientDriver will in turn return null connection. private boolean connectionNull = false; private void setDeferredResetPassword(String password) { deferredResetPassword_ = (password == null) ? null : flipBits(password.toCharArray()); } private String getDeferredResetPassword() { if (deferredResetPassword_ == null) { return null; } String password = new String(flipBits(deferredResetPassword_)); flipBits(deferredResetPassword_); // re-encrypt password return password; } protected byte[] cnntkn_ = null; // resource manager Id for XA Connections. private int rmId_ = 0; protected NetXAResource xares_ = null; protected java.util.Hashtable indoubtTransactions_ = null; protected int currXACallInfoOffset_ = 0; private short seqNo_ = 1; // Flag to indicate a read only transaction protected boolean readOnlyTransaction_ = true; //---------------------constructors/finalizer--------------------------------- public NetConnection(NetLogWriter netLogWriter, String databaseName, java.util.Properties properties) throws SqlException { super(netLogWriter, 0, "", -1, databaseName, properties); } public NetConnection(NetLogWriter netLogWriter, org.apache.derby.jdbc.ClientDataSource dataSource, String user, String password) throws SqlException { super(netLogWriter, user, password, dataSource); setDeferredResetPassword(password); } // For jdbc 1 connections public NetConnection(NetLogWriter netLogWriter, int driverManagerLoginTimeout, String serverName, int portNumber, String databaseName, java.util.Properties properties) throws SqlException { super(netLogWriter, driverManagerLoginTimeout, serverName, portNumber, databaseName, properties); netAgent_ = (NetAgent) super.agent_; if (netAgent_.exceptionOpeningSocket_ != null) { throw netAgent_.exceptionOpeningSocket_; } checkDatabaseName(); String password = ClientDataSource.getPassword(properties); securityMechanism_ = ClientDataSource.getSecurityMechanism(properties); flowConnect(password, securityMechanism_); if(!isConnectionNull()) completeConnect(); } // For JDBC 2 Connections public NetConnection(NetLogWriter netLogWriter, String user, String password, org.apache.derby.jdbc.ClientDataSource dataSource, int rmId, boolean isXAConn) throws SqlException { super(netLogWriter, user, password, isXAConn, dataSource); netAgent_ = (NetAgent) super.agent_; initialize(user, password, dataSource, rmId, isXAConn); } public NetConnection(NetLogWriter netLogWriter, String ipaddr, int portNumber, org.apache.derby.jdbc.ClientDataSource dataSource, boolean isXAConn) throws SqlException { super(netLogWriter, isXAConn, dataSource); netAgent_ = (NetAgent) super.agent_; if (netAgent_.exceptionOpeningSocket_ != null) { throw netAgent_.exceptionOpeningSocket_; } checkDatabaseName(); this.isXAConnection_ = isXAConn; flowSimpleConnect(); productID_ = targetSrvrlslv_; super.completeConnect(); } private void initialize(String user, String password, org.apache.derby.jdbc.ClientDataSource dataSource, int rmId, boolean isXAConn) throws SqlException { securityMechanism_ = dataSource.getSecurityMechanism(); setDeferredResetPassword(password); checkDatabaseName(); dataSource_ = dataSource; this.rmId_ = rmId; this.isXAConnection_ = isXAConn; flowConnect(password, securityMechanism_); completeConnect(); } // preferably without password in the method signature. // We can probally get rid of flowReconnect method. public void resetNetConnection(org.apache.derby.client.am.LogWriter logWriter, String user, String password, org.apache.derby.jdbc.ClientDataSource ds, boolean recomputeFromDataSource) throws SqlException { super.resetConnection(logWriter, user, ds, recomputeFromDataSource); //---------------------------------------------------- if (recomputeFromDataSource) { // do not reset managers on a connection reset. this information shouldn't // change and can be used to check secmec support. targetExtnam_ = null; targetSrvclsnm_ = null; targetSrvnam_ = null; targetSrvrlslv_ = null; publicKey_ = null; targetPublicKey_ = null; targetSecmec_ = 0; if (ds != null && securityMechanism_ == 0) { securityMechanism_ = ds.getSecurityMechanism(); } resetConnectionAtFirstSql_ = false; } if (password != null) { deferredResetPassword_ = null; } else { password = getDeferredResetPassword(); } // properties prddta_ and crrtkn_ will be initialized by // calls to constructPrddta() and constructCrrtkn() //---------------------------------------------------------- boolean isDeferredReset = flowReconnect(password, securityMechanism_); completeReset(isDeferredReset, recomputeFromDataSource); } protected void reset_(org.apache.derby.client.am.LogWriter logWriter, String user, String password, ClientDataSource ds, boolean recomputeFromDataSource) throws SqlException { checkResetPreconditions(logWriter, user, password, ds); resetNetConnection(logWriter, user, password, ds, recomputeFromDataSource); } protected void reset_(org.apache.derby.client.am.LogWriter logWriter, ClientDataSource ds, boolean recomputeFromDataSource) throws SqlException { checkResetPreconditions(logWriter, null, null, ds); resetNetConnection(logWriter, ds, recomputeFromDataSource); } private void resetNetConnection(org.apache.derby.client.am.LogWriter logWriter, org.apache.derby.jdbc.ClientDataSource ds, boolean recomputeFromDataSource) throws SqlException { super.resetConnection(logWriter, null, ds, recomputeFromDataSource); //---------------------------------------------------- if (recomputeFromDataSource) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -