Return-Path: Delivered-To: apmail-cayenne-commits-archive@www.apache.org Received: (qmail 36730 invoked from network); 7 Feb 2007 12:51:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 Feb 2007 12:51:18 -0000 Received: (qmail 93436 invoked by uid 500); 7 Feb 2007 12:51:25 -0000 Delivered-To: apmail-cayenne-commits-archive@cayenne.apache.org Received: (qmail 93420 invoked by uid 500); 7 Feb 2007 12:51:24 -0000 Mailing-List: contact commits-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cayenne.apache.org Delivered-To: mailing list commits@cayenne.apache.org Received: (qmail 93411 invoked by uid 99); 7 Feb 2007 12:51:24 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Feb 2007 04:51:24 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Feb 2007 04:51:17 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id DFFEF1A981A; Wed, 7 Feb 2007 04:50:56 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@cayenne.apache.org From: aadamchik@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070207125056.DFFEF1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@ Integration test peristence unit #1. org.apache.cayenne.jpa.itest.ch3.entity.SimpleEntity org.apache.cayenne.jpa.itest.ch3.entity.CallbackEntity + org.apache.cayenne.jpa.itest.ch3.entity.CallbackEntity2 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));