Search in sources :

Example 56 with Criteria

use of org.hibernate.Criteria in project API by ca-cwds.

the class ScreeningService method findByCriteria.

@SuppressWarnings("unchecked")
public List<gov.ca.cwds.data.persistence.ns.Screening> findByCriteria(Serializable keys) {
    Map<String, String> nameValuePairs = ServiceUtils.extractKeyValuePairs(keys);
    String responseTimes = nameValuePairs.get("responseTimes");
    String screeningDecisions = nameValuePairs.get("screeningDecisions");
    Session session = screeningDao.getSessionFactory().getCurrentSession();
    Criteria criteria = session.createCriteria(gov.ca.cwds.data.persistence.ns.Screening.class);
    if (StringUtils.isNotEmpty(responseTimes) && !responseTimes.equals("null")) {
        criteria.add(Restrictions.like("responseTime", responseTimes));
    }
    if (StringUtils.isNotEmpty(screeningDecisions) && !screeningDecisions.equals("null")) {
        criteria.add(Restrictions.like("screeningDecision", screeningDecisions));
    }
    return criteria.list();
}
Also used : Restrictions(org.hibernate.criterion.Restrictions) Criteria(org.hibernate.Criteria) Session(org.hibernate.Session)

Example 57 with Criteria

use of org.hibernate.Criteria in project midpoint by Evolveum.

the class ObjectUpdater method deleteObjectAttempt.

public <T extends ObjectType> void deleteObjectAttempt(Class<T> type, String oid, OperationResult result) throws ObjectNotFoundException {
    LOGGER_PERFORMANCE.debug("> delete object {}, oid={}", new Object[] { type.getSimpleName(), oid });
    Session session = null;
    OrgClosureManager.Context closureContext = null;
    try {
        session = baseHelper.beginTransaction();
        closureContext = closureManager.onBeginTransactionDelete(session, type, oid);
        Criteria query = session.createCriteria(ClassMapper.getHQLTypeClass(type));
        query.add(Restrictions.eq("oid", oid));
        RObject object = (RObject) query.uniqueResult();
        if (object == null) {
            throw new ObjectNotFoundException("Object of type '" + type.getSimpleName() + "' with oid '" + oid + "' was not found.", null, oid);
        }
        closureManager.updateOrgClosure(null, null, session, oid, type, OrgClosureManager.Operation.DELETE, closureContext);
        session.delete(object);
        if (LookupTableType.class.equals(type)) {
            lookupTableHelper.deleteLookupTableRows(session, oid);
        }
        if (AccessCertificationCampaignType.class.equals(type)) {
            caseHelper.deleteCertificationCampaignCases(session, oid);
        }
        session.getTransaction().commit();
    } catch (ObjectNotFoundException ex) {
        baseHelper.rollbackTransaction(session, ex, result, true);
        throw ex;
    } catch (RuntimeException ex) {
        baseHelper.handleGeneralException(ex, session, result);
    } finally {
        cleanupClosureAndSessionAndResult(closureContext, session, result);
    }
}
Also used : RObject(com.evolveum.midpoint.repo.sql.data.common.RObject) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Criteria(org.hibernate.Criteria) Session(org.hibernate.Session)

Example 58 with Criteria

use of org.hibernate.Criteria in project midpoint by Evolveum.

the class CertificationCaseHelper method updateLoadedCampaign.

// adds cases to campaign if requested by options
public <T extends ObjectType> void updateLoadedCampaign(PrismObject<T> object, Collection<SelectorOptions<GetOperationOptions>> options, Session session) throws SchemaException {
    if (!SelectorOptions.hasToLoadPath(AccessCertificationCampaignType.F_CASE, options)) {
        return;
    }
    LOGGER.debug("Loading certification campaign cases.");
    Criteria criteria = session.createCriteria(RAccessCertificationCase.class);
    criteria.add(Restrictions.eq("ownerOid", object.getOid()));
    // TODO fetch only XML representation
    List<RAccessCertificationCase> cases = criteria.list();
    if (cases == null || cases.isEmpty()) {
        return;
    }
    AccessCertificationCampaignType campaign = (AccessCertificationCampaignType) object.asObjectable();
    List<AccessCertificationCaseType> jaxbCases = campaign.getCase();
    for (RAccessCertificationCase rCase : cases) {
        AccessCertificationCaseType jaxbCase = rCase.toJAXB(prismContext);
        jaxbCases.add(jaxbCase);
    }
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) RAccessCertificationCase(com.evolveum.midpoint.repo.sql.data.common.container.RAccessCertificationCase) Criteria(org.hibernate.Criteria) AccessCertificationCampaignType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType)

Example 59 with Criteria

use of org.hibernate.Criteria in project midpoint by Evolveum.

the class LookupTableHelper method setupLookupTableRowsQuery.

