isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmatth...@apache.org
Subject svn commit: r1084891 - in /incubator/isis/trunk: core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/ runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/ runtimes/dflt/runtime/src/main/ja...
Date Thu, 24 Mar 2011 10:31:04 GMT
Author: rmatthews
Date: Thu Mar 24 10:31:03 2011
New Revision: 1084891

URL: http://svn.apache.org/viewvc?rev=1084891&view=rev
Log:
Tidying up AggregateOid

Modified:
    incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/AggregatedOid.java
    incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommand.java
    incubator/isis/trunk/runtimes/dflt/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/AdapterManagerDefault.java
    incubator/isis/trunk/runtimes/dflt/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/PersistorUtil_ValueAdapterTest.java
    incubator/isis/trunk/runtimes/dflt/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/testsystem/TestObjectFactory.java
    incubator/isis/trunk/runtimes/dflt/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/testsystem/TestProxyCollectionAdapter.java
    incubator/isis/trunk/runtimes/dflt/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/testsystem/TestProxyOidGenerator.java

Modified: incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/AggregatedOid.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/AggregatedOid.java?rev=1084891&r1=1084890&r2=1084891&view=diff
==============================================================================
--- incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/AggregatedOid.java
(original)
+++ incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/AggregatedOid.java
Thu Mar 24 10:31:03 2011
@@ -23,7 +23,6 @@ package org.apache.isis.core.metamodel.a
 import java.io.IOException;
 import java.io.Serializable;
 
-import org.apache.isis.applib.Identifier;
 import org.apache.isis.core.commons.encoding.DataInputExtended;
 import org.apache.isis.core.commons.encoding.DataOutputExtended;
 import org.apache.isis.core.commons.ensure.Assert;
@@ -37,14 +36,8 @@ public class AggregatedOid implements Oi
 
     private static final long serialVersionUID = 1L;
 
-	private static <T> T ensureNotNull(final T oid, String message) {
-		Assert.assertNotNull(message, oid);
-		return oid;
-	}
-
     private final Oid parentOid;
-    private final String fieldName;
-    private final int element;
+    private final String id;
     
     private AggregatedOid previous;
 
@@ -55,34 +48,21 @@ public class AggregatedOid implements Oi
     // Constructor, Encodeable
     ///////////////////////////////////////////////////////////
     public AggregatedOid(final Oid oid, final String id) {
-        this(oid, id, -1);
-    }
-    
-    //public
-    private AggregatedOid(final Oid oid, final String id, final int element) {
-        Assert.assertNotNull("Field required", id);
+        Assert.assertNotNull("ID required", id);
         this.parentOid = oid;
-        this.fieldName = id;
-        this.element = element;
+        this.id = id;
         initialized();
     }
 
-    public AggregatedOid(final Oid oid, final Identifier identifier) {
-        this(oid, ensureNotNull(identifier, "Field required").getMemberName());
-    }
-    /*
-*/
     public AggregatedOid(DataInputExtended input) throws IOException {
     	this.parentOid = input.readEncodable(Oid.class);
-    	this.fieldName = input.readUTF();
-    	this.element = input.readInt();
+    	this.id = input.readUTF();
     	initialized();
     }
     
     public void encode(DataOutputExtended output) throws IOException {
     	output.writeEncodable(parentOid);
-        output.writeUTF(fieldName);
-        output.writeInt(element);
+        output.writeUTF(id);
     }
 
 	private void initialized() {
@@ -96,22 +76,16 @@ public class AggregatedOid implements Oi
     public Oid getParentOid() {
         return parentOid;
     }
-    public String getFieldName() {
-        return fieldName;
-    }
-    
-    /*
-    public int getElement() {
-        return element;
+    public String getId() {
+        return id;
     }
-*/
-    
+        
     ///////////////////////////////////////////////////////////
     // makePersistent
     ///////////////////////////////////////////////////////////
 
     public void makePersistent() {
-        this.previous = new AggregatedOid(this.parentOid, this.fieldName, this.element);
+        this.previous = new AggregatedOid(this.parentOid, this.id);
         cacheState();
     }
     
@@ -163,7 +137,7 @@ public class AggregatedOid implements Oi
     }
     
     public boolean equals(final AggregatedOid other) {
-        return other.parentOid.equals(parentOid) &&  other.fieldName.equals(fieldName)
&& other.element == element;
+        return other.parentOid.equals(parentOid) &&  other.id.equals(id);
     }
 
     @Override
