[hibernate-commits] Hibernate SVN: r12831 - in core/trunk/core/src/main/java/org/hibernate: jdbc and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Jul 26 20:36:37 EDT 2007


Author: steve.ebersole at jboss.com
Date: 2007-07-26 20:36:37 -0400 (Thu, 26 Jul 2007)
New Revision: 12831

Removed:
   core/trunk/core/src/main/java/org/hibernate/util/GetGeneratedKeysHelper.java
   core/trunk/core/src/main/java/org/hibernate/util/NamedGeneratedKeysHelper.java
Modified:
   core/trunk/core/src/main/java/org/hibernate/id/IdentityGenerator.java
   core/trunk/core/src/main/java/org/hibernate/id/SequenceIdentityGenerator.java
   core/trunk/core/src/main/java/org/hibernate/jdbc/AbstractBatcher.java
Log:
HHH-2747 : JDBC3 getGeneratedKey

Modified: core/trunk/core/src/main/java/org/hibernate/id/IdentityGenerator.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/id/IdentityGenerator.java	2007-07-26 20:51:32 UTC (rev 12830)
+++ core/trunk/core/src/main/java/org/hibernate/id/IdentityGenerator.java	2007-07-27 00:36:37 UTC (rev 12831)
@@ -15,7 +15,6 @@
 import org.hibernate.dialect.Dialect;
 import org.hibernate.HibernateException;
 import org.hibernate.AssertionFailure;
-import org.hibernate.util.GetGeneratedKeysHelper;
 
 
 /**
@@ -72,7 +71,7 @@
 		public Serializable executeAndExtract(PreparedStatement insert) throws SQLException {
 			insert.executeUpdate();
 			return IdentifierGeneratorFactory.getGeneratedIdentity(
-					GetGeneratedKeysHelper.getGeneratedKey( insert ),
+					insert.getGeneratedKeys(),
 			        persister.getIdentifierType()
 			);
 		}

Modified: core/trunk/core/src/main/java/org/hibernate/id/SequenceIdentityGenerator.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/id/SequenceIdentityGenerator.java	2007-07-26 20:51:32 UTC (rev 12830)
+++ core/trunk/core/src/main/java/org/hibernate/id/SequenceIdentityGenerator.java	2007-07-27 00:36:37 UTC (rev 12831)
@@ -7,7 +7,6 @@
 import org.hibernate.HibernateException;
 import org.hibernate.MappingException;
 import org.hibernate.sql.Insert;
-import org.hibernate.util.NamedGeneratedKeysHelper;
 import org.hibernate.type.Type;
 import org.hibernate.engine.SessionImplementor;
 import org.apache.commons.logging.Log;
@@ -79,7 +78,7 @@
 		protected Serializable executeAndExtract(PreparedStatement insert) throws SQLException {
 			insert.executeUpdate();
 			return IdentifierGeneratorFactory.getGeneratedIdentity(
-					NamedGeneratedKeysHelper.getGeneratedKey( insert ),
+					insert.getGeneratedKeys(),
 			        getPersister().getIdentifierType()
 			);
 		}

Modified: core/trunk/core/src/main/java/org/hibernate/jdbc/AbstractBatcher.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/jdbc/AbstractBatcher.java	2007-07-26 20:51:32 UTC (rev 12830)
+++ core/trunk/core/src/main/java/org/hibernate/jdbc/AbstractBatcher.java	2007-07-27 00:36:37 UTC (rev 12831)
@@ -20,9 +20,7 @@
 import org.hibernate.engine.SessionFactoryImplementor;
 import org.hibernate.exception.JDBCExceptionHelper;
 import org.hibernate.pretty.Formatter;
-import org.hibernate.util.GetGeneratedKeysHelper;
 import org.hibernate.util.JDBCExceptionReporter;
-import org.hibernate.util.NamedGeneratedKeysHelper;
 
 /**
  * Manages prepared statements and batching.
@@ -492,10 +490,10 @@
 			}
 		}
 		else if ( useGetGeneratedKeys ) {
-			result = GetGeneratedKeysHelper.prepareStatement( conn, sql );
+			result = conn.prepareStatement( sql, PreparedStatement.RETURN_GENERATED_KEYS );
 		}
 		else if ( namedGeneratedKeys != null ) {
-			result = NamedGeneratedKeysHelper.prepareStatement( conn, sql, namedGeneratedKeys );
+			result = conn.prepareStatement( sql, namedGeneratedKeys );
 		}
 		else {
 			if ( callable ) {

Deleted: core/trunk/core/src/main/java/org/hibernate/util/GetGeneratedKeysHelper.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/util/GetGeneratedKeysHelper.java	2007-07-26 20:51:32 UTC (rev 12830)
+++ core/trunk/core/src/main/java/org/hibernate/util/GetGeneratedKeysHelper.java	2007-07-27 00:36:37 UTC (rev 12831)
@@ -1,87 +0,0 @@
-//$Id: GetGeneratedKeysHelper.java 9676 2006-03-22 17:38:55Z steve.ebersole at jboss.com $
-package org.hibernate.util;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-import org.hibernate.AssertionFailure;
-
-/**
- * @author Gavin King
- */
-public final class GetGeneratedKeysHelper {
-
-	private GetGeneratedKeysHelper() {
-	}
-
-	private static final Integer RETURN_GENERATED_KEYS;
-	private static final Method PREPARE_STATEMENT_METHOD;
-	private static final Method GET_GENERATED_KEYS_METHOD;
-
-	static {
-		try {
-			int returnGeneratedKeysEnumValue = Statement.class
-					.getDeclaredField( "RETURN_GENERATED_KEYS" )
-					.getInt( PreparedStatement.class );
-			RETURN_GENERATED_KEYS = new Integer( returnGeneratedKeysEnumValue );
-			PREPARE_STATEMENT_METHOD = Connection.class.getMethod(
-					"prepareStatement",
-			        new Class[] { String.class, Integer.TYPE }
-			);
-			GET_GENERATED_KEYS_METHOD = Statement.class.getDeclaredMethod(
-					"getGeneratedKeys",
-			        null
-			);
-		}
-		catch ( Exception e ) {
-			throw new AssertionFailure( "could not initialize getGeneratedKeys() support", e );
-		}
-	}
-
-	public static PreparedStatement prepareStatement(Connection conn, String sql) throws SQLException {
-		Object[] args = new Object[] { sql, RETURN_GENERATED_KEYS } ;
-		try {
-			return ( PreparedStatement ) PREPARE_STATEMENT_METHOD.invoke( conn, args );
-		}
-		catch ( InvocationTargetException ite ) {
-			if ( ite.getTargetException() instanceof SQLException ) {
-				throw ( SQLException ) ite.getTargetException();
-			}
-			else if ( ite.getTargetException() instanceof RuntimeException ) {
-				throw ( RuntimeException ) ite.getTargetException();
-			}
-			else {
-				throw new AssertionFailure( "InvocationTargetException preparing statement capable of returning generated keys (JDBC3)", ite );
-			}
-		}
-		catch ( IllegalAccessException iae ) {
-			throw new AssertionFailure( "IllegalAccessException preparing statement capable of returning generated keys (JDBC3)", iae );
-		}
-	}
-
-	public static ResultSet getGeneratedKey(PreparedStatement ps) throws SQLException {
-		try {
-			return ( ResultSet ) GET_GENERATED_KEYS_METHOD.invoke( ps, null );
-		}
-		catch ( InvocationTargetException ite ) {
-			if ( ite.getTargetException() instanceof SQLException ) {
-				throw ( SQLException ) ite.getTargetException();
-			}
-			else if ( ite.getTargetException() instanceof RuntimeException ) {
-				throw ( RuntimeException ) ite.getTargetException();
-			}
-			else {
-				throw new AssertionFailure( "InvocationTargetException extracting generated keys (JDBC3)", ite );
-			}
-		}
-		catch ( IllegalAccessException iae ) {
-			throw new AssertionFailure( "IllegalAccessException extracting generated keys (JDBC3)", iae );
-		}
-	}
-
-}

