Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GRAILS-6874 - support using the hibernate persistence interceptor in …
…a nested fashion. I suspect this was always the intended style of usage, but the implementation was bugged.
- Loading branch information
Showing
2 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...us/groovy/grails/orm/hibernate/support/HibernatePersistenceContextInterceptorTests.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.codehaus.groovy.grails.orm.hibernate.support | ||
|
||
import org.codehaus.groovy.grails.orm.hibernate.AbstractGrailsHibernateTests | ||
import org.springframework.transaction.support.TransactionSynchronizationManager | ||
import org.springframework.orm.hibernate3.SessionFactoryUtils | ||
import org.springframework.orm.hibernate3.SessionHolder | ||
import org.hibernate.Session | ||
import org.hibernate.SessionFactory | ||
import java.util.concurrent.CountDownLatch | ||
|
||
/** | ||
* @author Luke Daley | ||
* @since 1.4 | ||
*/ | ||
class HibernatePersistenceContextInterceptorTests extends AbstractGrailsHibernateTests { | ||
|
||
protected void setUp() { | ||
super.setUp() | ||
|
||
// We are going to manage the session ourselves through the interceptor | ||
def holder = TransactionSynchronizationManager.getResource(sessionFactory) | ||
def s = holder.session | ||
TransactionSynchronizationManager.unbindResource(sessionFactory) | ||
SessionFactoryUtils.releaseSession(s, sessionFactory) | ||
} | ||
|
||
void testSimpleLifecycle() { | ||
def interceptor = getInterceptor() | ||
assertEquals("interceptor open", false, interceptor.open) | ||
interceptor.init() | ||
assertEquals("interceptor open", true, interceptor.open) | ||
interceptor.destroy() | ||
assertEquals("interceptor open", false, interceptor.open) | ||
interceptor.init() | ||
assertEquals("interceptor open", true, interceptor.open) | ||
interceptor.destroy() | ||
assertEquals("interceptor open", false, interceptor.open) | ||
} | ||
|
||
void testNestedLifecycle() { | ||
def interceptor = getInterceptor() | ||
assertEquals("interceptor open", false, interceptor.open) | ||
|
||
interceptor.init() | ||
assertEquals("interceptor open", true, interceptor.open) | ||
interceptor.init() | ||
assertEquals("interceptor open", true, interceptor.open) | ||
interceptor.destroy() | ||
assertEquals("interceptor open", true, interceptor.open) | ||
interceptor.destroy() | ||
assertEquals("interceptor open", false, interceptor.open) | ||
|
||
interceptor.init() | ||
assertEquals("interceptor open", true, interceptor.open) | ||
interceptor.destroy() | ||
assertEquals("interceptor open", false, interceptor.open) | ||
} | ||
|
||
protected getInterceptor() { | ||
appCtx.persistenceInterceptor | ||
} | ||
} |