cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r504536 - in /cayenne/main/trunk/itests/jpa-chapter3/src: main/java/org/apache/cayenne/jpa/itest/ch3/entity/ main/resources/META-INF/ test/java/org/apache/cayenne/jpa/itest/ch3/ test/resources/
Date Wed, 07 Feb 2007 13:13:39 GMT
Author: aadamchik
Date: Wed Feb  7 05:13:38 2007
New Revision: 504536

URL: http://svn.apache.org/viewvc?view=rev&rev=504536
Log:
CAY-668: Link Cayenne callback API with JPA provider
(more itests)

Added:
    cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/EntityListener1.java
    cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/EntityListener2.java
    cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/EntityListenerState.java
    cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/ListenerEntity1.java
    cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/ListenerEntity2.java
Modified:
    cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/CallbackEntity.java
    cayenne/main/trunk/itests/jpa-chapter3/src/main/resources/META-INF/persistence.xml
    cayenne/main/trunk/itests/jpa-chapter3/src/test/java/org/apache/cayenne/jpa/itest/ch3/_3_5_1_LifecycleCallbackMethodsTest.java
    cayenne/main/trunk/itests/jpa-chapter3/src/test/resources/schema-hsqldb.sql

Modified: cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/CallbackEntity.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/CallbackEntity.java?view=diff&rev=504536&r1=504535&r2=504536
==============================================================================
--- cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/CallbackEntity.java
(original)
+++ cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/CallbackEntity.java
Wed Feb  7 05:13:38 2007
@@ -34,7 +34,6 @@
 
     @Id
     protected int id;
-    protected String property1;
 
     @Transient
     protected transient boolean prePersistCalled;
@@ -56,22 +55,6 @@
 
     @Transient
     protected transient boolean postLoadCalled;