Deleted: core/trunk/core/src/main/java/org/hibernate/util/NamedGeneratedKeysHelper.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/util/NamedGeneratedKeysHelper.java	2007-07-26 20:51:32 UTC (rev 12830)
+++ core/trunk/core/src/main/java/org/hibernate/util/NamedGeneratedKeysHelper.java	2007-07-27 00:36:37 UTC (rev 12831)
@@ -1,79 +0,0 @@
-package org.hibernate.util;
-
-import org.hibernate.AssertionFailure;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
-import java.sql.Connection;
-import java.sql.Statement;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.sql.ResultSet;
-
-/**
- * @author Steve Ebersole
- */
-public class NamedGeneratedKeysHelper {
-	private NamedGeneratedKeysHelper() {
-	}
-
-	private static final Method PREPARE_STATEMENT_METHOD;
-	private static final Method GET_GENERATED_KEYS_METHOD;
-
-	static {
-		try {
-			PREPARE_STATEMENT_METHOD = Connection.class.getMethod(
-					"prepareStatement",
-			        new Class[] { String.class, String[].class }
-			);
-			GET_GENERATED_KEYS_METHOD = Statement.class.getDeclaredMethod(
-					"getGeneratedKeys",
-			        null
-			);
-		}
-		catch ( Exception e ) {
-			throw new AssertionFailure( "could not initialize getGeneratedKeys() support", e );
-		}
-	}
-
-	public static PreparedStatement prepareStatement(Connection conn, String sql, String[] columnNames) throws SQLException {
-		Object[] args = new Object[] { sql, columnNames } ;
-		try {
-			return ( PreparedStatement ) PREPARE_STATEMENT_METHOD.invoke( conn, args );
-		}
-		catch ( InvocationTargetException ite ) {
-			if ( ite.getTargetException() instanceof SQLException ) {
-				throw ( SQLException ) ite.getTargetException();
-			}
-			else if ( ite.getTargetException() instanceof RuntimeException ) {
-				throw ( RuntimeException ) ite.getTargetException();
-			}
-			else {
-				throw new AssertionFailure( "InvocationTargetException preparing statement capable of returning generated keys (JDBC3)", ite );
-			}
-		}
-		catch ( IllegalAccessException iae ) {
-			throw new AssertionFailure( "IllegalAccessException preparing statement capable of returning generated keys (JDBC3)", iae );
-		}
-	}
-
-	public static ResultSet getGeneratedKey(PreparedStatement ps) throws SQLException {
-		try {
-			return ( ResultSet ) GET_GENERATED_KEYS_METHOD.invoke( ps, null );
-		}
-		catch ( InvocationTargetException ite ) {
-			if ( ite.getTargetException() instanceof SQLException ) {
-				throw ( SQLException ) ite.getTargetException();
-			}
-			else if ( ite.getTargetException() instanceof RuntimeException ) {
-				throw ( RuntimeException ) ite.getTargetException();
-			}
-			else {
-				throw new AssertionFailure( "InvocationTargetException extracting generated keys (JDBC3)", ite );
-			}
-		}
-		catch ( IllegalAccessException iae ) {
-			throw new AssertionFailure( "IllegalAccessException extracting generated keys (JDBC3)", iae );
-		}
-	}
-}




More information about the hibernate-commits mailing list