[teiid-commits] teiid SVN: r4236 - in trunk: client/src/main/resources/org/teiid/jdbc and 3 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Fri Jul 13 09:09:57 EDT 2012


Author: shawkins
Date: 2012-07-13 09:09:56 -0400 (Fri, 13 Jul 2012)
New Revision: 4236

Modified:
   trunk/client/src/main/java/org/teiid/jdbc/DataTypeTransformer.java
   trunk/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java
   trunk/client/src/main/resources/org/teiid/jdbc/i18n.properties
   trunk/common-core/src/main/java/org/teiid/core/types/ClobType.java
   trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java
   trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java
   trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java
Log:
TEIID-2100 adding getObject support and correcting misc. warnings

Modified: trunk/client/src/main/java/org/teiid/jdbc/DataTypeTransformer.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/DataTypeTransformer.java	2012-07-13 13:03:44 UTC (rev 4235)
+++ trunk/client/src/main/java/org/teiid/jdbc/DataTypeTransformer.java	2012-07-13 13:09:56 UTC (rev 4236)
@@ -44,7 +44,6 @@
 import org.teiid.core.types.BinaryType;
 import org.teiid.core.types.DataTypeManager;
 import org.teiid.core.types.TransformationException;
-import org.teiid.core.types.DataTypeManager.DefaultDataClasses;
 import org.teiid.core.util.ReaderInputStream;
 
 
@@ -65,29 +64,69 @@
      * @throws SQLException if failed to transform to the desired datatype
      */
     static final BigDecimal getBigDecimal(Object value) throws SQLException {
-    	return transform(value, BigDecimal.class, "BigDecimal"); //$NON-NLS-1$
+    	return transform(value, BigDecimal.class); 
     }
     
-    private static final <T> T transform(Object value, Class<T> type, String typeName) throws SQLException {
-    	return transform(value, type, type, typeName);
-    }
-    
-    private static final <T> T transform(Object value, Class<T> targetType, Class<?> runtimeType, String typeName) throws SQLException {
+    static final <T> T transform(Object value, Class<T> targetType) throws SQLException {
     	if (value == null || targetType.isAssignableFrom(value.getClass())) {
     		return targetType.cast(value);
     	}
+    	if (targetType == byte[].class) {
+    		if (value instanceof Blob) {
+                Blob blob = (Blob)value;
+                long length = blob.length();
+                if (length > Integer.MAX_VALUE) {
+                    throw new TeiidSQLException(JDBCPlugin.Util.getString("DataTypeTransformer.blob_too_big")); //$NON-NLS-1$
+                }
+                return targetType.cast(blob.getBytes(1, (int)length));
+            } else if (value instanceof String) {
+            	return targetType.cast(((String)value).getBytes());
+            } else if (value instanceof BinaryType) {
+            	return targetType.cast(((BinaryType)value).getBytesDirect());
+            }
+    	} else if (targetType == String.class) {
+    		if (value instanceof SQLXML) {
+        		return targetType.cast(((SQLXML)value).getString());
+        	} else if (value instanceof Clob) {
+        		Clob c = (Clob)value;
+        		long length = c.length();
+        		if (length == 0) {
+        			//there is a bug in SerialClob with 0 length
+        			return targetType.cast(""); //$NON-NLS-1$ 
+        		}
+        		return targetType.cast(c.getSubString(1, length>Integer.MAX_VALUE?Integer.MAX_VALUE:(int)length));
+        	}
+    	}
     	try {
-    		return targetType.cast(DataTypeManager.transformValue(DataTypeManager.convertToRuntimeType(value), runtimeType));
+    		return targetType.cast(DataTypeManager.transformValue(DataTypeManager.convertToRuntimeType(value), getRuntimeType(targetType)));
     	} catch (TransformationException e) {
     		String valueStr = value.toString();
     		if (valueStr.length() > 20) {
     			valueStr = valueStr.substring(0, 20) + "..."; //$NON-NLS-1$
     		}
-    		String msg = JDBCPlugin.Util.getString("DataTypeTransformer.Err_converting", valueStr, typeName); //$NON-NLS-1$
+    		String msg = JDBCPlugin.Util.getString("DataTypeTransformer.Err_converting", valueStr, targetType.getSimpleName()); //$NON-NLS-1$
             throw TeiidSQLException.create(e, msg);
     	} 
     }
     
+	static final <T> Class<?> getRuntimeType(Class<T> type) {
+		Class<?> runtimeType = type;
+		if (!DataTypeManager.getAllDataTypeClasses().contains(type)) {
+			if (type == Clob.class) {
+				runtimeType = DataTypeManager.DefaultDataClasses.CLOB;
+			} else if (type == Blob.class) {
+				runtimeType = DataTypeManager.DefaultDataClasses.BLOB;
+			} else if (type == SQLXML.class) {
+				runtimeType = DataTypeManager.DefaultDataClasses.XML;
+			} else if (type == byte[].class) {
+				runtimeType = DataTypeManager.DefaultDataClasses.VARBINARY;
+			} else {
+				runtimeType = DataTypeManager.DefaultDataClasses.OBJECT;
+			}
+		}
+		return runtimeType;
+	}
+    
     /**
      * Gets an object value and transforms it into a boolean
      * @param value, the object to be transformed
@@ -98,7 +137,7 @@
     	if (value == null) {
     		return false;
     	}
-    	return transform(value, Boolean.class, "Boolean"); //$NON-NLS-1$
+    	return transform(value, Boolean.class); 
     }
 
     /**
@@ -111,31 +150,15 @@
     	if (value == null) {
     		return 0;
     	}
-    	return transform(value, Byte.class, "Byte"); //$NON-NLS-1$
+    	return transform(value, Byte.class); 
     }
     
     static final byte[] getBytes(Object value) throws SQLException {
-        if (value == null) {
-            return null;
-        } else if (value instanceof byte[]) {
-        	return (byte[])value;
-        } else if (value instanceof Blob) {
-            Blob blob = (Blob)value;
-            long length = blob.length();
-            if (length > Integer.MAX_VALUE) {
-                throw new TeiidSQLException(JDBCPlugin.Util.getString("DataTypeTransformer.blob_too_big")); //$NON-NLS-1$
-            }
-            return blob.getBytes(1, (int)length);
-        } else if (value instanceof String) {
-        	return ((String)value).getBytes();
-        } else if (value instanceof BinaryType) {
-        	return ((BinaryType)value).getBytesDirect();
-        }
-        throw new TeiidSQLException(JDBCPlugin.Util.getString("DataTypeTransformer.cannot_get_bytes")); //$NON-NLS-1$
+    	return transform(value, byte[].class);
     }
     
     static final Character getCharacter(Object value) throws SQLException {
-    	return transform(value, Character.class, "Character"); //$NON-NLS-1$
+    	return transform(value, Character.class); 
     }
 
     /**
@@ -146,7 +169,7 @@
      * @throws SQLException if failed to transform to the desired datatype
      */
     static final Date getDate(Object value) throws SQLException {
-    	return transform(value, Date.class, "Date"); //$NON-NLS-1$
+    	return transform(value, Date.class); 
     }
 
     /**
@@ -159,7 +182,7 @@
     	if (value == null) {
     		return 0;
     	}
-    	return transform(value, Double.class, "Double"); //$NON-NLS-1$
+    	return transform(value, Double.class); 
     }
 
     /**
@@ -172,7 +195,7 @@
     	if (value == null) {
     		return 0;
     	}
-    	return transform(value, Float.class, "Float"); //$NON-NLS-1$
+    	return transform(value, Float.class); 
     }
 
     /**
@@ -185,7 +208,7 @@
     	if (value == null) {
     		return 0;
     	}
-    	return transform(value, Integer.class, "Integer"); //$NON-NLS-1$
+    	return transform(value, Integer.class); 
     }
 
     /**
@@ -198,7 +221,7 @@
     	if (value == null) {
     		return 0;
     	}
-    	return transform(value, Long.class, "Long"); //$NON-NLS-1$
+    	return transform(value, Long.class); 
     }
 
     /**
@@ -211,7 +234,7 @@
     	if (value == null) {
     		return 0;
     	}
-    	return transform(value, Short.class, "Short"); //$NON-NLS-1$
+    	return transform(value, Short.class); 
     }
 
     /**
@@ -222,7 +245,7 @@
      * @throws SQLException if failed to transform to the desired datatype
      */
     static final Time getTime(Object value) throws SQLException {
-    	return transform(value, Time.class, "Time"); //$NON-NLS-1$
+    	return transform(value, Time.class); 
     }
 
     /**
@@ -233,22 +256,11 @@
      * @throws SQLException if failed to transform to the desired datatype
      */
     static final Timestamp getTimestamp(Object value) throws SQLException {
-    	return transform(value, Timestamp.class, "Timestamp"); //$NON-NLS-1$
+    	return transform(value, Timestamp.class); 
     }
     
     static final String getString(Object value) throws SQLException {
-    	if (value instanceof SQLXML) {
-    		return ((SQLXML)value).getString();
-    	} else if (value instanceof Clob) {
-    		Clob c = (Clob)value;
-    		long length = c.length();
-    		if (length == 0) {
-    			//there is a bug in SerialClob with 0 length
-    			return ""; //$NON-NLS-1$ 
-    		}
-    		return c.getSubString(1, length>Integer.MAX_VALUE?Integer.MAX_VALUE:(int)length);
-    	}
-    	return transform(value, String.class, "String"); //$NON-NLS-1$
+    	return transform(value, String.class); 
     }
 
     /**
@@ -259,7 +271,7 @@
      * @throws SQLException if failed to transform to the desired datatype
      */
     static final Blob getBlob(Object value) throws SQLException {
-    	return transform(value, Blob.class, DefaultDataClasses.BLOB, "Blob"); //$NON-NLS-1$
+    	return transform(value, Blob.class); 
     }
 
     /**
@@ -270,7 +282,7 @@
      * @throws SQLException if failed to transform to the desired datatype
      */
     static final Clob getClob(Object value) throws SQLException {
-    	return transform(value, Clob.class, DefaultDataClasses.CLOB, "Clob"); //$NON-NLS-1$
+    	return transform(value, Clob.class); 
     }
 
     /**
@@ -280,7 +292,7 @@
      * @throws SQLException if failed to transform to the desired datatype
      */    
     static final SQLXML getSQLXML(Object value) throws SQLException {
-    	return transform(value, SQLXML.class, DefaultDataClasses.XML, "SQLXML"); //$NON-NLS-1$
+    	return transform(value, SQLXML.class); 
     }
     
     static final Reader getCharacterStream(Object value) throws SQLException {
@@ -321,6 +333,9 @@
 		if (clob == null) {
 			return null;
 		}
+		if (clob instanceof NClob) {
+			return (NClob)clob;
+		}
 		return (NClob) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[] {NClob.class}, new InvocationHandler() {
 			
 			@Override

Modified: trunk/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java	2012-07-13 13:03:44 UTC (rev 4235)
+++ trunk/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java	2012-07-13 13:09:56 UTC (rev 4236)
@@ -1667,11 +1667,12 @@
 	}
 
 	public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
-		throw SqlUtil.createFeatureNotSupportedException();
+		return DataTypeTransformer.transform(getObject(columnIndex), type);
 	}
 
 	public <T> T getObject(String columnLabel, Class<T> type)
 			throws SQLException {
-		throw SqlUtil.createFeatureNotSupportedException();
+		return DataTypeTransformer.transform(getObject(columnLabel), type);
 	}
+
 }

