FileDocCategorySizeDatePackage
NamedGeneratedKeysHelper.javaAPI DocHibernate 3.2.52632Mon Mar 27 10:47:06 BST 2006org.hibernate.util

NamedGeneratedKeysHelper

public class NamedGeneratedKeysHelper extends Object
author
Steve Ebersole

Fields Summary
private static final Method
PREPARE_STATEMENT_METHOD
private static final Method
GET_GENERATED_KEYS_METHOD
Constructors Summary
private NamedGeneratedKeysHelper()

	
Methods Summary
public static java.sql.ResultSetgetGeneratedKey(java.sql.PreparedStatement ps)

		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 );
		}
	
public static java.sql.PreparedStatementprepareStatement(java.sql.Connection conn, java.lang.String sql, java.lang.String[] columnNames)

		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 );
		}
	
		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 );
		}