Hibernate SVN: r19936 - tools.
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2010-07-12 02:59:59 -0400 (Mon, 12 Jul 2010)
New Revision: 19936
Removed:
tools/workspace/
Log:
remove workspace trace
13 years, 9 months
Hibernate SVN: r19935 - tools/branches.
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2010-07-12 02:53:59 -0400 (Mon, 12 Jul 2010)
New Revision: 19935
Added:
tools/branches/Branch_3_2/
Log:
attempt to retain old branch_3_2 history for now
Copied: tools/branches/Branch_3_2 (from rev 19934, tools/trunk)
13 years, 9 months
Hibernate SVN: r19934 - in tools: workspace and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2010-07-12 02:51:10 -0400 (Mon, 12 Jul 2010)
New Revision: 19934
Added:
tools/trunk/
Removed:
tools/workspace/tools/
Log:
moving branch 3.2 to trunk
Copied: tools/trunk (from rev 19933, tools/workspace/tools)
13 years, 9 months
Hibernate SVN: r19933 - tools.
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2010-07-12 02:48:46 -0400 (Mon, 12 Jul 2010)
New Revision: 19933
Added:
tools/workspace/
Removed:
tools/trunk/
Log:
moving branch 3.2 to trunk
Copied: tools/workspace (from rev 19932, tools/trunk)
13 years, 9 months
Hibernate SVN: r19932 - tools/trunk and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2010-07-12 02:42:59 -0400 (Mon, 12 Jul 2010)
New Revision: 19932
Added:
tools/trunk/tools/
Removed:
branches/Branch_3_2/HibernateExt/tools/
Log:
moving branch 3.2 to trunk
Copied: tools/trunk/tools (from rev 19931, branches/Branch_3_2/HibernateExt/tools)
13 years, 9 months
Hibernate SVN: r19931 - in core/trunk/core/src/main/java/org/hibernate: util and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-07-11 18:16:38 -0400 (Sun, 11 Jul 2010)
New Revision: 19931
Modified:
core/trunk/core/src/main/java/org/hibernate/hql/ast/exec/AbstractStatementExecutor.java
core/trunk/core/src/main/java/org/hibernate/util/JDBCExceptionReporter.java
Log:
HHH-5373 - Better account for SQLWarnings in temp table creation
Modified: core/trunk/core/src/main/java/org/hibernate/hql/ast/exec/AbstractStatementExecutor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/exec/AbstractStatementExecutor.java 2010-07-10 13:48:34 UTC (rev 19930)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/exec/AbstractStatementExecutor.java 2010-07-11 22:16:38 UTC (rev 19931)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,12 +20,12 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.hql.ast.exec;
import java.sql.PreparedStatement;
import java.sql.Connection;
+import java.sql.SQLWarning;
import java.sql.Statement;
import java.util.List;
import java.util.Collections;
@@ -43,12 +43,14 @@
import org.hibernate.sql.InsertSelect;
import org.hibernate.sql.Select;
import org.hibernate.sql.SelectFragment;
+import org.hibernate.util.JDBCExceptionReporter;
import org.hibernate.util.StringHelper;
import antlr.RecognitionException;
import antlr.collections.AST;
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Implementation of AbstractStatementExecutor.
@@ -56,6 +58,7 @@
* @author Steve Ebersole
*/
public abstract class AbstractStatementExecutor implements StatementExecutor {
+ private static final Logger LOG = LoggerFactory.getLogger( AbstractStatementExecutor.class );
private final Logger log;
private final HqlSqlWalker walker;
@@ -141,24 +144,24 @@
// simply allow the failure to be eaten and the subsequent insert-selects/deletes should fail
IsolatedWork work = new IsolatedWork() {
public void doWork(Connection connection) throws HibernateException {
- Statement stmnt = null;
try {
- stmnt = connection.createStatement();
- stmnt.executeUpdate( persister.getTemporaryIdTableDDL() );
- }
- catch( Throwable t ) {
- log.debug( "unable to create temporary id table [" + t.getMessage() + "]" );
- }
- finally {
- if ( stmnt != null ) {
+ Statement statement = connection.createStatement();
+ try {
+ statement.executeUpdate( persister.getTemporaryIdTableDDL() );
+ JDBCExceptionReporter.handleAndClearWarnings( statement, CREATION_WARNING_HANDLER );
+ }
+ finally {
try {
- stmnt.close();
+ statement.close();
}
catch( Throwable ignore ) {
// ignore
}
}
}
+ catch( Exception e ) {
+ log.debug( "unable to create temporary id table [" + e.getMessage() + "]" );
+ }
}
};
if ( shouldIsolateTemporaryTableDDL() ) {
@@ -175,30 +178,46 @@
}
}
+ private static JDBCExceptionReporter.WarningHandler CREATION_WARNING_HANDLER = new JDBCExceptionReporter.WarningHandlerLoggingSupport() {
+ public boolean doProcess() {
+ return LOG.isDebugEnabled();
+ }
+
+ public void prepare(SQLWarning warning) {
+ LOG.debug( "Warnings creating temp table", warning );
+ }
+
+ @Override
+ protected void logWarning(String description, String message) {
+ LOG.debug( description );
+ LOG.debug( message );
+ }
+ };
+
protected void dropTemporaryTableIfNecessary(final Queryable persister, final SessionImplementor session) {
if ( getFactory().getDialect().dropTemporaryTableAfterUse() ) {
IsolatedWork work = new IsolatedWork() {
public void doWork(Connection connection) throws HibernateException {
- Statement stmnt = null;
+ final String command = session.getFactory().getSettings().getDialect().getDropTemporaryTableString()
+ + ' ' + persister.getTemporaryIdTableName();
try {
- final String command = session.getFactory().getSettings().getDialect().getDropTemporaryTableString()
- + " " + persister.getTemporaryIdTableName();
- stmnt = connection.createStatement();
- stmnt.executeUpdate( command );
- }
- catch( Throwable t ) {
- log.warn( "unable to drop temporary id table after use [" + t.getMessage() + "]" );
- }
- finally {
- if ( stmnt != null ) {
+ Statement statement = connection.createStatement();
+ try {
+ statement = connection.createStatement();
+ statement.executeUpdate( command );
+ }
+ finally {
try {
- stmnt.close();
+ statement.close();
}
catch( Throwable ignore ) {
// ignore
}
}
}
+ catch( Exception e ) {
+ log.warn( "unable to drop temporary id table after use [" + e.getMessage() + "]" );
+ }
}
};
@@ -249,6 +268,7 @@
}
}
+ @SuppressWarnings({ "UnnecessaryUnboxing" })
protected boolean shouldIsolateTemporaryTableDDL() {
Boolean dialectVote = getFactory().getDialect().performTemporaryTableDDLInIsolation();
if ( dialectVote != null ) {
Modified: core/trunk/core/src/main/java/org/hibernate/util/JDBCExceptionReporter.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/util/JDBCExceptionReporter.java 2010-07-10 13:48:34 UTC (rev 19930)
+++ core/trunk/core/src/main/java/org/hibernate/util/JDBCExceptionReporter.java 2010-07-11 22:16:38 UTC (rev 19931)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,67 +20,200 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.util;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLWarning;
+import java.sql.Statement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class JDBCExceptionReporter {
-
public static final Logger log = LoggerFactory.getLogger(JDBCExceptionReporter.class);
public static final String DEFAULT_EXCEPTION_MSG = "SQL Exception";
public static final String DEFAULT_WARNING_MSG = "SQL Warning";
private JDBCExceptionReporter() {}
-
+
+ /**
+ * Standard (legacy) behavior for logging warnings associated with a JDBC {@link Connection} and clearing them.
+ * <p/>
+ * Calls {@link #handleAndClearWarnings(Connection, WarningHandler)} using {@link #STANDARD_WARNING_HANDLER}
+ *
+ * @param connection The JDBC connection potentially containing warnings
+ */
public static void logAndClearWarnings(Connection connection) {
- if ( log.isWarnEnabled() ) {
- try {
- logWarnings( connection.getWarnings() );
- }
- catch (SQLException sqle) {
- //workaround for WebLogic
- log.debug("could not log warnings", sqle);
- }
+ handleAndClearWarnings( connection, STANDARD_WARNING_HANDLER );
+ }
+
+ /**
+ * General purpose handling of warnings associated with a JDBC {@link Connection}.
+ *
+ * @param connection The JDBC connection potentially containing warnings
+ * @param handler The handler for each individual warning in the stack.
+ *
+ * @see #walkWarnings
+ */
+ @SuppressWarnings({ "ThrowableResultOfMethodCallIgnored" })
+ public static void handleAndClearWarnings(Connection connection, WarningHandler handler) {
+ try {
+ walkWarnings( connection.getWarnings(), handler );
}
+ catch ( SQLException sqle ) {
+ //workaround for WebLogic
+ log.debug( "could not log warnings", sqle );
+ }
try {
//Sybase fail if we don't do that, sigh...
connection.clearWarnings();
}
- catch (SQLException sqle) {
- log.debug("could not clear warnings", sqle);
+ catch ( SQLException sqle ) {
+ log.debug( "could not clear warnings", sqle );
}
}
+ /**
+ * General purpose handling of warnings associated with a JDBC {@link Statement}.
+ *
+ * @param statement The JDBC statement potentially containing warnings
+ * @param handler The handler for each individual warning in the stack.
+ *
+ * @see #walkWarnings
+ */
+ @SuppressWarnings({ "ThrowableResultOfMethodCallIgnored" })
+ public static void handleAndClearWarnings(Statement statement, WarningHandler handler) {
+ try {
+ walkWarnings( statement.getWarnings(), handler );
+ }
+ catch ( SQLException sqle ) {
+ //workaround for WebLogic
+ log.debug( "could not log warnings", sqle );
+ }
+ try {
+ //Sybase fail if we don't do that, sigh...
+ statement.clearWarnings();
+ }
+ catch ( SQLException sqle ) {
+ log.debug( "could not clear warnings", sqle );
+ }
+ }
+
+ /**
+ * Log the given warning and all of its nested warnings, preceded with the {@link #DEFAULT_WARNING_MSG default message}
+ *
+ * @param warning The warning to log
+ *
+ * @deprecated Use {@link #walkWarnings} instead
+ */
+ @Deprecated()
+ @SuppressWarnings({ "UnusedDeclaration" })
public static void logWarnings(SQLWarning warning) {
- logWarnings(warning, null);
+ walkWarnings( warning, STANDARD_WARNING_HANDLER );
}
+ /**
+ * Log the given warning and all of its nested warnings, preceded with the given message
+ *
+ * @param warning The warning to log
+ * @param message The prologue message
+ *
+ * @deprecated Use {@link #walkWarnings} instead
+ */
+ @Deprecated()
+ @SuppressWarnings({ "UnusedDeclaration" })
public static void logWarnings(SQLWarning warning, String message) {
- if ( log.isWarnEnabled() ) {
- if ( log.isDebugEnabled() && warning != null ) {
- message = StringHelper.isNotEmpty(message) ? message : DEFAULT_WARNING_MSG;
- log.debug( message, warning );
- }
- while (warning != null) {
- StringBuffer buf = new StringBuffer(30)
- .append( "SQL Warning: ")
- .append( warning.getErrorCode() )
- .append( ", SQLState: ")
- .append( warning.getSQLState() );
- log.warn( buf.toString() );
- log.warn( warning.getMessage() );
- warning = warning.getNextWarning();
- }
+ final WarningHandler handler = StringHelper.isNotEmpty(message)
+ ? new StandardWarningHandler( message )
+ : STANDARD_WARNING_HANDLER;
+ walkWarnings( warning, handler );
+ }
+
+ /**
+ * Contract for handling {@link SQLWarning warnings}
+ */
+ public static interface WarningHandler {
+ /**
+ * Should processing be done? Allows short-circuiting if not.
+ *
+ * @return True to process warnings, false otherwise.
+ */
+ public boolean doProcess();
+
+ /**
+ * Prepare for processing of a {@link SQLWarning warning} stack.
+ * <p/>
+ * Note that the warning here is also the first passed to {@link #handleWarning}
+ *
+ * @param warning The first warning in the stack.
+ */
+ public void prepare(SQLWarning warning);
+
+ /**
+ * Handle an individual warning in the stack.
+ *
+ * @param warning The warning to handle.
+ */
+ public void handleWarning(SQLWarning warning);
+ }
+
+ /**
+ * Basic support for {@link WarningHandler} implementations which log
+ */
+ public static abstract class WarningHandlerLoggingSupport implements WarningHandler {
+ public final void handleWarning(SQLWarning warning) {
+ StringBuffer buf = new StringBuffer(30)
+ .append( "SQL Warning Code: ").append( warning.getErrorCode() )
+ .append( ", SQLState: ").append( warning.getSQLState() );
+ logWarning( buf.toString(), warning.getMessage() );
}
+
+ /**
+ * Delegate to log common details of a {@link SQLWarning warning}
+ *
+ * @param description A description of the warning
+ * @param message The warning message
+ */
+ protected abstract void logWarning(String description, String message);
}
+ public static class StandardWarningHandler extends WarningHandlerLoggingSupport {
+ private final String introMessage;
+
+ public StandardWarningHandler(String introMessage) {
+ this.introMessage = introMessage;
+ }
+
+ public boolean doProcess() {
+ return log.isWarnEnabled();
+ }
+
+ public void prepare(SQLWarning warning) {
+ log.debug( introMessage, warning );
+ }
+
+ @Override
+ protected void logWarning(String description, String message) {
+ log.warn( description );
+ log.warn( message );
+ }
+ }
+
+ public static StandardWarningHandler STANDARD_WARNING_HANDLER = new StandardWarningHandler( DEFAULT_WARNING_MSG );
+
+ public static void walkWarnings(SQLWarning warning, WarningHandler handler) {
+ if ( warning == null || handler.doProcess() ) {
+ return;
+ }
+ handler.prepare( warning );
+ while ( warning != null ) {
+ handler.handleWarning( warning );
+ warning = warning.getNextWarning();
+ }
+ }
+
public static void logExceptions(SQLException ex) {
logExceptions(ex, null);
}
@@ -103,20 +236,6 @@
}
}
}
-
-// public static JDBCException newJDBCException(String string, SQLException root, String sql) {
-// string = string + " [" + sql + ']';
-// log.error(string, root);
-// logExceptions(root);
-// return new JDBCException(string, root, sql);
-// }
-//
-// public static JDBCException newJDBCException(String string, SQLException root) {
-// log.error(string, root);
-// logExceptions(root);
-// return new JDBCException(string, root);
-// }
-
}
13 years, 9 months
Hibernate SVN: r19930 - in core/trunk/entitymanager/src: test/java/org/hibernate/ejb/criteria/basic and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-07-10 09:48:34 -0400 (Sat, 10 Jul 2010)
New Revision: 19930
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImpl.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java
Log:
HHH-5370 - Building IN condition with CriteriaBuilder providing collection of values not working.
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImpl.java 2010-07-10 13:48:15 UTC (rev 19929)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImpl.java 2010-07-10 13:48:34 UTC (rev 19930)
@@ -88,7 +88,7 @@
* {@inheritDoc}
*/
public Predicate in(Collection<?> values) {
- return criteriaBuilder().in( this, values );
+ return criteriaBuilder().in( this, values.toArray() );
}
/**
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java 2010-07-10 13:48:15 UTC (rev 19929)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java 2010-07-10 13:48:34 UTC (rev 19930)
@@ -25,11 +25,13 @@
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.util.Collections;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Expression;
import javax.persistence.criteria.ParameterExpression;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
@@ -58,7 +60,7 @@
product.setId( "product1" );
product.setPrice( 1.23d );
product.setQuantity( 2 );
- product.setPartNumber( Integer.MAX_VALUE + 1 );
+ product.setPartNumber( ((long)Integer.MAX_VALUE) + 1 );
product.setRating( 1.999f );
product.setSomeBigInteger( BigInteger.valueOf( 987654321 ) );
product.setSomeBigDecimal( BigDecimal.valueOf( 987654.321 ) );
@@ -248,4 +250,39 @@
return hqlQueryImpl.getParameterMetadata().getNamedParameterNames().size();
}
+ public void testInExplicitTupleList() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Product> criteria = builder.createQuery( Product.class );
+ Root<Product> from = criteria.from( Product.class );
+ criteria.where( from.get( Product_.partNumber ).in( Collections.singletonList( ((long)Integer.MAX_VALUE) + 1 ) ) );
+ List<Product> result = em.createQuery( criteria ).getResultList();
+ assertEquals( 1, result.size() );
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void testInExplicitTupleListVarargs() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Product> criteria = builder.createQuery( Product.class );
+ Root<Product> from = criteria.from( Product.class );
+ criteria.where( from.get( Product_.partNumber ).in( ((long)Integer.MAX_VALUE) + 1 ) );
+ List<Product> result = em.createQuery( criteria ).getResultList();
+ assertEquals( 1, result.size() );
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void testInExpressionVarargs() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Product> criteria = builder.createQuery( Product.class );
+ Root<Product> from = criteria.from( Product.class );
+ criteria.where( from.get( Product_.partNumber ).in( from.get( Product_.partNumber ) ) );
+ List<Product> result = em.createQuery( criteria ).getResultList();
+ assertEquals( 1, result.size() );
+ em.getTransaction().commit();
+ em.close();
+ }
}
13 years, 9 months
Hibernate SVN: r19929 - in core/branches/Branch_3_5/entitymanager/src: test/java/org/hibernate/ejb/criteria/basic and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-07-10 09:48:15 -0400 (Sat, 10 Jul 2010)
New Revision: 19929
Modified:
core/branches/Branch_3_5/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImpl.java
core/branches/Branch_3_5/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java
Log:
HHH-5370 - Building IN condition with CriteriaBuilder providing collection of values not working.
Modified: core/branches/Branch_3_5/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImpl.java
===================================================================
--- core/branches/Branch_3_5/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImpl.java 2010-07-10 12:48:19 UTC (rev 19928)
+++ core/branches/Branch_3_5/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImpl.java 2010-07-10 13:48:15 UTC (rev 19929)
@@ -88,7 +88,7 @@
* {@inheritDoc}
*/
public Predicate in(Collection<?> values) {
- return criteriaBuilder().in( this, values );
+ return criteriaBuilder().in( this, values.toArray() );
}
/**
Modified: core/branches/Branch_3_5/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java
===================================================================
--- core/branches/Branch_3_5/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java 2010-07-10 12:48:19 UTC (rev 19928)
+++ core/branches/Branch_3_5/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java 2010-07-10 13:48:15 UTC (rev 19929)
@@ -25,6 +25,7 @@
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.util.Collections;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
@@ -58,7 +59,7 @@
product.setId( "product1" );
product.setPrice( 1.23d );
product.setQuantity( 2 );
- product.setPartNumber( Integer.MAX_VALUE + 1 );
+ product.setPartNumber( ((long)Integer.MAX_VALUE) + 1 );
product.setRating( 1.999f );
product.setSomeBigInteger( BigInteger.valueOf( 987654321 ) );
product.setSomeBigDecimal( BigDecimal.valueOf( 987654.321 ) );
@@ -246,4 +247,40 @@
AbstractQueryImpl hqlQueryImpl = (AbstractQueryImpl) query;
return hqlQueryImpl.getParameterMetadata().getNamedParameterNames().size();
}
+
+ public void testInExplicitTupleList() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Product> criteria = builder.createQuery( Product.class );
+ Root<Product> from = criteria.from( Product.class );
+ criteria.where( from.get( Product_.partNumber ).in( Collections.singletonList( ((long)Integer.MAX_VALUE) + 1 ) ) );
+ List<Product> result = em.createQuery( criteria ).getResultList();
+ assertEquals( 1, result.size() );
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void testInExplicitTupleListVarargs() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Product> criteria = builder.createQuery( Product.class );
+ Root<Product> from = criteria.from( Product.class );
+ criteria.where( from.get( Product_.partNumber ).in( ((long)Integer.MAX_VALUE) + 1 ) );
+ List<Product> result = em.createQuery( criteria ).getResultList();
+ assertEquals( 1, result.size() );
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void testInExpressionVarargs() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Product> criteria = builder.createQuery( Product.class );
+ Root<Product> from = criteria.from( Product.class );
+ criteria.where( from.get( Product_.partNumber ).in( from.get( Product_.partNumber ) ) );
+ List<Product> result = em.createQuery( criteria ).getResultList();
+ assertEquals( 1, result.size() );
+ em.getTransaction().commit();
+ em.close();
+ }
}
13 years, 9 months
Hibernate SVN: r19928 - in core/trunk/envers: src/main/java/org/hibernate/envers/synchronization and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2010-07-10 08:48:19 -0400 (Sat, 10 Jul 2010)
New Revision: 19928
Added:
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/jta/
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/jta/JtaExceptionListener.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/jta/JtaTransaction.java
Modified:
core/trunk/envers/pom.xml
core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/AuditProcess.java
core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/AuditProcessManager.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/AbstractEntityTest.java
core/trunk/envers/src/test/resources/hibernate.test.cfg.xml
core/trunk/envers/src/test/resources/testng.xml
Log:
HHH-5315:
- work units executed both in the before tx completion process and in the synchronization
- each test class has its own H2 database
- tests in a JTA environment
Modified: core/trunk/envers/pom.xml
===================================================================
--- core/trunk/envers/pom.xml 2010-07-09 18:03:11 UTC (rev 19927)
+++ core/trunk/envers/pom.xml 2010-07-10 12:48:19 UTC (rev 19928)
@@ -118,6 +118,12 @@
<artifactId>javassist</artifactId>
<scope>test</scope>
</dependency>
+ <!-- For JTA tests -->
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-testing</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<dependencyManagement>
@@ -139,6 +145,11 @@
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
+ <artifactId>hibernate-testing</artifactId>
+ <version>${version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
<artifactId>hibernate-tools</artifactId>
<version>3.2.0.ga</version>
</dependency>
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/AuditProcess.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/AuditProcess.java 2010-07-09 18:03:11 UTC (rev 19927)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/AuditProcess.java 2010-07-10 12:48:19 UTC (rev 19928)
@@ -37,11 +37,14 @@
import org.hibernate.FlushMode;
import org.hibernate.Session;
+import javax.transaction.Synchronization;
+
/**
* @author Adam Warski (adam at warski dot org)
*/
-public class AuditProcess implements BeforeTransactionCompletionProcess {
+public class AuditProcess implements BeforeTransactionCompletionProcess, Synchronization {
private final RevisionInfoGenerator revisionInfoGenerator;
+ private final SessionImplementor session;
private final LinkedList<AuditWorkUnit> workUnits;
private final Queue<AuditWorkUnit> undoQueue;
@@ -49,8 +52,9 @@
private Object revisionData;
- public AuditProcess(RevisionInfoGenerator revisionInfoGenerator) {
+ public AuditProcess(RevisionInfoGenerator revisionInfoGenerator, SessionImplementor session) {
this.revisionInfoGenerator = revisionInfoGenerator;
+ this.session = session;
workUnits = new LinkedList<AuditWorkUnit>();
undoQueue = new LinkedList<AuditWorkUnit>();
@@ -153,4 +157,12 @@
session.flush();
}
}
+
+ // Synchronization methods
+
+ public void beforeCompletion() {
+ doBeforeTransactionCompletion(session);
+ }
+
+ public void afterCompletion(int status) { }
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/AuditProcessManager.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/AuditProcessManager.java 2010-07-09 18:03:11 UTC (rev 19927)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/AuditProcessManager.java 2010-07-10 12:48:19 UTC (rev 19928)
@@ -52,10 +52,22 @@
AuditProcess auditProcess = auditProcesses.get(transaction);
if (auditProcess == null) {
// No worries about registering a transaction twice - a transaction is single thread
- auditProcess = new AuditProcess(revisionInfoGenerator);
+ auditProcess = new AuditProcess(revisionInfoGenerator, session);
auditProcesses.put(transaction, auditProcess);
+ /*
+ * HHH-5315: the process must be both a BeforeTransactionCompletionProcess and a TX Synchronization.
+ *
+ * In a resource-local tx env, the process is called after the flush, and populates the audit tables.
+ * Also, any exceptions that occur during that are propagated (if a Synchronization was used, the exceptions
+ * would be eaten).
+ *
+ * In a JTA env, the before transaction completion is called before the flush, so not all changes are yet
+ * written. However, Synchronization-s do propagate exceptions, so they can be safely used.
+ */
session.getActionQueue().registerProcess(auditProcess);
+ session.getTransaction().registerSynchronization(auditProcess);
+
session.getActionQueue().registerProcess(new AfterTransactionCompletionProcess() {
public void doAfterTransactionCompletion(boolean success, SessionImplementor session) {
auditProcesses.remove(transaction);
Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/AbstractEntityTest.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/AbstractEntityTest.java 2010-07-09 18:03:11 UTC (rev 19927)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/AbstractEntityTest.java 2010-07-10 12:48:19 UTC (rev 19928)
@@ -27,9 +27,13 @@
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
+import org.hibernate.cfg.Environment;
+import org.hibernate.ejb.AvailableSettings;
import org.hibernate.envers.AuditReader;
import org.hibernate.envers.AuditReaderFactory;
import org.hibernate.envers.event.AuditEventListener;
+import org.hibernate.testing.tm.ConnectionProviderImpl;
+import org.hibernate.testing.tm.TransactionManagerLookupImpl;
import org.testng.annotations.*;
import org.hibernate.ejb.Ejb3Configuration;
@@ -89,11 +93,15 @@
initListeners();
}
+ cfg.configure("hibernate.test.cfg.xml");
+
if (auditStrategy != null && !"".equals(auditStrategy)) {
cfg.setProperty("org.hibernate.envers.audit_strategy", auditStrategy);
- }
+ }
- cfg.configure("hibernate.test.cfg.xml");
+ // Separate database for each test class
+ cfg.setProperty("hibernate.connection.url", "jdbc:h2:mem:" + this.getClass().getName());
+
configure(cfg);
emf = cfg.buildEntityManagerFactory();
@@ -117,4 +125,10 @@
public Ejb3Configuration getCfg() {
return cfg;
}
+
+ protected void addJTAConfig(Ejb3Configuration cfg) {
+ cfg.setProperty("connection.provider_class", ConnectionProviderImpl.class.getName());
+ cfg.setProperty(Environment.TRANSACTION_MANAGER_STRATEGY, TransactionManagerLookupImpl.class.getName());
+ cfg.setProperty(AvailableSettings.TRANSACTION_TYPE, "JTA");
+ }
}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/jta/JtaExceptionListener.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/jta/JtaExceptionListener.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/jta/JtaExceptionListener.java 2010-07-10 12:48:19 UTC (rev 19928)
@@ -0,0 +1,74 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program 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 distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.envers.test.integration.jta;
+
+import org.hibernate.ejb.Ejb3Configuration;
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.entities.StrTestEntity;
+import org.hibernate.envers.test.integration.reventity.ExceptionListenerRevEntity;
+import org.hibernate.testing.tm.SimpleJtaTransactionManagerImpl;
+import org.testng.annotations.Test;
+
+import javax.persistence.EntityManager;
+
+/**
+ * Same as {@link org.hibernate.envers.test.integration.reventity.ExceptionListener}, but in a JTA environment.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class JtaExceptionListener extends AbstractEntityTest {
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(StrTestEntity.class);
+ cfg.addAnnotatedClass(ExceptionListenerRevEntity.class);
+
+ addJTAConfig(cfg);
+ }
+
+ @Test(expectedExceptions = RuntimeException.class)
+ public void testTransactionRollback() throws Exception {
+ SimpleJtaTransactionManagerImpl.getInstance().begin();
+
+ // Trying to persist an entity - however the listener should throw an exception, so the entity
+ // shouldn't be persisted
+ newEntityManager();
+ EntityManager em = getEntityManager();
+ em.getTransaction().begin();
+ StrTestEntity te = new StrTestEntity("x");
+ em.persist(te);
+
+ SimpleJtaTransactionManagerImpl.getInstance().commit();
+ }
+
+ @Test(dependsOnMethods = "testTransactionRollback")
+ public void testDataNotPersisted() throws Exception {
+ SimpleJtaTransactionManagerImpl.getInstance().begin();
+
+ // Checking if the entity became persisted
+ newEntityManager();
+ EntityManager em = getEntityManager();
+ Long count = (Long) em.createQuery("select count(s) from StrTestEntity s where s.str = 'x'").getSingleResult();
+ assert count == 0l;
+
+ SimpleJtaTransactionManagerImpl.getInstance().commit();
+ }
+}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/jta/JtaTransaction.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/jta/JtaTransaction.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/jta/JtaTransaction.java 2010-07-10 12:48:19 UTC (rev 19928)
@@ -0,0 +1,63 @@
+package org.hibernate.envers.test.integration.jta;
+
+import org.hibernate.ejb.Ejb3Configuration;
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.entities.IntTestEntity;
+import org.hibernate.testing.tm.SimpleJtaTransactionManagerImpl;
+import org.testng.annotations.Test;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+
+/**
+ * Same as {@link org.hibernate.envers.test.integration.basic.Simple}, but in a JTA environment.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class JtaTransaction extends AbstractEntityTest {
+ private Integer id1;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(IntTestEntity.class);
+
+ addJTAConfig(cfg);
+ }
+
+ @Test
+ public void initData() throws Exception {
+ SimpleJtaTransactionManagerImpl.getInstance().begin();
+
+ newEntityManager();
+ EntityManager em = getEntityManager();
+ em.joinTransaction();
+ IntTestEntity ite = new IntTestEntity(10);
+ em.persist(ite);
+ id1 = ite.getId();
+
+ SimpleJtaTransactionManagerImpl.getInstance().commit();
+
+ //
+
+ SimpleJtaTransactionManagerImpl.getInstance().begin();
+
+ newEntityManager();
+ em = getEntityManager();
+ ite = em.find(IntTestEntity.class, id1);
+ ite.setNumber(20);
+
+ SimpleJtaTransactionManagerImpl.getInstance().commit();
+ }
+
+ @Test(dependsOnMethods = "initData")
+ public void testRevisionsCounts() throws Exception {
+ assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(IntTestEntity.class, id1));
+ }
+
+ @Test(dependsOnMethods = "initData")
+ public void testHistoryOfId1() {
+ IntTestEntity ver1 = new IntTestEntity(10, id1);
+ IntTestEntity ver2 = new IntTestEntity(20, id1);
+
+ assert getAuditReader().find(IntTestEntity.class, id1, 1).equals(ver1);
+ assert getAuditReader().find(IntTestEntity.class, id1, 2).equals(ver2);
+ }
+}
Modified: core/trunk/envers/src/test/resources/hibernate.test.cfg.xml
===================================================================
--- core/trunk/envers/src/test/resources/hibernate.test.cfg.xml 2010-07-09 18:03:11 UTC (rev 19927)
+++ core/trunk/envers/src/test/resources/hibernate.test.cfg.xml 2010-07-10 12:48:19 UTC (rev 19928)
@@ -12,10 +12,10 @@
<property name="format_sql">true</property>
<property name="dialect">org.hibernate.dialect.H2Dialect</property>
- <property name="connection.url">jdbc:h2:mem:envers</property>
<property name="connection.driver_class">org.h2.Driver</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
+ <!-- The connection URL is set in AbstractEntityTest -->
<!--<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>-->
<!--<property name="connection.url">jdbc:mysql:///hibernate_tests?useUnicode=true&characterEncoding=UTF-8</property>-->
@@ -46,4 +46,4 @@
<listener class="org.hibernate.envers.event.AuditEventListener" />
</event>-->
</session-factory>
-</hibernate-configuration>
\ No newline at end of file
+</hibernate-configuration>
Modified: core/trunk/envers/src/test/resources/testng.xml
===================================================================
--- core/trunk/envers/src/test/resources/testng.xml 2010-07-09 18:03:11 UTC (rev 19927)
+++ core/trunk/envers/src/test/resources/testng.xml 2010-07-10 12:48:19 UTC (rev 19928)
@@ -38,6 +38,7 @@
<package name="org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited2.subclass" />
<package name="org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited2.joined" />
<package name="org.hibernate.envers.test.integration.interfaces.hbm.propertiesAudited2.union" />
+ <package name="org.hibernate.envers.test.integration.jta" />
<package name="org.hibernate.envers.test.integration.manytomany" />
<package name="org.hibernate.envers.test.integration.manytomany.biowned" />
<package name="org.hibernate.envers.test.integration.manytomany.inverseToSuperclass" />
13 years, 9 months