r7008 - in dumbhippo/trunk/server/src/com/dumbhippo/dm: annotations schema store
- From: commits mugshot org
- To: online-desktop-list gnome org
- Subject: r7008 - in dumbhippo/trunk/server/src/com/dumbhippo/dm: annotations schema store
- Date: Mon, 10 Dec 2007 17:09:26 -0600 (CST)
Author: otaylor
Date: 2007-12-10 17:09:26 -0600 (Mon, 10 Dec 2007)
New Revision: 7008
Modified:
dumbhippo/trunk/server/src/com/dumbhippo/dm/annotations/PropertyType.java
dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/DMClassHolder.java
dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/DMPropertyHolder.java
dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/PlainPropertyHolder.java
dumbhippo/trunk/server/src/com/dumbhippo/dm/store/StoreKey.java
dumbhippo/trunk/server/src/com/dumbhippo/dm/store/StoreNode.java
Log:
PropertyType DMClassHolder DMPropertyHolder PlainPropertyHolder: Allow
data model properties of type StoreKey. They don't do anything useful
on the wire, but they are useful substitute for a resource property
of type DMObject<?> (which isn't allowed) when we want to cache
"some resource" and use it for visibility checks
StoreNode StoreKey: Make StoreKey cloneable
Modified: dumbhippo/trunk/server/src/com/dumbhippo/dm/annotations/PropertyType.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/dm/annotations/PropertyType.java 2007-12-10 23:02:38 UTC (rev 7007)
+++ dumbhippo/trunk/server/src/com/dumbhippo/dm/annotations/PropertyType.java 2007-12-10 23:09:26 UTC (rev 7008)
@@ -9,7 +9,8 @@
STRING('s'),
RESOURCE('r'),
FEED('f'),
- URL('u');
+ URL('u'),
+ STORE_KEY('s'); // This one would not normally be sent over the wire; it's useful internally
private char typeChar;
Modified: dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/DMClassHolder.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/DMClassHolder.java 2007-12-10 23:02:38 UTC (rev 7007)
+++ dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/DMClassHolder.java 2007-12-10 23:09:26 UTC (rev 7008)
@@ -152,6 +152,9 @@
DMFilter filterAnnotation = dmoClass.getAnnotation(DMFilter.class);
if (filterAnnotation != null) {
+ if (baseClassHolder != null)
+ throw new RuntimeException(dmoClass.getName() + ": @DMFilter annotation must be specified on the base class");
+
try {
filter = FilterParser.parse(filterAnnotation.value());
} catch (com.dumbhippo.dm.parser.ParseException e) {
Modified: dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/DMPropertyHolder.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/DMPropertyHolder.java 2007-12-10 23:02:38 UTC (rev 7007)
+++ dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/DMPropertyHolder.java 2007-12-10 23:09:26 UTC (rev 7008)
@@ -37,6 +37,7 @@
import com.dumbhippo.dm.parser.FilterParser;
import com.dumbhippo.dm.parser.ParseException;
import com.dumbhippo.dm.schema.PropertyInfo.ContainerType;
+import com.dumbhippo.dm.store.StoreKey;
public abstract class DMPropertyHolder<K, T extends DMObject<K>, TI> implements Comparable<DMPropertyHolder<?,?,?>> {
@SuppressWarnings("unused")
@@ -380,7 +381,8 @@
ContainerType containerType = ContainerType.SINGLE;
Class<?> elementType;
- if (genericType instanceof ParameterizedType) {
+ // We handle StoreKey as a PlainType
+ if (genericType instanceof ParameterizedType && method.getReturnType() != StoreKey.class) {
ParameterizedType paramType = (ParameterizedType)genericType;
Class<?> rawType = (Class<?>)paramType.getRawType();
if (rawType == List.class)
@@ -411,10 +413,10 @@
if (elementClassInfo != null) {
propertyInfo = createResourcePropertyInfo(declaringType, keyType, elementClassInfo);
- } else if (elementType.isPrimitive() || (genericElementType == String.class) || (genericElementType == Date.class)) {
+ } else if (elementType.isPrimitive() || (elementType == String.class) || (elementType == StoreKey.class) || (elementType == Date.class)) {
propertyInfo = createPropertyInfo(declaringType, keyType, elementType);
} else {
- throw new RuntimeException("Property type must be DMObject, primitive, Date, or String");
+ throw new RuntimeException("Property type must be DMObject, primitive, Date, String, or StoreKey");
}
propertyInfo.setModel(model);
Modified: dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/PlainPropertyHolder.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/PlainPropertyHolder.java 2007-12-10 23:02:38 UTC (rev 7007)
+++ dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/PlainPropertyHolder.java 2007-12-10 23:09:26 UTC (rev 7008)
@@ -10,6 +10,7 @@
import com.dumbhippo.dm.fetch.FetchVisitor;
import com.dumbhippo.dm.filter.CompiledItemFilter;
import com.dumbhippo.dm.filter.FilterCompiler;
+import com.dumbhippo.dm.store.StoreKey;
public abstract class PlainPropertyHolder<K,T extends DMObject<K>, TI> extends DMPropertyHolder<K,T,TI> {
protected CompiledItemFilter<K,T,Object,DMObject<Object>> itemFilter;
@@ -42,6 +43,8 @@
} else {
if (elementType == String.class)
derivedType = PropertyType.STRING;
+ else if (elementType == StoreKey.class)
+ derivedType = PropertyType.STORE_KEY;
else
throw new RuntimeException("Unexpected type" + elementType);
}
@@ -64,6 +67,10 @@
if (derivedType != PropertyType.STRING)
throw new RuntimeException("PropertyType.URL for non-string property");
break;
+ case STORE_KEY:
+ if (derivedType != PropertyType.STORE_KEY)
+ throw new RuntimeException("PropertyType.STORE_KEY for non-store-key property");
+ break;
case RESOURCE:
throw new RuntimeException("PropertyType.RESOURCE for non-resource property");
case FEED:
@@ -85,7 +92,10 @@
@Override
public Object dehydrate(Object value) {
- return value;
+ if (propertyType == PropertyType.STORE_KEY)
+ return ((StoreKey)value).clone();
+ else
+ return value;
}
@Override
Modified: dumbhippo/trunk/server/src/com/dumbhippo/dm/store/StoreKey.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/dm/store/StoreKey.java 2007-12-10 23:02:38 UTC (rev 7007)
+++ dumbhippo/trunk/server/src/com/dumbhippo/dm/store/StoreKey.java 2007-12-10 23:09:26 UTC (rev 7008)
@@ -1,9 +1,12 @@
package com.dumbhippo.dm.store;
+import com.dumbhippo.dm.DMKey;
import com.dumbhippo.dm.DMObject;
+import com.dumbhippo.dm.DMViewpoint;
+import com.dumbhippo.dm.filter.CompiledFilter;
import com.dumbhippo.dm.schema.DMClassHolder;
-public class StoreKey<K,T extends DMObject<K>> {
+public class StoreKey<K,T extends DMObject<K>> implements Cloneable {
protected DMClassHolder<K,T> classHolder;
protected K key;
@@ -24,7 +27,29 @@
return classHolder;
}
+ public boolean isVisible(DMViewpoint viewpoint) {
+ CompiledFilter<K,T> filter = classHolder.getFilter();
+ if (filter != null)
+ return filter.filterKey(viewpoint, key) != null;
+ else
+ return true;
+ }
+
@Override
+ public StoreKey<K,T> clone() {
+ if (key instanceof DMKey) {
+ @SuppressWarnings("unchecked")
+ K clonedKey = (K)((DMKey)key).clone();
+ if (clonedKey == key)
+ return this;
+ else
+ return new StoreKey<K,T>(classHolder, clonedKey);
+ } else {
+ return this;
+ }
+ }
+
+ @Override
public boolean equals(Object o) {
if (!(o instanceof StoreKey))
return false;
Modified: dumbhippo/trunk/server/src/com/dumbhippo/dm/store/StoreNode.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/dm/store/StoreNode.java 2007-12-10 23:02:38 UTC (rev 7007)
+++ dumbhippo/trunk/server/src/com/dumbhippo/dm/store/StoreNode.java 2007-12-10 23:09:26 UTC (rev 7008)
@@ -11,6 +11,7 @@
import com.dumbhippo.dm.CachedFeed;
import com.dumbhippo.dm.ClientMatcher;
import com.dumbhippo.dm.ClientNotificationSet;
+import com.dumbhippo.dm.DMKey;
import com.dumbhippo.dm.DMObject;
import com.dumbhippo.dm.NotCachedException;
import com.dumbhippo.dm.schema.DMClassHolder;
@@ -155,4 +156,18 @@
else
return feedLogs[feedPropertyIndex];
}
+
+ // Returning a StoreKey rather than a StoreNode is perhaps a little dubious, but we want cloning
+ // a StoreKey to give us something we can store in the cache (for properties of type StoreKey)
+ @Override
+ public StoreKey<K,T> clone() {
+ if (key instanceof DMKey) {
+ @SuppressWarnings("unchecked")
+ K clonedKey = (K)((DMKey)key).clone();
+ return new StoreKey<K,T>(classHolder, clonedKey);
+ } else {
+ return new StoreKey<K,T>(classHolder, key);
+ }
+ }
+
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]