Search in sources :

Example 6 with HtmlMaterialRevisionProperty

use of fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionProperty in project muikku by otavanopisto.

the class HtmlMaterialRevisionPropertyDAO method findByHtmlMaterialAndKeyRevisionLeAndMaxRevision.

public HtmlMaterialRevisionProperty findByHtmlMaterialAndKeyRevisionLeAndMaxRevision(HtmlMaterial htmlMaterial, String key, Long revisionLe) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<HtmlMaterialRevisionProperty> criteria = criteriaBuilder.createQuery(HtmlMaterialRevisionProperty.class);
    Root<HtmlMaterialRevisionProperty> root = criteria.from(HtmlMaterialRevisionProperty.class);
    Join<HtmlMaterialRevisionProperty, HtmlMaterialRevision> revisionJoin = root.join(HtmlMaterialRevisionProperty_.htmlMaterialRevision);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(HtmlMaterialRevisionProperty_.key), key), criteriaBuilder.equal(revisionJoin.get(HtmlMaterialRevision_.htmlMaterial), htmlMaterial), criteriaBuilder.lessThanOrEqualTo(revisionJoin.get(HtmlMaterialRevision_.revision), revisionLe)));
    // TODO: This could be optimized
    criteria.orderBy(criteriaBuilder.desc(revisionJoin.get(HtmlMaterialRevision_.revision)));
    TypedQuery<HtmlMaterialRevisionProperty> query = entityManager.createQuery(criteria);
    query.setMaxResults(1);
    return getSingleResult(query);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) HtmlMaterialRevision(fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevision) HtmlMaterialRevisionProperty(fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionProperty)

Example 7 with HtmlMaterialRevisionProperty

use of fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionProperty in project muikku by otavanopisto.

the class HtmlMaterialRevisionPropertyDAO method create.

public HtmlMaterialRevisionProperty create(HtmlMaterialRevision htmlMaterialRevision, String key, String value) {
    HtmlMaterialRevisionProperty htmlMaterialRevisionProperty = new HtmlMaterialRevisionProperty();
    htmlMaterialRevisionProperty.setFileRevision(htmlMaterialRevision);
    htmlMaterialRevisionProperty.setValue(value);
    htmlMaterialRevisionProperty.setKey(key);
    return persist(htmlMaterialRevisionProperty);
}
Also used : HtmlMaterialRevisionProperty(fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionProperty)

Aggregations

HtmlMaterialRevisionProperty (fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionProperty)7 HtmlMaterialRevision (fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevision)4 EntityManager (javax.persistence.EntityManager)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 HtmlMaterialRevisionExtensionProperty (fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionExtensionProperty)2 CoOpsNotFoundException (fi.foyt.coops.CoOpsNotFoundException)1 CoOpsUsageException (fi.foyt.coops.CoOpsUsageException)1 Patch (fi.foyt.coops.model.Patch)1 CoOpsSession (fi.otavanopisto.muikku.plugins.material.coops.model.CoOpsSession)1 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)1 ArrayList (java.util.ArrayList)1