-
-    public int idField() {
-        return id;
-    }
-
-    public void updateIdField(int id) {
-        this.id = id;
-    }
-
-    public String getProperty1() {
-        return property1;
-    }
-
-    public void setProperty1(String property1) {
-        this.property1 = property1;
-    }
 
     @PrePersist
     public void prePersistMethod() {

Added: cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/EntityListener1.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/EntityListener1.java?view=auto&rev=504536
==============================================================================
--- cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/EntityListener1.java
(added)
+++ cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/EntityListener1.java
Wed Feb  7 05:13:38 2007
@@ -0,0 +1,65 @@
+/*****************************************************************
+ *   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.cayenne.jpa.itest.ch3.entity;
+
+import javax.persistence.PostLoad;
+import javax.persistence.PostPersist;
+import javax.persistence.PostRemove;
+import javax.persistence.PostUpdate;
+import javax.persistence.PrePersist;
+import javax.persistence.PreRemove;
+import javax.persistence.PreUpdate;
+
+public class EntityListener1 {
+
+    @PrePersist
+    public void prePersistMethod(Object entity) {
+        EntityListenerState.addPrePersistListener(this);
+    }
+
+    @PostPersist
+    public void postPersistMethod(Object entity) {
+        EntityListenerState.addPostPersistListener(this);
+    }
+
+    @PreRemove
+    public void preRemoveMethod(Object entity) {
+        EntityListenerState.addPreRemoveListener(this);
+    }
+
+    @PostRemove
+    public void postRemoveMethod(Object entity) {
+        EntityListenerState.addPostRemoveListener(this);
+    }
+
+    @PreUpdate
+    public void preUpdateMethod(Object entity) {
+        EntityListenerState.addPreUpdateListener(this);
+    }
+
+    @PostUpdate
+    public void postUpdateMethod(Object entity) {
+        EntityListenerState.addPostUpdateListener(this);
+    }
+
+    @PostLoad
+    public void postLoadMethod(Object entity) {
+        EntityListenerState.addPostLoadListener(this);
+    }
+}

Added: cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/EntityListener2.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/EntityListener2.java?view=auto&rev=504536
==============================================================================
--- cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/EntityListener2.java
(added)
+++ cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/EntityListener2.java
Wed Feb  7 05:13:38 2007
@@ -0,0 +1,65 @@
+/*****************************************************************
+ *   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.cayenne.jpa.itest.ch3.entity;
+
+import javax.persistence.PostLoad;
+import javax.persistence.PostPersist;
+import javax.persistence.PostRemove;
+import javax.persistence.PostUpdate;
+import javax.persistence.PrePersist;
+import javax.persistence.PreRemove;
+import javax.persistence.PreUpdate;
+
+public class EntityListener2 {
+
+    @PrePersist
+    public void prePersistMethod(Object entity) {
+        EntityListenerState.addPrePersistListener(this);
+    }
+
+    @PostPersist
+    public void postPersistMethod(Object entity) {
+        EntityListenerState.addPostPersistListener(this);
+    }
+
+    @PreRemove
+    public void preRemoveMethod(Object entity) {
+        EntityListenerState.addPreRemoveListener(this);
+    }
+
+    @PostRemove
+    public void postRemoveMethod(Object entity) {
+        EntityListenerState.addPostRemoveListener(this);
+    }
+
+    @PreUpdate
+    public void preUpdateMethod(Object entity) {
+        EntityListenerState.addPreUpdateListener(this);
+    }
+
+    @PostUpdate
+    public void postUpdateMethod(Object entity) {
+        EntityListenerState.addPostUpdateListener(this);
+    }
+
+    @PostLoad
+    public void postLoadMethod(Object entity) {
+        EntityListenerState.addPostLoadListener(this);
+    }
+}

Added: cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/EntityListenerState.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/EntityListenerState.java?view=auto&rev=504536
==============================================================================
--- cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/EntityListenerState.java
(added)
+++ cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/EntityListenerState.java
Wed Feb  7 05:13:38 2007
@@ -0,0 +1,96 @@
+/*****************************************************************
+ *   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.cayenne.jpa.itest.ch3.entity;
+
+public class EntityListenerState {
+
+    public static String prePersistCalled;
+    public static String postPersistCalled;
+    public static String preRemoveCalled;
+    public static String postRemoveCalled;
+    public static String preUpdateCalled;
+    public static String postUpdateCalled;
+    public static String postLoadCalled;
+
+    public static void reset() {
+        prePersistCalled = "";
+        postPersistCalled = "";
+        preRemoveCalled = "";
+        postRemoveCalled = "";
+        preUpdateCalled = "";
+        postUpdateCalled = "";
+        postLoadCalled = "";
+    }
+
+    public static String getPostLoadCalled() {
+        return postLoadCalled;
+    }
+
+    public static String getPostPersistCalled() {
+        return postPersistCalled;
+    }
+
+    public static String getPostRemoveCalled() {
+        return postRemoveCalled;
+    }
+
+    public static String getPostUpdateCalled() {
+        return postUpdateCalled;
+    }
+
+    public static String getPrePersistCalled() {
+        return prePersistCalled;
+    }
+
+    public static String getPreRemoveCalled() {
+        return preRemoveCalled;
+    }
+
+    public static String getPreUpdateCalled() {
+        return preUpdateCalled;
+    }
+
+    public static void addPostLoadListener(Object listener) {
+        EntityListenerState.postLoadCalled += ":" + listener.getClass().getName();
+    }
+
+    public static void addPrePersistListener(Object listener) {
+        EntityListenerState.prePersistCalled += ":" + listener.getClass().getName();
+    }
+
+    public static void addPostPersistListener(Object listener) {
+        EntityListenerState.postPersistCalled += ":" + listener.getClass().getName();
+    }
+
+    public static void addPreRemoveListener(Object listener) {
+        EntityListenerState.preRemoveCalled += ":" + listener.getClass().getName();
+    }
+
+    public static void addPostRemoveListener(Object listener) {
+        EntityListenerState.postRemoveCalled += ":" + listener.getClass().getName();
+    }
+
+    public static void addPreUpdateListener(Object listener) {
+        EntityListenerState.preUpdateCalled += ":" + listener.getClass().getName();
+    }
+
+    public static void addPostUpdateListener(Object listener) {
+        EntityListenerState.postUpdateCalled += ":" + listener.getClass().getName();
+    }
+}

Added: cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/ListenerEntity1.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/ListenerEntity1.java?view=auto&rev=504536
==============================================================================
--- cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/ListenerEntity1.java
(added)
+++ cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/ListenerEntity1.java
Wed Feb  7 05:13:38 2007
@@ -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.cayenne.jpa.itest.ch3.entity;
+
+import javax.persistence.Entity;
+import javax.persistence.EntityListeners;
+import javax.persistence.Id;
+
+@Entity
+@EntityListeners( {
+        EntityListener1.class, EntityListener2.class
+})
+public class ListenerEntity1 {
+
+    @Id
+    protected int id;
+}

Added: cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/ListenerEntity2.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/ListenerEntity2.java?view=auto&rev=504536
==============================================================================
--- cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/ListenerEntity2.java
(added)
+++ cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/ListenerEntity2.java
Wed Feb  7 05:13:38 2007
@@ -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.cayenne.jpa.itest.ch3.entity;
+
+import javax.persistence.Entity;
+import javax.persistence.EntityListeners;
+import javax.persistence.Id;
+
+@Entity
+@EntityListeners( {
+        EntityListener2.class, EntityListener1.class
+})
+public class ListenerEntity2 {
+
+    @Id
+    protected int id;
+}

Modified: cayenne/main/trunk/itests/jpa-chapter3/src/main/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/jpa-chapter3/src/main/resources/META-INF/persistence.xml?view=diff&rev=504536&r1=504535&r2=504536
==============================================================================
--- cayenne/main/trunk/itests/jpa-chapter3/src/main/resources/META-INF/persistence.xml (original)
+++ cayenne/main/trunk/itests/jpa-chapter3/src/main/resources/META-INF/persistence.xml Wed
Feb  7 05:13:38 2007
@@ -24,5 +24,7 @@
 		<class>org.apache.cayenne.jpa.itest.ch3.entity.SimpleEntity</class>
 		<class>org.apache.cayenne.jpa.itest.ch3.entity.CallbackEntity</class>
 		<class>org.apache.cayenne.jpa.itest.ch3.entity.CallbackEntity2</class>
+		<class>org.apache.cayenne.jpa.itest.ch3.entity.ListenerEntity1</class>
+		<class>org.apache.cayenne.jpa.itest.ch3.entity.ListenerEntity2</class>
 	</persistence-unit>
 </persistence>

Modified: cayenne/main/trunk/itests/jpa-chapter3/src/test/java/org/apache/cayenne/jpa/itest/ch3/_3_5_1_LifecycleCallbackMethodsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/jpa-chapter3/src/test/java/org/apache/cayenne/jpa/itest/ch3/_3_5_1_LifecycleCallbackMethodsTest.java?view=diff&rev=504536&r1=504535&r2=504536
==============================================================================
--- cayenne/main/trunk/itests/jpa-chapter3/src/test/java/org/apache/cayenne/jpa/itest/ch3/_3_5_1_LifecycleCallbackMethodsTest.java
(original)
+++ cayenne/main/trunk/itests/jpa-chapter3/src/test/java/org/apache/cayenne/jpa/itest/ch3/_3_5_1_LifecycleCallbackMethodsTest.java
Wed Feb  7 05:13:38 2007
@@ -23,10 +23,17 @@
 import org.apache.cayenne.itest.jpa.EntityManagerCase;
 import org.apache.cayenne.jpa.itest.ch3.entity.CallbackEntity;
 import org.apache.cayenne.jpa.itest.ch3.entity.CallbackEntity2;
+import org.apache.cayenne.jpa.itest.ch3.entity.EntityListener1;
+import org.apache.cayenne.jpa.itest.ch3.entity.EntityListener2;
+import org.apache.cayenne.jpa.itest.ch3.entity.EntityListenerState;
+import org.apache.cayenne.jpa.itest.ch3.entity.ListenerEntity1;
+import org.apache.cayenne.jpa.itest.ch3.entity.ListenerEntity2;
 
 public class _3_5_1_LifecycleCallbackMethodsTest extends EntityManagerCase {
 
     public void testPrePersist() {
+
+        // regular entity
         CallbackEntity e = new CallbackEntity();
         assertFalse(e.isPrePersistCalled());
 
@@ -37,9 +44,32 @@
         em.persist(e);
         assertTrue(e.isPrePersistCalled());
 
+        // entity with same callback method handling multiple callbacks
         CallbackEntity2 e2 = new CallbackEntity2();
         assertFalse(e2.isMixedCallbackCalled());
         em.persist(e2);
         assertTrue(e2.isMixedCallbackCalled());
+
+        // external listeners
+        EntityListenerState.reset();
+        assertEquals("", EntityListenerState.getPrePersistCalled());
+        ListenerEntity1 e3 = new ListenerEntity1();
+        em.persist(e3);
+        assertEquals(":"
+                + EntityListener1.class.getName()
+                + ":"
+                + EntityListener2.class.getName(), EntityListenerState
+                .getPrePersistCalled());
+
+        EntityListenerState.reset();
+        assertEquals("", EntityListenerState.getPrePersistCalled());
+        ListenerEntity2 e4 = new ListenerEntity2();
+        em.persist(e4);
+        // here annotations must be called in a different order from e3.
+        assertEquals(":"
+                + EntityListener2.class.getName()
+                + ":"
+                + EntityListener1.class.getName(), EntityListenerState
+                .getPrePersistCalled());
     }
 }

Modified: cayenne/main/trunk/itests/jpa-chapter3/src/test/resources/schema-hsqldb.sql
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/jpa-chapter3/src/test/resources/schema-hsqldb.sql?view=diff&rev=504536&r1=504535&r2=504536
==============================================================================
--- cayenne/main/trunk/itests/jpa-chapter3/src/test/resources/schema-hsqldb.sql (original)
+++ cayenne/main/trunk/itests/jpa-chapter3/src/test/resources/schema-hsqldb.sql Wed Feb  7
05:13:38 2007
@@ -2,7 +2,11 @@
 insert into AUTO_PK_SUPPORT (TABLE_NAME, NEXT_ID) VALUES ('SimpleEntity', 1);
 insert into AUTO_PK_SUPPORT (TABLE_NAME, NEXT_ID) VALUES ('CallbackEntity', 1);
 insert into AUTO_PK_SUPPORT (TABLE_NAME, NEXT_ID) VALUES ('CallbackEntity2', 1);
+insert into AUTO_PK_SUPPORT (TABLE_NAME, NEXT_ID) VALUES ('ListenerEntity1', 1);
+insert into AUTO_PK_SUPPORT (TABLE_NAME, NEXT_ID) VALUES ('ListenerEntity2', 1);
 
 create table SimpleEntity (id int not null, property1 VARCHAR(100), primary key(id));
-create table CallbackEntity (id int not null, property1 VARCHAR(100), primary key(id));
+create table CallbackEntity (id int not null, primary key(id));
 create table CallbackEntity2 (id int not null, primary key(id));
+create table ListenerEntity1 (id int not null, primary key(id));
+create table ListenerEntity2 (id int not null, primary key(id));



Mime
View raw message