private Criteria setupLookupTableRowsQuery(Session session, RelationalValueSearchQuery queryDef, String oid) {
    Criteria criteria = session.createCriteria(RLookupTableRow.class);
    criteria.add(Restrictions.eq("ownerOid", oid));
    if (queryDef != null && queryDef.getColumn() != null && queryDef.getSearchType() != null && StringUtils.isNotEmpty(queryDef.getSearchValue())) {
        String param = queryDef.getColumn().getLocalPart();
        String value = queryDef.getSearchValue();
        if (LookupTableRowType.F_LABEL.equals(queryDef.getColumn())) {
            param = "label.norm";
            PolyString poly = new PolyString(value);
            poly.recompute(new PrismDefaultPolyStringNormalizer());
            value = poly.getNorm();
        }
        switch(queryDef.getSearchType()) {
            case EXACT:
                criteria.add(Restrictions.eq(param, value));
                break;
            case STARTS_WITH:
                criteria.add(Restrictions.like(param, value + "%"));
                break;
            case SUBSTRING:
                criteria.add(Restrictions.like(param, "%" + value + "%"));
        }
    }
    return criteria;
}
Also used : PrismDefaultPolyStringNormalizer(com.evolveum.midpoint.prism.polystring.PrismDefaultPolyStringNormalizer) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Criteria(org.hibernate.Criteria) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 60 with Criteria

use of org.hibernate.Criteria in project midpoint by Evolveum.

the class LookupTableHelper method updateLoadedLookupTable.

public <T extends ObjectType> void updateLoadedLookupTable(PrismObject<T> object, Collection<SelectorOptions<GetOperationOptions>> options, Session session) throws SchemaException {
    if (!SelectorOptions.hasToLoadPath(LookupTableType.F_ROW, options)) {
        return;
    }
    LOGGER.debug("Loading lookup table data.");
    GetOperationOptions getOption = findLookupTableGetOption(options);
    RelationalValueSearchQuery queryDef = getOption == null ? null : getOption.getRelationalValueSearchQuery();
    Criteria criteria = setupLookupTableRowsQuery(session, queryDef, object.getOid());
    if (queryDef != null && queryDef.getPaging() != null) {
        ObjectPaging paging = queryDef.getPaging();
        if (paging.getOffset() != null) {
            criteria.setFirstResult(paging.getOffset());
        }
        if (paging.getMaxSize() != null) {
            criteria.setMaxResults(paging.getMaxSize());
        }
        ItemPath orderByPath = paging.getOrderBy();
        if (paging.getDirection() != null && orderByPath != null && !orderByPath.isEmpty()) {
            if (orderByPath.size() > 1 || !(orderByPath.first() instanceof NameItemPathSegment) && !(orderByPath.first() instanceof IdentifierPathSegment)) {
                throw new SchemaException("OrderBy has to consist of just one naming or identifier segment");
            }
            ItemPathSegment first = orderByPath.first();
            String orderBy = first instanceof NameItemPathSegment ? ((NameItemPathSegment) first).getName().getLocalPart() : RLookupTableRow.ID_COLUMN_NAME;
            switch(paging.getDirection()) {
                case ASCENDING:
                    criteria.addOrder(Order.asc(orderBy));
                    break;
                case DESCENDING:
                    criteria.addOrder(Order.desc(orderBy));
                    break;
            }
        }
    }
    List<RLookupTableRow> rows = criteria.list();
    if (rows == null || rows.isEmpty()) {
        return;
    }
    LookupTableType lookup = (LookupTableType) object.asObjectable();
    List<LookupTableRowType> jaxbRows = lookup.getRow();
    for (RLookupTableRow row : rows) {
        LookupTableRowType jaxbRow = row.toJAXB();
        jaxbRows.add(jaxbRow);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RelationalValueSearchQuery(com.evolveum.midpoint.schema.RelationalValueSearchQuery) Criteria(org.hibernate.Criteria) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) RLookupTableRow(com.evolveum.midpoint.repo.sql.data.common.other.RLookupTableRow) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) LookupTableRowType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType) LookupTableType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType)

Aggregations

Criteria (org.hibernate.Criteria)180 Session (org.hibernate.Session)95 Test (org.junit.Test)69 List (java.util.List)39 Transaction (org.hibernate.Transaction)39 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)27 ArrayList (java.util.ArrayList)15 TestForIssue (org.hibernate.testing.TestForIssue)12 Iterator (java.util.Iterator)9 Period (org.hisp.dhis.period.Period)8 Map (java.util.Map)6 State (org.hibernate.test.cache.infinispan.functional.entities.State)5 OnmsCriteria (org.opennms.netmgt.model.OnmsCriteria)5 HibernateCallback (org.springframework.orm.hibernate3.HibernateCallback)5 HashSet (java.util.HashSet)3 Criterion (org.hibernate.criterion.Criterion)3 Statistics (org.hibernate.stat.Statistics)3 Pager (org.hisp.dhis.common.Pager)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 HashMap (java.util.HashMap)2