Search in sources :

Example 6 with HtmlMaterialRevision

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

the class HtmlMaterialRevisionDAO method listByFileAndRevisionGtAndRevisonLeOrderedByRevision.

public List<HtmlMaterialRevision> listByFileAndRevisionGtAndRevisonLeOrderedByRevision(HtmlMaterial htmlMaterial, Long revisionGe, Long revisionLt) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<HtmlMaterialRevision> criteria = criteriaBuilder.createQuery(HtmlMaterialRevision.class);
    Root<HtmlMaterialRevision> root = criteria.from(HtmlMaterialRevision.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(HtmlMaterialRevision_.htmlMaterial), htmlMaterial), criteriaBuilder.greaterThan(root.get(HtmlMaterialRevision_.revision), revisionGe), criteriaBuilder.lessThanOrEqualTo(root.get(HtmlMaterialRevision_.revision), revisionLt)));
    criteria.orderBy(criteriaBuilder.asc(root.get(HtmlMaterialRevision_.revision)));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) HtmlMaterialRevision(fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevision)

Example 7 with HtmlMaterialRevision

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

the class HtmlMaterialRevisionDAO method listByFileAndRevisionGeAndRevisonLtOrderedByRevision.

public List<HtmlMaterialRevision> listByFileAndRevisionGeAndRevisonLtOrderedByRevision(HtmlMaterial htmlMaterial, Long revisionGe, Long revisionLt) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<HtmlMaterialRevision> criteria = criteriaBuilder.createQuery(HtmlMaterialRevision.class);
    Root<HtmlMaterialRevision> root = criteria.from(HtmlMaterialRevision.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(HtmlMaterialRevision_.htmlMaterial), htmlMaterial), criteriaBuilder.greaterThanOrEqualTo(root.get(HtmlMaterialRevision_.revision), revisionGe), criteriaBuilder.lessThan(root.get(HtmlMaterialRevision_.revision), revisionLt)));
    criteria.orderBy(criteriaBuilder.asc(root.get(HtmlMaterialRevision_.revision)));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) HtmlMaterialRevision(fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevision)

Example 8 with HtmlMaterialRevision

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

the class HtmlMaterialRevisionDAO method create.

public HtmlMaterialRevision create(HtmlMaterial htmlMaterial, String sessionId, Long revision, Date created, String data, String checksum) {
    HtmlMaterialRevision htmlMaterialRevision = new HtmlMaterialRevision();
    htmlMaterialRevision.setChecksum(checksum);
    htmlMaterialRevision.setCreated(created);
    htmlMaterialRevision.setData(data);
    htmlMaterialRevision.setFile(htmlMaterial);
    htmlMaterialRevision.setRevision(revision);
    htmlMaterialRevision.setSessionId(sessionId);
    return persist(htmlMaterialRevision);
}
Also used : HtmlMaterialRevision(fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevision)

Example 9 with HtmlMaterialRevision

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

the class HtmlMaterialRevisionDAO method maxRevisionByHtmlMaterial.

public Long maxRevisionByHtmlMaterial(HtmlMaterial htmlMaterial) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Long> criteria = criteriaBuilder.createQuery(Long.class);
    Root<HtmlMaterialRevision> root = criteria.from(HtmlMaterialRevision.class);
    criteria.select(criteriaBuilder.max(root.get(HtmlMaterialRevision_.revision)));
    criteria.where(criteriaBuilder.equal(root.get(HtmlMaterialRevision_.htmlMaterial), htmlMaterial));
    return entityManager.createQuery(criteria).getSingleResult();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) HtmlMaterialRevision(fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevision)

Example 10 with HtmlMaterialRevision

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

the class HtmlMaterialRevisionPropertyDAO method listKeysByHtmlMaterial.

public List<String> listKeysByHtmlMaterial(HtmlMaterial htmlMaterial) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<String> criteria = criteriaBuilder.createQuery(String.class);
    Root<HtmlMaterialRevisionProperty> root = criteria.from(HtmlMaterialRevisionProperty.class);
    Join<HtmlMaterialRevisionProperty, HtmlMaterialRevision> revisionJoin = root.join(HtmlMaterialRevisionProperty_.htmlMaterialRevision);
    criteria.select(root.get(HtmlMaterialRevisionProperty_.key)).distinct(true);
    criteria.where(criteriaBuilder.equal(revisionJoin.get(HtmlMaterialRevision_.htmlMaterial), htmlMaterial));
    return entityManager.createQuery(criteria).getResultList();
}
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)

Aggregations

HtmlMaterialRevision (fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevision)12 EntityManager (javax.persistence.EntityManager)7 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)7 HtmlMaterialRevisionProperty (fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionProperty)4 CoOpsUsageException (fi.foyt.coops.CoOpsUsageException)3 CoOpsConflictException (fi.foyt.coops.CoOpsConflictException)2 CoOpsInternalErrorException (fi.foyt.coops.CoOpsInternalErrorException)2 Patch (fi.foyt.coops.model.Patch)2 CoOpsDiffAlgorithm (fi.otavanopisto.muikku.plugins.material.coops.CoOpsDiffAlgorithm)2 CoOpsSession (fi.otavanopisto.muikku.plugins.material.coops.model.CoOpsSession)2 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)2 Date (java.util.Date)2 CoOpsNotFoundException (fi.foyt.coops.CoOpsNotFoundException)1 CoOpsPatchEvent (fi.otavanopisto.muikku.plugins.material.coops.event.CoOpsPatchEvent)1 HtmlMaterialRevisionExtensionProperty (fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionExtensionProperty)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1