Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3CA56FA56 for ; Mon, 1 Apr 2013 03:58:48 +0000 (UTC) Received: (qmail 84641 invoked by uid 500); 1 Apr 2013 03:58:48 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 84602 invoked by uid 500); 1 Apr 2013 03:58:47 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 84584 invoked by uid 99); 1 Apr 2013 03:58:46 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Apr 2013 03:58:46 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Apr 2013 03:58:42 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 3F99F2388994; Mon, 1 Apr 2013 03:58:21 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1463079 - in /db/derby/code/trunk/java/client/org/apache/derby: client/am/Configuration.java client/am/LogWriter.java client/net/NetLogWriter.java client/net/NetPackageRequest.java jdbc/ClientBaseDataSourceRoot.java Date: Mon, 01 Apr 2013 03:58:20 -0000 To: derby-commits@db.apache.org From: dag@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130401035821.3F99F2388994@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dag Date: Mon Apr 1 03:58:20 2013 New Revision: 1463079 URL: http://svn.apache.org/r1463079 Log: DERBY-6125 Code clean up in client driver. Patch derby-6125-03-a. This patch - makes a mutable public array (dncPackageConsistencyToken) private. - removes a couple of assignment with values that are never used (e.g. myPVH) - makes some members final and public - reworks an invariant to use SanityManager assert - replaces a StringBuffer with StringBuilder - makes a lazy initialization thread safe (codePointNameTable__) - removes a couple of noop bit operations - removes an unused method (computeDncLogWriter with existing connection overload) Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Configuration.java db/derby/code/trunk/java/client/org/apache/derby/client/am/LogWriter.java db/derby/code/trunk/java/client/org/apache/derby/client/net/NetLogWriter.java db/derby/code/trunk/java/client/org/apache/derby/client/net/NetPackageRequest.java db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSourceRoot.java Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Configuration.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Configuration.java?rev=1463079&r1=1463078&r2=1463079&view=diff ============================================================================== --- db/derby/code/trunk/java/client/org/apache/derby/client/am/Configuration.java (original) +++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Configuration.java Mon Apr 1 03:58:20 2013 @@ -28,7 +28,6 @@ import java.security.PrivilegedException import org.apache.derby.iapi.services.info.ProductGenusNames; import org.apache.derby.iapi.services.info.ProductVersionHolder; -import org.apache.derby.jdbc.ClientDataSourceInterface; import org.apache.derby.shared.common.reference.SQLState; public class Configuration { @@ -61,9 +60,15 @@ public class Configuration { // Hard-wired for JDBC // // Currently ASCII hex value of "SYSLVL01". - public final static byte[] dncPackageConsistencyToken = + private final static byte[] dncPackageConsistencyToken = {0x53, 0x59, 0x53, 0x4c, 0x56, 0x4c, 0x30, 0x31}; + public static byte[] getDncPackageConsistencyToken() { + byte [] cpy = new byte[dncPackageConsistencyToken.length]; + System.arraycopy(dncPackageConsistencyToken, 0, cpy, 0, cpy.length); + return cpy; + } + // We will not set package VERSION in the initial release. // If we have to change the package version in the future then we can. public static final String dncPackageVersion = null; @@ -189,8 +194,7 @@ public class Configuration { // Create ProductVersionHolder in security block for Java 2 security. private static ProductVersionHolder buildProductVersionHolder() throws java.security.PrivilegedActionException, IOException { - ProductVersionHolder myPVH = null; - myPVH = AccessController.doPrivileged( + return AccessController.doPrivileged( new PrivilegedExceptionAction() { public ProductVersionHolder run() throws IOException { @@ -199,8 +203,6 @@ public class Configuration { return ProductVersionHolder.getProductVersionHolderFromMyEnv(versionStream); } }); - - return myPVH; } /** Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/LogWriter.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/LogWriter.java?rev=1463079&r1=1463078&r2=1463079&view=diff ============================================================================== --- db/derby/code/trunk/java/client/org/apache/derby/client/am/LogWriter.java (original) +++ db/derby/code/trunk/java/client/org/apache/derby/client/am/LogWriter.java Mon Apr 1 03:58:20 2013 @@ -23,21 +23,20 @@ package org.apache.derby.client.am; import java.io.IOException; import java.io.PrintWriter; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; import java.security.AccessController; import java.security.PrivilegedExceptionAction; import java.sql.SQLException; import java.util.Properties; +import org.apache.derby.iapi.services.sanity.SanityManager; import org.apache.derby.jdbc.ClientBaseDataSourceRoot; import org.apache.derby.jdbc.ClientDataSourceInterface; import org.apache.derby.shared.common.reference.Attribute; import org.apache.derby.shared.common.reference.SQLState; public class LogWriter { - protected java.io.PrintWriter printWriter_; - protected int traceLevel_; + final protected PrintWriter printWriter_; + final private int traceLevel_; + private boolean driverConfigurationHasBeenWrittenToJdbc1Stream_ = false; private boolean driverConfigurationHasBeenWrittenToJdbc2Stream_ = false; @@ -48,8 +47,14 @@ public class LogWriter { } final protected boolean loggingEnabled(int traceLevel) { - // It is an invariant that the printWriter is never null, so remove the - return printWriter_ != null && (traceLevel & traceLevel_) != 0; + if (SanityManager.DEBUG) { + if (printWriter_ == null) { + SanityManager.THROWASSERT( + "Broken invariant: printWriter_ == null"); + } + } + + return (traceLevel & traceLevel_) != 0; } // When garbage collector doesn't kick in in time @@ -112,10 +117,6 @@ public class LogWriter { dncprintln(staticContextTracepointRecord); } - private String getMemoryMapDisplay(java.util.Map memory) { - return memory.toString(); // need to loop thru all keys in the map and print values - } - // ------------- API entry and exit trace methods ---------------------------- // Entry and exit are be traced separately because input arguments need // to be traced before any potential exception can occur. @@ -877,7 +878,7 @@ public class LogWriter { } private String escapePassword(String pw) { - StringBuffer sb = new StringBuffer(pw); + StringBuilder sb = new StringBuilder(pw); for (int j = 0; j < pw.length(); j++) { sb.setCharAt(j, '*'); } Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetLogWriter.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetLogWriter.java?rev=1463079&r1=1463078&r2=1463079&view=diff ============================================================================== --- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetLogWriter.java (original) +++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetLogWriter.java Mon Apr 1 03:58:20 2013 @@ -125,6 +125,14 @@ public class NetLogWriter extends org.ap // Initialize the codepoint name table if not previously initialized. // This is done lazily so that it is not created if the trace isn't used (save some init time). + + if (codePointNameTable__ == null) { + initCodePointTable(); + } + } + + // synchonized so only one thread can initialize the table + private synchronized void initCodePointTable() { if (codePointNameTable__ == null) { codePointNameTable__ = new CodePointNameTable(); } @@ -187,13 +195,13 @@ public class NetLogWriter extends org.ap return; } synchronized (printWriter_) { - super.tracepoint("[net]", tracepoint, className, methodName); + tracepoint("[net]", tracepoint, className, methodName); int fullLen = len; boolean printColPos = true; while (fullLen >= 2) { // format each DssHdr seperately // get the length of this DssHdr - len = ((buff[offset] & 0xff) << 8) + ((buff[offset + 1] & 0xff) << 0); + len = ((buff[offset] & 0xff) << 8) + (buff[offset + 1] & 0xff); // check for valid dss header or not all of dss block if ((len < 10) || (len > fullLen)) { @@ -334,7 +342,7 @@ public class NetLogWriter extends org.ap // Gets the int value of the two byte unsigned codepoint. private static int getCodePoint(byte[] buff, int offset) { return ((buff[offset++] & 0xff) << 8) + - ((buff[offset] & 0xff) << 0); + (buff[offset] & 0xff); } private static String getHeader(int type) { Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetPackageRequest.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetPackageRequest.java?rev=1463079&r1=1463078&r2=1463079&view=diff ============================================================================== --- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetPackageRequest.java (original) +++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetPackageRequest.java Mon Apr 1 03:58:20 2013 @@ -68,8 +68,8 @@ public class NetPackageRequest extends N byte[] pkgNameBytes = ccsidMgr.convertFromJavaString( section.getPackageName(), netAgent_); - boolean scldtalenRequired = false; - scldtalenRequired = checkPKGNAMlengths(netAgent_.netConnection_.databaseName_, + boolean scldtalenRequired = + checkPKGNAMlengths(netAgent_.netConnection_.databaseName_, dbnameBytes.length, maxIdentifierLength, NetConfiguration.PKG_IDENTIFIER_FIXED_LEN); @@ -128,7 +128,8 @@ public class NetPackageRequest extends N // Mark the beginning of PKGNAMCSN bytes. markForCachingPKGNAMCSN(); buildCommonPKGNAMinfo(section); - writeScalarPaddedBytes(Configuration.dncPackageConsistencyToken, + writeScalarPaddedBytes( + Configuration.getDncPackageConsistencyToken(), NetConfiguration.PKGCNSTKN_FIXED_LEN, NetConfiguration.NON_CHAR_DDM_DATA_PAD_BYTE); // store the PKGNAMCbytes @@ -188,7 +189,7 @@ public class NetPackageRequest extends N if (string == null) { write2Bytes(0xffff); } else { - byte[] sqlBytes = null; + byte[] sqlBytes; if (netAgent_.typdef_.isCcsidMbcSet()) { sqlBytes = getBytes(string, netAgent_.typdef_.getCcsidMbcEncoding()); @@ -218,7 +219,6 @@ public class NetPackageRequest extends N // SQLSTATEMENT_s; PROTOCOL TYPE NOCS; ENVLID 0xCB; Length Override 4 private void buildSQLSTTGRP(String string) throws SqlException { buildNOCMorNOCS(string); - return; } // SQLSTT : FDOCA EARLY ROW Modified: db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSourceRoot.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSourceRoot.java?rev=1463079&r1=1463078&r2=1463079&view=diff ============================================================================== --- db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSourceRoot.java (original) +++ db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSourceRoot.java Mon Apr 1 03:58:20 2013 @@ -601,50 +601,6 @@ public abstract class ClientBaseDataSour return dncLogWriter; } - // Compute a DNC log writer after a connection is created. - // Declared public for use by am.Connection. Not a public external. - public static LogWriter computeDncLogWriter( - Connection connection, - PrintWriter logWriter, - String traceDirectory, - String traceFile, - boolean traceFileAppend, - String logWriterInUseSuffix, - int traceFileSuffixIndex, - int traceLevel) throws SqlException { - - // Otherwise, the trace file will still be created even TRACE_NONE. - if (traceLevel == TRACE_NONE) { - return null; - } - - PrintWriter printWriter = computePrintWriter( - logWriter, - traceDirectory, - traceFile, - traceFileAppend, - logWriterInUseSuffix, - traceFileSuffixIndex); - - if (printWriter == null) { - return null; - } - - LogWriter dncLogWriter = - connection.agent_.newLogWriter_(printWriter, traceLevel); - - if (printWriter != logWriter && - (traceDirectory != null || traceFile != null)) - // When printWriter is an internal trace file and - // traceDirectory is not null, each connection has - // its own trace file and the trace file is not cached, - // so we can close it when DNC log writer is closed. - { - dncLogWriter.printWriterNeedsToBeClosed_ = true; - } - return dncLogWriter; - } - // This method handles all the override semantics. The logWriter // overrides the traceFile, and traceDirectory settings. If neither // traceFile, nor logWriter, nor traceDirectory are set, then null is