Skip to content

Instantly share code, notes, and snippets.

@mlesikov
Created June 20, 2011 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlesikov/1035215 to your computer and use it in GitHub Desktop.
Save mlesikov/1035215 to your computer and use it in GitHub Desktop.
GWT request factory twig locator
/**
* Objects implementing this interface can be located by {@link TwigEntityLocator}.
*/
public interface Entity {
/**
* Gets object id.
*
* @return object id.
*/
Long getId();
/**
* Get version.
*
* @return version number.
*/
Integer getVersion();
}
public class TwigEntityLocator extends Locator<Entity, Long> {
private Provider<ObjectDatastore> datastore;
@Inject
public TwigEntityLocator(Provider<ObjectDatastore> datastore) {
this.datastore = datastore;
}
@Override
public Entity create(Class<? extends Entity> clazz) {
try {
return clazz.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
@Override
public Entity find(Class<? extends Entity> clazz, Long id) {
return datastore.get().load(clazz, id);
}
@Override
public Class<Entity> getDomainType() {
return Entity.class;
}
@Override
public Long getId(Entity domainObject) {
return domainObject.getId();
}
@Override
public Class<Long> getIdType() {
return Long.class;
}
@Override
public Integer getVersion(Entity domainObject) {
return domainObject.getVersion();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment