[teiid-commits] teiid SVN: r2283 - in trunk: common-core/src/test/java/org/teiid/core/types and 3 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Wed Jun 23 12:01:47 EDT 2010


Author: shawkins
Date: 2010-06-23 12:01:46 -0400 (Wed, 23 Jun 2010)
New Revision: 2283

Modified:
   trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java
   trunk/common-core/src/test/java/org/teiid/core/types/TestClobValue.java
   trunk/common-core/src/test/java/org/teiid/core/types/TestSQLXMLImpl.java
   trunk/engine/src/main/java/org/teiid/query/resolver/command/ExecResolver.java
   trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java
   trunk/engine/src/test/java/org/teiid/query/resolver/TestProcedureResolving.java
Log:
TEIID-76 allowing procedures to be vdb qualified

Modified: trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java	2010-06-23 02:52:46 UTC (rev 2282)
+++ trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java	2010-06-23 16:01:46 UTC (rev 2283)
@@ -697,31 +697,10 @@
      * @since   JDK1. 0
      */
     public static boolean startsWithIgnoreCase(final String text, final String prefix) {
-        if (isEmpty(text)) {
+        if (text == null || prefix == null) {
             return false;
         }
-        if (prefix == null) {
-            return false;
-        }
-        int textLength   = text.length();
-        int prefixLength = prefix.length();
-        if (prefixLength == 0) {
-            return true;
-        }
-        if (prefixLength > textLength) {
-            return false;
-        }
-        char[] chArray = prefix.toCharArray();
-        for (int i = 0; i != chArray.length; ++i) {
-            char ch1 = chArray[i];
-            char ch2 = text.charAt(i);
-            if (ch1 == ch2 || Character.toLowerCase(ch1) == Character.toLowerCase(ch2)) {
-                // continue
-            } else {
-                return false;
-            }
-        }
-        return true;
+        return text.regionMatches(true, 0, prefix, 0, prefix.length());
     }
     
     /**
@@ -738,32 +717,10 @@
      *          suffix argument is null <code>false</code> is returned.
      */
     public static boolean endsWithIgnoreCase(final String text, final String suffix) {
-        if (isEmpty(text)) {
+    	if (text == null || suffix == null) {
             return false;
         }
-        if (suffix == null) {
-            return false;
-        }
-        int textLength   = text.length();
-        int suffixLength = suffix.length();
-        if (suffixLength == 0) {
-            return true;
-        }
-        if (suffixLength > textLength) {
-            return false;
-        }
-        int offset = textLength - suffixLength;
-        char[] chArray = suffix.toCharArray();
-        for (int i = 0; i != chArray.length; ++i) {
-            char ch1 = chArray[i];
-            char ch2 = text.charAt(offset + i);
-            if (ch1 == ch2 || Character.toLowerCase(ch1) == Character.toLowerCase(ch2)) {
-                // continue
-            } else {
-                return false;
-            }
-        }
-        return true;
+        return text.regionMatches(true, text.length() - suffix.length(), suffix, 0, suffix.length());
     }
  
     /**
@@ -1064,4 +1021,5 @@
 	    }
 	    return (String[]) result.toArray(new String[result.size()]);
 	}
+	
 }

Modified: trunk/common-core/src/test/java/org/teiid/core/types/TestClobValue.java
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/types/TestClobValue.java	2010-06-23 02:52:46 UTC (rev 2282)
+++ trunk/common-core/src/test/java/org/teiid/core/types/TestClobValue.java	2010-06-23 16:01:46 UTC (rev 2283)
@@ -37,6 +37,7 @@
 import org.junit.Test;
 import org.teiid.core.util.UnitTestUtil;
 
+ at SuppressWarnings("nls")
 public class TestClobValue {
 
     @Test public void testClobValue() throws Exception {

Modified: trunk/common-core/src/test/java/org/teiid/core/types/TestSQLXMLImpl.java
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/types/TestSQLXMLImpl.java	2010-06-23 02:52:46 UTC (rev 2282)
+++ trunk/common-core/src/test/java/org/teiid/core/types/TestSQLXMLImpl.java	2010-06-23 16:01:46 UTC (rev 2283)
@@ -22,29 +22,24 @@
 
 package org.teiid.core.types;
 
+import static org.junit.Assert.*;
+
 import java.io.IOException;
 import java.io.Reader;
 import java.sql.SQLException;
 
 import javax.xml.transform.stream.StreamSource;
 
-import org.teiid.core.types.SQLXMLImpl;
-import org.teiid.core.types.Streamable;
+import org.junit.Test;
 import org.teiid.core.util.ObjectConverterUtil;
 
-import junit.framework.TestCase;
+ at SuppressWarnings("nls")
+public class TestSQLXMLImpl {
 
-
-/**
- * Basically we want to make sure that nobody has changed the fundamental contract
- * of translator
- */
-public class TestSQLXMLImpl extends TestCase {
-
     String testStr = "<foo>test</foo>"; //$NON-NLS-1$
         
 	//## JDBC4.0-begin ##
-    public void testGetSource() throws Exception {        
+    @Test public void testGetSource() throws Exception {        
         SQLXMLImpl xml = new SQLXMLImpl(testStr);
         assertTrue(xml.getSource(null) instanceof StreamSource);
         
@@ -53,57 +48,62 @@
     }
 	//## JDBC4.0-end ##
     
-    public void testGetCharacterStream() throws Exception {
+    @Test public void testGetCharacterStream() throws Exception {
         SQLXMLImpl xml = new SQLXMLImpl(testStr);
-        assertEquals(testStr, getContents(xml.getCharacterStream()));
+        assertEquals(testStr, ObjectConverterUtil.convertToString(xml.getCharacterStream()));
     }
 
-    public void testGetBinaryStream() throws Exception {
+    @Test public void testGetBinaryStream() throws Exception {
         SQLXMLImpl xml = new SQLXMLImpl(testStr);
         assertEquals(testStr, new String(ObjectConverterUtil.convertToByteArray(xml.getBinaryStream()), Streamable.ENCODING));
     }
 
-    public void testGetString() throws Exception {
+    @Test public void testGetString() throws Exception {
         SQLXMLImpl xml = new SQLXMLImpl(testStr);
         assertEquals(testStr, xml.getString());
     }
 
-    public void testSetBinaryStream() throws Exception {
+    @Test(expected=SQLException.class) public void testSetBinaryStream() throws Exception {
         SQLXMLImpl xml = new SQLXMLImpl(testStr);        
-        try {
-            xml.setBinaryStream();
-            fail("we do not support this yet.."); //$NON-NLS-1$
-        } catch (SQLException e) {
-        }
+        xml.setBinaryStream();
     }
 
-    public void testSetCharacterStream() throws Exception {
+    @Test(expected=SQLException.class) public void testSetCharacterStream() throws Exception {
         SQLXMLImpl xml = new SQLXMLImpl(testStr);        
-        try {
-            xml.setCharacterStream();
-            fail("we do not support this yet.."); //$NON-NLS-1$
-        } catch (SQLException e) {
-        }
+        xml.setCharacterStream();
     }
 
-    public void testSetString() throws Exception {
+    @Test(expected=SQLException.class) public void testSetString() throws Exception {
         SQLXMLImpl xml = new SQLXMLImpl(testStr);        
-        try {
-            xml.setString(testStr);
-            fail("we do not support this yet.."); //$NON-NLS-1$
-        } catch (SQLException e) {
-        }
+        xml.setString(testStr);
     }
     
-    private String getContents(Reader reader) throws IOException {
-        StringBuffer sb = new StringBuffer();
-        int chr = reader.read();
-        while(chr != -1) {
-            sb.append((char)chr);
-            chr = reader.read();
-        }
-        reader.close();       
-        return sb.toString();
-    } 
+    @Test public void testGetString1() throws Exception {
+    	SQLXMLImpl clob = new SQLXMLImpl() {
+    		public java.io.Reader getCharacterStream() throws java.sql.SQLException {
+    			return new Reader() {
+
+    				int pos = 0;
+    				
+					@Override
+					public void close() throws IOException {
+						
+					}
+
+					@Override
+					public int read(char[] cbuf, int off, int len)
+							throws IOException {
+						if (pos < 5) {
+							cbuf[off] = 'a';
+							pos++;
+							return 1;
+						}
+						return -1;
+					}
+    			};
+    		}
+    	};
+    	assertEquals("aaaaa", clob.getString());
+    }
     
 }

Modified: trunk/engine/src/main/java/org/teiid/query/resolver/command/ExecResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/command/ExecResolver.java	2010-06-23 02:52:46 UTC (rev 2282)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/command/ExecResolver.java	2010-06-23 16:01:46 UTC (rev 2283)
@@ -74,7 +74,22 @@
 
         StoredProcedure storedProcedureCommand = (StoredProcedure) command;
         
-        StoredProcedureInfo storedProcedureInfo = metadata.getStoredProcedureInfoForProcedure(storedProcedureCommand.getProcedureName());
+        StoredProcedureInfo storedProcedureInfo = null;
+        try {
+        	storedProcedureInfo = metadata.getStoredProcedureInfoForProcedure(storedProcedureCommand.getProcedureName());
+        } catch (QueryMetadataException e) {
+        	String[] parts = storedProcedureCommand.getProcedureName().split("\\.", 2); //$NON-NLS-1$
+	    	if (parts.length > 1 && parts[0].equalsIgnoreCase(metadata.getVirtualDatabaseName())) {
+	            try {
+	            	storedProcedureInfo = metadata.getStoredProcedureInfoForProcedure(parts[1]);
+	            	storedProcedureCommand.setProcedureName(parts[1]);
+	            } catch(QueryMetadataException e1) {
+	            } 
+	        }
+	    	if (storedProcedureInfo == null) {
+	    		throw e;
+	    	}
+        }
 
         storedProcedureCommand.setUpdateCount(storedProcedureInfo.getUpdateCount());
         storedProcedureCommand.setModelID(storedProcedureInfo.getModelID());

Modified: trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java	2010-06-23 02:52:46 UTC (rev 2282)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java	2010-06-23 16:01:46 UTC (rev 2283)
@@ -879,22 +879,16 @@
 	    // If that didn't work, try to strip a vdb name from potentialID
 	    String vdbName = null;
 	    if(groupID == null) {
-			String newPotentialID = potentialID;
-	        int vdbIndex = potentialID.indexOf(ElementSymbol.SEPARATOR);
-	        if(vdbIndex >= 0) {
-	            String potentialVdbName = potentialID.substring(0, vdbIndex);
-	            if (potentialVdbName.equalsIgnoreCase(metadata.getVirtualDatabaseName())) {
-		            newPotentialID = potentialID.substring(vdbIndex+1);
-		
-		            try {
-		                groupID = metadata.getGroupID(newPotentialID);
-		                vdbName = potentialVdbName;
-		            } catch(QueryMetadataException e) {
-		                // ignore - just didn't find it
-		            } 
-		            if(groupID != null) {
-		            	potentialID = newPotentialID;
-		            }
+	    	String[] parts = potentialID.split("\\.", 2); //$NON-NLS-1$
+	    	if (parts.length > 1 && parts[0].equalsIgnoreCase(metadata.getVirtualDatabaseName())) {
+	            try {
+	                groupID = metadata.getGroupID(parts[1]);
+	            } catch(QueryMetadataException e) {
+	                // ignore - just didn't find it
+	            } 
+	            if(groupID != null) {
+	            	potentialID = parts[1];
+	            	vdbName = parts[0];
 	            }
 	        }
 	    }

Modified: trunk/engine/src/test/java/org/teiid/query/resolver/TestProcedureResolving.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/resolver/TestProcedureResolving.java	2010-06-23 02:52:46 UTC (rev 2282)
+++ trunk/engine/src/test/java/org/teiid/query/resolver/TestProcedureResolving.java	2010-06-23 16:01:46 UTC (rev 2283)
@@ -1619,4 +1619,8 @@
         TestResolver.helpResolve(proc.toString(), FakeMetadataFactory.example1Cached(), null); 
     }
     
+    @Test public void testVDBQualified() throws Exception {
+        helpResolve("EXEC myvdb.pm1.vsp29()", FakeMetadataFactory.example1Cached());   //$NON-NLS-1$
+    }
+    
 }



More information about the teiid-commits mailing list