Skip to content

Instantly share code, notes, and snippets.

@dagvadorj
Created January 19, 2013 10:59
Show Gist options
  • Save dagvadorj/4572029 to your computer and use it in GitHub Desktop.
Save dagvadorj/4572029 to your computer and use it in GitHub Desktop.
/**
* 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