You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by db...@apache.org on 2018/12/20 02:11:16 UTC

[1/2] trafodion git commit: support customer define client charset

Repository: trafodion
Updated Branches:
  refs/heads/master 7e94e7908 -> dd184e01d


support customer define client charset


Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/31b962c7
Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/31b962c7
Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/31b962c7

Branch: refs/heads/master
Commit: 31b962c720cf3a3be15e2ddacc3e2d66287ae10a
Parents: 889631a
Author: Aven <sh...@esgyn.cn>
Authored: Tue Dec 11 10:16:24 2018 +0800
Committer: Aven <sh...@esgyn.cn>
Committed: Tue Dec 11 10:16:24 2018 +0800

----------------------------------------------------------------------
 .../trafodion/jdbc/t4/InterfaceConnection.java  |  8 +-
 .../trafodion/jdbc/t4/InterfaceUtilities.java   | 85 +++++++++++---------
 .../org/trafodion/jdbc/t4/T4Properties.java     | 33 ++++++--
 .../org/trafodion/jdbc/t4/TrafT4ResultSet.java  | 12 +--
 4 files changed, 80 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/31b962c7/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceConnection.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceConnection.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceConnection.java
index 6cd0601..582dfee 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceConnection.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceConnection.java
@@ -175,6 +175,11 @@ class InterfaceConnection {
 			t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "", temp, p);
 		}
 		sqlwarning_ = null;
+
+        this.termCharset_ =
+                t4props.getClientCharset() == null ? InterfaceUtilities.SQLCHARSETCODE_UTF8
+                        : InterfaceUtilities.getCharsetValue(t4props.getClientCharset());
+
 		connect();
 	}
 	
