openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r596737 - in /openjpa/branches/1.0.x: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/
Date Tue, 20 Nov 2007 16:33:32 GMT
Author: mikedd
Date: Tue Nov 20 08:33:31 2007
New Revision: 596737

URL: http://svn.apache.org/viewvc?rev=596737&view=rev
Log:
OPENJPA-446

Added:
    openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/Record.java
  (with props)
    openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestDetachment.java
  (with props)
Modified:
    openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java

Modified: openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java?rev=596737&r1=596736&r2=596737&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java
(original)
+++ openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java
Tue Nov 20 08:33:31 2007
@@ -552,7 +552,8 @@
     public void settingStringField(PersistenceCapable pc, int idx, String cur,
         String next, int set) {
         accessingField(idx);
-        if (cur == next || !_loaded.get(idx))
+        if (cur == next || (cur != null && cur.equals(next))
+                || !_loaded.get(idx))
             return;
         lock();
         try {

Added: openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/Record.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/Record.java?rev=596737&view=auto
==============================================================================
--- openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/Record.java
(added)
+++ openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/Record.java
Tue Nov 20 08:33:31 2007
@@ -0,0 +1,34 @@
+package org.apache.openjpa.persistence.detachment;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.apache.openjpa.persistence.Persistent;
+
+@Entity
+public class Record {
+
+    @Persistent
+    private String content;
+
+    @Id
+    @GeneratedValue
+    private int id;
+
+    public String getContent() {
+        return content;
+    }
+
+    public void setContent(String content) {
+        this.content = content;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+}

Propchange: openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/Record.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestDetachment.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestDetachment.java?rev=596737&view=auto
==============================================================================
--- openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestDetachment.java
(added)
+++ openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestDetachment.java
Tue Nov 20 08:33:31 2007
@@ -0,0 +1,78 @@
+package org.apache.openjpa.persistence.detachment;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestDetachment extends SingleEMFTestCase {
+
+    private int id;
+
+    public void setUp() {
+        super.setUp(Record.class);
+        id = prepare();
+    }
+
+    public void testAttachWithNewString() {
+        // set up record with string "default" as content
+        Record record = detach(id);
+
+        // set different text
+        record.setContent("a text different than the one in the record");
+
+        attach(record);
+    }
+
+    public void testSetSameStringInstance() {
+        Record record = detach(id);
+
+        // same text, same String instance
+        record.setContent(record.getContent());
+
+        attach(record);
+    }
+
+    public void testSetSameString() {
+        Record record = detach(id);
+        // same text, different String instance
+        record.setContent(record.getContent() + "");
+
+        attach(record);
+    }
+
+    /**
+     * Creates a new record, sets the content to "default" and returns the id.
+     */
+    private int prepare() {
+        EntityManager em = emf.createEntityManager();
+
+        em.getTransaction().begin();
+        Record record = new Record();
+        record.setContent("default");
+        em.persist(record);
+        em.getTransaction().commit();
+        em.close();
+        return record.getId();
+    }
+
+    /**
+     * Fetches the record with the given id and returns a detached instance.
+     */
+    private Record detach(int id) {
+        EntityManager em = emf.createEntityManager();
+        Record record = em.find(Record.class, id);
+        em.close(); // detach
+        return record;
+    }
+
+    /**
+     * Merges the record into a new persistence context.
+     */
+    private void attach(Record record) {
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        record = em.merge(record);
+        em.getTransaction().commit();
+        em.close();
+    }
+}

Propchange: openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestDetachment.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message