@@ -175,8 +149,7 @@ public class AggregatedOid implements Oi
 	private void cacheState() {
 		int hashCode = 17;
         hashCode = 37 * hashCode + parentOid.hashCode();
-        hashCode = 37 * hashCode + fieldName.hashCode();
-        hashCode = 37 * hashCode + element;
+        hashCode = 37 * hashCode + id.hashCode();
         cachedHashCode = hashCode;
 	}
 
@@ -187,7 +160,7 @@ public class AggregatedOid implements Oi
 
     @Override
     public String toString() {
-        return "AOID[" + parentOid + "," + fieldName + (element == -1 ? "" : "," + element)
+ "]";
+        return "AOID[" + parentOid + "," + id + "]";
     }
 
 

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommand.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommand.java?rev=1084891&r1=1084890&r2=1084891&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommand.java
(original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommand.java
Thu Mar 24 10:31:03 2011
@@ -106,7 +106,7 @@ final class WriteObjectCommand implement
         } else {
             String specName = field.getSpecification().getFullIdentifier();
             StateWriter aggregateWriter = writer.addAggregate(association.getId());
-            aggregateWriter.writeId(((AggregatedOid) field.getOid()).getFieldName());
+            aggregateWriter.writeId(((AggregatedOid) field.getOid()).getId());
             writeFields(aggregateWriter, specName, field);
         }
     }
@@ -145,7 +145,7 @@ final class WriteObjectCommand implement
             List<StateWriter> elements = new ArrayList<StateWriter>();
             for (ObjectAdapter element : collectionFacet.iterable(collection)) {
                StateWriter elementWriter = writer.createElementWriter();
-               elementWriter.writeId(((AggregatedOid) element.getOid()).getFieldName());
+               elementWriter.writeId(((AggregatedOid) element.getOid()).getId());
                writeFields(elementWriter, element.getSpecification().getFullIdentifier(),
element);
                elements.add(elementWriter);
             }

Modified: incubator/isis/trunk/runtimes/dflt/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/AdapterManagerDefault.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/AdapterManagerDefault.java?rev=1084891&r1=1084890&r2=1084891&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/AdapterManagerDefault.java
(original)
+++ incubator/isis/trunk/runtimes/dflt/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/AdapterManagerDefault.java
Thu Mar 24 10:31:03 2011
@@ -32,6 +32,7 @@ import org.apache.isis.applib.Identifier
 import org.apache.isis.core.commons.debug.DebugBuilder;
 import org.apache.isis.core.commons.debug.DebuggableWithTitle;
 import org.apache.isis.core.commons.ensure.Assert;
+import org.apache.isis.core.commons.exceptions.IsisException;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.core.metamodel.adapter.ResolveState;
 import org.apache.isis.core.metamodel.adapter.oid.AggregatedOid;
@@ -209,20 +210,13 @@ public class AdapterManagerDefault exten
     }
 
     public ObjectAdapter adapterForAggregated(Object pojo, ObjectAdapter parent) {
-        
         final ObjectAdapter adapter = getAdapterFor(pojo);
         if (adapter != null) {
             return adapter;
         }
-
-        
-        
         String id = getOidGenerator().createAggregateId(pojo);
         final Oid aggregatedOid = new AggregatedOid(parent.getOid(), id);
-         AggregateAdapters aggregatedAdapter = createOrRecreateRootAdapter(pojo, aggregatedOid);
-
-        // same locking as parent
-//        aggregatedAdapter.setOptimisticLock(parent.getVersion());
+        AggregateAdapters aggregatedAdapter = createOrRecreateRootAdapter(pojo, aggregatedOid);
         return map(aggregatedAdapter);
     }
 
