Author: epbernard
Date: 2007-08-10 09:35:22 -0400 (Fri, 10 Aug 2007)
New Revision: 12915
Added:
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/NoOpListener.java
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/lock/UnversionedLock.java
Modified:
trunk/HibernateExt/entitymanager/src/test-resources/explicitpar/META-INF/persistence.xml
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/PackagedEntityManagerTest.java
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/ejb3configuration/EventOverridingTest.java
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/FlushTest.java
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/lock/LockTest.java
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java
Log:
More tests on explicit events
Added: trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/NoOpListener.java
===================================================================
--- trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/NoOpListener.java
(rev 0)
+++
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/NoOpListener.java 2007-08-10
13:35:22 UTC (rev 12915)
@@ -0,0 +1,14 @@
+//$Id: $
+package org.hibernate.ejb.test;
+
+import org.hibernate.event.PreInsertEventListener;
+import org.hibernate.event.PreInsertEvent;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class NoOpListener implements PreInsertEventListener {
+ public boolean onPreInsert(PreInsertEvent event) {
+ return false;
+ }
+}
Modified:
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/PackagedEntityManagerTest.java
===================================================================
---
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/PackagedEntityManagerTest.java 2007-08-10
05:35:01 UTC (rev 12914)
+++
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/PackagedEntityManagerTest.java 2007-08-10
13:35:22 UTC (rev 12915)
@@ -27,6 +27,8 @@
import org.hibernate.stat.Statistics;
import org.hibernate.validator.InvalidStateException;
import org.hibernate.JDBCException;
+import org.hibernate.event.EventListeners;
+import org.hibernate.engine.SessionImplementor;
//$Id$
@@ -215,6 +217,19 @@
}
+ public void testListeners() throws Exception {
+ EntityManagerFactory emf = Persistence.createEntityManagerFactory(
"manager1", new HashMap() );
+ EntityManager em = emf.createEntityManager();
+ EventListeners eventListeners = ( (SessionImplementor) em.getDelegate()
).getListeners();
+ assertEquals(
+ "Explicit pre-insert event through hibernate.ejb.event.pre-insert does not
work",
+ eventListeners.getPreInsertEventListeners().length,
+ eventListeners.getPreUpdateEventListeners().length + 1);
+
+ em.close();
+ emf.close();
+ }
+
// This test does not make sense anymore, validator being autoregistered at the HAN
level
// public void testListenersOverridingCfgXmlPar() throws Exception {
// EntityManagerFactory emf = Persistence.createEntityManagerFactory(
"cfgxmlpar", new HashMap() );
Modified:
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/ejb3configuration/EventOverridingTest.java
===================================================================
---
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/ejb3configuration/EventOverridingTest.java 2007-08-10
05:35:01 UTC (rev 12914)
+++
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/ejb3configuration/EventOverridingTest.java 2007-08-10
13:35:22 UTC (rev 12915)
@@ -36,7 +36,7 @@
public void testEventPerProperties() throws Exception {
EntityManagerFactory emf = Persistence.createEntityManagerFactory(
"manager1", new HashMap() );
EntityManager em = emf.createEntityManager();
- assertEquals( "Only validator should be present", 1,
+ assertEquals( "Only validator and explicit NoOp should be present", 2,
( (SessionImplementor) em.getDelegate()
).getListeners().getPreInsertEventListeners().length);
em.close();
emf.close();
Modified:
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/FlushTest.java
===================================================================
---
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/FlushTest.java 2007-08-10
05:35:01 UTC (rev 12914)
+++
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/FlushTest.java 2007-08-10
13:35:22 UTC (rev 12915)
@@ -107,7 +107,9 @@
List list = query.getResultList();
for (Object obj : list) {
if (obj instanceof Decorate) {
- founds.add((Decorate) obj);
+ Decorate decorate = (Decorate) obj;
+ founds.add( decorate );
+ decorate.getPet().getName(); //load
}
}
return founds;
Modified:
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/lock/LockTest.java
===================================================================
---
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/lock/LockTest.java 2007-08-10
05:35:01 UTC (rev 12914)
+++
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/lock/LockTest.java 2007-08-10
13:35:22 UTC (rev 12915)
@@ -55,11 +55,33 @@
em.remove( lock );
em.getTransaction().commit();
}
+ em.close();
}
+ public void testLockWriteOnUnversioned() throws Exception {
+ UnversionedLock lock = new UnversionedLock();
+ lock.setName( "second" );
+ EntityManager em = factory.createEntityManager();
+ em.getTransaction().begin();
+ em.persist( lock );
+ em.getTransaction().commit();
+
+ em.getTransaction().begin();
+ lock = em.getReference( UnversionedLock.class, lock.getId() );
+ em.lock( lock, LockModeType.READ );
+ em.getTransaction().commit();
+
+ em.getTransaction().begin();
+ lock = em.getReference( UnversionedLock.class, lock.getId() );
+ em.remove( lock );
+ em.getTransaction().commit();
+ em.close();
+ }
+
public Class[] getAnnotatedClasses() {
return new Class[]{
- Lock.class
+ Lock.class,
+ UnversionedLock.class
};
}
}
Added:
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/lock/UnversionedLock.java
===================================================================
---
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/lock/UnversionedLock.java
(rev 0)
+++
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/lock/UnversionedLock.java 2007-08-10
13:35:22 UTC (rev 12915)
@@ -0,0 +1,34 @@
+//$Id: $
+package org.hibernate.ejb.test.lock;
+
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Entity;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class UnversionedLock {
+ @Id
+ @GeneratedValue
+ private Integer id;
+ private String name;
+
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Modified:
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java
===================================================================
---
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java 2007-08-10
05:35:01 UTC (rev 12914)
+++
trunk/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java 2007-08-10
13:35:22 UTC (rev 12915)
@@ -202,6 +202,25 @@
em.close();
}
+ public void testTransactionAndContains() throws Exception {
+ EntityManager em = factory.createEntityManager();
+ em.getTransaction().begin();
+ Book book = new Book();
+ book.name = "Java for Dummies";
+ em.persist( book );
+ em.getTransaction().commit();
+ em.close();
+ em = factory.createEntityManager();
+ em.getTransaction().begin();
+ List result = em.createQuery("select book from Book book where book.name =
:title").
+ setParameter( "title", book.name ).getResultList();
+ assertEquals( "EntityManager.commit() should trigger a flush()", 1,
result.size() );
+ assertTrue( em.contains( result.get( 0 ) ) );
+ em.getTransaction().commit();
+ assertTrue( em.contains( result.get( 0 ) ) );
+ em.close();
+ }
+
public void testRollbackOnlyOnPersistenceException() throws Exception {
Book book = new Book();
book.name = "Stolen keys";
Modified:
trunk/HibernateExt/entitymanager/src/test-resources/explicitpar/META-INF/persistence.xml
===================================================================
---
trunk/HibernateExt/entitymanager/src/test-resources/explicitpar/META-INF/persistence.xml 2007-08-10
05:35:01 UTC (rev 12914)
+++
trunk/HibernateExt/entitymanager/src/test-resources/explicitpar/META-INF/persistence.xml 2007-08-10
13:35:22 UTC (rev 12915)
@@ -34,7 +34,7 @@
value="read-write, RegionName"/>
<!-- event overriding -->
- <property name="hibernate.ejb.event.pre-insert"
value=""/>
+ <property name="hibernate.ejb.event.pre-insert"
value="org.hibernate.ejb.test.NoOpListener"/>
<!-- remove JACC and validator -->
<!-- alternatively to <class> and <property> declarations, you
can use a regular hibernate.cfg.xml file -->