[teiid-commits] teiid SVN: r2583 - in branches/7.1.x: client/src/main/java/org/teiid/adminapi/impl and 3 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Thu Sep 16 13:29:21 EDT 2010


Author: shawkins
Date: 2010-09-16 13:29:21 -0400 (Thu, 16 Sep 2010)
New Revision: 2583

Modified:
   branches/7.1.x/build/kits/jboss-container/teiid-releasenotes.html
   branches/7.1.x/client/src/main/java/org/teiid/adminapi/impl/ListOverMap.java
   branches/7.1.x/client/src/main/java/org/teiid/adminapi/impl/PermissionMap.java
   branches/7.1.x/client/src/main/java/org/teiid/adminapi/impl/SourceMappingMetadata.java
   branches/7.1.x/client/src/main/java/org/teiid/jdbc/ConnectionImpl.java
   branches/7.1.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java
   branches/7.1.x/client/src/main/java/org/teiid/jdbc/TeiidDataSource.java
   branches/7.1.x/client/src/test/java/org/teiid/jdbc/TestStatement.java
   branches/7.1.x/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-extensions.xml
Log:
TEIID-139 adding basic support for transaction statements from jdbc and removing mm references

Modified: branches/7.1.x/build/kits/jboss-container/teiid-releasenotes.html
===================================================================
--- branches/7.1.x/build/kits/jboss-container/teiid-releasenotes.html	2010-09-15 21:23:25 UTC (rev 2582)
+++ branches/7.1.x/build/kits/jboss-container/teiid-releasenotes.html	2010-09-16 17:29:21 UTC (rev 2583)
@@ -26,6 +26,7 @@
 </UL>
 <H2><A NAME="Highlights"></A>Highlights</H2>
 <UL>
+    <LI><B>Transaction Statements</B> - JDBC/ODBC now accepts START TRANSACTION, COMMIT, and ROLLBACK statements to control local transactions.
 	<LI><B>Procedure Result Caching</B> - virtual procedure definitions may use a cache hint to cache results in the result set cache.
 	<LI><B>Improved Plan Caching</B> - plans used by internal materialization and stored procedure plans will be automatically cached in the prepared plan cache.  Improvements were also made to reduce the memory footprint of the plans.
     <LI><B>Refined Load Balancing and Fail Over</B> - clients can use use the statement "SET NEWINSTANCE TRUE" to allow their connection to select a new server instance.  See the Client Developer's Guide for more information. 

Modified: branches/7.1.x/client/src/main/java/org/teiid/adminapi/impl/ListOverMap.java
===================================================================
--- branches/7.1.x/client/src/main/java/org/teiid/adminapi/impl/ListOverMap.java	2010-09-15 21:23:25 UTC (rev 2582)
+++ branches/7.1.x/client/src/main/java/org/teiid/adminapi/impl/ListOverMap.java	2010-09-16 17:29:21 UTC (rev 2583)
@@ -1,7 +1,6 @@
 /*
  * JBoss, Home of Professional Open Source.
  * Copyright (C) 2008 Red Hat, Inc.
- * Copyright (C) 2000-2007 MetaMatrix, Inc.
  * Licensed to Red Hat, Inc. under one or more contributor 
  * license agreements.  See the copyright.txt file in the
  * distribution for a full listing of individual contributors.

Modified: branches/7.1.x/client/src/main/java/org/teiid/adminapi/impl/PermissionMap.java
===================================================================
--- branches/7.1.x/client/src/main/java/org/teiid/adminapi/impl/PermissionMap.java	2010-09-15 21:23:25 UTC (rev 2582)
+++ branches/7.1.x/client/src/main/java/org/teiid/adminapi/impl/PermissionMap.java	2010-09-16 17:29:21 UTC (rev 2583)
@@ -1,7 +1,6 @@
 /*
  * JBoss, Home of Professional Open Source.
  * Copyright (C) 2008 Red Hat, Inc.
- * Copyright (C) 2000-2007 MetaMatrix, Inc.
  * Licensed to Red Hat, Inc. under one or more contributor 
  * license agreements.  See the copyright.txt file in the
  * distribution for a full listing of individual contributors.

Modified: branches/7.1.x/client/src/main/java/org/teiid/adminapi/impl/SourceMappingMetadata.java
===================================================================
--- branches/7.1.x/client/src/main/java/org/teiid/adminapi/impl/SourceMappingMetadata.java	2010-09-15 21:23:25 UTC (rev 2582)
+++ branches/7.1.x/client/src/main/java/org/teiid/adminapi/impl/SourceMappingMetadata.java	2010-09-16 17:29:21 UTC (rev 2583)
@@ -1,7 +1,6 @@
 /*
  * JBoss, Home of Professional Open Source.
  * Copyright (C) 2008 Red Hat, Inc.
- * Copyright (C) 2000-2007 MetaMatrix, Inc.
  * Licensed to Red Hat, Inc. under one or more contributor 
  * license agreements.  See the copyright.txt file in the
  * distribution for a full listing of individual contributors.

Modified: branches/7.1.x/client/src/main/java/org/teiid/jdbc/ConnectionImpl.java
===================================================================
--- branches/7.1.x/client/src/main/java/org/teiid/jdbc/ConnectionImpl.java	2010-09-15 21:23:25 UTC (rev 2582)
+++ branches/7.1.x/client/src/main/java/org/teiid/jdbc/ConnectionImpl.java	2010-09-16 17:29:21 UTC (rev 2583)
@@ -383,13 +383,6 @@
         }
     }
     
-    /**
-     * <p>This creates a MMStatement object for sending SQL statements to the MetaMatrix
-     * server.  This should be used for statements without parameters.  For statements
-     * that are executed many times, use the PreparedStatement object.</p>
-     * @return a Statement object.
-     * @throws a SQLException if a MetaMatrix server access error occurs.
-     */
     public Statement createStatement() throws SQLException {
         return createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
     }