@@ -372,7 +366,7 @@ public class AdapterManagerDefault exten
         Oid rootOid = rootAdapter.getOid();
 
         for (OneToManyAssociation otma : rootAdapter.getSpecification().getCollections())
{
-            AggregatedOid aggregatedOid = new AggregatedOid(rootOid, otma.getIdentifier());
+            AggregatedOid aggregatedOid = new AggregatedOid(rootOid, otma.getName());
             ObjectAdapter collectionAdapter = getAdapterFor(aggregatedOid);
             if (collectionAdapter != null) {
                 // collection adapters are lazily created and so there may not be one.
@@ -520,8 +514,12 @@ public class AdapterManagerDefault exten
         ensureMapsConsistent(ownerAdapter);
         Assert.assertNotNull(pojo);
 
+        if (!(identifiedHolder instanceof OneToManyAssociation)) {
+            throw new IsisException("only applicable to collections " + pojo + " in " + identifiedHolder);
+        }
+        
         // persistence of aggregated follows the parent
-        final Oid aggregatedOid = new AggregatedOid(ownerAdapter.getOid(), identifier);
+        final Oid aggregatedOid = new AggregatedOid(ownerAdapter.getOid(), identifier.getMemberName());
         ObjectAdapter aggregatedAdapter = createOrRecreateAdapter(pojo, aggregatedOid);
 
         // we copy over the type onto the adapter itself

Modified: incubator/isis/trunk/runtimes/dflt/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/PersistorUtil_ValueAdapterTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/PersistorUtil_ValueAdapterTest.java?rev=1084891&r1=1084890&r2=1084891&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/PersistorUtil_ValueAdapterTest.java
(original)
+++ incubator/isis/trunk/runtimes/dflt/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/PersistorUtil_ValueAdapterTest.java
Thu Mar 24 10:31:03 2011
@@ -43,7 +43,7 @@ public class PersistorUtil_ValueAdapterT
         field = new TestProxyField("fieldName", system.getSpecification(Object.class));
         FacetUtil.addFacet(new AggregatedFacetAlways(field));
         value = new Object();
-        aggregatedAdapter = getAdapterManager().adapterFor(value, parent, field);
+        aggregatedAdapter = getAdapterManager().adapterForAggregated(value, parent);
     }
 
     public void testOidKnowsParent() throws Exception {
@@ -51,9 +51,9 @@ public class PersistorUtil_ValueAdapterT
         assertEquals(parent.getOid(), aggregatedOid.getParentOid());
     }
 
-    public void testOidKnowsField() throws Exception {
+    public void testOidHasSubId() throws Exception {
         final AggregatedOid aggregatedOid = (AggregatedOid) aggregatedAdapter.getOid();
-        assertEquals("fieldName", aggregatedOid.getFieldName());
+        assertEquals("8", aggregatedOid.getId());
     }
 
     public void testResolveStateStartsAsGhost() throws Exception {

Modified: incubator/isis/trunk/runtimes/dflt/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/testsystem/TestObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/testsystem/TestObjectFactory.java?rev=1084891&r1=1084890&r2=1084891&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/testsystem/TestObjectFactory.java
(original)
+++ incubator/isis/trunk/runtimes/dflt/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/testsystem/TestObjectFactory.java
Thu Mar 24 10:31:03 2011
@@ -23,7 +23,6 @@ import java.lang.reflect.Modifier;
 
 import org.apache.isis.core.metamodel.spec.ObjectInstantiationException;
 import org.apache.isis.runtimes.dflt.runtime.persistence.objectfactory.ObjectFactoryAbstract;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectfactory.ObjectFactoryAbstract.Mode;
 
 public class TestObjectFactory extends ObjectFactoryAbstract {
 

Modified: incubator/isis/trunk/runtimes/dflt/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/testsystem/TestProxyCollectionAdapter.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/testsystem/TestProxyCollectionAdapter.java?rev=1084891&r1=1084890&r2=1084891&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/testsystem/TestProxyCollectionAdapter.java
(original)
+++ incubator/isis/trunk/runtimes/dflt/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/testsystem/TestProxyCollectionAdapter.java
Thu Mar 24 10:31:03 2011
@@ -29,7 +29,6 @@ import java.util.Vector;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.EnumerationUtils;
 import org.apache.commons.collections.iterators.IteratorEnumeration;
-
 import org.apache.isis.core.commons.ensure.Assert;
 import org.apache.isis.core.commons.exceptions.NotYetImplementedException;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;

Modified: incubator/isis/trunk/runtimes/dflt/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/testsystem/TestProxyOidGenerator.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/testsystem/TestProxyOidGenerator.java?rev=1084891&r1=1084890&r2=1084891&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/testsystem/TestProxyOidGenerator.java
(original)
+++ incubator/isis/trunk/runtimes/dflt/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/testsystem/TestProxyOidGenerator.java
Thu Mar 24 10:31:03 2011
@@ -49,7 +49,7 @@ public class TestProxyOidGenerator exten
     }
     
     public String createAggregateId(Object pojo) {
-        return "";
+        return "8";
     }
 
     public void debugData(final DebugBuilder debug) {}



Mime
View raw message