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

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Fri Sep 21 15:08:02 EDT 2012


Author: shawkins
Date: 2012-09-21 15:08:02 -0400 (Fri, 21 Sep 2012)
New Revision: 4464

Added:
   trunk/client/src/main/java/org/teiid/jdbc/AsynchPositioningException.java
   trunk/client/src/main/java/org/teiid/jdbc/TeiidResultSet.java
Modified:
   trunk/client/src/main/java/org/teiid/jdbc/JDBCPlugin.java
   trunk/client/src/main/java/org/teiid/jdbc/NonBlockingRowProcessor.java
   trunk/client/src/main/resources/org/teiid/jdbc/i18n.properties
   trunk/client/src/test/java/org/teiid/jdbc/TestResultSet.java
   trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestSystemVirtualModel.java
Log:
TEIID-2224 fixing positioning hangs and adding an available method

Added: trunk/client/src/main/java/org/teiid/jdbc/AsynchPositioningException.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/AsynchPositioningException.java	                        (rev 0)
+++ trunk/client/src/main/java/org/teiid/jdbc/AsynchPositioningException.java	2012-09-21 19:08:02 UTC (rev 4464)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.jdbc;
+
+public class AsynchPositioningException extends TeiidSQLException {
+
+	private static final long serialVersionUID = 4965087364648306848L;
+	
+	public AsynchPositioningException() {
+		super(JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20030));
+	}
+
+}


Property changes on: trunk/client/src/main/java/org/teiid/jdbc/AsynchPositioningException.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: trunk/client/src/main/java/org/teiid/jdbc/JDBCPlugin.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/JDBCPlugin.java	2012-09-21 19:07:25 UTC (rev 4463)
+++ trunk/client/src/main/java/org/teiid/jdbc/JDBCPlugin.java	2012-09-21 19:08:02 UTC (rev 4464)
@@ -58,6 +58,7 @@
 		TEIID20023,
 		TEIID20027,
 		TEIID20028,
-		TEIID20029
+		TEIID20029, 
+		TEIID20030
 	}	
 }

Modified: trunk/client/src/main/java/org/teiid/jdbc/NonBlockingRowProcessor.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/NonBlockingRowProcessor.java	2012-09-21 19:07:25 UTC (rev 4463)
+++ trunk/client/src/main/java/org/teiid/jdbc/NonBlockingRowProcessor.java	2012-09-21 19:08:02 UTC (rev 4464)
@@ -27,6 +27,7 @@
 import java.util.logging.Logger;
 
 import org.teiid.client.util.ResultsFuture;
+import org.teiid.core.TeiidRuntimeException;
 
 /**
  * Handles the future processing logic and makes the appropriate calls to the callback
@@ -52,6 +53,7 @@
 				return;
 			}
 			final ResultSetImpl resultSet = stmt.getResultSet();
+			resultSet.asynch = true;
 			Runnable rowProcessor = new Runnable() {
 				@Override
 				public void run() {
@@ -109,6 +111,9 @@
 		} catch (Exception e) {
 			onException(e);
 			return false;
+		} catch (Throwable t) {
+			onException(new TeiidRuntimeException(t));
+			return false;	
 		}
 	}
 
@@ -116,7 +121,7 @@
 		if (e instanceof ExecutionException) {
 			ExecutionException ee = (ExecutionException)e;
 			if (ee.getCause() instanceof Exception) {
-				e = (Exception)ee.getCause();
+				e = (Exception) ee.getCause();
 			}
 		}
 		try {

Added: trunk/client/src/main/java/org/teiid/jdbc/TeiidResultSet.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/TeiidResultSet.java	                        (rev 0)
+++ trunk/client/src/main/java/org/teiid/jdbc/TeiidResultSet.java	2012-09-21 19:08:02 UTC (rev 4464)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.jdbc;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+public interface TeiidResultSet extends ResultSet {
+	
+    /**
+     * Returns an estimate of the minimum number of rows that can be read (after the current) 
+     * without blocking or the end of the ResultSet is reached.  
+     *
+     * @return     an estimate of the minimum number of rows that can be read (after the current) 
+     *             without blocking or the end of the ResultSet is reached.
+     * @exception  SQLException if the statement is closed or another error condition occurs.
+     */
+	int available() throws SQLException;
+
+}


