cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r504529 - 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 12:50:56 GMT
Author: aadamchik
Date: Wed Feb  7 04:50:56 2007
New Revision: 504529

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

Added:
    cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/CallbackEntity2.java
    cayenne/main/trunk/itests/jpa-chapter3/src/test/java/org/apache/cayenne/jpa/itest/ch3/_3_5_1_LifecycleCallbackMethodsTest.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/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=504529&r1=504528&r2=504529
==============================================================================
--- 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 04:50:56 2007
@@ -37,10 +37,7 @@
     protected String property1;
 
     @Transient
-    protected transient boolean prePersistCalled1;
-
-    @Transient
-    protected transient boolean prePersistCalled2;
+    protected transient boolean prePersistCalled;
 
     @Transient
     protected transient boolean postPersistCalled;
@@ -77,13 +74,8 @@
     }
 
     @PrePersist
-    public void prePersistMethod1() {
-        prePersistCalled1 = true;
-    }
-
-    @PrePersist
-    public void prePersistMethod2() {
-        prePersistCalled2 = true;
+    public void prePersistMethod() {
+        prePersistCalled = true;
     }
 
     @PostPersist
@@ -136,12 +128,8 @@
         return postUpdateCalled;
     }
 
-    public boolean isPrePersistCalled1() {
-        return prePersistCalled1;
-    }
-
-    public boolean isPrePersistCalled2() {
-        return prePersistCalled2;
+    public boolean isPrePersistCalled() {
+        return prePersistCalled;
     }
 
     public boolean isPreRemoveCalled() {

Added: cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/CallbackEntity2.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/CallbackEntity2.java?view=auto&rev=504529
==============================================================================
--- cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/CallbackEntity2.java
(added)
+++ cayenne/main/trunk/itests/jpa-chapter3/src/main/java/org/apache/cayenne/jpa/itest/ch3/entity/CallbackEntity2.java
Wed Feb  7 04:50:56 2007
@@ -0,0 +1,59 @@
+/*****************************************************************
+ *   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.Id;
+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;
+import javax.persistence.Transient;
+
+@Entity
+public class CallbackEntity2 {
+
+    @Id
+    protected int id;
+
+    @Transient
+    protected transient boolean mixedCallbackCalled;
+
+    @PrePersist
+    @PostPersist
+    @PreRemove
+    @PostRemove
+    @PreUpdate
+    @PostUpdate
+    @PostLoad
+    public void mixedCallbackMethod() {
+        mixedCallbackCalled = true;
+    }
+
+    public boolean isMixedCallbackCalled() {
+        return mixedCallbackCalled;
+    }
+
+    public void setMixedCallbackCalled(boolean mixedCallbackCalled) {
+        this.mixedCallbackCalled = mixedCallbackCalled;
+    }
+}

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=504529&r1=504528&r2=504529
==============================================================================
--- 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 04:50:56 2007
@@ -23,5 +23,6 @@
 		<description>Integration test peristence unit #1.</description>
 		<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>
 	</persistence-unit>
 </persistence>

Added: 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=auto&rev=504529
==============================================================================
--- cayenne/main/trunk/itests/jpa-chapter3/src/test/java/org/apache/cayenne/jpa/itest/ch3/_3_5_1_LifecycleCallbackMethodsTest.java
(added)
+++ cayenne/main/trunk/itests/jpa-chapter3/src/test/java/org/apache/cayenne/jpa/itest/ch3/_3_5_1_LifecycleCallbackMethodsTest.java
Wed Feb  7 04:50:56 2007
@@ -0,0 +1,45 @@
+/*****************************************************************
+ *   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;
+
+import javax.persistence.EntityManager;
+
+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;
+
+public class _3_5_1_LifecycleCallbackMethodsTest extends EntityManagerCase {
+
+    public void testPrePersist() {
+        CallbackEntity e = new CallbackEntity();
+        assertFalse(e.isPrePersistCalled());
+
+        EntityManager em = getEntityManager();
+
+        // spec reqires the callback to be invoked as a part of persist, without waiting
+        // for flush or commit.
+        em.persist(e);
+        assertTrue(e.isPrePersistCalled());
+
+        CallbackEntity2 e2 = new CallbackEntity2();
+        assertFalse(e2.isMixedCallbackCalled());
+        em.persist(e2);
+        assertTrue(e2.isMixedCallbackCalled());
+    }
+}

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=504529&r1=504528&r2=504529
==============================================================================
--- 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
04:50:56 2007
@@ -1,6 +1,8 @@
 create table AUTO_PK_SUPPORT (TABLE_NAME CHAR(100) NOT NULL,  NEXT_ID INTEGER NOT NULL, PRIMARY
KEY(TABLE_NAME));
 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);
 
 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 CallbackEntity2 (id int not null, primary key(id));



Mime
View raw message