From 06b297938d9c16eff26a29d2fed5a867a6122b15 Mon Sep 17 00:00:00 2001 From: Barry Lind Date: Sun, 20 Oct 2002 02:55:50 +0000 Subject: [PATCH] Applied patch from Teofilis Martisius to improve performance. Also removed some unused files and fixed the which needed a small change after the previous patch to build.xml. Modified Files: jdbc/Makefile jdbc/org/postgresql/core/Encoding.java jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java Removed Files: jdbc/utils/CheckVersion.java jdbc/utils/buildDriver jdbc/utils/changelog.pl --- src/interfaces/jdbc/Makefile | 6 +- .../jdbc/org/postgresql/core/Encoding.java | 45 ++++++++++++- .../postgresql/jdbc1/AbstractJdbc1Connection.java | 10 ++- src/interfaces/jdbc/utils/CheckVersion.java | 74 ---------------------- src/interfaces/jdbc/utils/buildDriver | 47 -------------- src/interfaces/jdbc/utils/changelog.pl | 23 ------- 6 files changed, 55 insertions(+), 150 deletions(-) delete mode 100644 src/interfaces/jdbc/utils/CheckVersion.java delete mode 100755 src/interfaces/jdbc/utils/buildDriver delete mode 100644 src/interfaces/jdbc/utils/changelog.pl diff --git a/src/interfaces/jdbc/Makefile b/src/interfaces/jdbc/Makefile index fc881a34ba..3fbafe54ce 100644 --- a/src/interfaces/jdbc/Makefile +++ b/src/interfaces/jdbc/Makefile @@ -4,7 +4,7 @@ # # Copyright (c) 2001, PostgreSQL Global Development Group # -# $Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/Makefile,v 1.35 2002/07/23 03:59:54 barry Exp $ +# $Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/Makefile,v 1.36 2002/10/20 02:55:50 barry Exp $ # #------------------------------------------------------------------------- @@ -29,7 +29,7 @@ install: installdirs -Dinstall.directory=$(javadir) $(properties) installdirs: - $(mkinstalldirs) $(javadir) + $(mkinstalldirs) $(javadir) uninstall: $(ANT) -buildfile $(srcdir)/build.xml uninstall \ @@ -39,4 +39,4 @@ clean distclean maintainer-clean: $(ANT) -buildfile $(srcdir)/build.xml clean check: all - $(ANT) -buildfile $(srcdir)/build.xml test + $(ANT) -buildfile $(srcdir)/build.xml test $(properties) diff --git a/src/interfaces/jdbc/org/postgresql/core/Encoding.java b/src/interfaces/jdbc/org/postgresql/core/Encoding.java index 95d4af5781..ea395b844b 100644 --- a/src/interfaces/jdbc/org/postgresql/core/Encoding.java +++ b/src/interfaces/jdbc/org/postgresql/core/Encoding.java @@ -8,7 +8,7 @@ import org.postgresql.util.*; /* * Converts to and from the character encoding used by the backend. * - * $Id: Encoding.java,v 1.6 2002/09/06 21:23:05 momjian Exp $ + * $Id: Encoding.java,v 1.7 2002/10/20 02:55:50 barry Exp $ */ public class Encoding @@ -161,6 +161,9 @@ public class Encoding } else { + if (encoding.equals("UTF-8")) { + return decodeUTF8(encodedString, offset, length); + } return new String(encodedString, offset, length, encoding); } } @@ -223,4 +226,44 @@ public class Encoding return false; } } + + /** + * custom byte[] -> String conversion routine, 3x-10x faster than + * standard new String(byte[]) + */ + private static final int pow2_6 = 64; // 26 + private static final int pow2_12 = 4096; // 212 + private static char[] cdata = new char[50]; + + private synchronized String decodeUTF8(byte data[], int offset, int length) { + char[] l_cdata = cdata; + if (l_cdata.length < (length-offset)) { + l_cdata = new char[length-offset]; + } + int i = offset; + int j = 0; + int z, y, x, val; + while (i < length) { + z = data[i] & 0xFF; + if (z < 0x80) { + l_cdata[j++] = (char)data[i]; + i++; + } else if (z >= 0xE0) { // length == 3 + y = data[i+1] & 0xFF; + x = data[i+2] & 0xFF; + val = (z-0xE0)*pow2_12 + (y-0x80)*pow2_6 + (x-0x80); + l_cdata[j++] = (char) val; + i+= 3; + } else { // length == 2 (maybe add checking for length > 3, throw exception if it is + y = data[i+1] & 0xFF; + val = (z - 0xC0)* (pow2_6)+(y-0x80); + l_cdata[j++] = (char) val; + i+=2; + } + } + + String s = new String(l_cdata, 0, j); + return s; + } + } diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java index dbf785709b..f161c6616c 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java @@ -14,7 +14,7 @@ import org.postgresql.largeobject.LargeObjectManager; import org.postgresql.util.*; -/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.11 2002/10/17 05:33:52 barry Exp $ +/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.12 2002/10/20 02:55:50 barry Exp $ * This class defines methods of the jdbc1 specification. This class is * extended by org.postgresql.jdbc2.AbstractJdbc2Connection which adds the jdbc2 * methods. The real Connection class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Connection @@ -367,10 +367,16 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec //jdbc by default assumes autocommit is on until setAutoCommit(false) //is called. Therefore we need to ensure a new connection is //initialized to autocommit on. + //We also set the client encoding so that the driver only needs + //to deal with utf8. We can only do this in 7.3 because multibyte + //support is now always included if (haveMinimumServerVersion("7.3")) { java.sql.ResultSet acRset = - ExecSQL("show autocommit"); + ExecSQL("set client_encoding = 'UNICODE'; show autocommit"); + + //set encoding to be unicode + encoding = Encoding.getEncoding("UNICODE", null); if (!acRset.next()) { diff --git a/src/interfaces/jdbc/utils/CheckVersion.java b/src/interfaces/jdbc/utils/CheckVersion.java deleted file mode 100644 index a2438cd4f9..0000000000 --- a/src/interfaces/jdbc/utils/CheckVersion.java +++ /dev/null @@ -1,74 +0,0 @@ -package utils; - -/* - * This little app checks to see what version of JVM is being used. - * It does this by checking first the java.vm.version property, and - * if that fails, it looks for certain classes that should be present. - */ -public class CheckVersion -{ - /* - * Check for the existence of a class by attempting to load it - */ - public static boolean checkClass(String c) - { - try - { - Class.forName(c); - } - catch (Exception e) - { - return false; - } - return true; - } - - /* - * This first checks java.vm.version for 1.1, 1.2 or 1.3. - * - * It writes jdbc1 to stdout for the 1.1.x VM. - * - * For 1.2 or 1.3, it checks for the existence of the javax.sql.DataSource - * interface, and if found writes enterprise to stdout. If the interface - * is not found, it writes jdbc2 to stdout. - * - * PS: It also looks for the existence of java.lang.Byte which appeared in - * JDK1.1.0 incase java.vm.version is not heeded by some JVM's. - * - * If it can't work it out, it writes huho to stdout. - * - * The make file uses the written results to determine which rule to run. - * - * Bugs: This needs thorough testing. - */ - public static void main(String args[]) - { - String vmversion = System.getProperty("java.vm.version"); - - System.out.println("postgresql.jdbc=" + System.getProperty("postgresql.jdbc")); - - // We are running a 1.1 JVM - if (vmversion.startsWith("1.1")) - { - System.out.println("jdbc1"); - //System.exit(0); - } - else - // We are running a 1.2 or 1.3 JVM - if (vmversion.startsWith("1.2") || - vmversion.startsWith("1.3") || - checkClass("java.lang.Byte") - ) - { - - // Check to see if we have the standard extensions. If so, then - // we want the enterprise edition, otherwise the jdbc2 driver. - if (checkClass("javax.sql.DataSource")) - System.out.println("enterprise"); - else - System.out.println("jdbc2"); - //System.exit(0); - } - System.setProperty("postgresql.jdbc", "yoyo"); - } -} diff --git a/src/interfaces/jdbc/utils/buildDriver b/src/interfaces/jdbc/utils/buildDriver deleted file mode 100755 index 8cca1d9c36..0000000000 --- a/src/interfaces/jdbc/utils/buildDriver +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/sh -# -# $Id: buildDriver,v 1.2 2000/12/20 16:22:49 peter Exp $ -# -# This script generates the org/postgresql/Driver.java file from the template -# org/postgresql/Driver.java.in -# -# We do this because we need to include the version number from Makefile.global -# and some other goodies. -# -# This used to be in Makefile, but as it's now done three times, it's better -# to have it as a separate script. -# -# If you have any problems, please let us know ;-) -# -# Syntax: buildDriver version class -# -# Where: -# version The version string from Makefile.global -# class The class implementing java.sql.Connection -# edition The driver edition being built -# source The file to build. We assume that ${source}.in exists -# - -VERSION=$1 -CLASS=$2 -EDITION=$3 -SOURCE=$4 - -#--------------------------------------------------------------------------- -# Extract the version. This will work until version x.9 (and assuming we don't -# have 7.10 etc). We only handle 1 digit for MINORVERSION to handle things like -# 7.1devel etc -# -MAJORVERSION=`echo $VERSION | cut -f1 -d'.'` -MINORVERSION=`echo $VERSION | cut -f2 -d'.' | cut -c1` - -#--------------------------------------------------------------------------- -# Now finally build the driver -sed \ - -e "s/@JDBCCONNECTCLASS@/$CLASS/g" \ - -e "s/@VERSION@/$VERSION $EDITION/g" \ - -e "s/@MAJORVERSION@/$MAJORVERSION/g" \ - -e "s/@MINORVERSION@/$MINORVERSION/g" \ - <${SOURCE}.in \ - >$SOURCE -#--------------------------------------------------------------------------- diff --git a/src/interfaces/jdbc/utils/changelog.pl b/src/interfaces/jdbc/utils/changelog.pl deleted file mode 100644 index 3cba15aa91..0000000000 --- a/src/interfaces/jdbc/utils/changelog.pl +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/perl - -while(<>) { - chomp(); - s/\t+/ /g; - if(substr($_,0,3) eq ' - ') { - print "" if $inlist; - $inlist=0; - print "
\n"; - } elsif(substr($_,0,1) eq " ") { - print $_; - } else { - print "" if $inlist; - $inlist=0; - print "

".$_."

\n"; - } - } -} -- 2.11.0