@@ -439,14 +432,6 @@
         }
     }
 
-    /**
-     * <p>This method returns the current status of the connection in regards to it's
-     * auto-commit state.  By default, the auto-commit is set to true.  Meaning that
-     * any transaction that occurs is automatically commited to the MetaMatrix server.
-     * #See corresponding setAutoCommit() method.</p>
-     * @return true if the statements on this connection get committed on execution.
-     * @throws SQLException should never happen
-     */
     public boolean getAutoCommit() throws SQLException {
         //Check to see the connection is open
        checkConnection();
@@ -563,26 +548,10 @@
         return closed;
     }
 
-    /**
-     * <p>This method will return whether this connection is read only or not.
-     * It will throw a SQLException if a MetaMatrix server access error occurs.
-     * @return boolean value indication if connection is readonly
-     * @throws SQLException, should never occur
-     */
     public boolean isReadOnly() throws SQLException {
          return readOnly; 
     }
 
-    /**
-     * <p>This method will convert the given SQL String into a MetaMatrix SQL Request.
-     * This will convert any date escape sequences into the appropriate MetaMatrix
-     * type, and any kind of data transformations that the MetaMatrix server would
-     * expect.  This method returns the native form of the statement that the driver
-     * would have sent.</p>
-     * @param sql string to be coverted into SQL understood by metamatrix
-     * @return uncoverted sql string(escape parsing takesplace in metamatrix)
-     * @throws SQLException, should never occur
-     */
     public String nativeSQL(String sql) throws SQLException {
         // return the string argument without any modifications.
         // escape syntaxes are directly supported in the server
@@ -639,16 +608,6 @@
         }
     }
 
-    /**
-     * <p>This method creates a MMPreparedStatement which is used for sending parameterized
-     * SQL statements to the MetaMatrix server.  A statement with or without IN parameters
-     * can be pre-compiled and stored in a MMPreparedStatement object.  Since the MetaMatrix
-     * server does not pre-compile statements, a sql statement will be constructed using the
-     * parameters supplied which would be used for execution of this preparedStatement object.</p>
-     * @param sql string representing a prepared statement
-     * @return a PreparedStatement object
-     * @throws SQLException if there is an error creating a prepared statement object
-     */
     public PreparedStatementImpl prepareStatement(String sql) throws SQLException {
         return prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
     }
@@ -676,34 +635,21 @@
         return newStatement;
     }
 
-    /**
-     * <p>This method creates a MMPreparedStatement which is used for sending parameterized
-     * SQL statements to the MetaMatrix server and it has the capability to retrieve auto-generated keys.</p>
-     * @param sql string representing a prepared statement
-     * @param intValue indicating the result set Type
-     * @param intValue indicating the result set concurrency
-     * @param intValue indicating the result set holdability
-     * @return a PreparedStatement object
-     * @throws SQLException if there is an error creating a prepared statement object
-     */
     public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
         int resultSetHoldability ) throws SQLException {
     	throw SqlUtil.createFeatureNotSupportedException();
     }
 