Property changes on: trunk/client/src/main/java/org/teiid/jdbc/TeiidResultSet.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: trunk/client/src/main/resources/org/teiid/jdbc/i18n.properties
===================================================================
--- trunk/client/src/main/resources/org/teiid/jdbc/i18n.properties	2012-09-21 19:07:25 UTC (rev 4463)
+++ trunk/client/src/main/resources/org/teiid/jdbc/i18n.properties	2012-09-21 19:08:02 UTC (rev 4464)
@@ -173,4 +173,5 @@
 unexpected_element=Unexpected Element {0} encountered, expecting one of {1}
 ambigious_gss_selection=Either configure "java.security.krb5.conf" property or combination of "java.security.krb5.realm" and "java.security.krb5.kdc" properties. Not both.
 no_gss_selection=No KRB5 configuration found. Either configure "java.security.krb5.conf" property or combination of "java.security.krb5.realm" and "java.security.krb5.kdc" properties.
-TEIID20029={0} value outside of 32-bit value range.  Please set the system property org.teiid.longDatesTimes to true to avoid this error.
\ No newline at end of file
+TEIID20029={0} value outside of 32-bit value range.  Please set the system property org.teiid.longDatesTimes to true to avoid this error.
+TEIID20030=The position cannot be set by a blocking call in asynch mode as the results have not yet been formed. 
\ No newline at end of file

Modified: trunk/client/src/test/java/org/teiid/jdbc/TestResultSet.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestResultSet.java	2012-09-21 19:07:25 UTC (rev 4463)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestResultSet.java	2012-09-21 19:08:02 UTC (rev 4464)
@@ -35,8 +35,6 @@
 import java.util.Calendar;
 import java.util.List;
 import java.util.TimeZone;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeoutException;
 
 import org.junit.Test;
 import org.mockito.Mockito;
