Sybase JDBC driver improvement 2

zhaozj2021-02-16  38

(Continued)

The implementation of Sun J2SE (1.4) is very slow to character set conversion. I use JFluid to find a simple database program that takes more than 60% of the character set conversion, so it is necessary to cache conversion results:

Package com.sybase.jdbc2.jdbc;

Import java.io.unsupportedEncodingexception;

Import java.util. *;

Public class cachedcharset {

Public String ConvertTo (String src) {

Try {

String dest = (String) CacheconVertto.get (SRC);

IF (dest == NULL) {

Byte [] bytes = src.getbytes (destcharset);

Dest = new string (bytes, RAW);

IF (cacheconvertto.size ()> expire_every)

Cacheconvertto.clear ();

CacheConvertTo.Put (src, dest);

}

Return DEST;

} catch (unsupporteencodingexception e) {

Throw new runtimeException (E.GetMessage (), E);

}

}

Public String Castfrom (String Dest) {

Try {

String src = (string) cachecastfrom.get (DEST);

IF (src == null) {

Byte [] bytes = dest.getbytes (raw);

SRC = New String (Bytes, Destcharset);

IF (cachecastfrom.size ()> eXpire_every)

Cachecastfrom.clear ();

CachecastFrom.Put (DEST, SRC);

}

Return SRC;

} catch (unsupporteencodingexception e) {

Throw new runtimeException (E.GetMessage (), E);

}

}

Public Static String ConvertTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTO (STRING SRC, STRING CHARS) {

IF (charset == null) Return SRC;

IF (src == null) Return NULL;

CachedCharset CC = (CachedCharset) poolcc.get (charset);

IF (cc == null) {

CC = New Cached Cachedcharset;

Poolcc.put (charset, cc);

}

Return Cc.convertTo (SRC);

}

Public Static String Castfrom (String Dest, String Chars) {

IF (charset == null) Return DEST;

IF (dest == null) Return NULL;

CachedCharset CC = (CachedCharset) poolcc.get (charset);

IF (cc == null) {

CC = New Cached Cachedcharset;

Poolcc.put (charset, cc);

}

Return cc.castfrom (dest);

Public cachedcharset (string charSet) {

this.Destcharset = charset;

}

Public Static Final String Raw = "ISO-8859-1";

String destcharset = NULL;

Public Static Final Int Expire_Every = 100000;

Public map cacheconvertto = new hashmap ();

Public map cachecastfrom = new hashmap ();

/ * Map: destcharset -> CachedCharset * /

Public Static Map Poolcc = New HashMap ();

}

For a variety of statements, we add GetGeneratedKeys and give all SQL to the character set pre-processing. Sybase gets the automatic number method is SELECT @@ identity, because the automatic number is always inserted, updated, so there is no need to worry that the SELECT operation will destroy the last query result. (Note that if the auto number is generated from the stored procedure, the stored procedure returns multiple ResultSets, and one of the resultSet is being accessed in the program, SELECT will destroy the previous ResultSet according to a defect in JDBC. Despite this, always Return Auto number.)

For ResultSet, we give all returned String and post-processing.

For Connection, it is responsible for resolving the new attributes in the URL and build a variety of STATEMENT packaging.

Limited to 9CBS constraints, friends who need source code please click:

Part3

è

http://www.9cbs.net/develop/read_article.asp?id=27125

转载请注明原文地址:https://www.9cbs.com/read-26575.html

New Post(0)