[hibernate-commits] Hibernate SVN: r11339 - trunk/Hibernate3/test/org/hibernate/test/exception.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Fri Mar 23 08:51:38 EDT 2007
Author: steve.ebersole at jboss.com
Date: 2007-03-23 08:51:38 -0400 (Fri, 23 Mar 2007)
New Revision: 11339
Modified:
trunk/Hibernate3/test/org/hibernate/test/exception/SQLExceptionConversionTest.java
Log:
db2 testsuite
Modified: trunk/Hibernate3/test/org/hibernate/test/exception/SQLExceptionConversionTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/exception/SQLExceptionConversionTest.java 2007-03-22 22:43:13 UTC (rev 11338)
+++ trunk/Hibernate3/test/org/hibernate/test/exception/SQLExceptionConversionTest.java 2007-03-23 12:51:38 UTC (rev 11339)
@@ -41,7 +41,7 @@
reportSkip( "MySQL (ISAM) does not support FK violation checking", "exception conversion" );
return;
}
-
+
SQLExceptionConverter converter = getDialect().buildSQLExceptionConverter();
Session session = openSession();
@@ -49,12 +49,12 @@
// Attempt to insert some bad values into the T_MEMBERSHIP table that should
// result in a constraint violation
+ PreparedStatement ps = null;
try {
- PreparedStatement ps = connection.prepareStatement("INSERT INTO T_MEMBERSHIP (user_id, group_id) VALUES (?, ?)");
+ ps = connection.prepareStatement("INSERT INTO T_MEMBERSHIP (user_id, group_id) VALUES (?, ?)");
ps.setLong(1, 52134241); // Non-existent user_id
ps.setLong(2, 5342); // Non-existent group_id
ps.executeUpdate();
- ps.close();
fail("INSERT should have failed");
}
@@ -65,6 +65,16 @@
ConstraintViolationException ex = (ConstraintViolationException) jdbcException;
System.out.println("Violated constraint name: " + ex.getConstraintName());
}
+ finally {
+ if ( ps != null ) {
+ try {
+ ps.close();
+ }
+ catch( Throwable ignore ) {
+ // ignore...
+ }
+ }
+ }
session.close();
}
@@ -76,16 +86,26 @@
Connection connection = session.connection();
// prepare a query against a non-existent table
+ PreparedStatement ps = null;
try {
- PreparedStatement ps = connection.prepareStatement("SELECT user_id, user_name FROM tbl_user");
+ ps = connection.prepareStatement("SELECT user_id, user_name FROM tbl_user");
ps.executeQuery();
- ps.close();
fail("SQL compilation should have failed");
}
catch( SQLException sqle ) {
assertEquals( "Bad conversion [" + sqle.getMessage() + "]", SQLGrammarException.class, converter.convert(sqle, null, null).getClass() );
}
+ finally {
+ if ( ps != null ) {
+ try {
+ ps.close();
+ }
+ catch( Throwable ignore ) {
+ // ignore...
+ }
+ }
+ }
session.close();
}
More information about the hibernate-commits
mailing list