Author: fmui
Date: Tue Aug 25 10:28:20 2015
New Revision: 1697642
URL: http://svn.apache.org/r1697642
Log:
added Session.existsPath()
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionImpl.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/cache/Cache.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/cache/CacheImpl.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/cache/NoCacheImpl.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/CacheTest.java
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java?rev=1697642&r1=1697641&r2=1697642&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java
Tue Aug 25 10:28:20 2015
@@ -626,7 +626,7 @@ public interface Session extends Seriali
* If the object doesn't exist (anymore), it is removed from the cache.
*
* @param objectId
- * object ID
+ * the object ID
* @return {@code true} if the object exists in the repository,
* {@code false} otherwise
*
@@ -641,7 +641,7 @@ public interface Session extends Seriali
* If the object doesn't exist (anymore), it is removed from the cache.
*
* @param objectId
- * object ID
+ * the object ID
* @return {@code true} if the object exists in the repository,
* {@code false} otherwise
*
@@ -650,6 +650,41 @@ public interface Session extends Seriali
boolean exists(String objectId);
/**
+ * Checks if an object with given path exists in the repository and is
+ * visible for the current user.
+ *
+ * If the object doesn't exist (anymore), it is removed from the cache.
+ *
+ * @param path
+ * the path
+ * @return {@code true} if the object exists in the repository,
+ * {@code false} otherwise
+ *
+ * @cmis 1.0
+ */
+ boolean existsPath(String path);
+
+ /**
+ * Checks if an object with given path exists in the repository and is
+ * visible for the current user.
+ *
+ * If the object doesn't exist (anymore), it is removed from the cache.
+ *
+ * @param parentPath
+ * the path of the parent folder
+ * @param name
+ * the (path segment) name of the object in the folder
+ *
+ * @return the requested object
+ *
+ * @throws CmisObjectNotFoundException
+ * if an object with the given ID doesn't exist
+ *
+ * @cmis 1.0
+ */
+ boolean existsPath(String parentPath, String name);
+
+ /**
* Removes the given object from the cache.
*
* @param objectId
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionImpl.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionImpl.java?rev=1697642&r1=1697641&r2=1697642&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionImpl.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionImpl.java
Tue Aug 25 10:28:20 2015
@@ -546,9 +546,7 @@ public class SessionImpl implements Sess
@Override
public CmisObject getObjectByPath(String path, OperationContext context) {
- if (path == null) {
- throw new IllegalArgumentException("Path must be set!");
- }
+ checkPath(path);
checkContext(context);
CmisObject result = null;
@@ -715,6 +713,8 @@ public class SessionImpl implements Sess
@Override
public boolean exists(String objectId) {
+ checkObjectId(objectId);
+
try {
binding.getObjectService().getObject(getRepositoryId(), objectId,
"cmis:objectId", Boolean.FALSE,
IncludeRelationships.NONE, "cmis:none", Boolean.FALSE,
Boolean.FALSE, null);
@@ -726,6 +726,48 @@ public class SessionImpl implements Sess
}
@Override
+ public boolean existsPath(String path) {
+ checkPath(path);
+
+ try {
+ ObjectData object =
binding.getObjectService().getObjectByPath(getRepositoryId(), path,
"cmis:objectId",
+ Boolean.FALSE, IncludeRelationships.NONE, "cmis:none",
Boolean.FALSE, Boolean.FALSE, null);
+
+ String cacheObjectId = cache.getObjectIdByPath(path);
+ if (cacheObjectId != null &&
!cacheObjectId.equals(object.getId())) {
+ cache.removePath(path);
+ }
+
+ return true;
+ } catch (CmisObjectNotFoundException onf) {
+ cache.removePath(path);
+ return false;
+ }
+ }
+
+ @Override
+ public boolean existsPath(String parentPath, String name) {
+ if (parentPath == null || parentPath.length() < 1) {
+ throw new IllegalArgumentException("Parent path must be set!");
+ }
+ if (parentPath.charAt(0) != '/') {
+ throw new IllegalArgumentException("Parent path must start with a
'/'!");
+ }
+ if (name == null || name.length() < 1) {
+ throw new IllegalArgumentException("Name must be set!");
+ }
+
+ StringBuilder path = new StringBuilder(parentPath.length() +
name.length() + 2);
+ path.append(parentPath);
+ if (!parentPath.endsWith("/")) {
+ path.append('/');
+ }
+ path.append(name);
+
+ return existsPath(path.toString());
+ }
+
+ @Override
public void removeObjectFromCache(ObjectId objectId) {
checkObjectId(objectId);
removeObjectFromCache(objectId.getId());
@@ -1528,6 +1570,15 @@ public class SessionImpl implements Sess
}
}
+ protected final void checkPath(String path) {
+ if (path == null || path.length() < 1) {
+ throw new IllegalArgumentException("Invalid path!");
+ }
+ if (path.charAt(0) != '/') {
+ throw new IllegalArgumentException("Path must start with a '/'!");
+ }
+ }
+
protected final void checkContext(OperationContext context) {
if (context == null) {
throw new IllegalArgumentException("Invalid Operation Context!");
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/cache/Cache.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/cache/Cache.java?rev=1697642&r1=1697641&r2=1697642&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/cache/Cache.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/cache/Cache.java
Tue Aug 25 10:28:20 2015
@@ -28,7 +28,7 @@ import org.apache.chemistry.opencmis.cli
* Implements a session cache providing following capabilities:
* <p>
* <ul>
- * <li>access CmisObject by object id</li>
+ * <li>access CmisObject by object object ID</li>
* <li>access CmisObject by object path</li>
* </ul>
*/
@@ -48,8 +48,12 @@ public interface Cache extends Serializa
CmisObject getByPath(String path, String cacheKey);
+ String getObjectIdByPath(String path);
+
void remove(String objectId);
+ void removePath(String path);
+
void clear();
int getCacheSize();
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/cache/CacheImpl.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/cache/CacheImpl.java?rev=1697642&r1=1697641&r2=1697642&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/cache/CacheImpl.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/cache/CacheImpl.java
Tue Aug 25 10:28:20 2015
@@ -229,6 +229,25 @@ public class CacheImpl implements Cache
}
@Override
+ public String getObjectIdByPath(String path) {
+ lock.writeLock().lock();
+ try {
+ CacheItem<String> item = pathToIdMap.get(path);
+ if (item == null) {
+ return null;
+ }
+ if (item.isExpired()) {
+ pathToIdMap.remove(path);
+ return null;
+ }
+
+ return item.getItem();
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+
+ @Override
public void put(CmisObject object, String cacheKey) {
// no object, no cache key - no cache
if ((object == null) || (cacheKey == null)) {
@@ -295,6 +314,20 @@ public class CacheImpl implements Cache
} finally {
lock.writeLock().unlock();
}
+ }
+
+ @Override
+ public void removePath(String path) {
+ if (path == null) {
+ return;
+ }
+
+ lock.writeLock().lock();
+ try {
+ pathToIdMap.remove(path);
+ } finally {
+ lock.writeLock().unlock();
+ }
}
@Override
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/cache/NoCacheImpl.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/cache/NoCacheImpl.java?rev=1697642&r1=1697641&r2=1697642&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/cache/NoCacheImpl.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/cache/NoCacheImpl.java
Tue Aug 25 10:28:20 2015
@@ -60,10 +60,19 @@ public class NoCacheImpl implements Cach
}
@Override
+ public String getObjectIdByPath(String path) {
+ return null;
+ }
+
+ @Override
public void remove(String objectId) {
}
@Override
+ public void removePath(String path) {
+ }
+
+ @Override
public void clear() {
}
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/CacheTest.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/CacheTest.java?rev=1697642&r1=1697641&r2=1697642&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/CacheTest.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/CacheTest.java
Tue Aug 25 10:28:20 2015
@@ -75,6 +75,49 @@ public class CacheTest {
}
@Test
+ public void cachePathObjectTest() {
+ Cache cache = createCache(100, 3600 * 1000);
+
+ String id = "1";
+ String path = "/1";
+ String cacheKey = "key";
+
+ // add object
+ CmisObject obj1 = createCmisObject(id);
+ cache.putPath(path, obj1, cacheKey);
+
+ // access object
+ assertTrue(cache.containsPath(path, cacheKey));
+
+ // access object
+ CmisObject obj2 = cache.getById(id, cacheKey);
+ assertEquals(obj1, obj2);
+
+ // access object
+ CmisObject obj3 = cache.getByPath(path, cacheKey);
+ assertEquals(obj1, obj3);
+
+ // access ID
+ String chachedId = cache.getObjectIdByPath(path);
+ assertEquals(obj1.getId(), chachedId);
+
+ // remove
+ cache.removePath(path);
+ assertNull(cache.getObjectIdByPath(path));
+ assertFalse(cache.containsPath(path, cacheKey));
+
+ // clear cache
+ cache.clear();
+
+ // access object (not found)
+ assertFalse(cache.containsId(id, cacheKey));
+
+ // access object (not found)
+ CmisObject obj4 = cache.getById(id, cacheKey);
+ assertNull(obj4);
+ }
+
+ @Test
public void cacheSizeTest() {
int cacheSize = 50000;
Cache cache = createCache(cacheSize, 3600 * 1000);