-    /**
-     * <p>This method will drop all changes made since the beginning of the transaction
-     * and release any MetaMatrix server locks currently held by this connection. This
-     * method rolls back transactions on all the statements currently open on this connection.
-     * This is used when then auto-commit has been disabled.</p>
-     * @see setAutoCommit(boolean) method for more information.
-     * @throws SQLException if there is an error rolling back.
-     */
     public void rollback() throws SQLException {
         rollback(true);
     }
-    
-    void rollback(boolean startTxn) throws SQLException {
+    
+    /**
+     * Rollback the current local transaction
+     * @param startTxn
+     * @throws SQLException
+     */
+    public void rollback(boolean startTxn) throws SQLException {
 
         //Check to see the connection is open
         checkConnection();
@@ -727,17 +673,6 @@
         }
     }
 
-    /**
-     * <p>This method will set the connection's auto commit mode accordingly.  By
-     * default this is set to true (auto-commit is turned on).  An auto-commit
-     * value of true means any statements will automatically be made permanent if
-     * they are successful after the last row of the ReulstSet has been retrieved
-     * or the next execute occurs, whichever comes first.  If set to false, changes
-     * can be either be committed (using the commit() method) or rolled back ("undo
-     * the changes" by using the rollback() method).</p>
-     * @param boolean value indicating if autoCommit is turned on
-     * @throws SQLException is metamatrix access error occurs.
-     */
     public void setAutoCommit(boolean autoCommit) throws SQLException {
         //Check to see the connection is open
         checkConnection();
@@ -756,7 +691,7 @@
     }
 
     /**
-     * <p>Metamatrix does not allow setting a catalog through a connection. This
+     * <p>Teiid does not allow setting a catalog through a connection. This
      * method silently ignores the request as per the specification.</p>
      * @param The string values which sets the catalog name on the connection.
      * @throws SQLException This should never occur.

Modified: branches/7.1.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java
===================================================================
--- branches/7.1.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java	2010-09-15 21:23:25 UTC (rev 2582)
+++ branches/7.1.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java	2010-09-16 17:29:21 UTC (rev 2583)
@@ -23,7 +23,6 @@
 package org.teiid.jdbc;
 
 import java.io.Serializable;
-import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
@@ -63,6 +62,7 @@
 import org.teiid.core.types.JDBCSQLTypeInfo;
 import org.teiid.core.types.SQLXMLImpl;
 import org.teiid.core.util.SqlUtil;
+import org.teiid.core.util.StringUtil;
 
 
 public class StatementImpl extends WrapperImpl implements TeiidStatement {
@@ -144,8 +144,9 @@
     //Map<out/inout/return param index --> index in results>
     protected Map outParamIndexMap = new HashMap();
     
-    private static Pattern SET_STATEMENT = Pattern.compile("\\s*set\\s*(\\w+)\\s*(\\w*)", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
-    private static Pattern SHOW_STATEMENT = Pattern.compile("\\s*show\\s*(\\w*)", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
+    private static Pattern TRANSACTION_STATEMENT = Pattern.compile("\\s*(commit|rollback|(start\\s*transaction))\\s*;?", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
+    private static Pattern SET_STATEMENT = Pattern.compile("\\s*set\\s*(\\w+)\\s*(\\w*);?", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
+    private static Pattern SHOW_STATEMENT = Pattern.compile("\\s*show\\s*(\\w*);?", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
     /**
      * Factory Constructor 
      * @param driverConnection
@@ -403,6 +404,22 @@
         		this.updateCounts = new int[] {0};
         		return;
         	}
+        	match = TRANSACTION_STATEMENT.matcher(commands[0]);
+        	if (match.matches()) {
+        		if (resultsMode == ResultsMode.RESULTSET) {
+        			throw new TeiidSQLException(JDBCPlugin.Util.getString("StatementImpl.set_result_set")); //$NON-NLS-1$
+        		}
+        		String command = match.group(1);
+        		if (StringUtil.startsWithIgnoreCase(command, "start")) { //$NON-NLS-1$
+        			this.getConnection().setAutoCommit(false);
+        		} else if (command.equalsIgnoreCase("commit")) { //$NON-NLS-1$
+        			this.getConnection().setAutoCommit(true);
+        		} else if (command.equalsIgnoreCase("rollback")) { //$NON-NLS-1$
+        			this.getConnection().rollback(false);
+        		}
+        		this.updateCounts = new int[] {0};
+        		return;
+        	}
         	match = SHOW_STATEMENT.matcher(commands[0]);
         	if (match.matches()) {
         		if (resultsMode == ResultsMode.UPDATECOUNT) {
@@ -996,7 +1013,7 @@
 		checkStatement();
 	}
 	
-	public Connection getConnection() throws SQLException {
+	public ConnectionImpl getConnection() throws SQLException {
 		return this.driverConnection;
 	}
 

Modified: branches/7.1.x/client/src/main/java/org/teiid/jdbc/TeiidDataSource.java
===================================================================
--- branches/7.1.x/client/src/main/java/org/teiid/jdbc/TeiidDataSource.java	2010-09-15 21:23:25 UTC (rev 2582)
+++ branches/7.1.x/client/src/main/java/org/teiid/jdbc/TeiidDataSource.java	2010-09-16 17:29:21 UTC (rev 2583)
@@ -279,7 +279,7 @@
 
     /**
      * Returns a string containing a comma delimited list of alternate 
-     * MetaMatrix Server(s).  
+     * server(s).  
      * 
      * The list will be in the form of server2[:port2][,server3[:port3]].  If no 
      * alternate servers have been defined <code>null</code> is returned. 

Modified: branches/7.1.x/client/src/test/java/org/teiid/jdbc/TestStatement.java
===================================================================
--- branches/7.1.x/client/src/test/java/org/teiid/jdbc/TestStatement.java	2010-09-15 21:23:25 UTC (rev 2582)
+++ branches/7.1.x/client/src/test/java/org/teiid/jdbc/TestStatement.java	2010-09-16 17:29:21 UTC (rev 2583)
@@ -84,5 +84,18 @@
 		assertEquals(Boolean.TRUE.toString(), p.getProperty(ExecutionProperties.ANSI_QUOTED_IDENTIFIERS));
 	}
 
+	@Test public void testTransactionStatements() throws Exception {
+		ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
+		Properties p = new Properties();
+		Mockito.stub(conn.getExecutionProperties()).toReturn(p);
+		StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
+		assertFalse(statement.execute("start transaction")); //$NON-NLS-1$
+		Mockito.verify(conn).setAutoCommit(false);
+		assertFalse(statement.execute("commit")); //$NON-NLS-1$
+		Mockito.verify(conn).setAutoCommit(true);
+		assertFalse(statement.execute("start transaction")); //$NON-NLS-1$
+		assertFalse(statement.execute("rollback")); //$NON-NLS-1$
+		Mockito.verify(conn).rollback(false);
+	}
 	
 }

Modified: branches/7.1.x/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-extensions.xml
===================================================================
--- branches/7.1.x/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-extensions.xml	2010-09-15 21:23:25 UTC (rev 2582)
+++ branches/7.1.x/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-extensions.xml	2010-09-16 17:29:21 UTC (rev 2583)
@@ -253,6 +253,19 @@
         </itemizedlist>
         <para>The SHOW statement is most commonly used to retrieve the query plan, see the plan <link linkend="plan_debug">debug example</link>.</para>        
        </section>
+       
+       <section id="transaction_statement">
+       	<title>Transaction Statements</title>
+       	<para>In situations where the direct use of the JDBC connection is not possible, transaction statements can be used to control a local transaction.</para>
+       	<itemizedlist>
+       		<listitem><para><emphasis>START TRANSACTION</emphasis> - synonym for <code>connection.setAutoCommit(false)</code></para>
+       		</listitem>
+       		<listitem><para><emphasis>COMMIT</emphasis> - synonym for <code>connection.setAutoCommit(true)</code></para>
+       		</listitem>
+       		<listitem><para><emphasis>ROLLBACK</emphasis> - synonym for <code>connection.rollback()</code> and returning to auto commit mode.</para>
+       		</listitem>
+       	</itemizedlist>
+       </section>
                             
        <section id="partial_results">
         <title>Partial Results Mode</title>



More information about the teiid-commits mailing list