You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2010/03/09 13:40:07 UTC
svn commit: r920846 - in /incubator/chemistry/trunk/opencmis/opencmis-client:
opencmis-client-api/src/main/java/org/apache/opencmis/client/api/
opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/
opencmis-client-impl/src/main/j...
Author: fmui
Date: Tue Mar 9 12:40:07 2010
New Revision: 920846
URL: http://svn.apache.org/viewvc?rev=920846&view=rev
Log:
re-introduced caching - not tested yet
Modified:
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/CmisObject.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/OperationContext.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/ObjectFactory.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/AbstractPersistentCmisObject.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/OperationContextImpl.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentDocumentImpl.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentFolderImpl.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentPolicyImpl.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentRelationshipImpl.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentSessionImpl.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/QueryResultImpl.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/cache/Cache.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/cache/CacheImpl.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/misc/CacheTest.java
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/CmisObject.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/CmisObject.java?rev=920846&r1=920845&r2=920846&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/CmisObject.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/CmisObject.java Tue Mar 9 12:40:07 2010
@@ -176,5 +176,5 @@ public interface CmisObject {
/**
* Reloads the data from the repository.
*/
- void refresh(OperationContext context);
+ void refresh();
}
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/OperationContext.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/OperationContext.java?rev=920846&r1=920845&r2=920846&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/OperationContext.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/OperationContext.java Tue Mar 9 12:40:07 2010
@@ -28,6 +28,8 @@ public interface OperationContext {
void setFilter(Set<String> propertyFilter);
+ void setFilterString(String propertyFilter);
+
/**
* Returns the filter extended by cmis:objectId, cmis:objectTypeId and cmis:baseTypeId.
*/
@@ -53,6 +55,8 @@ public interface OperationContext {
void setRenditionFilter(Set<String> renditionFilter);
+ void setRenditionFilterString(String renditionFilter);
+
String getRenditionFilterString();
boolean isIncludePathSegments();
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/ObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/ObjectFactory.java?rev=920846&r1=920845&r2=920846&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/ObjectFactory.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/ObjectFactory.java Tue Mar 9 12:40:07 2010
@@ -29,6 +29,7 @@ import org.apache.opencmis.client.api.Cm
import org.apache.opencmis.client.api.ContentStream;
import org.apache.opencmis.client.api.Document;
import org.apache.opencmis.client.api.Folder;
+import org.apache.opencmis.client.api.OperationContext;
import org.apache.opencmis.client.api.Policy;
import org.apache.opencmis.client.api.Property;
import org.apache.opencmis.client.api.QueryResult;
@@ -76,7 +77,7 @@ public interface ObjectFactory {
Folder createFolder(Folder parent, List<Property<?>> properties, List<Policy> policies,
List<Ace> addACEs, List<Ace> removeACEs);
- CmisObject convertObject(ObjectData objectData);
+ CmisObject convertObject(ObjectData objectData, OperationContext context);
QueryResult convertQueryResult(ObjectData objectData);
}
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/AbstractPersistentCmisObject.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/AbstractPersistentCmisObject.java?rev=920846&r1=920845&r2=920846&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/AbstractPersistentCmisObject.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/AbstractPersistentCmisObject.java Tue Mar 9 12:40:07 2010
@@ -65,13 +65,14 @@ public abstract class AbstractPersistent
private Acl acl;
private List<Policy> policies;
private List<Relationship> relationships;
+ private OperationContext creationContext;
private boolean isChanged = false;
/**
* Initializes the object.
*/
protected void initialize(PersistentSessionImpl session, ObjectType objectType,
- ObjectData objectData) {
+ ObjectData objectData, OperationContext context) {
if (session == null) {
throw new IllegalArgumentException("Session must be set!");
}
@@ -87,6 +88,7 @@ public abstract class AbstractPersistent
this.session = session;
this.objectType = objectType;
+ this.creationContext = new OperationContextImpl(context);
if (objectData != null) {
// handle properties
@@ -130,7 +132,7 @@ public abstract class AbstractPersistent
relationships = new ArrayList<Relationship>();
ObjectFactory of = session.getObjectFactory();
for (ObjectData rod : objectData.getRelationships()) {
- CmisObject relationship = of.convertObject(rod);
+ CmisObject relationship = of.convertObject(rod, this.creationContext);
if (relationship instanceof Relationship) {
relationships.add((Relationship) relationship);
}
@@ -634,8 +636,10 @@ public abstract class AbstractPersistent
List<Relationship> page = new ArrayList<Relationship>();
if (relList.getObjects() != null) {
for (ObjectData rod : relList.getObjects()) {
- page.add(new PersistentRelationshipImpl(getSession(), SessionUtil
- .getTypeFromObjectData(getSession(), rod), rod));
+ Relationship relationship = new PersistentRelationshipImpl(getSession(), SessionUtil
+ .getTypeFromObjectData(getSession(), rod), rod, ctxt);
+
+ page.add(relationship);
}
}
@@ -674,18 +678,18 @@ public abstract class AbstractPersistent
* org.apache.opencmis.client.api.CmisObject#refresh(org.apache.opencmis.client.api.OperationContext
* )
*/
- public void refresh(OperationContext context) {
+ public void refresh() {
String objectId = getObjectId();
// get the latest data from the repository
ObjectData objectData = getSession().getProvider().getObjectService().getObject(
- getRepositoryId(), objectId, context.getFilterString(),
- context.isIncludeAllowableActions(), context.getIncludeRelationships(),
- context.getRenditionFilterString(), context.isIncludePolicies(), context.isIncludeAcls(),
- null);
+ getRepositoryId(), objectId, creationContext.getFilterString(),
+ creationContext.isIncludeAllowableActions(), creationContext.getIncludeRelationships(),
+ creationContext.getRenditionFilterString(), creationContext.isIncludePolicies(),
+ creationContext.isIncludeAcls(), null);
// reset this object
- initialize(getSession(), getObjectType(), objectData);
+ initialize(getSession(), getObjectType(), objectData, this.creationContext);
}
}
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/OperationContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/OperationContextImpl.java?rev=920846&r1=920845&r2=920846&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/OperationContextImpl.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/OperationContextImpl.java Tue Mar 9 12:40:07 2010
@@ -32,6 +32,9 @@ import org.apache.opencmis.commons.enums
*/
public class OperationContextImpl implements OperationContext, Serializable {
+ public static final String PROPERTIES_STAR = "*";
+ public static final String RENDITION_NONE = "cmis:none";
+
private static final long serialVersionUID = 1L;
private TreeSet<String> filter;
@@ -43,7 +46,11 @@ public class OperationContextImpl implem
private boolean includePathSegments;
private String orderBy;
private boolean cacheEnabled;
+ private String cacheKey;
+ /**
+ * Default constructor.
+ */
public OperationContextImpl() {
setFilter(null);
setIncludeAcls(false);
@@ -54,8 +61,12 @@ public class OperationContextImpl implem
setIncludePathSegments(true);
setOrderBy(null);
setCacheEnabled(false);
+ generateCacheKey();
}
+ /**
+ * Copy constructor.
+ */
public OperationContextImpl(OperationContext source) {
setFilter(source.getFilter());
setIncludeAcls(source.isIncludeAcls());
@@ -66,8 +77,12 @@ public class OperationContextImpl implem
setIncludePathSegments(source.isIncludePathSegments());
setOrderBy(source.getOrderBy());
setCacheEnabled(source.isCacheEnabled());
+ generateCacheKey();
}
+ /**
+ * Constructor with parameters.
+ */
public OperationContextImpl(Set<String> propertyFilter, boolean includeAcls,
boolean includeAllowableActions, boolean includePolicies,
IncludeRelationships includeRelationships, Set<String> renditionFilter,
@@ -81,12 +96,27 @@ public class OperationContextImpl implem
setIncludePathSegments(includePathSegments);
setOrderBy(orderBy);
setCacheEnabled(cacheEnabled);
+ generateCacheKey();
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.OperationContext#getFilter()
+ */
public Set<String> getFilter() {
+ if (this.filter == null) {
+ return null;
+ }
+
return Collections.unmodifiableSet(this.filter);
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.OperationContext#setFilter(java.util.Set)
+ */
public void setFilter(Set<String> propertyFilter) {
if (propertyFilter != null) {
TreeSet<String> tempSet = new TreeSet<String>();
@@ -100,11 +130,14 @@ public class OperationContextImpl implem
if (toid.length() == 0) {
continue;
}
- if (toid.equals("*")) {
+ if (toid.equals(PROPERTIES_STAR)) {
tempSet = new TreeSet<String>();
- tempSet.add("*");
+ tempSet.add(PROPERTIES_STAR);
break;
}
+ if (toid.indexOf(',') > -1) {
+ throw new IllegalArgumentException("Property id must not contain a comma!");
+ }
tempSet.add(toid);
}
@@ -119,15 +152,42 @@ public class OperationContextImpl implem
else {
this.filter = null;
}
+
+ generateCacheKey();
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.OperationContext#setFilter(java.lang.String)
+ */
+ public void setFilterString(String propertyFilter) {
+ if (propertyFilter == null) {
+ setFilter(null);
+ return;
+ }
+
+ String[] propertyIds = propertyFilter.split(",");
+ TreeSet<String> tempSet = new TreeSet<String>();
+ for (String pid : propertyIds) {
+ tempSet.add(pid);
+ }
+
+ setFilter(tempSet);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.OperationContext#getFilterString()
+ */
public String getFilterString() {
if (this.filter == null) {
return null;
}
- if (this.filter.contains("*")) {
- return "*";
+ if (this.filter.contains(PROPERTIES_STAR)) {
+ return PROPERTIES_STAR;
}
this.filter.add(PropertyIds.CMIS_OBJECT_ID);
@@ -147,42 +207,102 @@ public class OperationContextImpl implem
return sb.toString();
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.OperationContext#isIncludeAcls()
+ */
public boolean isIncludeAcls() {
return includeAcls;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.OperationContext#setIncludeAcls(boolean)
+ */
public void setIncludeAcls(boolean include) {
this.includeAcls = include;
+ generateCacheKey();
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.OperationContext#isIncludeAllowableActions()
+ */
public boolean isIncludeAllowableActions() {
return this.includeAllowableActions;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.OperationContext#setIncludeAllowableActions(boolean)
+ */
public void setIncludeAllowableActions(boolean include) {
this.includeAllowableActions = include;
+ generateCacheKey();
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.OperationContext#isIncludePolicies()
+ */
public boolean isIncludePolicies() {
return this.includePolicies;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.OperationContext#setIncludePolicies(boolean)
+ */
public void setIncludePolicies(boolean include) {
this.includePolicies = include;
+ generateCacheKey();
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.OperationContext#getIncludeRelationships()
+ */
public IncludeRelationships getIncludeRelationships() {
return this.includeRelationships;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.apache.opencmis.client.api.OperationContext#setIncludeRelationships(org.apache.opencmis
+ * .commons.enums.IncludeRelationships)
+ */
public void setIncludeRelationships(IncludeRelationships include) {
this.includeRelationships = include;
+ generateCacheKey();
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.OperationContext#getRenditionFilter()
+ */
public Set<String> getRenditionFilter() {
+ if (this.renditionFilter == null) {
+ return null;
+ }
+
return Collections.unmodifiableSet(this.renditionFilter);
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.OperationContext#setRenditionFilter(java.util.Set)
+ */
public void setRenditionFilter(Set<String> renditionFilter) {
TreeSet<String> tempSet = new TreeSet<String>();
@@ -196,21 +316,50 @@ public class OperationContextImpl implem
if (trf.length() == 0) {
continue;
}
+ if (trf.indexOf(',') > -1) {
+ throw new IllegalArgumentException("Rendition must not contain a comma!");
+ }
tempSet.add(trf);
}
if (tempSet.size() == 0) {
- tempSet.add("cmis:none");
+ tempSet.add(RENDITION_NONE);
}
}
else {
- tempSet.add("cmis:none");
+ tempSet.add(RENDITION_NONE);
}
this.renditionFilter = tempSet;
+ generateCacheKey();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.OperationContext#setRenditionFilterString(java.lang.String)
+ */
+ public void setRenditionFilterString(String renditionFilter) {
+ if (renditionFilter == null) {
+ setRenditionFilter(null);
+ return;
+ }
+
+ String[] renditions = renditionFilter.split(",");
+ TreeSet<String> tempSet = new TreeSet<String>();
+ for (String rend : renditions) {
+ tempSet.add(rend);
+ }
+
+ setRenditionFilter(tempSet);
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.OperationContext#getRenditionFilterString()
+ */
public String getRenditionFilterString() {
if (this.renditionFilter == null) {
return null;
@@ -229,32 +378,90 @@ public class OperationContextImpl implem
return sb.toString();
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.OperationContext#isIncludePathSegments()
+ */
public boolean isIncludePathSegments() {
return includePathSegments;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.OperationContext#setIncludePathSegments(boolean)
+ */
public void setIncludePathSegments(boolean include) {
this.includePathSegments = include;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.OperationContext#getOrderBy()
+ */
public String getOrderBy() {
return this.orderBy;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.OperationContext#setOrderBy(java.lang.String)
+ */
public void setOrderBy(String orderBy) {
this.orderBy = orderBy;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.OperationContext#isCacheEnabled()
+ */
public boolean isCacheEnabled() {
return cacheEnabled;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.OperationContext#setCacheEnabled(boolean)
+ */
public void setCacheEnabled(boolean cacheEnabled) {
this.cacheEnabled = cacheEnabled;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.OperationContext#getCacheKey()
+ */
public String getCacheKey() {
- // TODO Auto-generated method stub
- return null;
+ return cacheKey;
+ }
+
+ /**
+ * Generates a new cache key from all parameters that are relevant for caching.
+ */
+ protected void generateCacheKey() {
+ if (!cacheEnabled) {
+ cacheKey = null;
+ }
+
+ StringBuilder sb = new StringBuilder();
+
+ sb.append(includeAcls ? "1" : "0");
+ sb.append(includeAllowableActions ? "1" : "0");
+ sb.append(includePolicies ? "1" : "0");
+ sb.append("|");
+ sb.append(filter == null ? "" : getFilterString());
+ sb.append("|");
+ sb.append(includeRelationships == null ? "" : includeRelationships.value());
+
+ sb.append("|");
+ sb.append(renditionFilter == null ? "" : getRenditionFilterString());
+
+ cacheKey = sb.toString();
}
}
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentDocumentImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentDocumentImpl.java?rev=920846&r1=920845&r2=920846&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentDocumentImpl.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentDocumentImpl.java Tue Mar 9 12:40:07 2010
@@ -42,8 +42,8 @@ public class PersistentDocumentImpl exte
* Constructor.
*/
public PersistentDocumentImpl(PersistentSessionImpl session, ObjectType objectType,
- ObjectData objectData) {
- initialize(session, objectType, objectData);
+ ObjectData objectData, OperationContext context) {
+ initialize(session, objectType, objectData, context);
}
// properties
@@ -146,7 +146,7 @@ public class PersistentDocumentImpl exte
List<Document> result = new ArrayList<Document>();
if (versions != null) {
for (ObjectData objectData : versions) {
- CmisObject doc = objectFactory.convertObject(objectData);
+ CmisObject doc = objectFactory.convertObject(objectData, context);
if (!(doc instanceof Document)) {
// should not happen...
continue;
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentFolderImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentFolderImpl.java?rev=920846&r1=920845&r2=920846&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentFolderImpl.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentFolderImpl.java Tue Mar 9 12:40:07 2010
@@ -64,12 +64,12 @@ public class PersistentFolderImpl extend
* Constructor.
*/
public PersistentFolderImpl(PersistentSessionImpl session, ObjectType objectType,
- ObjectData objectData) {
- initialize(session, objectType, objectData);
+ ObjectData objectData, OperationContext context) {
+ initialize(session, objectType, objectData, context);
}
public PersistentFolderImpl(PersistentSessionImpl session) {
- initialize(session, null, null);
+ initialize(session, null, null, null);
}
public Document createDocument(String name, String typeId) {
@@ -179,7 +179,7 @@ public class PersistentFolderImpl extend
List<Document> page = new ArrayList<Document>();
if (checkedOutDocs.getObjects() != null) {
for (ObjectData objectData : checkedOutDocs.getObjects()) {
- CmisObject doc = objectFactory.convertObject(objectData);
+ CmisObject doc = objectFactory.convertObject(objectData, ctxt);
if (!(doc instanceof Document)) {
// should not happen...
continue;
@@ -242,7 +242,7 @@ public class PersistentFolderImpl extend
List<CmisObject> page = new ArrayList<CmisObject>();
for (ObjectInFolderData objectData : children.getObjects()) {
if (objectData.getObject() != null) {
- page.add(objectFactory.convertObject(objectData.getObject()));
+ page.add(objectFactory.convertObject(objectData.getObject(), ctxt));
}
}
@@ -281,7 +281,7 @@ public class PersistentFolderImpl extend
context.getIncludeRelationships(), context.getRenditionFilterString(),
context.isIncludePathSegments(), null);
- return convertProviderContainer(providerContainerList);
+ return convertProviderContainer(providerContainerList, context);
}
/*
@@ -293,6 +293,12 @@ public class PersistentFolderImpl extend
return getFolderTree(depth, getSession().getDefaultContext());
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.Folder#getFolderTree(int,
+ * org.apache.opencmis.client.api.OperationContext)
+ */
public List<Container<FileableCmisObject>> getFolderTree(int depth, OperationContext context) {
String objectId = getObjectId();
@@ -303,14 +309,14 @@ public class PersistentFolderImpl extend
context.getIncludeRelationships(), context.getRenditionFilterString(),
context.isIncludePathSegments(), null);
- return convertProviderContainer(providerContainerList);
+ return convertProviderContainer(providerContainerList, context);
}
/**
* Converts a provider container into an API container.
*/
private List<Container<FileableCmisObject>> convertProviderContainer(
- List<ObjectInFolderContainer> providerContainerList) {
+ List<ObjectInFolderContainer> providerContainerList, OperationContext context) {
if (providerContainerList == null) {
return null;
}
@@ -325,14 +331,15 @@ public class PersistentFolderImpl extend
}
// convert the object
- CmisObject object = of.convertObject(oifc.getObject().getObject());
+ CmisObject object = of.convertObject(oifc.getObject().getObject(), context);
if (!(object instanceof FileableCmisObject)) {
// the repository must not return objects that are not fileable, but you never know...
continue;
}
// convert the children
- List<Container<FileableCmisObject>> children = convertProviderContainer(oifc.getChildren());
+ List<Container<FileableCmisObject>> children = convertProviderContainer(oifc.getChildren(),
+ context);
// add both to current container
result.add(new ContainerImpl<FileableCmisObject>((FileableCmisObject) object, children));
@@ -440,7 +447,7 @@ public class PersistentFolderImpl extend
ObjectData newObjectData = getProvider().getObjectService().getObject(repositoryId, objectId,
null, false, IncludeRelationships.NONE, null, true, true, null);
- getSession().getCache().put(this);
+ // getSession().getCache().put(this);
}
private List<String> convertToPoliciesData(List<Policy> policies) {
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentPolicyImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentPolicyImpl.java?rev=920846&r1=920845&r2=920846&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentPolicyImpl.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentPolicyImpl.java Tue Mar 9 12:40:07 2010
@@ -18,6 +18,7 @@
*/
package org.apache.opencmis.client.runtime;
+import org.apache.opencmis.client.api.OperationContext;
import org.apache.opencmis.client.api.Policy;
import org.apache.opencmis.client.api.objecttype.ObjectType;
import org.apache.opencmis.commons.PropertyIds;
@@ -29,8 +30,8 @@ public class PersistentPolicyImpl extend
* Constructor.
*/
public PersistentPolicyImpl(PersistentSessionImpl session, ObjectType objectType,
- ObjectData objectData) {
- initialize(session, objectType, objectData);
+ ObjectData objectData, OperationContext context) {
+ initialize(session, objectType, objectData, context);
}
public String getPolicyText() {
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentRelationshipImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentRelationshipImpl.java?rev=920846&r1=920845&r2=920846&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentRelationshipImpl.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentRelationshipImpl.java Tue Mar 9 12:40:07 2010
@@ -32,8 +32,8 @@ public class PersistentRelationshipImpl
* Constructor.
*/
public PersistentRelationshipImpl(PersistentSessionImpl session, ObjectType objectType,
- ObjectData objectData) {
- initialize(session, objectType, objectData);
+ ObjectData objectData, OperationContext context) {
+ initialize(session, objectType, objectData, context);
}
/*
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentSessionImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentSessionImpl.java?rev=920846&r1=920845&r2=920846&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentSessionImpl.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentSessionImpl.java Tue Mar 9 12:40:07 2010
@@ -48,6 +48,7 @@ import org.apache.opencmis.client.api.ut
import org.apache.opencmis.client.api.util.Testable;
import org.apache.opencmis.client.provider.factory.CmisProviderFactory;
import org.apache.opencmis.client.runtime.cache.Cache;
+import org.apache.opencmis.client.runtime.cache.CacheImpl;
import org.apache.opencmis.client.runtime.repository.PersistentObjectFactoryImpl;
import org.apache.opencmis.client.runtime.repository.PersistentPropertyFactoryImpl;
import org.apache.opencmis.client.runtime.util.AbstractPagingList;
@@ -113,7 +114,7 @@ public class PersistentSessionImpl imple
/*
* Object cache (serializable)
*/
- // private Cache cache = null;
+ private Cache cache = null;
/*
* Lazy loaded repository info. Will be invalid after clear(). Access by getter always.
@@ -138,15 +139,15 @@ public class PersistentSessionImpl imple
this.locale = this.determineLocale(parameters);
PersistentSessionImpl.log.info("Session Locale: " + this.locale.toString());
- // int cacheSize = this.determineCacheSize(parameters);
- //
- // if (cacheSize == -1) {
- // this.cache = CacheImpl.newInstance();
- // }
- // else {
- // this.cache = CacheImpl.newInstance(cacheSize);
- // }
- // PersistentSessionImpl.log.info("Session Cache Size: " + this.cache.size());
+ int cacheSize = this.determineCacheSize(parameters);
+
+ if (cacheSize == -1) {
+ this.cache = CacheImpl.newInstance();
+ }
+ else {
+ this.cache = CacheImpl.newInstance(cacheSize);
+ }
+ PersistentSessionImpl.log.info("Session Cache Size: " + this.cache.getCacheSize());
}
private int determineCacheSize(Map<String, String> parameters) {
@@ -200,20 +201,18 @@ public class PersistentSessionImpl imple
/*
* clear cache
*/
-
- // int cacheSize = this.determineCacheSize(this.parameters);
- // if (cacheSize == -1) {
- // this.cache = CacheImpl.newInstance();
- // }
- // else {
- // this.cache = CacheImpl.newInstance(cacheSize);
- // }
- // PersistentSessionImpl.log.info("Session Cache Size: " + this.cache.size());
+ int cacheSize = this.determineCacheSize(this.parameters);
+ if (cacheSize == -1) {
+ this.cache = CacheImpl.newInstance();
+ }
+ else {
+ this.cache = CacheImpl.newInstance(cacheSize);
+ }
+ PersistentSessionImpl.log.info("Session Cache Size: " + this.cache.getCacheSize());
/*
- * clear repository info
+ * clear provider cache
*/
-
getProvider().clearAllCaches();
}
@@ -257,7 +256,7 @@ public class PersistentSessionImpl imple
List<Document> page = new ArrayList<Document>();
if (checkedOutDocs.getObjects() != null) {
for (ObjectData objectData : checkedOutDocs.getObjects()) {
- CmisObject doc = objectFactory.convertObject(objectData);
+ CmisObject doc = objectFactory.convertObject(objectData, ctxt);
if (!(doc instanceof Document)) {
// should not happen...
continue;
@@ -343,13 +342,34 @@ public class PersistentSessionImpl imple
if (objectId == null) {
throw new IllegalArgumentException("Object Id must be set!");
}
+ if (context == null) {
+ throw new IllegalArgumentException("Operation context must be set!");
+ }
+
+ CmisObject result = null;
+
+ // ask the cache first
+ if (context.isCacheEnabled()) {
+ result = this.cache.getById(objectId, context.getCacheKey());
+ if (result != null) {
+ return result;
+ }
+ }
+ // get the object
ObjectData objectData = this.provider.getObjectService().getObject(getRepositoryId(), objectId,
context.getFilterString(), context.isIncludeAllowableActions(),
context.getIncludeRelationships(), context.getRenditionFilterString(),
context.isIncludePolicies(), context.isIncludeAcls(), null);
- return getObjectFactory().convertObject(objectData);
+ result = getObjectFactory().convertObject(objectData, context);
+
+ // put into cache
+ if (context.isCacheEnabled()) {
+ this.cache.put(result, context.getCacheKey());
+ }
+
+ return result;
}
/*
@@ -371,13 +391,34 @@ public class PersistentSessionImpl imple
if (path == null) {
throw new IllegalArgumentException("Path must be set!");
}
+ if (context == null) {
+ throw new IllegalArgumentException("Operation context must be set!");
+ }
+
+ CmisObject result = null;
+ // ask the cache first
+ if (context.isCacheEnabled()) {
+ result = this.cache.getByPath(path, context.getCacheKey());
+ if (result != null) {
+ return result;
+ }
+ }
+
+ // get the object
ObjectData objectData = this.provider.getObjectService().getObjectByPath(getRepositoryId(),
path, context.getFilterString(), context.isIncludeAllowableActions(),
context.getIncludeRelationships(), context.getRenditionFilterString(),
context.isIncludePolicies(), context.isIncludeAcls(), null);
- return getObjectFactory().convertObject(objectData);
+ result = getObjectFactory().convertObject(objectData, context);
+
+ // put into cache
+ if (context.isCacheEnabled()) {
+ this.cache.putPath(path, result, context.getCacheKey());
+ }
+
+ return result;
}
public ObjectFactory getObjectFactory() {
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/QueryResultImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/QueryResultImpl.java?rev=920846&r1=920845&r2=920846&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/QueryResultImpl.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/QueryResultImpl.java Tue Mar 9 12:40:07 2010
@@ -79,7 +79,7 @@ public class QueryResultImpl implements
relationships = new ArrayList<Relationship>();
ObjectFactory of = session.getObjectFactory();
for (ObjectData rod : objectData.getRelationships()) {
- CmisObject relationship = of.convertObject(rod);
+ CmisObject relationship = of.convertObject(rod, session.getDefaultContext());
if (relationship instanceof Relationship) {
relationships.add((Relationship) relationship);
}
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/cache/Cache.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/cache/Cache.java?rev=920846&r1=920845&r2=920846&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/cache/Cache.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/cache/Cache.java Tue Mar 9 12:40:07 2010
@@ -18,31 +18,33 @@
*/
package org.apache.opencmis.client.runtime.cache;
-import java.util.List;
-
import org.apache.opencmis.client.api.CmisObject;
/**
* Implements a session cache providing following capabilities:
* <p>
- * <lu>
+ * <ul>
* <li>access CmisObject by object id</li>
* <li>access CmisObject by object path</li>
- * <li>access CmisObjects by paging parameter</li>
- * </lu>
+ * </ul>
*/
public interface Cache {
- boolean containsId(String objectId);
- boolean containsPath(String path);
+ boolean containsId(String objectId, String cacheKey);
+
+ boolean containsPath(String path, String cacheKey);
+
+ void put(CmisObject object, String cacheKey);
+
+ void putPath(String path, CmisObject object, String cacheKey);
+
+ CmisObject getById(String objectId, String cacheKey);
+
+ CmisObject getByPath(String path, String cacheKey);
+
+ void clear();
+
+ void resetPathCache();
- void put(CmisObject object);
- // public void put(List<CmisObject> pageRange, int pageNumber);
-
- CmisObject get(String objectId);
- CmisObject getByPath(String path);
- // public List<CmisObject> get(int pageNumber);
-
- void clear();
- int size();
+ int getCacheSize();
}
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/cache/CacheImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/cache/CacheImpl.java?rev=920846&r1=920845&r2=920846&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/cache/CacheImpl.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/cache/CacheImpl.java Tue Mar 9 12:40:07 2010
@@ -19,95 +19,216 @@
package org.apache.opencmis.client.runtime.cache;
import java.io.Serializable;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.opencmis.client.api.CmisObject;
+import org.apache.opencmis.commons.PropertyIds;
/**
- * Non synchronized cache implementation. The cache is limited to a specific
- * size of entries and works in a LRU mode
+ * Non synchronized cache implementation. The cache is limited to a specific size of entries and
+ * works in a LRU mode.
*/
public class CacheImpl implements Cache, Serializable {
- private LinkedHashMap<String, CmisObject> idMap = null;
- private LinkedHashMap<String, CmisObject> pathMap = null;
+ private static final long serialVersionUID = 1L;
- private static final float hashTableLoadFactor = 0.75f;
+ private static final float HASHTABLE_LOAD_FACTOR = 0.75f;
- private int cacheSize = 1000; // default
+ private int cacheSize;
- /**
- * serialization
- */
- private static final long serialVersionUID = 1978445442452564094L;
-
- public static Cache newInstance() {
- return new CacheImpl();
- }
-
- public static Cache newInstance(int cacheSize) {
- return new CacheImpl(cacheSize);
- }
-
- protected CacheImpl() {
- this.idMap = this.createLruCache();
- this.pathMap = this.createLruCache();
- }
-
- protected CacheImpl(int cacheSize) {
- this.cacheSize = cacheSize;
-
- this.idMap = this.createLruCache();
- this.pathMap = this.createLruCache();
- }
-
- private LinkedHashMap<String, CmisObject> createLruCache() {
- int hashTableCapacity = (int) Math
- .ceil(cacheSize / hashTableLoadFactor) + 1;
-
- LinkedHashMap<String, CmisObject> map = new LinkedHashMap<String, CmisObject>(
- hashTableCapacity, hashTableLoadFactor) {
-
- // (an anonymous inner class)
- private static final long serialVersionUID = -3928413932856712672L;
-
- @Override
- protected boolean removeEldestEntry(
- Map.Entry<String, CmisObject> eldest) {
- return size() > CacheImpl.this.cacheSize;
- }
- };
- return map;
- }
-
- public boolean containsId(String objectId) {
- return this.idMap.containsKey(objectId);
- }
-
- public void clear() {
- this.idMap.clear();
- this.pathMap.clear();
- }
-
- public boolean containsPath(String path) {
- return this.pathMap.containsKey(path);
- }
-
- public CmisObject get(String objectId) {
- return this.idMap.get(objectId);
- }
-
- public CmisObject getByPath(String path) {
- return this.pathMap.get(path);
- }
-
- public void put(CmisObject object) {
- this.idMap.put(object.getId(), object);
- }
-
- public int size() {
- return this.cacheSize;
- }
+ private LinkedHashMap<String, Map<String, CmisObject>> objectMap;
+ private Map<String, String> pathToIdMap;
+
+ /**
+ * Creates a new cache instance with a default size.
+ */
+ public static Cache newInstance() {
+ return new CacheImpl();
+ }
+
+ /**
+ * Creates a new cache instance with the given size.
+ */
+ public static Cache newInstance(int cacheSize) {
+ return new CacheImpl(cacheSize);
+ }
+
+ /**
+ * Default constructor.
+ */
+ protected CacheImpl() {
+ this(1000); // default cache size
+ }
+
+ /**
+ * Constructor taking a cache size.
+ */
+ protected CacheImpl(int cacheSize) {
+ this.cacheSize = cacheSize;
+ initialize();
+ }
+
+ /**
+ * Sets up the internal objects.
+ */
+ protected void initialize() {
+ int hashTableCapacity = (int) Math.ceil(cacheSize / HASHTABLE_LOAD_FACTOR) + 1;
+
+ final int cs = cacheSize;
+
+ objectMap = new LinkedHashMap<String, Map<String, CmisObject>>(hashTableCapacity,
+ HASHTABLE_LOAD_FACTOR) {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected boolean removeEldestEntry(Map.Entry<String, Map<String, CmisObject>> eldest) {
+ return size() > cs;
+ }
+ };
+
+ resetPathCache();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.runtime.cache.Cache#clear()
+ */
+ public void clear() {
+ initialize();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.runtime.cache.Cache#resetPathCache()
+ */
+ public void resetPathCache() {
+ pathToIdMap = new HashMap<String, String>();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.runtime.cache.Cache#containsId(java.lang.String,
+ * java.lang.String)
+ */
+ public boolean containsId(String objectId, String cacheKey) {
+ if (!objectMap.containsKey(objectId)) {
+ return false;
+ }
+
+ return objectMap.get(objectId).containsKey(cacheKey);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.runtime.cache.Cache#containsPath(java.lang.String,
+ * java.lang.String)
+ */
+ public boolean containsPath(String path, String cacheKey) {
+ if (!pathToIdMap.containsKey(path)) {
+ return false;
+ }
+
+ return containsId(pathToIdMap.get(path), cacheKey);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.runtime.cache.Cache#getById(java.lang.String, java.lang.String)
+ */
+ public CmisObject getById(String objectId, String cacheKey) {
+ Map<String, CmisObject> cacheKeyMap = objectMap.get(objectId);
+ if (cacheKeyMap == null) {
+ return null; // not found
+ }
+
+ return cacheKeyMap.get(cacheKey);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.runtime.cache.Cache#getByPath(java.lang.String,
+ * java.lang.String)
+ */
+ public CmisObject getByPath(String path, String cacheKey) {
+ String id = pathToIdMap.get(path);
+ if (id == null) {
+ return null; // not found
+ }
+
+ CmisObject object = getById(id, cacheKey);
+ if ((object == null) && (!objectMap.containsKey(id))) {
+ // clean up
+ pathToIdMap.remove(path);
+ }
+
+ return object;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.apache.opencmis.client.runtime.cache.Cache#put(org.apache.opencmis.client.api.CmisObject,
+ * java.lang.String)
+ */
+ public void put(CmisObject object, String cacheKey) {
+ // no object, no cache key - no cache
+ if ((object == null) || (cacheKey == null)) {
+ return;
+ }
+
+ // no id - no cache
+ if (object.getId() == null) {
+ return;
+ }
+
+ // get cache key map
+ Map<String, CmisObject> cacheKeyMap = objectMap.get(object.getId());
+ if (cacheKeyMap == null) {
+ cacheKeyMap = new HashMap<String, CmisObject>();
+ objectMap.put(object.getId(), cacheKeyMap);
+ }
+
+ // put into id cache
+ cacheKeyMap.put(cacheKey, object);
+
+ // folders may have a path, use it!
+ String path = object.getPropertyValue(PropertyIds.CMIS_PATH);
+ if (path != null) {
+ pathToIdMap.put(path, object.getId());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.runtime.cache.Cache#putPath(java.lang.String,
+ * org.apache.opencmis.client.api.CmisObject, java.lang.String)
+ */
+ public void putPath(String path, CmisObject object, String cacheKey) {
+ put(object, cacheKey);
+
+ if ((object != null) && (object.getId() != null) && (cacheKey != null)) {
+ pathToIdMap.put(path, object.getId());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.runtime.cache.Cache#getCacheSize()
+ */
+ public int getCacheSize() {
+ return this.cacheSize;
+ }
}
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java?rev=920846&r1=920845&r2=920846&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java Tue Mar 9 12:40:07 2010
@@ -29,6 +29,7 @@ import org.apache.opencmis.client.api.Cm
import org.apache.opencmis.client.api.ContentStream;
import org.apache.opencmis.client.api.Document;
import org.apache.opencmis.client.api.Folder;
+import org.apache.opencmis.client.api.OperationContext;
import org.apache.opencmis.client.api.Policy;
import org.apache.opencmis.client.api.Property;
import org.apache.opencmis.client.api.QueryResult;
@@ -120,7 +121,7 @@ public class PersistentObjectFactoryImpl
/**
* Converts object data into an API object.
*/
- public CmisObject convertObject(ObjectData objectData) {
+ public CmisObject convertObject(ObjectData objectData, OperationContext context) {
if (objectData == null) {
throw new IllegalArgumentException("Object data is null!");
}
@@ -130,13 +131,13 @@ public class PersistentObjectFactoryImpl
/* determine type */
switch (objectData.getBaseTypeId()) {
case CMIS_DOCUMENT:
- return new PersistentDocumentImpl(this.session, type, objectData);
+ return new PersistentDocumentImpl(this.session, type, objectData, context);
case CMIS_FOLDER:
- return new PersistentFolderImpl(this.session, type, objectData);
+ return new PersistentFolderImpl(this.session, type, objectData, context);
case CMIS_POLICY:
- return new PersistentPolicyImpl(this.session, type, objectData);
+ return new PersistentPolicyImpl(this.session, type, objectData, context);
case CMIS_RELATIONSHIP:
- return new PersistentRelationshipImpl(this.session, type, objectData);
+ return new PersistentRelationshipImpl(this.session, type, objectData, context);
default:
throw new CmisRuntimeException("unsupported type: " + objectData.getBaseTypeId());
}
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/misc/CacheTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/misc/CacheTest.java?rev=920846&r1=920845&r2=920846&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/misc/CacheTest.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/misc/CacheTest.java Tue Mar 9 12:40:07 2010
@@ -38,103 +38,108 @@ import com.sun.xml.ws.util.ByteArrayBuff
public class CacheTest {
- @Before
- public void setup() {
- }
-
- @Test
- public void cacheSingleObjectTest() {
- Cache cache = CacheImpl.newInstance();
-
- String id = "1";
- // String path = "/1";
-
- // add object
- CmisObject obj1 = this.createCmisObject(id);
- cache.put(obj1);
-
- // access object
- Assert.assertTrue(cache.containsId(id));
-
- // access object
- CmisObject obj2 = cache.get(id);
- Assert.assertEquals(obj1, obj2);
-
- // clear cache
- cache.clear();
-
- // access object (not found)
- Assert.assertFalse(cache.containsId(id));
-
- // access object (not found)
- CmisObject obj4 = cache.get(id);
- Assert.assertNull(obj4);
- }
-
- @Test
- public void cacheSizeTest() {
- int cacheSize = 50000;
- Cache cache = CacheImpl.newInstance(cacheSize);
- Assert.assertEquals(cacheSize, cache.size());
- }
-
- @Test
- public void lruTest() {
- int cacheSize = 3;
- Cache cache = CacheImpl.newInstance(cacheSize);
-
- for (int i = 0; i < cacheSize + 1; i++) {
- CmisObject obj = this.createCmisObject("id" + i);
- cache.put(obj);
- }
-
- Assert.assertNull(cache.get("id0")); // thrown out
- Assert.assertNotNull(cache.get("id1"));
- Assert.assertNotNull(cache.get("id2"));
- Assert.assertNotNull(cache.get("id3"));
- }
-
- @Test
- public void serializationTest() throws IOException, ClassNotFoundException {
- int cacheSize = 10;
- Cache cache = CacheImpl.newInstance(cacheSize);
-
- for (int i = 0; i < cacheSize; i++) {
- CmisObject obj = this.createCmisObject("id" + i);
- cache.put(obj);
- }
-
- ByteArrayBuffer buffer = new ByteArrayBuffer();
- ObjectOutputStream out = new ObjectOutputStream(buffer);
- out.writeObject(cache);
- out.close();
-
- ObjectInputStream in = new ObjectInputStream(buffer.newInputStream());
- Cache cache2 = (Cache) in.readObject();
- in.close();
-
- for (int k = 0; k < cacheSize; k++) {
- CmisObject o1 = cache.get("id" + k);
- CmisObject o2 = cache2.get("id" + k);
- Assert.assertEquals(o1.getId(), o2.getId());
- }
-
- }
-
- /**
- * Create a Mock for testing Cache is sufficient.
- *
- * @param id
- * @param path
- * @return a mocked object
- */
- private CmisObject createCmisObject(String id) {
- CmisObject obj = createNiceMock(CmisObject.class);
+ @Before
+ public void setup() {
+ }
+
+ @Test
+ public void cacheSingleObjectTest() {
+ Cache cache = CacheImpl.newInstance();
+
+ String id = "1";
+ // String path = "/1";
+ String cacheKey = "key";
+
+ // add object
+ CmisObject obj1 = this.createCmisObject(id);
+ cache.put(obj1, cacheKey);
+
+ // access object
+ Assert.assertTrue(cache.containsId(id, cacheKey));
+
+ // access object
+ CmisObject obj2 = cache.getById(id, cacheKey);
+ Assert.assertEquals(obj1, obj2);
+
+ // clear cache
+ cache.clear();
+
+ // access object (not found)
+ Assert.assertFalse(cache.containsId(id, cacheKey));
+
+ // access object (not found)
+ CmisObject obj4 = cache.getById(id, cacheKey);
+ Assert.assertNull(obj4);
+ }
+
+ @Test
+ public void cacheSizeTest() {
+ int cacheSize = 50000;
+ Cache cache = CacheImpl.newInstance(cacheSize);
+ Assert.assertEquals(cacheSize, cache.getCacheSize());
+ }
+
+ @Test
+ public void lruTest() {
+ int cacheSize = 3;
+ Cache cache = CacheImpl.newInstance(cacheSize);
+
+ String cacheKey = "key";
+
+ for (int i = 0; i < cacheSize + 1; i++) {
+ CmisObject obj = this.createCmisObject("id" + i);
+ cache.put(obj, cacheKey);
+ }
+
+ Assert.assertNull(cache.getById("id0", cacheKey)); // thrown out
+ Assert.assertNotNull(cache.getById("id1", cacheKey));
+ Assert.assertNotNull(cache.getById("id2", cacheKey));
+ Assert.assertNotNull(cache.getById("id3", cacheKey));
+ }
+
+ @Test
+ public void serializationTest() throws IOException, ClassNotFoundException {
+ int cacheSize = 10;
+ Cache cache = CacheImpl.newInstance(cacheSize);
+
+ String cacheKey = "key";
+
+ for (int i = 0; i < cacheSize; i++) {
+ CmisObject obj = this.createCmisObject("id" + i);
+ cache.put(obj, cacheKey);
+ }
+
+ ByteArrayBuffer buffer = new ByteArrayBuffer();
+ ObjectOutputStream out = new ObjectOutputStream(buffer);
+ out.writeObject(cache);
+ out.close();
+
+ ObjectInputStream in = new ObjectInputStream(buffer.newInputStream());
+ Cache cache2 = (Cache) in.readObject();
+ in.close();
+
+ for (int k = 0; k < cacheSize; k++) {
+ CmisObject o1 = cache.getById("id" + k, cacheKey);
+ CmisObject o2 = cache2.getById("id" + k, cacheKey);
+ Assert.assertEquals(o1.getId(), o2.getId());
+ }
+
+ }
+
+ /**
+ * Create a Mock for testing Cache is sufficient.
+ *
+ * @param id
+ * @param path
+ * @return a mocked object
+ */
+ private CmisObject createCmisObject(String id) {
+ CmisObject obj = createNiceMock(CmisObject.class);
- expect(obj.getId()).andReturn(id).anyTimes();
+ expect(obj.getId()).andReturn(id).anyTimes();
- replay(obj);
+ replay(obj);
- return obj;
- }
+ return obj;
+ }
}