chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fguilla...@apache.org
Subject svn commit: r911836 - /incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/
Date Fri, 19 Feb 2010 15:15:22 GMT
Author: fguillaume
Date: Fri Feb 19 15:15:20 2010
New Revision: 911836

URL: http://svn.apache.org/viewvc?rev=911836&view=rev
Log:
Untie SimpleObjectEntry from the Connection, as ObjectEntry aren't live objects

Modified:
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleDocument.java
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleFolder.java
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObject.java
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectEntry.java
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimplePolicy.java
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleRelationship.java

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java?rev=911836&r1=911835&r2=911836&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java
Fri Feb 19 15:15:20 2010
@@ -126,7 +126,7 @@
         if (folder != null) {
             entry.setValue(Property.PARENT_ID, folder.getId());
         }
-        return new SimpleDocument(entry);
+        return new SimpleDocument(entry, this);
     }
 
     public Folder newFolder(String typeId, Folder folder) {
@@ -138,7 +138,7 @@
         if (folder != null) {
             entry.setValue(Property.PARENT_ID, folder.getId());
         }
-        return new SimpleFolder(entry);
+        return new SimpleFolder(entry, this);
     }
 
     public Relationship newRelationship(String typeId) {
@@ -146,7 +146,7 @@
         if (type == null || type.getBaseType() != BaseType.RELATIONSHIP) {
             throw new IllegalArgumentException(typeId);
         }
-        return new SimpleRelationship(newObjectEntry(typeId));
+        return new SimpleRelationship(newObjectEntry(typeId), this);
     }
 
     public Policy newPolicy(String typeId, Folder folder) {
@@ -158,7 +158,7 @@
         if (folder != null) {
             entry.setValue(Property.PARENT_ID, folder.getId());
         }
-        return new SimplePolicy(entry);
+        return new SimplePolicy(entry, this);
     }
 
     /*
@@ -252,7 +252,11 @@
     public Collection<ObjectEntry> getObjectParents(ObjectId object,
             String filter) {
         // TODO filter
-        Set<String> ids = repository.parents.get(object.getId());
+        String objectId = object.getId();
+        if (objectId == null) {
+            return Collections.emptyList();
+        }
+        Set<String> ids = repository.parents.get(objectId);
         List<ObjectEntry> parents = new ArrayList<ObjectEntry>(ids.size());
         for (String id : ids) {
             SimpleData data = repository.datas.get(id);
@@ -502,7 +506,7 @@
         if (entry.getBaseType() != BaseType.FOLDER) {
             throw new IllegalArgumentException("Not a folder: " + path);
         }
-        return new SimpleFolder(entry);
+        return new SimpleFolder(entry, this);
     }
 
     public CMISObject getObject(ObjectId object) {
@@ -513,13 +517,14 @@
         String typeId = (String) data.get(Property.TYPE_ID);
         switch (repository.getType(typeId).getBaseType()) {
         case DOCUMENT:
-            return new SimpleDocument(new SimpleObjectEntry(data, this));
+            return new SimpleDocument(new SimpleObjectEntry(data, this), this);
         case FOLDER:
-            return new SimpleFolder(new SimpleObjectEntry(data, this));
+            return new SimpleFolder(new SimpleObjectEntry(data, this), this);
         case RELATIONSHIP:
-            return new SimpleRelationship(new SimpleObjectEntry(data, this));
+            return new SimpleRelationship(new SimpleObjectEntry(data, this),
+                    this);
         case POLICY:
-            return new SimplePolicy(new SimpleObjectEntry(data, this));
+            return new SimplePolicy(new SimpleObjectEntry(data, this), this);
         default:
             throw new AssertionError(typeId);
         }
@@ -866,7 +871,7 @@
                 null);
         List<CMISObject> objects = new ArrayList<CMISObject>(res.size());
         for (ObjectEntry e : res) {
-            objects.add(SimpleObject.construct((SimpleObjectEntry) e));
+            objects.add(SimpleObject.construct((SimpleObjectEntry) e, this));
         }
         return objects;
     }

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleDocument.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleDocument.java?rev=911836&r1=911835&r2=911836&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleDocument.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleDocument.java
Fri Feb 19 15:15:20 2010
@@ -19,6 +19,7 @@
 import java.io.IOException;
 import java.util.Collection;
 
+import org.apache.chemistry.Connection;
 import org.apache.chemistry.ContentStream;
 import org.apache.chemistry.ContentStreamPresence;
 import org.apache.chemistry.Document;
@@ -26,8 +27,8 @@
 
 public class SimpleDocument extends SimpleObject implements Document {
 
-    public SimpleDocument(SimpleObjectEntry entry) {
-        super(entry);
+    public SimpleDocument(SimpleObjectEntry entry, Connection connection) {
+        super(entry, connection);
     }
 
     protected byte[] getContentBytes() {

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleFolder.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleFolder.java?rev=911836&r1=911835&r2=911836&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleFolder.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleFolder.java
Fri Feb 19 15:15:20 2010
@@ -22,6 +22,7 @@
 import java.util.Set;
 
 import org.apache.chemistry.CMISObject;
+import org.apache.chemistry.Connection;
 import org.apache.chemistry.Document;
 import org.apache.chemistry.Folder;
 import org.apache.chemistry.ObjectId;
@@ -30,8 +31,8 @@
 
 public class SimpleFolder extends SimpleObject implements Folder {
 
-    public SimpleFolder(SimpleObjectEntry entry) {
-        super(entry);
+    public SimpleFolder(SimpleObjectEntry entry, Connection connection) {
+        super(entry, connection);
     }
 
     public void add(CMISObject object) {
@@ -46,27 +47,27 @@
 
     public Collection<ObjectId> deleteTree(Unfiling unfiling)
             throws UpdateConflictException {
-        return entry.connection.getSPI().deleteTree(this, unfiling, true);
+        return connection.getSPI().deleteTree(this, unfiling, true);
     }
 
     public List<CMISObject> getChildren() {
-        SimpleRepository repository = (SimpleRepository) entry.connection.getRepository();
+        SimpleRepository repository = (SimpleRepository) connection.getRepository();
         Set<String> ids = repository.children.get(getId());
         List<CMISObject> children = new ArrayList<CMISObject>(ids.size());
         for (String id : ids) {
             SimpleData d = repository.datas.get(id);
             children.add(SimpleObject.construct(new SimpleObjectEntry(d,
-                    entry.connection)));
+                    connection), connection));
         }
         return children;
     }
 
     public Document newDocument(String typeId) {
-        return entry.connection.newDocument(typeId, this);
+        return connection.newDocument(typeId, this);
     }
 
     public Folder newFolder(String typeId) {
-        return entry.connection.newFolder(typeId, this);
+        return connection.newFolder(typeId, this);
     }
 
 }

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObject.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObject.java?rev=911836&r1=911835&r2=911836&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObject.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObject.java
Fri Feb 19 15:15:20 2010
@@ -45,41 +45,45 @@
 
     protected final SimpleObjectEntry entry;
 
+    protected final Connection connection;
+
     private final Type type;
 
-    protected SimpleObject(SimpleObjectEntry entry) {
+    protected SimpleObject(SimpleObjectEntry entry, Connection connection) {
         this.entry = entry;
-        type = entry.connection.getRepository().getType(entry.getTypeId());
+        this.connection = connection;
+        type = connection.getRepository().getType(entry.getTypeId());
     }
 
-    protected static SimpleObject construct(SimpleObjectEntry entry) {
-        BaseType baseType = entry.connection.getRepository().getType(
+    protected static SimpleObject construct(SimpleObjectEntry entry,
+            Connection connection) {
+        BaseType baseType = connection.getRepository().getType(
                 entry.getTypeId()).getBaseType();
         switch (baseType) {
         case DOCUMENT:
-            return new SimpleDocument(entry);
+            return new SimpleDocument(entry, connection);
         case FOLDER:
-            return new SimpleFolder(entry);
+            return new SimpleFolder(entry, connection);
         case POLICY:
-            return new SimplePolicy(entry);
+            return new SimplePolicy(entry, connection);
         case RELATIONSHIP:
-            return new SimpleRelationship(entry);
+            return new SimpleRelationship(entry, connection);
         default:
             throw new AssertionError();
         }
     }
 
     public Connection getConnection() {
-        return entry.connection;
+        return connection;
     }
 
     public void move(Folder targetFolder, Folder sourceFolder)
             throws NameConstraintViolationException, UpdateConflictException {
-        entry.connection.getSPI().moveObject(this, targetFolder, sourceFolder);
+        connection.getSPI().moveObject(this, targetFolder, sourceFolder);
     }
 
     public void delete() throws UpdateConflictException {
-        entry.connection.getSPI().deleteObject(this, false);
+        connection.getSPI().deleteObject(this, false);
     }
 
     public void unfile() {
@@ -88,7 +92,7 @@
     }
 
     public Folder getParent() {
-        SimpleConnection connection = (SimpleConnection) entry.connection;
+        SimpleConnection connection = (SimpleConnection) this.connection;
         Set<String> parents = connection.repository.parents.get(getId());
         if (parents == SimpleRepository.NO_PARENT) {
             return null;
@@ -98,11 +102,12 @@
         }
         String pid = parents.iterator().next();
         SimpleData data = connection.repository.datas.get(pid);
-        return new SimpleFolder(new SimpleObjectEntry(data, connection));
+        return new SimpleFolder(new SimpleObjectEntry(data, connection),
+                connection);
     }
 
     public Collection<Folder> getParents() {
-        SimpleConnection connection = (SimpleConnection) entry.connection;
+        SimpleConnection connection = (SimpleConnection) this.connection;
         Set<String> parents = connection.repository.parents.get(getId());
         if (parents == SimpleRepository.NO_PARENT) {
             return Collections.emptyList();
@@ -110,7 +115,8 @@
         List<Folder> list = new ArrayList<Folder>(parents.size());
         for (String pid : parents) {
             SimpleData data = connection.repository.datas.get(pid);
-            list.add(new SimpleFolder(new SimpleObjectEntry(data, connection)));
+            list.add(new SimpleFolder(new SimpleObjectEntry(data, connection),
+                    connection));
         }
         return list;
     }
@@ -172,7 +178,7 @@
 
     public void save() {
         if (getId() == null) {
-            ((SimpleConnection) entry.connection).saveObject(this);
+            ((SimpleConnection) connection).saveObject(this);
         }
     }
 

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectEntry.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectEntry.java?rev=911836&r1=911835&r2=911836&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectEntry.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectEntry.java
Fri Feb 19 15:15:20 2010
@@ -38,15 +38,15 @@
 
     protected final SimpleData data;
 
-    protected final Connection connection;
-
     protected ChangeInfo changeInfo;
 
+    protected String path;
+
     protected String pathSegment;
 
     public SimpleObjectEntry(SimpleData data, Connection connection) {
         this.data = data;
-        this.connection = connection;
+        path = getPath(connection);
     }
 
     public String getId() {
@@ -89,16 +89,18 @@
 
     public Serializable getValue(String id) {
         if (id.equals(Property.PATH)) {
-            // non-local value
-            return getPath();
+            return path;
         }
         return data.get(id);
     }
 
     // TODO add a getPath method to the SPI
-    protected String getPath() {
+    protected String getPath(Connection connection) {
         ObjectEntry parent;
         if (getBaseType() == BaseType.FOLDER) {
+            if (getId() == null) {
+                return null;
+            }
             parent = connection.getSPI().getFolderParent(this, null);
         } else {
             Collection<ObjectEntry> parents = connection.getSPI().getObjectParents(

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimplePolicy.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimplePolicy.java?rev=911836&r1=911835&r2=911836&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimplePolicy.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimplePolicy.java
Fri Feb 19 15:15:20 2010
@@ -16,12 +16,13 @@
  */
 package org.apache.chemistry.impl.simple;
 
+import org.apache.chemistry.Connection;
 import org.apache.chemistry.Policy;
 
 public class SimplePolicy extends SimpleObject implements Policy {
 
-    public SimplePolicy(SimpleObjectEntry entry) {
-        super(entry);
+    public SimplePolicy(SimpleObjectEntry entry, Connection connection) {
+        super(entry, connection);
     }
 
 }

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleRelationship.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleRelationship.java?rev=911836&r1=911835&r2=911836&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleRelationship.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleRelationship.java
Fri Feb 19 15:15:20 2010
@@ -16,12 +16,13 @@
  */
 package org.apache.chemistry.impl.simple;
 
+import org.apache.chemistry.Connection;
 import org.apache.chemistry.Relationship;
 
 public class SimpleRelationship extends SimpleObject implements Relationship {
 
-    public SimpleRelationship(SimpleObjectEntry entry) {
-        super(entry);
+    public SimpleRelationship(SimpleObjectEntry entry, Connection connection) {
+        super(entry, connection);
     }
 
 }



Mime
View raw message