cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From torehal...@apache.org
Subject svn commit: r454201 - in /incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src: main/java/org/apache/cayenne/ObjectId.java test/java/org/apache/cayenne/CompoundPkChangeTst.java
Date Sun, 08 Oct 2006 20:22:00 GMT
Author: torehalset
Date: Sun Oct  8 13:22:00 2006
New Revision: 454201

URL: http://svn.apache.org/viewvc?view=rev&rev=454201
Log:
CAY-675 compound primary key change

Added:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/CompoundPkChangeTst.java
Modified:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/ObjectId.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/ObjectId.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/ObjectId.java?view=diff&rev=454201&r1=454200&r2=454201
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/ObjectId.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/ObjectId.java
Sun Oct  8 13:22:00 2006
@@ -311,7 +311,13 @@
      * @since 1.2
      */
     public ObjectId createReplacementId() {
-        return new ObjectId(getEntityName(), replacementIdMap);
+        // merge existing and replaced ids to handle a replaced subset of
+        // a compound primary key
+        Map newIdMap = new HashMap(getIdSnapshot());
+        if (replacementIdMap != null) {
+            newIdMap.putAll(replacementIdMap);
+        }
+        return new ObjectId(getEntityName(), newIdMap);
     }
 
     /**

Added: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/CompoundPkChangeTst.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/CompoundPkChangeTst.java?view=auto&rev=454201
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/CompoundPkChangeTst.java
(added)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/CompoundPkChangeTst.java
Sun Oct  8 13:22:00 2006
@@ -0,0 +1,119 @@
+/*****************************************************************
+ *   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;
+
+import org.apache.art.CompoundPkTestEntity;
+import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.unit.CayenneTestCase;
+
+
+public class CompoundPkChangeTst extends CayenneTestCase {
+    
+    private static final String key1v1 = "-key1-v1-";
+    private static final String key2v1 = "-key2-v1-";
+    private static final String key1v2 = "-key1-v2-";
+    private static final String key2v2 = "-key2-v2-";
+    private static final String key1v3 = "-key1-v3-";
+    private static final String key2v3 = "-key2-v3-";
+
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        deleteTestData();
+    }
+
+    public void testCompoundPkChangeSingleElement() throws Exception {
+        DataContext context = createDataContext();
+        
+        CompoundPkTestEntity dao = (CompoundPkTestEntity) context
+                .createAndRegisterNewObject(CompoundPkTestEntity.class);
+        CompoundPkTestEntity refreshedDao = null;
+        
+        dao.setKey1(key1v1);
+        dao.setKey2(key2v1);
+        dao.setName("testing testing");
+
+        context.commitChanges();
+        assertEquals(key1v1, dao.getObjectId().getIdSnapshot().get(CompoundPkTestEntity.KEY1_PK_COLUMN));
+        assertEquals(key2v1, dao.getObjectId().getIdSnapshot().get(CompoundPkTestEntity.KEY2_PK_COLUMN));
+        
+        refreshedDao = (CompoundPkTestEntity) context.refetchObject(dao.getObjectId());
+        assertEquals(dao.getObjectId(), refreshedDao.getObjectId());
+
+        dao.setKey2(key2v2);
+
+        context.commitChanges();
+        assertEquals(key1v1, dao.getObjectId().getIdSnapshot().get(CompoundPkTestEntity.KEY1_PK_COLUMN));
+        assertEquals(key2v2, dao.getObjectId().getIdSnapshot().get(CompoundPkTestEntity.KEY2_PK_COLUMN));
+
+        refreshedDao = (CompoundPkTestEntity) context.refetchObject(dao.getObjectId());
+        assertEquals(dao.getObjectId(), refreshedDao.getObjectId());
+
+        dao.setKey2(key2v3);
+
+        context.commitChanges();
+        assertEquals(key1v1, dao.getObjectId().getIdSnapshot().get(CompoundPkTestEntity.KEY1_PK_COLUMN));
+        assertEquals(key2v3, dao.getObjectId().getIdSnapshot().get(CompoundPkTestEntity.KEY2_PK_COLUMN));
+        
+        refreshedDao = (CompoundPkTestEntity) context.refetchObject(dao.getObjectId());
+        assertEquals(dao.getObjectId(), refreshedDao.getObjectId());
+
+    }
+
+    public void testCompoundPkChangeAllElements() throws Exception {
+        DataContext context = createDataContext();
+        
+
+        CompoundPkTestEntity dao = (CompoundPkTestEntity) context
+                .createAndRegisterNewObject(CompoundPkTestEntity.class);
+        CompoundPkTestEntity refreshedDao = null;
+        
+        dao.setKey1(key1v1);
+        dao.setKey2(key2v1);
+        dao.setName("testing testing");
+
+        context.commitChanges();
+        assertEquals(key1v1, dao.getObjectId().getIdSnapshot().get(CompoundPkTestEntity.KEY1_PK_COLUMN));
+        assertEquals(key2v1, dao.getObjectId().getIdSnapshot().get(CompoundPkTestEntity.KEY2_PK_COLUMN));
+        
+        refreshedDao = (CompoundPkTestEntity) context.refetchObject(dao.getObjectId());
+        assertEquals(dao.getObjectId(), refreshedDao.getObjectId());
+
+        dao.setKey1(key1v2);
+        dao.setKey2(key2v2);
+
+        context.commitChanges();
+        assertEquals(key1v2, dao.getObjectId().getIdSnapshot().get(CompoundPkTestEntity.KEY1_PK_COLUMN));
+        assertEquals(key2v2, dao.getObjectId().getIdSnapshot().get(CompoundPkTestEntity.KEY2_PK_COLUMN));
+
+        refreshedDao = (CompoundPkTestEntity) context.refetchObject(dao.getObjectId());
+        assertEquals(dao.getObjectId(), refreshedDao.getObjectId());
+
+        dao.setKey1(key1v3);
+        dao.setKey2(key2v3);
+
+        context.commitChanges();
+        assertEquals(key1v3, dao.getObjectId().getIdSnapshot().get(CompoundPkTestEntity.KEY1_PK_COLUMN));
+        assertEquals(key2v3, dao.getObjectId().getIdSnapshot().get(CompoundPkTestEntity.KEY2_PK_COLUMN));
+        
+        refreshedDao = (CompoundPkTestEntity) context.refetchObject(dao.getObjectId());
+        assertEquals(dao.getObjectId(), refreshedDao.getObjectId());
+
+    }
+}



Mime
View raw message