Created
January 19, 2013 10:59
-
-
Save dagvadorj/4572029 to your computer and use it in GitHub Desktop.
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
/** | |
* Service facade for entities with revisions | |
* | |
* @author Dagvadorj Galbadrakh | |
*/ | |
@Stateless | |
public class RevisionBean implements RevisionBeanRemote { | |
@EJB | |
private EntityBeanRemote entityBean; | |
@Override | |
public <T extends RevisionModel> void deleteRevision(T entity) { | |
entityBean.delete(entity); | |
} | |
@SuppressWarnings("unchecked") | |
@Override | |
public <T extends RevisionModel, V extends RevisableModel<T>> T getRevision( | |
V entity, Date revisionDate) throws IllegalArgumentException { | |
List<T> results = entityBean | |
.getEm() | |
.createQuery( | |
"select r from " | |
+ entity.getClass().getSimpleName() | |
+ " o join o.revisions r where o=?1 and r.effectiveDate <= ?2 order by r.effectiveDate desc") | |
.setParameter(1, entity).setParameter(2, revisionDate) | |
.getResultList(); | |
if (results.isEmpty()) | |
throw new IllegalArgumentException("No revision this early!"); | |
else | |
return results.get(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment