openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r618821 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/event/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/ openjpa-persistence-jdbc/src/test/resources/META-INF/ openjpa-persistence/s...
Date Tue, 05 Feb 2008 23:26:39 GMT
Author: pcl
Date: Tue Feb  5 15:26:33 2008
New Revision: 618821

URL: http://svn.apache.org/viewvc?rev=618821&view=rev
Log:
OPENJPA-506. Fixed behaviors for global listeners to get TCK working on trunk again. It turns
out that global listeners and per-instance listeners are bound into the OpenJPA event framework
differently.

Added:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/PostDeleteListener.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/PostPersistListener.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/UpdateListener.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/EntityListenerEntity.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/GlobalListenerEntity.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/ListenerImpl.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/ListenerTestEntity.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestEntityListeners.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/listener-orm.xml
Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/LifecycleEventManager.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceListenerAdapter.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/LifecycleEventManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/LifecycleEventManager.java?rev=618821&r1=618820&r2=618821&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/LifecycleEventManager.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/LifecycleEventManager.java
Tue Feb  5 15:26:33 2008
@@ -488,6 +488,42 @@
                                 ((AttachListener) listener).afterAttach(ev);
                         }
                         break;
+
+                    case LifecycleEvent.AFTER_PERSIST_PERFORMED:
+                        if (responds || listener instanceof PostPersistListener)
+                        {
+                            if (mock)
+                                return Boolean.TRUE;
+                            if (ev == null)
+                                ev = new LifecycleEvent(source, rel, type);
+                            ((PostPersistListener) listener)
+                                .afterPersistPerformed(ev);
+                        }
+                        break;
+                    case LifecycleEvent.BEFORE_UPDATE:
+                    case LifecycleEvent.AFTER_UPDATE_PERFORMED:
+                        if (responds || listener instanceof UpdateListener) {
+                            if (mock)
+                                return Boolean.TRUE;
+                            if (ev == null)
+                                ev = new LifecycleEvent(source, rel, type);
+                            if (type == LifecycleEvent.BEFORE_UPDATE)
+                                ((UpdateListener) listener).beforeUpdate(ev);
+                            else
+                                ((UpdateListener) listener)
+                                    .afterUpdatePerformed(ev);
+                        }
+                        break;
+                    case LifecycleEvent.AFTER_DELETE_PERFORMED:
+                        if (responds || listener instanceof PostDeleteListener){
+                            if (mock)
+                                return Boolean.TRUE;
+                            if (ev == null)
+                                ev = new LifecycleEvent(source, rel, type);
+                            ((PostDeleteListener) listener)
+                                .afterDeletePerformed(ev);
+                        }
+                        break;
                     default:
                         throw new InvalidStateException(
                             _loc.get("unknown-lifecycle-event",

Added: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/PostDeleteListener.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/PostDeleteListener.java?rev=618821&view=auto
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/PostDeleteListener.java
(added)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/PostDeleteListener.java
Tue Feb  5 15:26:33 2008
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.event;
+
+/**
+ * @since 1.1.0
+ */
+public interface PostDeleteListener {
+    
+    /**
+     * Receives notifications before an update is performed. Differs from
+     * {@link DeleteListener#afterDelete(LifecycleEvent)} in that the latter
+     * is called after the delete operation, whereas this is called after the
+     * delete statements have been sent to the data store.
+     */
+    public void afterDeletePerformed(LifecycleEvent event);
+}

Added: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/PostPersistListener.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/PostPersistListener.java?rev=618821&view=auto
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/PostPersistListener.java
(added)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/PostPersistListener.java
Tue Feb  5 15:26:33 2008
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.event;
+
+/**
+ * @since 1.1.0
+ */
+public interface PostPersistListener {
+
+    /**
+     * Receives notifications after a persist operation has been written to the
+     * data store. Differs from {@link PersistListener#afterPersist} in that
+     * the latter is called at the end of the persist() operation itself, not
+     * after the flush.
+     */
+    public void afterPersistPerformed(LifecycleEvent event);
+}

Added: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/UpdateListener.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/UpdateListener.java?rev=618821&view=auto
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/UpdateListener.java
(added)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/UpdateListener.java
Tue Feb  5 15:26:33 2008
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.event;
+
+/**
+ * @since 1.1.0
+ */
+public interface UpdateListener {
+
+    /**
+     * Receives notifications before an update is performed. Differs from
+     * {@link StoreListener#beforeStore} in that the latter is called for
+     * updated and new records, whereas this is only invoked for updated
+     * records.
+     */
+    public void beforeUpdate(LifecycleEvent event);
+
+    /**
+     * Receives notifications before an update is performed. Differs from
+     * {@link StoreListener#afterStore} in that the latter is called for
+     * updated and new records, whereas this is only invoked for updated
+     * records, and that this is called after the record is actually flushed
+     * to the store.
+     */
+    public void afterUpdatePerformed(LifecycleEvent event);
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/EntityListenerEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/EntityListenerEntity.java?rev=618821&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/EntityListenerEntity.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/EntityListenerEntity.java
Tue Feb  5 15:26:33 2008
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.callbacks;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.EntityListeners;
+
+@Entity
+@EntityListeners(value = ListenerImpl.class)
+public class EntityListenerEntity implements ListenerTestEntity {
+    @Id @GeneratedValue
+    private long id;
+
+    private int value;
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public int getValue() {
+        return value;
+    }
+
+    public void setValue(int value) {
+        this.value = value;
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/GlobalListenerEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/GlobalListenerEntity.java?rev=618821&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/GlobalListenerEntity.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/GlobalListenerEntity.java
Tue Feb  5 15:26:33 2008
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.callbacks;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.EntityListeners;
+
+import org.apache.openjpa.persistence.callbacks.ListenerImpl;
+
+@Entity
+public class GlobalListenerEntity implements ListenerTestEntity {
+    @Id @GeneratedValue
+    private long id;
+
+    private int value;
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public int getValue() {
+        return value;
+    }
+
+    public void setValue(int value) {
+        this.value = value;
+    }
+}
\ No newline at end of file

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/ListenerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/ListenerImpl.java?rev=618821&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/ListenerImpl.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/ListenerImpl.java
Tue Feb  5 15:26:33 2008
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.callbacks;
+
+import javax.persistence.PrePersist;
+import javax.persistence.PostPersist;
+import javax.persistence.PostLoad;
+import javax.persistence.PreUpdate;
+import javax.persistence.PostUpdate;
+import javax.persistence.PreRemove;
+import javax.persistence.PostRemove;
+
+public class ListenerImpl {
+
+    static int prePersistCount;
+    static int postPersistCount;
+    static int preUpdateCount;
+    static int postUpdateCount;
+    static int preRemoveCount;
+    static int postRemoveCount;
+    static int postLoadCount;
+
+    @PrePersist
+    public void prePersist(Object o) {
+        prePersistCount++;
+    }
+
+    @PostPersist
+    public void postPersist(Object o) {
+        postPersistCount++;
+    }
+
+    @PostLoad
+    public void postLoad(Object o) {
+        postLoadCount++;
+    }
+
+    @PreUpdate
+    public void preUpdate(Object o) {
+        preUpdateCount++;
+    }
+
+    @PostUpdate
+    public void postUpdate(Object o) {
+        postUpdateCount++;
+    }
+
+    @PreRemove
+    public void preRemove(Object o) {
+        preRemoveCount++;
+    }
+
+    @PostRemove
+    public void postRemove(Object o) {
+        postRemoveCount++;
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/ListenerTestEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/ListenerTestEntity.java?rev=618821&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/ListenerTestEntity.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/ListenerTestEntity.java
Tue Feb  5 15:26:33 2008
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.callbacks;
+
+public interface ListenerTestEntity {
+
+    public long getId();
+
+    public int getValue();
+
+    public void setValue(int val);
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestEntityListeners.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestEntityListeners.java?rev=618821&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestEntityListeners.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestEntityListeners.java
Tue Feb  5 15:26:33 2008
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.callbacks;
+
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+public class TestEntityListeners extends SingleEMFTestCase {
+
+    public void setUp() {
+        setUp(CLEAR_TABLES);
+        ListenerImpl.prePersistCount = 0;
+        ListenerImpl.postPersistCount = 0;
+        ListenerImpl.preUpdateCount = 0;
+        ListenerImpl.postUpdateCount = 0;
+        ListenerImpl.preRemoveCount = 0;
+        ListenerImpl.postRemoveCount = 0;
+        ListenerImpl.postLoadCount = 0;
+    }
+
+    @Override
+    protected String getPersistenceUnitName() {
+        return "listener-pu";
+    }
+
+    public void testEntityListeners() {
+        helper(true);
+    }
+
+    public void testGlobalListeners() {
+        helper(false);
+    }
+
+    public void helper(boolean entityListeners) {
+        OpenJPAEntityManager em = emf.createEntityManager();
+        try {
+            em.getTransaction().begin();
+            ListenerTestEntity o;
+            if (entityListeners)
+                o = new EntityListenerEntity();
+            else
+                o = new GlobalListenerEntity();
+            em.persist(o);
+
+            assertStatus(1, 0, 0, 0, 0, 0, 0);
+
+            em.getTransaction().commit();
+            long id = o.getId();
+            em.close();
+
+            assertStatus(1, 1, 0, 0, 0, 0, 0);
+
+            em = emf.createEntityManager();
+            em.getTransaction().begin();
+            if (entityListeners)
+                o = em.find(EntityListenerEntity.class, id);
+            else
+                o = em.find(GlobalListenerEntity.class, id);
+
+            assertNotNull(o);
+            assertStatus(1, 1, 0, 0, 0, 0, 1);
+
+            o.setValue(o.getValue() + 1);
+
+            em.flush();
+            assertStatus(1, 1, 1, 1, 0, 0, 1);
+
+            em.remove(o);
+            assertStatus(1, 1, 1, 1, 1, 0, 1);
+
+            em.getTransaction().commit();
+
+            assertStatus(1, 1, 1, 1, 1, 1, 1);
+
+            em.close();
+        } finally {
+            if (em != null && em.getTransaction().isActive())
+                em.getTransaction().rollback();
+            if (em != null && em.isOpen())
+                em.close();
+        }
+    }
+
+    private void assertStatus(
+        int prePersist, int postPersist,
+        int preUpdate, int postUpdate,
+        int preRemove, int postRemove,
+        int postLoad) {
+        assertEquals(prePersist, ListenerImpl.prePersistCount);
+        assertEquals(postPersist, ListenerImpl.postPersistCount);
+        assertEquals(preUpdate, ListenerImpl.preUpdateCount);
+        assertEquals(postUpdate, ListenerImpl.postUpdateCount);
+        assertEquals(preRemove, ListenerImpl.preRemoveCount);
+        assertEquals(postRemove, ListenerImpl.postRemoveCount);
+        assertEquals(postLoad, ListenerImpl.postLoadCount);
+    }
+
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/listener-orm.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/listener-orm.xml?rev=618821&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/listener-orm.xml (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/listener-orm.xml Tue
Feb  5 15:26:33 2008
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<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">
+    <package>org.apache.openjpa.persistence.callbacks</package>
+    <entity class="EntityListenerEntity">
+        <exclude-default-listeners>true</exclude-default-listeners>
+    </entity>
+    <persistence-unit-metadata>
+        <persistence-unit-defaults>
+            <entity-listeners>
+                <entity-listener class="ListenerImpl">
+                </entity-listener>
+            </entity-listeners>
+        </persistence-unit-defaults>
+    </persistence-unit-metadata>
+</entity-mappings>
\ No newline at end of file

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml?rev=618821&r1=618820&r2=618821&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml Tue
Feb  5 15:26:33 2008
@@ -79,4 +79,14 @@
 
     <persistence-unit name="empty-pu">
     </persistence-unit>
+
+    <persistence-unit name="listener-pu">
+        <mapping-file>META-INF/listener-orm.xml</mapping-file>
+        <class>org.apache.openjpa.persistence.callbacks.EntityListenerEntity</class>
+        <class>org.apache.openjpa.persistence.callbacks.GlobalListenerEntity</class>
+        <properties>
+            <property name="openjpa.jdbc.SynchronizeMappings"
+                  value="buildSchema(ForeignKeys=true)"/>
+        </properties>
+    </persistence-unit>
 </persistence>

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceListenerAdapter.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceListenerAdapter.java?rev=618821&r1=618820&r2=618821&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceListenerAdapter.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceListenerAdapter.java
Tue Feb  5 15:26:33 2008
@@ -27,13 +27,16 @@
 import org.apache.openjpa.event.LifecycleEventManager;
 import org.apache.openjpa.event.LoadListener;
 import org.apache.openjpa.event.PersistListener;
-import org.apache.openjpa.event.StoreListener;
+import org.apache.openjpa.event.PostPersistListener;
+import org.apache.openjpa.event.UpdateListener;
+import org.apache.openjpa.event.PostDeleteListener;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.util.CallbackException;
 
 class PersistenceListenerAdapter
     implements LifecycleEventManager.ListenerAdapter, PersistListener,
-    LoadListener, StoreListener, DeleteListener {
+    PostPersistListener, LoadListener, UpdateListener, DeleteListener,
+    PostDeleteListener {
 
     private static final Localizer _loc = Localizer.forPackage
         (PersistenceListenerAdapter.class);
@@ -83,6 +86,10 @@
     }
 
     public void afterPersist(LifecycleEvent event) {
+        throw new UnsupportedOperationException();
+    }
+
+    public void afterPersistPerformed(LifecycleEvent event) {
         makeCallback(event);
     }
 
@@ -94,11 +101,11 @@
         makeCallback(event);
     }
 
-    public void beforeStore(LifecycleEvent event) {
+    public void beforeUpdate(LifecycleEvent event) {
         makeCallback(event);
     }
 
-    public void afterStore(LifecycleEvent event) {
+    public void afterUpdatePerformed(LifecycleEvent event) {
         makeCallback(event);
     }
 
@@ -107,6 +114,10 @@
     }
 
     public void afterDelete(LifecycleEvent event) {
+        throw new UnsupportedOperationException();
+    }
+
+    public void afterDeletePerformed(LifecycleEvent event) {
         makeCallback(event);
     }
 }



Mime
View raw message