|
From: <hib...@li...> - 2006-05-03 23:14:17
|
Author: epbernard
Date: 2006-05-03 19:14:10 -0400 (Wed, 03 May 2006)
New Revision: 9864
Added:
trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/defaultpar/IncrementListener.java
trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/defaultpar/Money.java
trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/defaultpar/OtherIncrementListener.java
Modified:
trunk/HibernateExt/ejb/build.xml
trunk/HibernateExt/ejb/doc/reference/en/modules/configuration.xml
trunk/HibernateExt/ejb/doc/reference/en/modules/listeners.xml
trunk/HibernateExt/ejb/lib/hibernate-annotations.jar
trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java
trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/EventListenerConfigurator.java
trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/event/CallbackResolver.java
trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/event/EntityCallbackHandler.java
trunk/HibernateExt/ejb/src/test-resources/defaultpar/META-INF/orm.xml
trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/PackagedEntityManagerTest.java
trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/callbacks/CallbacksTest.java
trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/defaultpar/Mouse.java
trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/packaging/JarVisitorTest.java
Log:
EJB-165 entity listeners and default entity listeners
Modified: trunk/HibernateExt/ejb/build.xml
===================================================================
--- trunk/HibernateExt/ejb/build.xml 2006-05-03 23:13:22 UTC (rev 9863)
+++ trunk/HibernateExt/ejb/build.xml 2006-05-03 23:14:10 UTC (rev 9864)
@@ -16,7 +16,7 @@
<!-- Name of project and version, used to create filenames -->
<property name="Name" value="Hibernate EntityManager"/>
<property name="name" value="hibernate-entitymanager"/>
- <property name="version" value="3.1.0.Beta8"/>
+ <property name="version" value="3.1.0.CR1"/>
<property name="javadoc.packagenames" value="org.hibernate.ejb.*"/>
<property name="jdbc.dir" value="jdbc"/>
<property name="copy.test" value="true"/>
Modified: trunk/HibernateExt/ejb/doc/reference/en/modules/configuration.xml
===================================================================
--- trunk/HibernateExt/ejb/doc/reference/en/modules/configuration.xml 2006-05-03 23:13:22 UTC (rev 9863)
+++ trunk/HibernateExt/ejb/doc/reference/en/modules/configuration.xml 2006-05-03 23:14:10 UTC (rev 9864)
@@ -85,7 +85,8 @@
<listitem>
<para>(attribute) Transaction type used. Either JTA or
- RESOURCE_LOCAL (default JTA).</para>
+ RESOURCE_LOCAL (default to JTA in a JavaEE environment and to
+ RESOURCE_LOCAL in a JavaSE environment).</para>
</listitem>
</varlistentry>
@@ -359,11 +360,12 @@
<row>
<entry>hibernate.ejb.discard_pc_on_close</entry>
- <entry>If true, the persistence context will be discarded (think clear()
- when the method is called. Otherwise the persistence context will stay alive
- till the transaction completion: all objects will remain managed, and any
- change will be sy,chronized with the database (default to false,
- ie wait the transaction completion)</entry>
+ <entry>If true, the persistence context will be discarded (think
+ clear() when the method is called. Otherwise the persistence
+ context will stay alive till the transaction completion: all
+ objects will remain managed, and any change will be sy,chronized
+ with the database (default to false, ie wait the transaction
+ completion)</entry>
</row>
</tbody>
</tgroup>
Modified: trunk/HibernateExt/ejb/doc/reference/en/modules/listeners.xml
===================================================================
--- trunk/HibernateExt/ejb/doc/reference/en/modules/listeners.xml 2006-05-03 23:13:22 UTC (rev 9863)
+++ trunk/HibernateExt/ejb/doc/reference/en/modules/listeners.xml 2006-05-03 23:14:10 UTC (rev 9864)
@@ -188,4 +188,52 @@
<literal>@ExcludeSuperclassListeners</literal>, all superclasses
<literal>@EntityListeners</literal> will then be ignored.</para>
</section>
+
+ <section>
+ <title>XML definition</title>
+
+ <para>The EJB3 specification allows annotation overriding through EJB3
+ deployment descriptor. There is also an additional feature that can be
+ useful: default event listeners.</para>
+
+ <programlisting><?xml version="1.0" encoding="UTF-8"?>
+
+<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"
+ version="1.0"
+ >
+ <persistence-unit-metadata>
+ <persistence-unit-defaults>
+ <entity-listeners>
+ <entity-listener class="org.hibernate.ejb.test.pack.defaultpar.IncrementListener">
+ <pre-persist method-name="increment"/>
+ </entity-listener>
+ </entity-listeners>
+ </persistence-unit-defaults>
+ </persistence-unit-metadata>
+ <package>org.hibernate.ejb.test.pack.defaultpar</package>
+ <entity class="ApplicationServer">
+ <entity-listeners>
+ <entity-listener class="OtherIncrementListener">
+ <pre-persist method-name="increment"/>
+ </entity-listener>
+ </entity-listeners>
+
+
+ <pre-persist method-name="calculate"/>
+ </entity>
+</entity-mappings></programlisting>
+
+ <para>You can override entity listeners on a given entity. An entity
+ listener correspond to a given class and one or several event fire a given
+ method call. You can also define event on the entity itself to describe
+ the callbacks.</para>
+
+ <para>Last but not least, you can define some default entity listeners
+ that will apply first on the entity listener stack of all the mapped
+ entities of a given persistence unit. If you don't want an entity to
+ inherit the default listeners, you can use @ExcludeDefaultListeners (or
+ <exclude-default-listeners/>).</para>
+ </section>
</chapter>
\ No newline at end of file
Modified: trunk/HibernateExt/ejb/lib/hibernate-annotations.jar
===================================================================
(Binary files differ)
Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java
===================================================================
--- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java 2006-05-03 23:13:22 UTC (rev 9863)
+++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java 2006-05-03 23:14:10 UTC (rev 9864)
@@ -655,7 +655,6 @@
//initialize listeners
listenerConfigurator.setProperties( preparedProperties );
- listenerConfigurator.setValidator( true );
listenerConfigurator.configure();
//some spec compliance checking
Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/EventListenerConfigurator.java
===================================================================
--- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/EventListenerConfigurator.java 2006-05-03 23:13:22 UTC (rev 9863)
+++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/EventListenerConfigurator.java 2006-05-03 23:14:10 UTC (rev 9864)
@@ -13,6 +13,7 @@
import java.util.StringTokenizer;
import org.hibernate.HibernateException;
+import org.hibernate.MappingException;
import org.hibernate.ejb.event.CallbackHandlerConsumer;
import org.hibernate.ejb.event.EJB3AutoFlushEventListener;
import org.hibernate.ejb.event.EJB3DeleteEventListener;
@@ -45,6 +46,7 @@
import org.hibernate.event.PreUpdateEventListener;
import org.hibernate.event.SaveOrUpdateEventListener;
import org.hibernate.mapping.PersistentClass;
+import org.hibernate.reflection.ReflectionManager;
import org.hibernate.secure.JACCPreDeleteEventListener;
import org.hibernate.secure.JACCPreInsertEventListener;
import org.hibernate.secure.JACCPreLoadEventListener;
@@ -58,11 +60,8 @@
public class EventListenerConfigurator {
private static final Object[] READER_METHOD_ARGS = new Object[0];
- private Properties properties;
private Ejb3Configuration configuration;
- private boolean isValidator;
private boolean isSecurity;
- private String jaccContextID;
public EventListenerConfigurator(Ejb3Configuration configuration) {
this.configuration = configuration;
@@ -127,18 +126,10 @@
);
}
- public void setValidator(boolean validator) {
- isValidator = validator;
- }
-
public void setProperties(Properties properties) {
- this.properties = properties;
if ( properties.containsKey( HibernatePersistence.JACC_ENABLED ) ) {
isSecurity = true;
}
- if ( properties.containsKey( HibernatePersistence.JACC_CONTEXT_ID ) ) {
- jaccContextID = properties.getProperty( HibernatePersistence.JACC_CONTEXT_ID );
- }
//override events if needed
Enumeration<?> enumeration = properties.propertyNames();
while ( enumeration.hasMoreElements() ) {
@@ -162,9 +153,18 @@
EntityCallbackHandler callbackHandler = new EntityCallbackHandler();
configuration.buildMappings(); //needed to get all the classes
Iterator classes = configuration.getClassMappings();
+ ReflectionManager reflectionManager = configuration.getHibernateConfiguration().getReflectionManager();
while ( classes.hasNext() ) {
PersistentClass clazz = (PersistentClass) classes.next();
- callbackHandler.add( clazz.getMappedClass() );
+ if ( clazz.getClassName() != null ) {
+ //we can have non java class persisted by hibernate
+ try {
+ callbackHandler.add( reflectionManager.classForName( clazz.getClassName(), this.getClass() ), reflectionManager );
+ }
+ catch (ClassNotFoundException e) {
+ throw new MappingException("entity class not found: " + clazz.getNodeName(), e);
+ }
+ }
}
EventListeners listenerConfig = configuration.getEventListeners();
Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/event/CallbackResolver.java
===================================================================
--- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/event/CallbackResolver.java 2006-05-03 23:13:22 UTC (rev 9863)
+++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/event/CallbackResolver.java 2006-05-03 23:14:10 UTC (rev 9864)
@@ -17,7 +17,14 @@
import javax.persistence.ExcludeSuperclassListeners;
import javax.persistence.MappedSuperclass;
import javax.persistence.PersistenceException;
+import javax.persistence.ExcludeDefaultListeners;
+import org.hibernate.reflection.XClass;
+import org.hibernate.reflection.XMethod;
+import org.hibernate.reflection.ReflectionManager;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
/**
* @author <a href="mailto:kab...@jb...">Kabir Khan</a>
* @version $Revision$
@@ -35,101 +42,38 @@
}
}
}
+ private static Log log = LogFactory.getLog( CallbackResolver.class );
private CallbackResolver() {
}
- public static Callback resolveCallback(Class beanClass, Class annotation, List<Class> listeners) throws Exception {
- Callback callback = null;
- Method[] methods = beanClass.getDeclaredMethods();
-
- for ( int i = 0; i < methods.length ; i++ ) {
- if ( methods[i].getAnnotation( annotation ) != null ) {
- if ( callback == null ) {
- callback = new BeanCallback( methods[i] );
- Class returnType = methods[i].getReturnType();
- Class[] args = methods[i].getParameterTypes();
- if ( returnType != Void.TYPE || args.length != 0 ) {
- throw new RuntimeException(
- "Callback methods annotated on the bean class must return void and take no arguments: " + annotation
- .getName() + " - " + methods[i]
- );
- }
- if ( ! methods[i].isAccessible() ) {
- methods[i].setAccessible( true );
- }
- }
- else {
- throw new RuntimeException(
- "You can only annotate one callback method with "
- + annotation.getName() + " in bean class: " + beanClass.getName()
- );
- }
- }
- }
-
- for ( Class listener : listeners ) {
- if ( listener != null ) {
- try {
- methods = listener.getDeclaredMethods();
- for ( int i = 0; i < methods.length ; i++ ) {
- if ( methods[i].getAnnotation( annotation ) != null ) {
- if ( callback == null ) {
- callback = new ListenerCallback( methods[i], listener.newInstance() );
- Class returnType = methods[i].getReturnType();
- Class[] args = methods[i].getParameterTypes();
- if ( returnType != Void.TYPE || args.length != 1 ) {
- throw new RuntimeException(
- "Callback methods annotated in a listener bean class must return void and take one argument: " + annotation
- .getName() + " - " + methods[i]
- );
- }
- if ( ! methods[i].isAccessible() ) {
- methods[i].setAccessible( true );
- }
- }
- else {
- throw new RuntimeException(
- "You can only annotate one callback method with "
- + annotation.getName() + " in bean class: " + beanClass.getName() + " and callback listener: "
- + listener.getName()
- );
- }
- }
- }
- }
- catch (Exception e) {
- throw new RuntimeException( e.getCause() );
- }
- }
- }
- return callback;
- }
-
- public static Callback[] resolveCallback(Class beanClass, Class annotation) {
+ public static Callback[] resolveCallback(XClass beanClass, Class annotation, ReflectionManager reflectionManager) {
List<Callback> callbacks = new ArrayList<Callback>();
List<Class> orderedListeners = new ArrayList<Class>();
- Class currentClazz = beanClass;
+ XClass currentClazz = beanClass;
boolean stopListeners = false;
- //TODO add exclude default listeners
+ boolean stopDefaultListeners = false;
do {
//FIXME exclude overriden callback methods
Callback callback = null;
- Method[] methods = currentClazz.getDeclaredMethods();
- for ( int i = 0; i < methods.length ; i++ ) {
- if ( methods[i].getAnnotation( annotation ) != null ) {
+ List<XMethod> methods = currentClazz.getDeclaredMethods();
+ final int size = methods.size();
+ for ( int i = 0; i < size ; i++ ) {
+ final XMethod xMethod = methods.get( i );
+ if ( xMethod.isAnnotationPresent( annotation ) ) {
if ( callback == null ) {
- callback = new BeanCallback( methods[i] );
- Class returnType = methods[i].getReturnType();
- Class[] args = methods[i].getParameterTypes();
+ Method method = reflectionManager.toMethod( xMethod );
+ callback = new BeanCallback( method );
+ Class returnType = method.getReturnType();
+ Class[] args = method.getParameterTypes();
if ( returnType != Void.TYPE || args.length != 0 ) {
throw new RuntimeException(
"Callback methods annotated on the bean class must return void and take no arguments: " + annotation
- .getName() + " - " + methods[i]
+ .getName() + " - " + xMethod
);
}
- if ( ! methods[i].isAccessible() ) {
- methods[i].setAccessible( true );
+ if ( ! method.isAccessible() ) {
+ method.setAccessible( true );
}
callbacks.add( 0, callback ); //superclass first
}
@@ -144,6 +88,7 @@
if ( !stopListeners ) {
getListeners( currentClazz, orderedListeners );
stopListeners = currentClazz.isAnnotationPresent( ExcludeSuperclassListeners.class );
+ stopDefaultListeners = currentClazz.isAnnotationPresent( ExcludeDefaultListeners.class );
}
do {
@@ -156,15 +101,34 @@
}
while ( currentClazz != null );
+ //handle default listeners
+ log.error("default listeners for: " + beanClass.getName() + annotation );
+ if (! stopDefaultListeners) {
+ log.error("notstopped" );
+ List<Class> defaultListeners = (List<Class>) reflectionManager.getDefaults().get( EntityListeners.class );
+
+ if (defaultListeners != null) {
+ int defaultListenerSize = defaultListeners.size();
+ log.error("defaultlistenerssize" + defaultListenerSize );
+ for (int i = defaultListenerSize - 1 ; i >= 0 ; i--) {
+ orderedListeners.add( defaultListeners.get(i) );
+ }
+ }
+ }
+
for ( Class listener : orderedListeners ) {
Callback callback = null;
if ( listener != null ) {
- Method[] methods = listener.getDeclaredMethods();
- for ( int i = 0; i < methods.length ; i++ ) {
- if ( methods[i].getAnnotation( annotation ) != null ) {
+ XClass xListener = reflectionManager.toXClass( listener );
+ List<XMethod> methods = xListener.getDeclaredMethods();
+ final int size = methods.size();
+ for ( int i = 0; i < size ; i++ ) {
+ final XMethod xMethod = methods.get(i);
+ final Method method = reflectionManager.toMethod( xMethod );
+ if ( xMethod.isAnnotationPresent( annotation ) ) {
if ( callback == null ) {
try {
- callback = new ListenerCallback( methods[i], listener.newInstance() );
+ callback = new ListenerCallback( method, listener.newInstance() );
}
catch (IllegalAccessException e) {
throw new PersistenceException(
@@ -178,16 +142,16 @@
+ " as a listener of beanClass", e
);
}
- Class returnType = methods[i].getReturnType();
- Class[] args = methods[i].getParameterTypes();
+ Class returnType = method.getReturnType();
+ Class[] args = method.getParameterTypes();
if ( returnType != Void.TYPE || args.length != 1 ) {
throw new PersistenceException(
"Callback methods annotated in a listener bean class must return void and take one argument: " + annotation
- .getName() + " - " + methods[i]
+ .getName() + " - " + method
);
}
- if ( ! methods[i].isAccessible() ) {
- methods[i].setAccessible( true );
+ if ( ! method.isAccessible() ) {
+ method.setAccessible( true );
}
callbacks.add( 0, callback ); // listeners first
}
@@ -205,7 +169,7 @@
return callbacks.toArray( new Callback[ callbacks.size() ] );
}
- private static void getListeners(Class currentClazz, List<Class> orderedListeners) {
+ private static void getListeners(XClass currentClazz, List<Class> orderedListeners) {
EntityListeners entityListeners = (EntityListeners) currentClazz.getAnnotation( EntityListeners.class );
if ( entityListeners != null ) {
Class[] classes = entityListeners.value();
Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/event/EntityCallbackHandler.java
===================================================================
--- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/event/EntityCallbackHandler.java 2006-05-03 23:13:22 UTC (rev 9863)
+++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/event/EntityCallbackHandler.java 2006-05-03 23:14:10 UTC (rev 9864)
@@ -16,6 +16,9 @@
import javax.persistence.PreRemove;
import javax.persistence.PreUpdate;
+import org.hibernate.reflection.XClass;
+import org.hibernate.reflection.ReflectionManager;
+
/**
* Keep track of all lifecycle callbacks and listeners for a given persistence unit
*
@@ -30,14 +33,14 @@
private HashMap<Class, Callback[]> postUpdates = new HashMap<Class, Callback[]>();
private HashMap<Class, Callback[]> postLoads = new HashMap<Class, Callback[]>();
- public void add(Class entity) {
- addCallback( entity, preCreates, PrePersist.class );
- addCallback( entity, postCreates, PostPersist.class );
- addCallback( entity, preRemoves, PreRemove.class );
- addCallback( entity, postRemoves, PostRemove.class );
- addCallback( entity, preUpdates, PreUpdate.class );
- addCallback( entity, postUpdates, PostUpdate.class );
- addCallback( entity, postLoads, PostLoad.class );
+ public void add(XClass entity, ReflectionManager reflectionManager) {
+ addCallback( entity, preCreates, PrePersist.class, reflectionManager );
+ addCallback( entity, postCreates, PostPersist.class, reflectionManager );
+ addCallback( entity, preRemoves, PreRemove.class, reflectionManager );
+ addCallback( entity, postRemoves, PostRemove.class, reflectionManager );
+ addCallback( entity, preUpdates, PreUpdate.class, reflectionManager );
+ addCallback( entity, postUpdates, PostUpdate.class, reflectionManager );
+ addCallback( entity, postLoads, PostLoad.class, reflectionManager );
}
public boolean preCreate(Object bean) {
@@ -82,9 +85,11 @@
}
- private void addCallback(Class entity, HashMap<Class, Callback[]> map, Class annotation) {
+ private void addCallback(
+ XClass entity, HashMap<Class, Callback[]> map, Class annotation, ReflectionManager reflectionManager
+ ) {
Callback[] callbacks = null;
- callbacks = CallbackResolver.resolveCallback( entity, annotation );
- map.put( entity, callbacks );
+ callbacks = CallbackResolver.resolveCallback( entity, annotation, reflectionManager );
+ map.put( reflectionManager.toClass( entity ), callbacks );
}
}
Modified: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/PackagedEntityManagerTest.java
===================================================================
--- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/PackagedEntityManagerTest.java 2006-05-03 23:13:22 UTC (rev 9863)
+++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/PackagedEntityManagerTest.java 2006-05-03 23:14:10 UTC (rev 9864)
@@ -13,6 +13,9 @@
import org.hibernate.ejb.test.pack.defaultpar.Lighter;
import org.hibernate.ejb.test.pack.defaultpar.Mouse;
import org.hibernate.ejb.test.pack.defaultpar.Version;
+import org.hibernate.ejb.test.pack.defaultpar.IncrementListener;
+import org.hibernate.ejb.test.pack.defaultpar.OtherIncrementListener;
+import org.hibernate.ejb.test.pack.defaultpar.Money;
import org.hibernate.ejb.test.pack.excludehbmpar.Caipirinha;
import org.hibernate.ejb.test.pack.explodedpar.Carpet;
import org.hibernate.ejb.test.pack.explodedpar.Elephant;
@@ -65,6 +68,42 @@
emf.close();
}
+ public void testListenersDefaultPar() throws Exception {
+ IncrementListener.reset();
+ OtherIncrementListener.reset();
+ EntityManagerFactory emf = Persistence.createEntityManagerFactory( "defaultpar", new HashMap() );
+ EntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
+ ApplicationServer as = new ApplicationServer();
+ as.setName( "JBoss AS" );
+ Version v = new Version();
+ v.setMajor( 4 );
+ v.setMinor( 0 );
+ v.setMicro( 3 );
+ as.setVersion( v );
+ em.persist( as );
+ em.flush();
+ assertEquals( "Failure in default listeners", 1, IncrementListener.getIncrement() );
+ assertEquals( "Failuer in XML overriden listeners", 1, OtherIncrementListener.getIncrement() );
+
+ Mouse mouse = new Mouse();
+ mouse.setName( "mickey" );
+ em.persist( mouse );
+ em.flush();
+ assertEquals( "Failure in @ExcludeDefaultListeners", 1, IncrementListener.getIncrement() );
+ assertEquals( 1, OtherIncrementListener.getIncrement() );
+
+ Money money = new Money();
+ em.persist( money );
+ em.flush();
+ assertEquals( "Failure in @ExcludeDefaultListeners", 2, IncrementListener.getIncrement() );
+ assertEquals( 1, OtherIncrementListener.getIncrement() );
+
+ em.getTransaction().rollback();
+ em.close();
+ emf.close();
+ }
+
public void testExplodedPar() throws Exception {
EntityManagerFactory emf = Persistence.createEntityManagerFactory( "explodedpar", new HashMap() );
EntityManager em = emf.createEntityManager();
@@ -303,4 +342,4 @@
super( arg0 );
}
-}
+}
\ No newline at end of file
Modified: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/callbacks/CallbacksTest.java
===================================================================
--- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/callbacks/CallbacksTest.java 2006-05-03 23:13:22 UTC (rev 9863)
+++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/callbacks/CallbacksTest.java 2006-05-03 23:14:10 UTC (rev 9864)
@@ -78,7 +78,8 @@
assertNotNull( id );
}
- public void testListenerAnnotation() throws Exception {
+ //Not a test since the spec did not make the proper change on listeners
+ public void listenerAnnotation() throws Exception {
EntityManager em = factory.createEntityManager();
Translation tl = new Translation();
em.getTransaction().begin();
Added: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/defaultpar/IncrementListener.java
===================================================================
--- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/defaultpar/IncrementListener.java 2006-05-03 23:13:22 UTC (rev 9863)
+++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/defaultpar/IncrementListener.java 2006-05-03 23:14:10 UTC (rev 9864)
@@ -0,0 +1,24 @@
+//$Id: $
+package org.hibernate.ejb.test.pack.defaultpar;
+
+import javax.persistence.PrePersist;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class IncrementListener {
+ private static int increment;
+
+ public static int getIncrement() {
+ return increment;
+ }
+
+ public static void reset() {
+ increment = 0;
+ }
+
+ @PrePersist
+ public void increment(Object entity) {
+ increment++;
+ }
+}
Added: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/defaultpar/Money.java
===================================================================
--- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/defaultpar/Money.java 2006-05-03 23:13:22 UTC (rev 9863)
+++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/defaultpar/Money.java 2006-05-03 23:14:10 UTC (rev 9864)
@@ -0,0 +1,24 @@
+//$Id: $
+package org.hibernate.ejb.test.pack.defaultpar;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Money {
+ private Integer id;
+
+ @Id @GeneratedValue
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+}
Modified: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/defaultpar/Mouse.java
===================================================================
--- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/defaultpar/Mouse.java 2006-05-03 23:13:22 UTC (rev 9863)
+++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/defaultpar/Mouse.java 2006-05-03 23:14:10 UTC (rev 9864)
@@ -1,9 +1,12 @@
//$Id$
package org.hibernate.ejb.test.pack.defaultpar;
+import javax.persistence.ExcludeDefaultListeners;
+
/**
* @author Emmanuel Bernard
*/
+@ExcludeDefaultListeners
public class Mouse {
private Integer id;
private String name;
Added: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/defaultpar/OtherIncrementListener.java
===================================================================
--- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/defaultpar/OtherIncrementListener.java 2006-05-03 23:13:22 UTC (rev 9863)
+++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/defaultpar/OtherIncrementListener.java 2006-05-03 23:14:10 UTC (rev 9864)
@@ -0,0 +1,21 @@
+//$Id: $
+package org.hibernate.ejb.test.pack.defaultpar;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class OtherIncrementListener {
+ private static int increment;
+
+ public static int getIncrement() {
+ return OtherIncrementListener.increment;
+ }
+
+ public static void reset() {
+ increment = 0;
+ }
+
+ public void increment(Object entity) {
+ OtherIncrementListener.increment++;
+ }
+}
Modified: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/packaging/JarVisitorTest.java
===================================================================
--- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/packaging/JarVisitorTest.java 2006-05-03 23:13:22 UTC (rev 9863)
+++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/packaging/JarVisitorTest.java 2006-05-03 23:14:10 UTC (rev 9864)
@@ -50,7 +50,7 @@
JarVisitor jarVisitor = new InputStreamZippedJarVisitor( new URL( jarFileName ), filters );
assertEquals( "defaultpar", jarVisitor.getUnqualifiedJarName() );
Set entries = jarVisitor.getMatchingEntries()[1];
- assertEquals( 2, entries.size() );
+ assertEquals( 3, entries.size() );
JarVisitor.Entry entry = new JarVisitor.Entry( ApplicationServer.class.getName(), null );
assertTrue( entries.contains( entry ) );
entry = new JarVisitor.Entry( org.hibernate.ejb.test.pack.defaultpar.Version.class.getName(), null );
Modified: trunk/HibernateExt/ejb/src/test-resources/defaultpar/META-INF/orm.xml
===================================================================
--- trunk/HibernateExt/ejb/src/test-resources/defaultpar/META-INF/orm.xml 2006-05-03 23:13:22 UTC (rev 9863)
+++ trunk/HibernateExt/ejb/src/test-resources/defaultpar/META-INF/orm.xml 2006-05-03 23:14:10 UTC (rev 9864)
@@ -5,6 +5,15 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"
version="1.0"
>
+ <persistence-unit-metadata>
+ <persistence-unit-defaults>
+ <entity-listeners>
+ <entity-listener class="org.hibernate.ejb.test.pack.defaultpar.IncrementListener">
+ <pre-persist method-name="increment"/>
+ </entity-listener>
+ </entity-listeners>
+ </persistence-unit-defaults>
+ </persistence-unit-metadata>
<package>org.hibernate.ejb.test.pack.defaultpar</package>
<entity class="Lighter" access="FIELD" metadata-complete="true">
<attributes>
@@ -14,4 +23,11 @@
<basic name="power"></basic>
</attributes>
</entity>
+ <entity class="ApplicationServer">
+ <entity-listeners>
+ <entity-listener class="OtherIncrementListener">
+ <pre-persist method-name="increment"/>
+ </entity-listener>
+ </entity-listeners>
+ </entity>
</entity-mappings>
\ No newline at end of file
|