Author: fmui
Date: Mon Jul 23 15:16:34 2012
New Revision: 1364672
URL: http://svn.apache.org/viewvc?rev=1364672&view=rev
Log:
Browser Binding server optimization
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/server/TypeCacheImpl.java
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.java?rev=1364672&r1=1364671&r2=1364672&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.java
Mon Jul 23 15:16:34 2012
@@ -33,6 +33,7 @@ import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
+import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.data.Ace;
import org.apache.chemistry.opencmis.commons.data.Acl;
import org.apache.chemistry.opencmis.commons.data.AclCapabilities;
@@ -904,14 +905,25 @@ public class JSONConverter {
return null;
}
- JSONObject result = new JSONObject();
+ // get the type
+ TypeDefinition type = null;
+ if (typeCache != null) {
+ PropertyData<?> typeProp =
properties.getProperties().get(PropertyIds.OBJECT_TYPE_ID);
+ if (typeProp instanceof PropertyId) {
+ String typeId = ((PropertyId) typeProp).getFirstValue();
+ if (typeId != null) {
+ type = typeCache.getTypeDefinition(typeId);
+ }
+ }
- for (PropertyData<?> property : properties.getPropertyList()) {
- TypeDefinition type = null;
- if (typeCache != null) {
+ if (type == null) {
type = typeCache.getTypeDefinitionForObject(objectId);
}
+ }
+
+ JSONObject result = new JSONObject();
+ for (PropertyData<?> property : properties.getPropertyList()) {
PropertyDefinition<?> propDef = null;
if (type != null) {
propDef = type.getPropertyDefinitions().get(property.getId());
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/server/TypeCacheImpl.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/server/TypeCacheImpl.java?rev=1364672&r1=1364671&r2=1364672&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/server/TypeCacheImpl.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/server/TypeCacheImpl.java
Mon Jul 23 15:16:34 2012
@@ -21,44 +21,64 @@ package org.apache.chemistry.opencmis.co
import java.util.HashMap;
import java.util.Map;
+import org.apache.chemistry.opencmis.commons.PropertyIds;
+import org.apache.chemistry.opencmis.commons.data.ObjectData;
+import org.apache.chemistry.opencmis.commons.data.PropertyData;
+import org.apache.chemistry.opencmis.commons.data.PropertyId;
import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
+import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
import org.apache.chemistry.opencmis.commons.impl.TypeCache;
import org.apache.chemistry.opencmis.commons.server.CmisService;
-import org.apache.chemistry.opencmis.commons.server.ObjectInfo;
/**
* Temporary type cache used for one call.
*/
public class TypeCacheImpl implements TypeCache {
- private final String repositoryId;
- private final CmisService service;
- private final Map<String, TypeDefinition> typeDefinitions;
-
- public TypeCacheImpl(String repositoryId, CmisService service) {
- this.repositoryId = repositoryId;
- this.service = service;
- typeDefinitions = new HashMap<String, TypeDefinition>();
- }
-
- public TypeDefinition getTypeDefinition(String typeId) {
- TypeDefinition type = typeDefinitions.get(typeId);
- if (type == null) {
- type = service.getTypeDefinition(repositoryId, typeId,
null);
- if (type != null) {
- typeDefinitions.put(type.getId(), type);
- }
- }
-
- return type;
- }
-
- public TypeDefinition getTypeDefinitionForObject(String objectId) {
- ObjectInfo info = service.getObjectInfo(repositoryId, objectId);
- if (info == null) {
- return null;
- }
+ private final String repositoryId;
+ private final CmisService service;
+ private final Map<String, TypeDefinition> typeDefinitions;
+ private final Map<String, TypeDefinition> objectToTypeDefinitions;
+
+ public TypeCacheImpl(String repositoryId, CmisService service) {
+ this.repositoryId = repositoryId;
+ this.service = service;
+ typeDefinitions = new HashMap<String, TypeDefinition>();
+ objectToTypeDefinitions = new HashMap<String, TypeDefinition>();
+ }
+
+ public TypeDefinition getTypeDefinition(String typeId) {
+ TypeDefinition type = typeDefinitions.get(typeId);
+ if (type == null) {
+ type = service.getTypeDefinition(repositoryId, typeId, null);
+ if (type != null) {
+ typeDefinitions.put(type.getId(), type);
+ }
+ }
+
+ return type;
+ }
+
+ public TypeDefinition getTypeDefinitionForObject(String objectId) {
+ TypeDefinition type = objectToTypeDefinitions.get(objectId);
+ if (type == null) {
+ ObjectData obj = service.getObject(repositoryId, objectId,
+ "cmis:objectId,cmis:objectTypeId,cmis:baseTypeId", false,
IncludeRelationships.NONE, "cmis:none",
+ false, false, null);
+
+ if (obj != null && obj.getProperties() != null) {
+ PropertyData<?> typeProp =
obj.getProperties().getProperties().get(PropertyIds.OBJECT_TYPE_ID);
+ if (typeProp instanceof PropertyId) {
+ String typeId = ((PropertyId) typeProp).getFirstValue();
+ if (typeId != null) {
+ type = getTypeDefinition(typeId);
+ }
+ }
+ }
- return getTypeDefinition(info.getTypeId());
- }
+ objectToTypeDefinitions.put(objectId, type);
+ }
+
+ return type;
+ }
}