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();
}
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);
}
}
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);
}
}
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;
}
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);
}
}
Aggregations