[hibernate-commits] Hibernate SVN: r20142 - in core/branches/Branch_3_5: core/src/main/java/org/hibernate/engine and 1 other directories.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Fri Aug 13 18:26:52 EDT 2010
Author: steve.ebersole at jboss.com
Date: 2010-08-13 18:26:52 -0400 (Fri, 13 Aug 2010)
New Revision: 20142
Modified:
core/branches/Branch_3_5/core/src/main/java/org/hibernate/action/BulkOperationCleanupAction.java
core/branches/Branch_3_5/core/src/main/java/org/hibernate/engine/ActionQueue.java
core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/querycache/QueryCacheTest.java
Log:
HHH-5426 - HQL update/delete does not invalidate the query cache
Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/action/BulkOperationCleanupAction.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/action/BulkOperationCleanupAction.java 2010-08-13 20:21:07 UTC (rev 20141)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/action/BulkOperationCleanupAction.java 2010-08-13 22:26:52 UTC (rev 20142)
@@ -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,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.action;
@@ -55,7 +54,7 @@
* @author Steve Ebersole
*/
public class BulkOperationCleanupAction implements Executable, Serializable {
- private final Serializable[] affectedTableSpaces;
+ private final String[] affectedTableSpaces;
private final Set entityCleanups = new HashSet();
private final Set collectionCleanups = new HashSet();
@@ -91,7 +90,7 @@
}
}
- this.affectedTableSpaces = ( Serializable[] ) tmpSpaces.toArray( new Serializable[ tmpSpaces.size() ] );
+ this.affectedTableSpaces = ( String[] ) tmpSpaces.toArray( new String[ tmpSpaces.size() ] );
}
/**
@@ -137,7 +136,7 @@
}
}
- this.affectedTableSpaces = ( Serializable[] ) tmpSpaces.toArray( new Serializable[ tmpSpaces.size() ] );
+ this.affectedTableSpaces = ( String[] ) tmpSpaces.toArray( new String[ tmpSpaces.size() ] );
}
Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/engine/ActionQueue.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/engine/ActionQueue.java 2010-08-13 20:21:07 UTC (rev 20141)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/engine/ActionQueue.java 2010-08-13 22:26:52 UTC (rev 20142)
@@ -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,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.engine;
@@ -150,7 +149,7 @@
}
public void addAction(BulkOperationCleanupAction cleanupAction) {
- registerProcess( cleanupAction.getAfterTransactionCompletionProcess() );
+ registerCleanupActions( cleanupAction );
}
public void registerProcess(AfterTransactionCompletionProcess process) {
@@ -268,16 +267,20 @@
executable.execute();
}
finally {
- beforeTransactionProcesses.register( executable.getBeforeTransactionCompletionProcess() );
- if ( session.getFactory().getSettings().isQueryCacheEnabled() ) {
- final String[] spaces = (String[]) executable.getPropertySpaces();
- afterTransactionProcesses.addSpacesToInvalidate( spaces );
- session.getFactory().getUpdateTimestampsCache().preinvalidate( executable.getPropertySpaces() );
- }
- afterTransactionProcesses.register( executable.getAfterTransactionCompletionProcess() );
+ registerCleanupActions( executable );
}
}
+ private void registerCleanupActions(Executable executable) {
+ beforeTransactionProcesses.register( executable.getBeforeTransactionCompletionProcess() );
+ if ( session.getFactory().getSettings().isQueryCacheEnabled() ) {
+ final String[] spaces = (String[]) executable.getPropertySpaces();
+ afterTransactionProcesses.addSpacesToInvalidate( spaces );
+ session.getFactory().getUpdateTimestampsCache().preinvalidate( spaces );
+ }
+ afterTransactionProcesses.register( executable.getAfterTransactionCompletionProcess() );
+ }
+
private void prepareActions(List queue) throws HibernateException {
int size = queue.size();
for ( int i = 0; i < size; i++ ) {
Modified: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/querycache/QueryCacheTest.java
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/querycache/QueryCacheTest.java 2010-08-13 20:21:07 UTC (rev 20141)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/querycache/QueryCacheTest.java 2010-08-13 22:26:52 UTC (rev 20142)
@@ -42,6 +42,51 @@
public static Test suite() {
return new FunctionalTestClassTestSuite( QueryCacheTest.class );
}
+
+ public void testInvalidationFromBulkHQL() {
+ // http://opensource.atlassian.com/projects/hibernate/browse/HHH-5426
+
+ getSessions().getCache().evictQueryRegions();
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ List list = new ArrayList();
+ s.beginTransaction();
+ for (int i = 0; i < 3; i++) {
+ Item a = new Item();
+ a.setName("a" + i);
+ a.setDescription("a" + i);
+ list.add(a);
+ s.persist(a);
+ }
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ String queryString = "select count(*) from Item";
+ // this query will hit the database and create the cache
+ Long result = (Long) s.createQuery(queryString).setCacheable(true).uniqueResult();
+ assertEquals(3, result.intValue());
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ String updateString = "delete from Item";
+ s.createQuery(updateString).executeUpdate();
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ // and this one SHOULD not be served by the cache
+ Number result2 = (Number) s.createQuery(queryString).setCacheable(true).uniqueResult();
+ assertEquals(0, result2.intValue());
+ s.getTransaction().commit();
+ s.close();
+ }
+
//https://jira.jboss.org/jira/browse/JBPAPP-4224
public void testHitCacheInSameSession() {
getSessions().evictQueries();
More information about the hibernate-commits
mailing list