openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwsut...@apache.org
Subject svn commit: r1361371 - in /openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test: java/org/apache/openjpa/persistence/callbacks/ resources/META-INF/
Date Fri, 13 Jul 2012 20:11:26 GMT
Author: kwsutter
Date: Fri Jul 13 20:11:25 2012
New Revision: 1361371

URL: http://svn.apache.org/viewvc?rev=1361371&view=rev
Log:
OPENJPA-2230.  Set the _activated flag when processing EventListeners in super classes.

Added:
    openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/EntityListenerMappedSuperClass.java
    openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/MSCListenerEntity.java
    openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestMSCEntityListeners.java
Modified:
    openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/GlobalListenerEntity.java
    openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/EntityListenerMappedSuperClass.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/EntityListenerMappedSuperClass.java?rev=1361371&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/EntityListenerMappedSuperClass.java
(added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/EntityListenerMappedSuperClass.java
Fri Jul 13 20:11:25 2012
@@ -0,0 +1,29 @@
+/*
+ * 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.EntityListeners;
+import javax.persistence.MappedSuperclass;
+
+@MappedSuperclass
+@EntityListeners({ListenerImpl.class})
+public abstract class EntityListenerMappedSuperClass {
+
+}

Modified: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/GlobalListenerEntity.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/GlobalListenerEntity.java?rev=1361371&r1=1361370&r2=1361371&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/GlobalListenerEntity.java
(original)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/GlobalListenerEntity.java
Fri Jul 13 20:11:25 2012
@@ -21,9 +21,6 @@ package org.apache.openjpa.persistence.c
 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 {

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/MSCListenerEntity.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/MSCListenerEntity.java?rev=1361371&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/MSCListenerEntity.java
(added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/MSCListenerEntity.java
Fri Jul 13 20:11:25 2012
@@ -0,0 +1,47 @@
+/*
+ * 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;
+
+@Entity
+public class MSCListenerEntity extends EntityListenerMappedSuperClass 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/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestMSCEntityListeners.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestMSCEntityListeners.java?rev=1361371&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestMSCEntityListeners.java
(added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestMSCEntityListeners.java
Fri Jul 13 20:11:25 2012
@@ -0,0 +1,119 @@
+/*
+ * 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;
+
+/*
+ * Separate testcase from TestEntityListeners to avoid the declaration of
+ * a System level event listener in the orm.xml file...
+ */
+public class TestMSCEntityListeners extends SingleEMFTestCase {
+
+    private static final int MSC_LISTENER_ENTITY = 4;
+    
+    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 "msclistener-pu";
+    }
+
+    public void testMSCEntityListeners() {
+        helper(MSC_LISTENER_ENTITY);
+    }
+
+    public void helper(int entityListeners) {
+        OpenJPAEntityManager em = emf.createEntityManager();
+        try {
+            em.getTransaction().begin();
+            ListenerTestEntity o = null;
+            switch (entityListeners) {
+            case MSC_LISTENER_ENTITY:
+                o = new MSCListenerEntity();
+                break;
+                
+            }
+            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();
+            switch (entityListeners) {
+            case MSC_LISTENER_ENTITY:
+                o = em.find(MSCListenerEntity.class, id);
+                break;
+                
+            }
+            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);
+    }
+
+}

Modified: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml?rev=1361371&r1=1361370&r2=1361371&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
(original)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
Fri Jul 13 20:11:25 2012
@@ -111,6 +111,15 @@
         </properties>
     </persistence-unit>
     
+    <persistence-unit name="msclistener-pu">
+        <class>org.apache.openjpa.persistence.callbacks.MSCListenerEntity</class>
+        <class>org.apache.openjpa.persistence.callbacks.EntityListenerMappedSuperClass</class>
+        <properties>
+            <property name="openjpa.jdbc.SynchronizeMappings"
+                  value="buildSchema(ForeignKeys=true)"/>
+        </properties>
+    </persistence-unit>
+    
     <persistence-unit name="test-unique-constraint">
         <mapping-file>org/apache/openjpa/persistence/jdbc/unique/orm.xml</mapping-file>
         <class>org.apache.openjpa.persistence.jdbc.unique.UniqueA</class>



Mime
View raw message