openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dez...@apache.org
Subject svn commit: r627516 - in /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype: EntityWithGeneratedValueAndPostPersist.java TestEntityWithGeneratedValueAndPostPersist.java ValueCache.java
Date Wed, 13 Feb 2008 16:35:17 GMT
Author: dezzio
Date: Wed Feb 13 08:35:08 2008
New Revision: 627516

URL: http://svn.apache.org/viewvc?rev=627516&view=rev
Log:
Generated values for non-ID fields have interacted poorly with post persist call backs prior
to r617525.  This test ensures no regression to the buggy behavior.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/EntityWithGeneratedValueAndPostPersist.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestEntityWithGeneratedValueAndPostPersist.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/ValueCache.java
  (with props)

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/EntityWithGeneratedValueAndPostPersist.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/EntityWithGeneratedValueAndPostPersist.java?rev=627516&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/EntityWithGeneratedValueAndPostPersist.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/EntityWithGeneratedValueAndPostPersist.java
Wed Feb 13 08:35:08 2008
@@ -0,0 +1,69 @@
+/*
+ * 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.generationtype;
+
+import javax.persistence.*;
+
+@Entity
+public class EntityWithGeneratedValueAndPostPersist {
+    @Id
+    private long id;
+    
+    @Basic
+    @GeneratedValue
+    private int bingo;
+    
+    @Basic
+    private String name;
+    
+    @Transient
+    private ValueCache cache;
+    
+    public EntityWithGeneratedValueAndPostPersist(long id) {
+        this.id = id;
+    }
+    
+    public String getName() {
+        return name;
+    }
+    
+    public void setName(String name) {
+        this.name = name;
+    }
+    
+    public long getId() {
+        return id;
+    }
+    
+    public int getBingo() {
+        return bingo;
+    }
+    
+    public void setCache(ValueCache cache) {
+        this.cache = cache;
+    }
+    
+    @PostPersist
+    private void postPersistCallback() {
+        if (cache == null)
+            throw new IllegalStateException("Expected a cache");
+        
+        cache.setValue(bingo);
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/EntityWithGeneratedValueAndPostPersist.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestEntityWithGeneratedValueAndPostPersist.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestEntityWithGeneratedValueAndPostPersist.java?rev=627516&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestEntityWithGeneratedValueAndPostPersist.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestEntityWithGeneratedValueAndPostPersist.java
Wed Feb 13 08:35:08 2008
@@ -0,0 +1,98 @@
+/*
+ * 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.generationtype;
+
+import javax.persistence.*;
+
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+/**
+ * Tests OpenJPA's support for the GeneratedValue annotation
+ * applied to a non-ID field in interaction with the PostPersist callback.  
+ * 
+ * @author David Ezzio
+ */
+public class TestEntityWithGeneratedValueAndPostPersist 
+        extends SingleEMFTestCase implements ValueCache {
+
+    private int cache;
+    
+    public void setUp() { 
+        setUp(EntityWithGeneratedValueAndPostPersist.class, CLEAR_TABLES);
+        cache = 0;
+    }
+
+    // satisfy the ValueCache interface
+    public void setValue(int val) {
+        cache = val;
+    }
+    
+    public void testValueCapturedInPostPersistAfterCommit() {
+        
+        // get EM and start tx
+        EntityManager em = getEM();
+        em.getTransaction().begin();
+
+        // create a new entity
+        EntityWithGeneratedValueAndPostPersist pc = 
+                new EntityWithGeneratedValueAndPostPersist(1);
+        pc.setName("TestEntityWithGeneratedValueAndPostPersist-commit");
+        pc.setCache(this);
+
+        // persist and commit
+        em.persist(pc);
+        em.getTransaction().commit();
+        
+        // check the value captured by the PostPersist callback
+        assertEquals("Entity's current value does not match value captured " +
+        		"in postPersist", pc.getBingo(), cache);
+    }
+    
+    public void testValueCapturedInPostPersistAfterFlush() {
+        
+        // get EM and start tx
+        EntityManager em = getEM();
+        em.getTransaction().begin();
+
+        // create a new Thingamabob
+        EntityWithGeneratedValueAndPostPersist pc = 
+                new EntityWithGeneratedValueAndPostPersist(1);
+        pc.setName("TestEntityWithGeneratedValueAndPostPersist-flush");
+        pc.setCache(this);
+
+        // persist and flush
+        em.persist(pc);
+        em.flush();
+
+        // check the value captured by the PostPersist callback
+        assertEquals("Entity's current value does not match value captured " +
+        		"in postPersist", pc.getBingo(), cache);
+        
+        // commit
+        em.getTransaction().commit();
+        
+        // check the value captured by the PostPersist callback
+        assertEquals("Entity's current value does not match value captured " +
+        		"in postPersist", pc.getBingo(), cache);
+    }
+    
+    private EntityManager getEM() {
+        return emf.createEntityManager();
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestEntityWithGeneratedValueAndPostPersist.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/ValueCache.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/ValueCache.java?rev=627516&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/ValueCache.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/ValueCache.java
Wed Feb 13 08:35:08 2008
@@ -0,0 +1,23 @@
+/*
+ * 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.generationtype;
+
+public interface ValueCache {
+    public void setValue(int val);
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/ValueCache.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message