@@ -50,7 +48,9 @@
 @SuppressWarnings("nls")
 public class TestResultSet {
 
-    /** test next() without walking through */
+    private static final int BATCH_SIZE = 400;
+
+	/** test next() without walking through */
     @Test public void testNext1() throws SQLException {  
         ResultSet cs =  helpExecuteQuery();
         assertEquals(" Actual doesn't match with expected. ", new Integer(0), new Integer(cs.getRow())); //$NON-NLS-1$
@@ -59,12 +59,13 @@
     
     /** test next() with walking through all the rows and compare records */
     @Test public void testNext2() throws SQLException {  
-        List[] expected = TestAllResultsImpl.exampleResults1(1000);
+        List<?>[] expected = TestAllResultsImpl.exampleResults1(1000);
         ResultSetImpl cs =  helpExecuteQuery();
 
         int i=0;
         while(cs.next()) { 
            assertEquals(" Actual doesn't match with expected. ", expected[i], cs.getCurrentRecord()); //$NON-NLS-1$
+           assertEquals((i < 800?BATCH_SIZE:200) - (i%BATCH_SIZE) - 1, cs.available());
            i++;
         }
 
@@ -204,7 +205,7 @@
     /** walk all way through from the end back to first row */
     @Test public void testPrevious1() throws SQLException {  
         ResultSetImpl cs = helpExecuteQuery();
-        List[] expected = TestAllResultsImpl.exampleResults1(1000);
+        List<?>[] expected = TestAllResultsImpl.exampleResults1(1000);
         while(cs.next()) {
             //System.out.println(" rs.next == " + cs.getCurrentRecord());
         }
@@ -236,7 +237,7 @@
     @Test public void testPrevious3() throws Exception {  
         //large batch size
         ResultSetImpl cs = helpExecuteQuery(600, 10000, ResultSet.TYPE_SCROLL_INSENSITIVE);
-        List[] expected = TestAllResultsImpl.exampleResults1(10000);
+        List<?>[] expected = TestAllResultsImpl.exampleResults1(10000);
         while(cs.next()) {
         }
         // cursor is after the last row. getRow() should return 0 when not on a valid row
@@ -256,7 +257,7 @@
     @Test public void testPrevious4() throws Exception {  
         //small batch size
         ResultSetImpl cs = helpExecuteQuery(50, 1000, ResultSet.TYPE_SCROLL_INSENSITIVE);
-        List[] expected = TestAllResultsImpl.exampleResults1(1000);
+        List<?>[] expected = TestAllResultsImpl.exampleResults1(1000);
         while(cs.next()) {
             //System.out.println(" rs.next == " + cs.getCurrentRecord());
         }
@@ -578,9 +579,9 @@
         
         // check result set metadata
         // expected column info.
-        List columnName = getBQTRSMetaData1a();
-        List columnType = getBQTRSMetaData1b();
-        List columnTypeName = getBQTRSMetaData1c();
+        List<String> columnName = getBQTRSMetaData1a();
+        List<Integer> columnType = getBQTRSMetaData1b();
+        List<String> columnTypeName = getBQTRSMetaData1c();
 
         ResultSetMetaData rm = cs.getMetaData();
         assertNotNull(rm);
@@ -731,13 +732,13 @@
 
     private ResultSetImpl helpExecuteQuery() {
         try {
-			return helpExecuteQuery(400, 1000, ResultSet.TYPE_SCROLL_INSENSITIVE);
+			return helpExecuteQuery(BATCH_SIZE, 1000, ResultSet.TYPE_SCROLL_INSENSITIVE);
 		} catch (Exception e) {
 			throw new RuntimeException(e);
 		}
     }
     
-    private ResultSetImpl helpExecuteQuery(int fetchSize, int totalResults, int cursorType) throws SQLException, TeiidProcessingException, InterruptedException, ExecutionException, TimeoutException {
+    private ResultSetImpl helpExecuteQuery(int fetchSize, int totalResults, int cursorType) throws SQLException, TeiidProcessingException {
         StatementImpl statement = createMockStatement(cursorType);
 		return TestAllResultsImpl.helpTestBatching(statement, fetchSize, Math.min(fetchSize, totalResults), totalResults);
     }
@@ -755,22 +756,22 @@
 
     ////////////////////////Expected Results////////////////
     /** column name */
-    private List getBQTRSMetaData1a() {
-        List results = new ArrayList();
+    private List<String> getBQTRSMetaData1a() {
+        List<String> results = new ArrayList<String>();
         results.add("IntKey"); //$NON-NLS-1$
         return results;   
     }
 
     /** column type */
-    private List getBQTRSMetaData1b() {
-        List results = new ArrayList();
-        results.add(new Integer(Types.INTEGER));
+    private List<Integer> getBQTRSMetaData1b() {
+        List<Integer> results = new ArrayList<Integer>();
+        results.add(Types.INTEGER);
         return results;   
     }
 
     /** column type name*/
-    private List getBQTRSMetaData1c() {
-        List results = new ArrayList();
+    private List<String> getBQTRSMetaData1c() {
+        List<String> results = new ArrayList<String>();
         results.add("integer"); //$NON-NLS-1$
         return results;   
     }               

Modified: trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestSystemVirtualModel.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestSystemVirtualModel.java	2012-09-21 19:07:25 UTC (rev 4463)
+++ trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestSystemVirtualModel.java	2012-09-21 19:08:02 UTC (rev 4464)
@@ -39,9 +39,11 @@
 import org.teiid.client.util.ResultsFuture;
 import org.teiid.core.util.UnitTestUtil;
 import org.teiid.jdbc.AbstractMMQueryTestCase;
+import org.teiid.jdbc.AsynchPositioningException;
 import org.teiid.jdbc.FakeServer;
 import org.teiid.jdbc.RequestOptions;
 import org.teiid.jdbc.StatementCallback;
+import org.teiid.jdbc.TeiidResultSet;
 import org.teiid.jdbc.TeiidStatement;
 import org.teiid.jdbc.TestMMDatabaseMetaData;
 
@@ -161,11 +163,24 @@
 		Statement stmt = this.internalConnection.createStatement();
 		TeiidStatement ts = stmt.unwrap(TeiidStatement.class);
 		final ResultsFuture<Integer> result = new ResultsFuture<Integer>(); 
-		ts.submitExecute("select * from SYS.Schemas", new StatementCallback() {
+		ts.submitExecute("select * from SYS.columns a, sys.tables b", new StatementCallback() {
 			int rowCount;
 			@Override
 			public void onRow(Statement s, ResultSet rs) {
 				rowCount++;
+				try {
+					if (!rs.isLast()) {
+						assertTrue(rs.unwrap(TeiidResultSet.class).available() > 0);
+					}
+				} catch (AsynchPositioningException e) {
+					try {
+						assertEquals(0, rs.unwrap(TeiidResultSet.class).available());
+					} catch (SQLException e1) {
+						result.getResultsReceiver().exceptionOccurred(e1);
+					}
+				} catch (SQLException e) {
+					result.getResultsReceiver().exceptionOccurred(e);
+				}
 			}
 			
 			@Override
@@ -178,7 +193,7 @@
 				result.getResultsReceiver().receiveResults(rowCount);
 			}
 		}, new RequestOptions());
-		assertEquals(4, result.get().intValue());
+		assertEquals(7905, result.get().intValue());
 	}
 	
 	@Test public void testAsynchContinuous() throws Exception {



More information about the teiid-commits mailing list