Sybase JDBC Driver Improvement 2

  (Continued) 

  Sun J2SE (1.4) for the realization of character set conversion has been very slow, I used to do Profile Jfluid found a simple database program in the character set conversion spent the time was occupied by more than 60%, it is necessary for the conversion results Cache: 

  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 (UnsupportedEncodingException 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 (UnsupportedEncodingException e) ( 

  Throw new RuntimeException (e.getMessage (), e); 

  ) 

  ) 

  Public static String convertTo (String src, String charset) ( 

  If (charset == null) return src; 

  If (src == null) return null; 

  CachedCharset cc = (CachedCharset) poolCC.get (charset); 

  If (cc == null)

  Cc = new CachedCharset (charset); 

  PoolCC.put (charset, cc); 

  ) 

  Return cc.convertTo (src); 

  ) 

  Public static String castFrom (String dest, String charset) ( 

  If (charset == null) return dest; 

  If (dest == null) return null; 

  CachedCharset cc = (CachedCharset) poolCC.get (charset); 

  If (cc == null)

  Cc = new CachedCharset (charset); 

  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 all Statement, we getGeneratedKeys add to it, and for all the characters in the sql joined pretreatment.    Sybase access to the code is automatically SELECT @ @ identity, as in the access code automatically insert, update, and other operations, it is not necessary to worry about SELECT operation will destroy the last query results.    (Note that if the code automatically generated from the storage process, and a number of ResultSet returned to the storage process, and one of these procedures are being ResultSet visit, then according to a flaw JDBC, SELECT will be destroyed in front of ResultSet. Nevertheless, the total energy Back to automatic number.) 

  The ResultSet, we all return to the String with post-processing. 

  The Connection, which is responsible for analysis of the additional attributes in the URL, and the establishment of Statement packaging. 

Bookmark it: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Google
  • DotNetKicks
  • DZone
  • Furl
  • Netvouz

Tags: , ,

Releated Articles


0 Comments to “Sybase JDBC Driver Improvement 2”

No Comments. Send your comment.

Leave a Reply

You must be logged in to post a comment.