[teiid-commits] teiid SVN: r4284 - in trunk: client-jdk15/src/main/java and 2 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Wed Aug 1 11:46:51 EDT 2012


Author: shawkins
Date: 2012-08-01 11:46:51 -0400 (Wed, 01 Aug 2012)
New Revision: 4284

Removed:
   trunk/client-jdk15/src/main/java/net/
Modified:
   trunk/client/src/main/java/org/teiid/client/BatchSerializer.java
   trunk/common-core/src/main/java/org/teiid/core/types/XMLType.java
   trunk/common-core/src/main/java/org/teiid/core/util/ExternalizeUtil.java
Log:
TEIID-2126 making xmltype serialization free of direct enum serialization

Modified: trunk/client/src/main/java/org/teiid/client/BatchSerializer.java
===================================================================
--- trunk/client/src/main/java/org/teiid/client/BatchSerializer.java	2012-08-01 14:24:00 UTC (rev 4283)
+++ trunk/client/src/main/java/org/teiid/client/BatchSerializer.java	2012-08-01 15:46:51 UTC (rev 4284)
@@ -234,11 +234,11 @@
 
     private static class XmlColumnSerializer1 extends ColumnSerializer {
         protected void writeObject(ObjectOutput out, Object obj) throws IOException {
-        	((Externalizable)obj).writeExternal(out);
+        	((XMLType)obj).writeExternal(out, (byte)1);
         }
         protected Object readObject(ObjectInput in) throws IOException, ClassNotFoundException {
         	XMLType xt = new XMLType();
-        	xt.readExternal(in);
+        	xt.readExternal(in, (byte)1);
             return xt;
         }
     }

Modified: trunk/common-core/src/main/java/org/teiid/core/types/XMLType.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/XMLType.java	2012-08-01 14:24:00 UTC (rev 4283)
+++ trunk/common-core/src/main/java/org/teiid/core/types/XMLType.java	2012-08-01 15:46:51 UTC (rev 4284)
@@ -41,6 +41,8 @@
 import javax.xml.transform.Result;
 import javax.xml.transform.Source;
 
+import org.teiid.core.util.ExternalizeUtil;
+
 /**
  * This class represents the SQLXML object along with the Streamable interface.
  * 
@@ -144,6 +146,11 @@
 	@Override
 	public void readExternal(ObjectInput in) throws IOException,
 			ClassNotFoundException {
+		readExternal(in, (byte)0);
+	}
+	
+	public void readExternal(ObjectInput in, byte version) throws IOException,
+		ClassNotFoundException {
 		super.readExternal(in);
 		try {
 			this.encoding = (String)in.readObject();
@@ -151,7 +158,15 @@
 			this.encoding = Streamable.ENCODING;
 		}
 		try {
-			this.type = (Type)in.readObject();
+			if (version > 0) {
+				try {
+					this.type = ExternalizeUtil.readEnum(in, Type.class);
+				} catch (IllegalArgumentException e) {
+					this.type = Type.UNKNOWN;
+				}
+			} else {
+				this.type = (Type)in.readObject();
+			}
 		} catch (OptionalDataException e) {
 			this.type = Type.UNKNOWN;
 		} catch(IOException e) {
@@ -163,12 +178,20 @@
 	
 	@Override
 	public void writeExternal(ObjectOutput out) throws IOException {
+		writeExternal(out, (byte)0);
+	}
+	
+	public void writeExternal(ObjectOutput out, byte version) throws IOException {
 		super.writeExternal(out);
 		if (this.encoding == null) {
 			this.encoding = getEncoding(this);
 		}
 		out.writeObject(this.encoding);
-		out.writeObject(this.type);
+		if (version > 0) {
+			ExternalizeUtil.writeEnum(out, this.type);
+		} else {
+			out.writeObject(this.type);
+		}
 	}
 
 	/**

Modified: trunk/common-core/src/main/java/org/teiid/core/util/ExternalizeUtil.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/util/ExternalizeUtil.java	2012-08-01 14:24:00 UTC (rev 4283)
+++ trunk/common-core/src/main/java/org/teiid/core/util/ExternalizeUtil.java	2012-08-01 15:46:51 UTC (rev 4284)
@@ -155,4 +155,20 @@
         return map;
     }
     
+    public static void writeEnum(ObjectOutput out, Enum<?> value) throws IOException {
+    	if (value == null) {
+    		out.writeObject(null);
+    	} else {
+    		out.writeUTF(value.name());
+    	}
+    }
+    
+    public static <T extends Enum<T>> T readEnum(ObjectInput in, Class<T> clazz) throws IOException {
+    	String name = in.readUTF();
+    	if (name == null) {
+    		return null;
+    	}
+		return Enum.valueOf(clazz, name);
+    }
+    
 }



More information about the teiid-commits mailing list