Hello,
I am writing a request factory sample in gwt 2.3, for this sample i
want to write a generic entity locator. I've read David Chandler's
sample
http://turbomanage.wordpress.com/2011/03/25/using-gwt-requestfactory-with-objectify/
but David is using ObjectifyLocator with google app engine.
// David's generic ObjectifyLocator.java
/**
* Generic @Locator for objects that extend DatastoreObject
*/
public class ObjectifyLocator extends Locator<DatastoreObject, Long>
{
@Override
public DatastoreObject create(Class<? extends DatastoreObject> clazz)
{
try
{
return clazz.newInstance();
} catch (InstantiationException e)
{
throw new RuntimeException(e);
} catch (IllegalAccessException e)
{
throw new RuntimeException(e);
}
}
@Override
public DatastoreObject find(Class<? extends DatastoreObject> clazz,
Long id)
{
DAOBase daoBase = new DAOBase();
return daoBase.ofy().find(clazz, id);
}
@Override
public Class<DatastoreObject> getDomainType()
{
// Never called
return null;
}
@Override
public Long getId(DatastoreObject domainObject)
{
return domainObject.getId();
}
@Override
public Class<Long> getIdType()
{
return Long.class;
}
@Override
public Object getVersion(DatastoreObject domainObject)
{
return domainObject.getVersion();
}
}
My Classes :
Base entity : getId, getVersion etc. (base class for all entities)
Category : entity
CategoryLocator : locator class
CategoryProxy : DTO Proxy for Category entity.
// CategoryLocator
public class CategoryLocator extends Locator<Category, Long> {
@Override
public Category create(Class<? extends Category> clazz) {
return new Category();
}
@Override
public Category find(Class<? extends Category> clazz, Long id) {
return getCategoryDAO().findById(id);
}
private CategoryDao getCategoryDAO() {
return new CategoryDao();
}
@Override
public Class<Category> getDomainType() {
return Category.class;
}
@Override
public Long getId(Category domainObject) {
return domainObject.getId();
}
@Override
public Class<Long> getIdType() {
return Long.class;
}
@Override
public Object getVersion(Category domainObject) {
return domainObject.getVersion();
}
}
// CategoryProxy
@ProxyFor(value = Category.class, locator = CategoryLocator.class)
public interface CategoryProxy extends EntityProxy {
Long getId();
String getName();
void setName(String name);
}
How can i write only a generic entity locator class for my all proxy
classes such as ObjectifyLocator.class without google app engine
structure?
Thanks,
Cem.