Created
June 20, 2011 06:41
-
-
Save mlesikov/1035215 to your computer and use it in GitHub Desktop.
GWT request factory twig locator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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