Modified: trunk/client/src/main/resources/org/teiid/jdbc/i18n.properties
===================================================================
--- trunk/client/src/main/resources/org/teiid/jdbc/i18n.properties	2012-07-13 13:03:44 UTC (rev 4235)
+++ trunk/client/src/main/resources/org/teiid/jdbc/i18n.properties	2012-07-13 13:09:56 UTC (rev 4236)
@@ -107,7 +107,6 @@
 MMStatement.Bad_timeout_value=Invalid timeout value supplied. Valid range is greater than or equal to zero.
 WarningUtil.Failures_occurred=Partial results failures occurred
 DataTypeTransformer.blob_too_big=The blob value is too large for the max supported length of 2147483647 bytes
-DataTypeTransformer.cannot_get_bytes=Cannot convert this value to a byte array.
 WrapperImpl.wrong_class=Wrapped object is not an instance of {0}
 MMXAConnection.rolling_back=rolling back transaction.
 MMXAConnection.rolling_back_error=Error while rolling back transaction.

Modified: trunk/common-core/src/main/java/org/teiid/core/types/ClobType.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/ClobType.java	2012-07-13 13:03:44 UTC (rev 4235)
+++ trunk/common-core/src/main/java/org/teiid/core/types/ClobType.java	2012-07-13 13:09:56 UTC (rev 4236)
@@ -31,6 +31,7 @@
 import java.io.StringWriter;
 import java.io.Writer;
 import java.sql.Clob;
+import java.sql.NClob;
 import java.sql.SQLException;
 
 import org.teiid.core.CorePlugin;
@@ -44,7 +45,7 @@
  * This is wrapper on top of a "clob" object, which implements the "java.sql.Clob"
  * interface. This class also implements the Streamable interface
  */
-public final class ClobType extends Streamable<Clob> implements Clob, Sequencable, Comparable<ClobType> {
+public final class ClobType extends Streamable<Clob> implements Clob, NClob, Sequencable, Comparable<ClobType> {
 
 	private static final long serialVersionUID = 2753412502127824104L;
     

Modified: trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java	2012-07-13 13:03:44 UTC (rev 4235)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java	2012-07-13 13:09:56 UTC (rev 4236)
@@ -289,8 +289,11 @@
     public QueryNode getVirtualPlan(Object groupID)
         throws TeiidComponentException, QueryMetadataException {
 		
-        if (this.queryNodes != null && this.queryNodes.containsKey(groupID)) {
-            return this.queryNodes.get(groupID);
+        if (this.queryNodes != null) {
+        	QueryNode node = this.queryNodes.get(groupID);
+        	if (node != null) {
+        		return node;
+        	}
         }
         
         if(groupID instanceof TempMetadataID && !(actualMetadata instanceof TempMetadataAdapter)) {

Modified: trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java	2012-07-13 13:03:44 UTC (rev 4235)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java	2012-07-13 13:09:56 UTC (rev 4236)
@@ -487,10 +487,10 @@
         LiveTableQueryNode queryNode = new LiveTableQueryNode(tableRecord);
 
         // get any bindings and add them onto the query node
-        List bindings = tableRecord.getBindings();
+        List<String> bindings = tableRecord.getBindings();
         if(bindings != null) {
-            for(Iterator bindIter = bindings.iterator();bindIter.hasNext();) {
-                queryNode.addBinding((String)bindIter.next());
+            for(Iterator<String> bindIter = bindings.iterator();bindIter.hasNext();) {
+                queryNode.addBinding(bindIter.next());
             }
         }
 
@@ -624,16 +624,16 @@
         return 0;
     }
 
-    public Collection getIndexesInGroup(final Object groupID) throws TeiidComponentException, QueryMetadataException {
+    public Collection<KeyRecord> getIndexesInGroup(final Object groupID) throws TeiidComponentException, QueryMetadataException {
         ArgCheck.isInstanceOf(Table.class, groupID);
         return ((Table)groupID).getIndexes();
     }
 
-    public Collection getUniqueKeysInGroup(final Object groupID)
+    public Collection<KeyRecord> getUniqueKeysInGroup(final Object groupID)
         throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(Table.class, groupID);
     	Table tableRecordImpl = (Table)groupID;
-    	ArrayList<ColumnSet> result = new ArrayList<ColumnSet>(tableRecordImpl.getUniqueKeys());
+    	ArrayList<KeyRecord> result = new ArrayList<KeyRecord>(tableRecordImpl.getUniqueKeys());
     	if (tableRecordImpl.getPrimaryKey() != null) {
 	    	result.add(tableRecordImpl.getPrimaryKey());
     	}
@@ -645,7 +645,7 @@
     	return result;
     }
 
-    public Collection getForeignKeysInGroup(final Object groupID)
+    public Collection<ForeignKey> getForeignKeysInGroup(final Object groupID)
         throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(Table.class, groupID);
     	return ((Table)groupID).getForeignKeys();
@@ -658,26 +658,26 @@
         return fkRecord.getPrimaryKey();
     }
 
-    public Collection getAccessPatternsInGroup(final Object groupID)
+    public Collection<KeyRecord> getAccessPatternsInGroup(final Object groupID)
         throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(Table.class, groupID);
     	return ((Table)groupID).getAccessPatterns();
     }
 
-    public List getElementIDsInIndex(final Object index) throws TeiidComponentException, QueryMetadataException {
+    public List<Column> getElementIDsInIndex(final Object index) throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(ColumnSet.class, index);
-    	return ((ColumnSet)index).getColumns();
+    	return ((ColumnSet<?>)index).getColumns();
     }
 
-    public List getElementIDsInKey(final Object key) throws TeiidComponentException, QueryMetadataException {
+    public List<Column> getElementIDsInKey(final Object key) throws TeiidComponentException, QueryMetadataException {
         ArgCheck.isInstanceOf(ColumnSet.class, key);
-        return ((ColumnSet)key).getColumns();
+        return ((ColumnSet<?>)key).getColumns();
     }
 
-    public List getElementIDsInAccessPattern(final Object accessPattern)
+    public List<Column> getElementIDsInAccessPattern(final Object accessPattern)
         throws TeiidComponentException, QueryMetadataException {
         ArgCheck.isInstanceOf(ColumnSet.class, accessPattern);
-        return ((ColumnSet)accessPattern).getColumns();
+        return ((ColumnSet<?>)accessPattern).getColumns();
     }
 
     public boolean isXMLGroup(final Object groupID) throws TeiidComponentException, QueryMetadataException {

Modified: trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java	2012-07-13 13:03:44 UTC (rev 4235)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java	2012-07-13 13:09:56 UTC (rev 4236)
@@ -424,7 +424,7 @@
 		QueryNode cachedNode = (QueryNode)qmi.getFromMetadataCache(virtualGroup.getMetadataID(), cacheString);
         if (cachedNode == null) {
         	Command result = qnode.getCommand();
-        	List bindings = null;
+        	List<String> bindings = null;
             if (result == null) {
                 try {
                 	result = QueryParser.getQueryParser().parseCommand(qnode.getQuery());



More information about the teiid-commits mailing list