Hi All,

I have an issue with caching a list of "almost static" EntityProxies on the 
client side. 

First I checked the possibility to mark the url as "cachable" but since 
RequestFactory urls are generated by GWT, it seamed too complicated to do.

I then decided to cache the EntityProxies in cookies. Saving to JSON was 
ok, relaoding was a little tricky since I didn't get the point of all 
methods declared in EntityProxyCategory (see the code below).

Finally things almost work but when I do a request, I receive a *SEVERE: 
Server Error 413* (which is thrown by the servlet before processing the 
request)

here's my code

@Category(LocalEntityProxyCategory.class)
protected interface CateoriesForCookieHolderFactory extends AutoBeanFactory 
{
AutoBean<CategoriesForCookieHolder> categoriesForCookieHolder();

AutoBean<CategoryProxy> category();

AutoBean<ContextDynamicFieldProxy> contextDynamicFieldProxy();
}

public static class LocalEntityProxyCategory {
/**
 * EntityProxies are equal if they are from the same RequestContext and
 * their stableIds are equal.
 */
public static boolean equals(AutoBean<? extends EntityProxy> bean, Object 
o) {
if (!(o instanceof EntityProxy)) {
return false;
}
AutoBean<EntityProxy> other = AutoBeanUtils.getAutoBean((EntityProxy) o);
if (other == null) {
// Unexpected, could be an user-provided implementation?
return false;
}

// Object comparison intentional. True if both null or both the same
return stableId(bean).equals(stableId(other))
&& nonDiffingRequestContext(bean) == nonDiffingRequestContext(other);
}

/**
 * Hashcode is always that of the stableId, since it's stable across time.
 */
public static int hashCode(AutoBean<? extends EntityProxy> bean) {
return stableId(bean).hashCode();
}

/**
 * Effectively overrides {@link BaseProxyCategory#stableId(AutoBean)} to
 * return a narrower bound.
 */
public static <T extends EntityProxy> EntityProxyId<T> stableId(
final AutoBean<? extends T> bean) {
return new SimpleProxyId<T>(bean);
}

private static AbstractRequestContext nonDiffingRequestContext(
AutoBean<?> bean) {
AbstractRequestContext context = requestContext(bean);

return context;
}
}

public class SimpleProxyId<T extends EntityProxy> implements 
EntityProxyId<T> {
long id;
Class<T> clazz;

@SuppressWarnings("unchecked")
public SimpleProxyId(AutoBean<? extends T> bean) {
BasicProxy proxy = (BasicProxy) bean.as();
id = proxy.getId();
clazz = (Class<T>) proxy.getClass();
}

@Override
public Class<T> getProxyClass() {
return clazz;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((clazz == null) ? 0 : clazz.hashCode());
result = prime * result + (int) (id ^ (id >>> 32));
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SimpleProxyId other = (SimpleProxyId) obj;
if (clazz == null) {
if (other.clazz != null)
return false;
} else if (!clazz.equals(other.clazz))
return false;
if (id != other.id)
return false;
return true;
}
}

I think it is too complicated to do such caching (for what it is, maybe, it 
could be a good idea to include a mechanism either for url resource caching 
or for EntityProxy json read and write)

Best Regards,
Zied Hamdi
http://1vu.fr

-- 
-- 
http://groups.google.com/group/Google-Web-Toolkit-Contributors
--- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to