@@ -899,11 +904,8 @@ class InterfaceConnection {
 		setISOMapping(cr.isoMapping);
 
 		if (cr.isoMapping == InterfaceUtilities.getCharsetValue("ISO8859_1")) {
-			setTerminalCharset(InterfaceUtilities.getCharsetValue("ISO8859_1"));
 			this.inContext.ctxDataLang = 0;
 			this.inContext.ctxErrorLang = 0;
-		} else {
-			setTerminalCharset(InterfaceUtilities.getCharsetValue("UTF-8"));
 		}
 		
 		if(cr.securityEnabled) {

http://git-wip-us.apache.org/repos/asf/trafodion/blob/31b962c7/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceUtilities.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceUtilities.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceUtilities.java
index a5329bf..aa1cd66 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceUtilities.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceUtilities.java
@@ -22,34 +22,37 @@ package org.trafodion.jdbc.t4;
 
 import java.math.BigDecimal;
 import java.math.BigInteger;
+import java.nio.charset.Charset;
 import java.util.Hashtable;
 
 public class InterfaceUtilities {
-	static private Hashtable valueToCharset;
+	static private Hashtable<Integer, String> valueToCharset;
 	static {
-		valueToCharset = new Hashtable(11);
-		valueToCharset.put(new Integer(1), "ISO8859_1"); // ISO
-		valueToCharset.put(new Integer(10), "MS932"); // SJIS
-		valueToCharset.put(new Integer(11), "UTF-16BE"); // UCS2
-		valueToCharset.put(new Integer(12), "EUCJP"); // EUCJP
-		valueToCharset.put(new Integer(13), "MS950"); // BIG5
+		valueToCharset = new Hashtable<Integer, String>(11);
+		valueToCharset.put(new Integer(1), "ISO-8859-1"); // ISO
+		valueToCharset.put(new Integer(10), "Shift_JIS"); // SJIS
+		valueToCharset.put(new Integer(11), "UTF-16"); // UNICODE
+		valueToCharset.put(new Integer(12), "EUC-JP"); // EUCJP
+		valueToCharset.put(new Integer(13), "Big5"); // BIG5
 		valueToCharset.put(new Integer(14), "GB18030"); // GB18030
 		valueToCharset.put(new Integer(15), "UTF-8"); // UTF8
-		valueToCharset.put(new Integer(16), "MS949"); // MB_KSC5601
+		valueToCharset.put(new Integer(16), "KSC5601"); // MB_KSC5601
 		valueToCharset.put(new Integer(17), "GB2312"); // GB2312
+		valueToCharset.put(new Integer(18), "GBK"); // GBK
 	}
-	static private Hashtable charsetToValue;
+	static private Hashtable<String, Integer> charsetToValue;
 	static {
-		charsetToValue = new Hashtable(11);
-		charsetToValue.put("ISO8859_1", new Integer(1)); // ISO
-		charsetToValue.put("MS932", new Integer(10)); // SJIS
-		charsetToValue.put("UTF-16BE", new Integer(11)); // UCS2
-		charsetToValue.put("EUCJP", new Integer(12)); // EUCJP
-		charsetToValue.put("MS950", new Integer(13)); // BIG5
+		charsetToValue = new Hashtable<String, Integer>(11);
+		charsetToValue.put("ISO-8859-1", new Integer(1)); // ISO
+		charsetToValue.put("Shift_JIS", new Integer(10)); // SJIS
+		charsetToValue.put("UTF-16", new Integer(11)); // UNICODE
+		charsetToValue.put("EUC-JP", new Integer(12)); // EUCJP
+		charsetToValue.put("Big5", new Integer(13)); // BIG5
 		charsetToValue.put("GB18030", new Integer(14)); // GB18030
 		charsetToValue.put("UTF-8", new Integer(15)); // UTF8
-		charsetToValue.put("MS949", new Integer(16)); // MB_KSC5601
+		charsetToValue.put("KSC5601", new Integer(16)); // MB_KSC5601
 		charsetToValue.put("GB2312", new Integer(17)); // GB2312
+		charsetToValue.put("GBK", new Integer(18)); // GBK
 	}
 
 	static final int SQLCHARSETCODE_UNKNOWN = 0;
@@ -57,34 +60,40 @@ public class InterfaceUtilities {
 
 	// these are the only real column types
 	static final int SQLCHARSETCODE_ISO88591 = 1;
-	static final String SQLCHARSET_ISO88591 = "ISO88591";
+	static final String SQLCHARSET_ISO88591 = "ISO-8859-1";
 	static final int SQLCHARSETCODE_UNICODE = 11;
-	static final String SQLCHARSET_UNICODE = "UCS2";
+	static final String SQLCHARSET_UNICODE = "UTF-16";
 
 	// ISO_MAPPING values
 	static final int SQLCHARSETCODE_SJIS = 10;
 	static final int SQLCHARSETCODE_UTF8 = 15;
 
-	static String getCharsetName(int charset) {
-		String ret = (String) valueToCharset.get(new Integer(charset));
-
-		if (ret == null)
-			ret = SQLCHARSET_UNKNOWN;
-
-		return ret;
-	}
-
-	static int getCharsetValue(String charset) {
-		Integer i = (Integer) charsetToValue.get(charset);
-		int ret;
-
-		if (i == null)
-			ret = SQLCHARSETCODE_UNKNOWN;
-		else
-			ret = i.intValue();
-
-		return ret;
-	}
+    static String getCharsetName(int charset) {
+        String ret = valueToCharset.get(charset);
+
+        if (ret == null)
+            return SQLCHARSET_UNKNOWN;
+
+        return ret;
+    }
+
+    static int getCharsetValue(String charset) {
+        Integer i = charsetToValue.get(charset);
+        if (i == null) {
+            i = charsetToValue.get(convertToCanonicalCharsetName(charset));
+            if (i == null) {
+                return SQLCHARSETCODE_UNKNOWN;
+            } else {
+                return i.intValue();
+            }
+        } else {
+            return i.intValue();
+        }
+    }
+
+    private static String convertToCanonicalCharsetName (String aliasName) {
+        return Charset.forName(aliasName).name();
+    }
 
 	static private final int[] powersOfTen = { 10, 100, 1000, 10000 };
 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/31b962c7/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/T4Properties.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/T4Properties.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/T4Properties.java
index 46abb29..455034e 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/T4Properties.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/T4Properties.java
@@ -182,6 +182,9 @@ public class T4Properties {
 	static String t4GlobalLogFile = null;
 	static Logger t4GlobalLogger = null;
 	static FileHandler t4GlobalLogFileHandler = null;
+
+	private String clientCharset;
+
 	void initializeLogging() {
 		if (t4GlobalLogger != null) {
 			return;
@@ -435,6 +438,8 @@ public class T4Properties {
 
         setLobChunkSize(getProperty("lobChunkSize"));
         setUseLobHandle(getProperty("useLobHandle"));
+
+        setClientCharset(getProperty("clientCharset"));
 	}
 
 	T4Properties getT4Properties() {
@@ -505,10 +510,19 @@ public class T4Properties {
 		props.setProperty("SPJEnv", String.valueOf(SPJEnv_));
 		props.setProperty("keepRawFetchBuffer", String.valueOf(keepRawFetchBuffer_));
 		props.setProperty("cpuToUse", String.valueOf(cpuToUse_));
-		props.setProperty("sessionName", String.valueOf(sessionName));
-		props.setProperty("replacementString", String.valueOf(replacementString_));
-		props.setProperty("ISO88591", String.valueOf(ISO88591_));
 
+        // NOTE
+        // String.valueOf(null) will give a "null" string, this may raise bug.
+        // So do not use String.valueOf() for a String variable
+        if (sessionName != null) {
+            props.setProperty("sessionName", sessionName);
+        }
+        if (replacementString_ != null) {
+            props.setProperty("replacementString", replacementString_);
+        }
+        if (ISO88591_ != null) {
+            props.setProperty("ISO88591", ISO88591_);
+        }
 		if (_roleName != null)
 			props.setProperty("roleName", _roleName);
 		if (_applicationName != null)
@@ -531,7 +545,8 @@ public class T4Properties {
         props.setProperty("clipVarchar", String.valueOf(clipVarchar_));
         props.setProperty("lobChunkSize", String.valueOf(lobChunkSize_));
         props.setProperty("useLobHandle", String.valueOf(useLobHandle_));
-
+        if (clientCharset != null)
+            props.setProperty("clientCharset", clientCharset);
 		return props;
 	}
 
@@ -2589,6 +2604,12 @@ public class T4Properties {
     Properties getClientInfoProperties() {
         return this.clientInfoProp;
     }
-	
-	
+
+    public String getClientCharset() {
+        return clientCharset;
+    }
+
+    public void setClientCharset(String clientCharset) {
+        this.clientCharset = clientCharset;
+    }
 }

http://git-wip-us.apache.org/repos/asf/trafodion/blob/31b962c7/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4ResultSet.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4ResultSet.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4ResultSet.java
index 0754e47..ac87638 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4ResultSet.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4ResultSet.java
@@ -4598,12 +4598,7 @@ public class TrafT4ResultSet extends TrafT4Handle implements java.sql.ResultSet
 			if (obj != null) {
 				if (obj instanceof byte[]) {
 					try {
-						if (this.irs_.ic_.getISOMapping() == InterfaceUtilities.SQLCHARSETCODE_ISO88591
-								&& !this.irs_.ic_.getEnforceISO()
-								&& sqlCharset == InterfaceUtilities.SQLCHARSETCODE_ISO88591)
-							data = new String((byte[]) obj, irs_.ic_.t4props_.getISO88591());
-						else
-							data = this.irs_.ic_.decodeBytes((byte[]) obj, sqlCharset);
+						data = this.irs_.ic_.decodeBytes((byte[]) obj, this.irs_.ic_.getTerminalCharset());
 
 						wasNull_ = false;
 					} catch (CharacterCodingException e) {
@@ -4617,11 +4612,6 @@ public class TrafT4ResultSet extends TrafT4Handle implements java.sql.ResultSet
 								this.connection_.getLocale(), "unsupported_encoding", e.getCharsetName());
 						se.initCause(e);
 						throw se;
-					} catch (UnsupportedEncodingException e) {
-						SQLException se = TrafT4Messages.createSQLException(this.connection_.ic_.t4props_,
-								this.connection_.getLocale(), "unsupported_encoding", e.getMessage());
-						se.initCause(e);
-						throw se;
 					}
 				} else {
 					data = obj.toString();


[2/2] trafodion git commit: Merge [TRAFODION-3247] PR 1760 Support client-defined char sets in JDBC

Posted by db...@apache.org.
Merge [TRAFODION-3247] PR 1760 Support client-defined char sets in JDBC


Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/dd184e01
Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/dd184e01
Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/dd184e01

Branch: refs/heads/master
Commit: dd184e01d0be3f68064ff45aa43fd982d141f978
Parents: 7e94e79 31b962c
Author: Dave Birdsall <db...@apache.org>
Authored: Thu Dec 20 02:10:36 2018 +0000
Committer: Dave Birdsall <db...@apache.org>
Committed: Thu Dec 20 02:10:36 2018 +0000

----------------------------------------------------------------------
 .../trafodion/jdbc/t4/InterfaceConnection.java  |  8 +-
 .../trafodion/jdbc/t4/InterfaceUtilities.java   | 85 +++++++++++---------
 .../org/trafodion/jdbc/t4/T4Properties.java     | 33 ++++++--
 .../org/trafodion/jdbc/t4/TrafT4ResultSet.java  | 12 +--
 4 files changed, 80 insertions(+), 58 deletions(-)
----------------------------------------------------------------------