📄 netconnection.java
字号:
//-------------------Abstract object factories-------------------------------- protected org.apache.derby.client.am.Agent newAgent_(org.apache.derby.client.am.LogWriter logWriter, int loginTimeout, String serverName, int portNumber) throws SqlException { return new NetAgent(this, (NetLogWriter) logWriter, loginTimeout, serverName, portNumber); } protected Statement newStatement_(int type, int concurrency, int holdability) throws SqlException { return new NetStatement(netAgent_, this, type, concurrency, holdability).statement_; } protected void resetStatement_(Statement statement, int type, int concurrency, int holdability) throws SqlException { ((NetStatement) statement.materialStatement_).resetNetStatement(netAgent_, this, type, concurrency, holdability); } protected PreparedStatement newPositionedUpdatePreparedStatement_(String sql, org.apache.derby.client.am.Section section) throws SqlException { return new NetPreparedStatement(netAgent_, this, sql, section).preparedStatement_; } protected PreparedStatement newPreparedStatement_(String sql, int type, int concurrency, int holdability, int autoGeneratedKeys, String[] columnNames) throws SqlException { return new NetPreparedStatement(netAgent_, this, sql, type, concurrency, holdability, autoGeneratedKeys, columnNames).preparedStatement_; } protected void resetPreparedStatement_(PreparedStatement ps, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability, int autoGeneratedKeys, String[] columnNames) throws SqlException { ((NetPreparedStatement) ps.materialPreparedStatement_).resetNetPreparedStatement(netAgent_, this, sql, resultSetType, resultSetConcurrency, resultSetHoldability, autoGeneratedKeys, columnNames); } protected CallableStatement newCallableStatement_(String sql, int type, int concurrency, int holdability) throws SqlException { return new NetCallableStatement(netAgent_, this, sql, type, concurrency, holdability).callableStatement_; } protected void resetCallableStatement_(CallableStatement cs, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SqlException { ((NetCallableStatement) cs.materialCallableStatement_).resetNetCallableStatement(netAgent_, this, sql, resultSetType, resultSetConcurrency, resultSetHoldability); } protected DatabaseMetaData newDatabaseMetaData_() { return new NetDatabaseMetaData(netAgent_, this); } //-------------------private helper methods-------------------------------- private void checkDatabaseName() throws SqlException { // netAgent_.logWriter may not be initialized yet if (databaseName_ == null) { throw new SqlException(agent_.logWriter_, "Required property \"databaseName\" not set"); } } private void checkUserLength(String user) throws SqlException { int usridLength = user.length(); if ((usridLength == 0) || (usridLength > NetConfiguration.USRID_MAXSIZE)) { throw new SqlException(netAgent_.logWriter_, "userid length, " + usridLength + ", is not allowed."); } } private void checkPasswordLength(String password) throws SqlException { int passwordLength = password.length(); if ((passwordLength == 0) || (passwordLength > NetConfiguration.PASSWORD_MAXSIZE)) { throw new SqlException(netAgent_.logWriter_, "password length, " + passwordLength + ", is not allowed."); } } private void checkUser(String user) throws SqlException { if (user == null) { throw new SqlException(netAgent_.logWriter_, "null userid not supported"); } checkUserLength(user); } private void checkUserPassword(String user, String password) throws SqlException { checkUser(user); if (password == null) { throw new SqlException(netAgent_.logWriter_, "null password not supported"); } checkPasswordLength(password); } // Determine if a security mechanism is supported by // the security manager used for the connection. // An exception is thrown if the security mechanism is not supported // by the secmgr. private void checkSecmgrForSecmecSupport(int securityMechanism) throws SqlException { boolean secmecSupported = false; int[] supportedSecmecs = null; // Point to a list (array) of supported security mechanisms. supportedSecmecs = NetConfiguration.SECMGR_SECMECS; // check to see if the security mechanism is on the supported list. for (int i = 0; (i < supportedSecmecs.length) && (!secmecSupported); i++) { if (supportedSecmecs[i] == securityMechanism) { secmecSupported = true; } } // throw an exception if not supported (not on list). if (!secmecSupported) { throw new SqlException(agent_.logWriter_, "Security mechananism specified by app not supported by connection"); } } // If secchkcd is not 0, map to SqlException // according to the secchkcd received. private SqlException mapSecchkcd(int secchkcd) { if (secchkcd == CodePoint.SECCHKCD_00) { return null; } // the net driver will not support new password at this time. // Here is the message for -30082 (STATE "08001"): // Attempt to establish connection failed with security // reason {0} {1} + reason-code + reason-string. switch (secchkcd) { case CodePoint.SECCHKCD_01: // ERROR SVRCOD return new SqlException(agent_.logWriter_, "Connection authorization failure occurred. Reason: security mechanism not supported"); //"08001", -30082); case CodePoint.SECCHKCD_10: // ERROR SVRCOD return new SqlException(agent_.logWriter_, "Connection authorization failure occurred. Reason: password missing."); case CodePoint.SECCHKCD_12: // ERROR SVRCOD return new SqlException(agent_.logWriter_, "Connection authorization failure occurred. Reason: userid missing."); case CodePoint.SECCHKCD_13: // ERROR SVRCOD return new SqlException(agent_.logWriter_, "Connection authorization failure occurred. Reason: userid invalid."); case CodePoint.SECCHKCD_14: // ERROR SVRCOD return new SqlException(agent_.logWriter_, "Connection authorization failure occurred. Reason: userid revoked."); case CodePoint.SECCHKCD_15: // ERROR SVRCOD return new SqlException(agent_.logWriter_, "Connection authorization failure occurred. Reason: new password invalid."); case CodePoint.SECCHKCD_0A: // ERROR SVRCOD return new SqlException(agent_.logWriter_, "Connection authorization failure occurred. Reason: local security service non-retryable error."); case CodePoint.SECCHKCD_0B: // ERROR SVRCOD return new SqlException(agent_.logWriter_, "Connection authorization failure occurred. Reason: SECTKN missing on ACCSEC when it is required or it is invalid"); case CodePoint.SECCHKCD_0E: // ERROR SVRCOD return new SqlException(agent_.logWriter_, "Connection authorization failure occurred. Reason: password expired."); case CodePoint.SECCHKCD_0F: // ERROR SVRCOD return new SqlException(agent_.logWriter_, "Connection authorization failure occurred. Reason: password invalid."); default: // ERROR SVRCOD return new SqlException(agent_.logWriter_, "Connection authorization failure occurred. Reason: not specified."); } } // Construct the correlation token. // The crrtkn has the following format. // // <Almost IP address>.<local port number><current time in millis> // | | | || | // +----+--------------+ +-----+---------++---------+--------+ // | | | // 8 bytes 4 bytes 6 bytes // Total lengtho of 19 bytes. // // 1 char for each 1/2 byte in the IP address. // If the first character of the <IP address> or <port number> // starts with '0' thru '9', it will be mapped to 'G' thru 'P'. // Reason for mapping the IP address is in order to use the crrtkn as the LUWID when using SNA in a hop site. protected void constructCrrtkn() throws SqlException { byte[] localAddressBytes = null; long time = 0; int num = 0; int halfByte = 0; int i = 0; int j = 0; // allocate the crrtkn array. if (crrtkn_ == null) { crrtkn_ = new byte[19]; } else { java.util.Arrays.fill(crrtkn_, (byte) 0); } localAddressBytes = netAgent_.socket_.getLocalAddress().getAddress(); // IP addresses are returned in a 4 byte array. // Obtain the character representation of each half byte. for (i = 0, j = 0; i < 4; i++, j += 2) { // since a byte is signed in java, convert any negative // numbers to positive before shifting. num = localAddressBytes[i] < 0 ? localAddressBytes[i] + 256 : localAddressBytes[i]; halfByte = (num >> 4) & 0x0f; // map 0 to G // The first digit of the IP address is is replaced by // the characters 'G' thro 'P'(in order to use the crrtkn as the LUWID when using // SNA in a hop site). For example, 0 is mapped to G, 1 is mapped H,etc. if (i == 0) { crrtkn_[j] = netAgent_.sourceCcsidManager_.numToSnaRequiredCrrtknChar_[halfByte]; } else { crrtkn_[j] = netAgent_.sourceCcsidManager_.numToCharRepresentation_[halfByte]; } halfByte = (num) & 0x0f; crrtkn_[j + 1] = netAgent_.sourceCcsidManager_.numToCharRepresentation_[halfByte]; } // fill the '.' in between the IP address and the port number crrtkn_[8] = netAgent_.sourceCcsidManager_.dot_; // Port numbers have values which fit in 2 unsigned bytes. // Java returns port numbers in an int so the value is not negative. // Get the character representation by converting the // 4 low order half bytes to the character representation. num = netAgent_.socket_.getLocalPort(); halfByte = (num >> 12) & 0x0f; crrtkn_[9] = netAgent_.sourceCcsidManager_.numToSnaRequiredCrrtknChar_[halfByte]; halfByte = (num >> 8) & 0x0f; crrtkn_[10] = netAgent_.sourceCcsidManager_.numToCharRepresentation_[halfByte]; halfByte = (num >> 4) & 0x0f; crrtkn_[11] = netAgent_.sourceCcsidManager_.numToCharRepresentation_[halfByte]; halfByte = (num) & 0x0f; crrtkn_[12] = netAgent_.sourceCcsidManager_.numToCharRepresentation_[halfByte]; // The final part of CRRTKN is a 6 byte binary number that makes the // crrtkn unique, which is usually the time stamp/process id. // If the new time stamp is the // same as one of the already created ones, then recreate the time stamp. time = System.currentTimeMillis(); for (i = 0; i < 6; i++) { // store 6 bytes of 8 byte time into crrtkn crrtkn_[i + 13] = (byte) (time >>> (40 - (i * 8))); } } private void constructExtnam() throws SqlException { extnam_ = "derbydnc" + java.lang.Thread.currentThread().getName(); } private void constructPrddta() throws SqlException { int prddtaLen = 1; if (prddta_ == null) { prddta_ = new byte[NetConfiguration.PRDDTA_MAXSIZE]; } else { java.util.Arrays.fill(prddta_, (byte) 0); } for (int i = 0; i < NetConfiguration.PRDDTA_ACCT_SUFFIX_LEN_BYTE; i++) { prddta_[i] = netAgent_.sourceCcsidManager_.space_; } prddtaLen = netAgent_.sourceCcsidManager_.convertFromUCS2(NetConfiguration.PRDID, prddta_, prddtaLen, netAgent_); prddtaLen = netAgent_.sourceCcsidManager_.convertFromUCS2(NetConfiguration.PRDDTA_PLATFORM_ID, prddta_, prddtaLen, netAgent_); int extnamTruncateLength = Utils.min(extnam_.length(), NetConfiguration.PRDDTA_APPL_ID_FIXED_LEN); netAgent_.sourceCcsidManager_.convertFromUCS2(extnam_.substring(0, extnamTruncateLength), prddta_, prddtaLen, netAgent_); prddtaLen += NetConfiguration.PRDDTA_APPL_ID_FIXED_LEN; if (user_ != null) { int userTruncateLength = Utils.min(user_.length(), NetConfiguration.PRDDTA_USER_ID_FIXED_LEN); netAgent_.sourceCcsidManager_.convertFromUCS2(user_.substring(0, userTruncateLength), prddta_, prddtaLen, netAgent_); } prddtaLen += NetConfiguration.PRDDTA_USER_ID_FIXED_LEN; prddta_[NetConfiguration.PRDDTA_ACCT_SUFFIX_LEN_BYTE] = 0; prddtaLen++; // the length byte value does not include itself. prddta_[NetConfiguration.PRDDTA_LEN_BYTE] = (byte) (prddtaLen - 1); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -