List of usage examples for org.hibernate.criterion Restrictions and
public static LogicalExpression and(Criterion lhs, Criterion rhs)
From source file:de.arago.rike.svg.SVG.java
License:Open Source License
@Override protected boolean checkViewData(IDataWrapper data) { if (!SecurityHelper.isLoggedIn(data.getUser())) return false; if (data.getSessionAttribute("taskListFilter") == null) { data.setSessionAttribute("taskListFilter", new TaskListFilter() { @Override// w w w . ja v a 2s . co m public void setDefaultOptions() { super.setDefaultOptions(); DataHelperRike<Milestone> helper = new DataHelperRike<Milestone>(Milestone.class); List<Milestone> list = helper.list(helper .filter().addOrder(Order.asc("dueDate")).add(Restrictions .and(Restrictions.isNotNull("dueDate"), Restrictions.ge("dueDate", new Date()))) .setMaxResults(1)); if (list.size() > 0) { setIsActive(true); setMilestone("milestone_" + list.get(0).getId().toString()); } } }); } Long nextUpdate = (Long) data.getSessionAttribute("nextUpdate"); if (nextUpdate == null || nextUpdate < System.currentTimeMillis() || data.getSessionAttribute("lastActivity") == null) { data.setSessionAttribute("nextUpdate", System.currentTimeMillis() + Long.parseLong(GlobalConfig.get(CHECK_PERIOD_SECONDS)) * 1000); data.setSessionAttribute("lastActivity", lastChange()); } if (data.getSessionAttribute("portletTitle") == null) { String milestone = ((TaskListFilter) data.getSessionAttribute("taskListFilter")).getMilestone(); data.setSessionAttribute("portletTitle", new PortletTitleWithMilestone(milestone, "Dependencies")); } return true; }
From source file:de.escidoc.core.aa.business.persistence.hibernate.HibernateUserAccountDao.java
License:Open Source License
/** * See Interface for functional description. * * @param attributes set of key/value pairs * @see UserAccountDaoInterface #retrieveAttributes(java.lang.String) */// w w w .j a va2 s . c o m @Override public List<UserAttribute> retrieveAttributes(final Set<HashMap<String, String>> attributes) throws SqlDatabaseSystemException { if (attributes == null) { throw new SqlDatabaseSystemException("attributes may not be null"); } final DetachedCriteria detachedCriteria = DetachedCriteria.forClass(UserAttribute.class, "userAttribute"); Criterion criterion = null; for (final Map<String, String> attribute : attributes) { for (final Entry<String, String> entry : attribute.entrySet()) { if (criterion == null) { criterion = Restrictions.and(Restrictions.eq("name", entry.getKey()), Restrictions.eq("value", entry.getValue())); } else { final Criterion criterion1 = Restrictions.and(Restrictions.eq("name", entry.getKey()), Restrictions.eq("value", entry.getValue())); criterion = Restrictions.or(criterion, criterion1); } } } detachedCriteria.add(criterion); final List<UserAttribute> result; try { result = getHibernateTemplate().findByCriteria(detachedCriteria); } catch (final DataAccessException e) { throw new SqlDatabaseSystemException(e); } return result; }
From source file:de.escidoc.core.common.business.filter.CqlFilter.java
License:Open Source License
/** * Evaluate a CQL boolean node./* w w w. j ava 2s . c o m*/ * * @param node * CQL node * @return Hibernate query reflecting the given CQL query * @throws InvalidSearchQueryException * thrown if the given search query could not be translated into a SQL query */ protected Criterion evaluate(final CQLBooleanNode node) throws InvalidSearchQueryException { Criterion result = null; final Criterion left = evaluate(node.left); final Criterion right = evaluate(node.right); if (node instanceof CQLAndNode) { if (left != null || right != null) { result = Restrictions.and(getAndRestriction(left), getAndRestriction(right)); } } else if (node instanceof CQLOrNode) { if (left != null || right != null) { result = Restrictions.or(getOrRestriction(left), getOrRestriction(right)); } } else { throw new InvalidSearchQueryException(node + ": node type not implemented"); } return result; }
From source file:de.forsthaus.backend.dao.impl.SecRightDAOImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from w w w. j av a 2 s. c o m*/ public List<SecRight> getRightsLikeRightNameAndType(String aRightName, int aRightType) { // check if the empty right is selected. This right is only for visual // behavior. if (aRightType == -1) { return getRightsLikeRightName(aRightName); } final DetachedCriteria criteria = DetachedCriteria.forClass(SecRight.class); criteria.add(Restrictions.and(Restrictions.ilike("rigName", aRightName, MatchMode.ANYWHERE), Restrictions.eq("rigType", Integer.valueOf(aRightType)))); return getHibernateTemplate().findByCriteria(criteria); }
From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.AbstractLeafNode.java
License:Open Source License
private Criterion getAnyAssignmentCriterion(String effectivePropertyName, String attrType) { Criterion criterion;/*from w ww . j a v a 2 s.c o m*/ criterion = Restrictions.not(Restrictions.isNull(effectivePropertyName)); if (!BBAttribute.FIXED_ATTRIBUTE_DATETYPE.equals(attrType)) { criterion = Restrictions.and(criterion, Restrictions.not(Restrictions.eq(effectivePropertyName, Constants.DB_NU1L))); } return criterion; }
From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.SealLeafNode.java
License:Open Source License
/** {@inheritDoc} */ @Override//from w w w. ja va2 s . co m DetachedCriteria getWhereCriteria(DetachedCriteria criteria) { String effectivePropertyName = null; if (getExtensionSize() == 0) { effectivePropertyName = String.format("%s.%s", getResultTypeDBNameShortWithSuffix(), getPropertyName()); } else { effectivePropertyName = String.format("%s.%s", getLeafTypeDBNameShortWithSuffix(), getPropertyName()); } final String[] properties = StringUtils.split(getPropertyName(), '.'); if (!getResultType().isSpecialProperty(getPropertyName()) && properties != null && properties.length > 1) { final String associationPath = String.format("%s.%s", getResultTypeDBNameShortWithSuffix(), properties[0]); final String alias = String.format("%sAlias", properties[0]); criteria.createAlias(associationPath, alias); effectivePropertyName = String.format("%s.%s", alias, properties[1]); } SealState sealState = (SealState) getPattern(); switch (sealState) { case VALID: Criterion validCriterion = getCriterionForComparator(effectivePropertyName, Comparator.EQ, null); Criterion notOutdatedCriterion = Restrictions.not(getOutdatedCriterion(effectivePropertyName)); criteria.add(Restrictions.and(validCriterion, notOutdatedCriterion)); break; case INVALID: criteria.add(getCriterionForComparator(effectivePropertyName, Comparator.EQ, null)); break; case NOT_AVAILABLE: Criterion isNull = Restrictions.isNull(effectivePropertyName); Criterion eqCriterion = getCriterionForComparator(effectivePropertyName, Comparator.EQ, null); criteria.add(Restrictions.or(isNull, eqCriterion)); break; case OUTDATED: criteria.add(getOutdatedCriterion(effectivePropertyName)); break; default: throw new IllegalStateException("The seal state " + sealState + " is not supported!"); } return criteria; }
From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.SealLeafNode.java
License:Open Source License
/** * Returns the Criterion for the outdated entities. * // ww w .java2 s. c om * @param effectivePropertyName the field name representing the seal state * @return the Criterion for the outdated entities */ private Criterion getOutdatedCriterion(String effectivePropertyName) { int expirationInDays = IteraplanProperties.getIntProperty(IteraplanProperties.SEAL_EXPIRATION_DAYS); Date minusDays = new DateTime().minusDays(expirationInDays).toDate(); String idPropertyName = String.format("%s.%s", getResultTypeDBNameShortWithSuffix(), "id"); final DetachedCriteria maxSealDate = DetachedCriteria.forClass(Seal.class, "seal"); maxSealDate.setProjection(Projections.max("seal.date")); maxSealDate.add(Restrictions.eqProperty("seal.bb", idPropertyName)); final DetachedCriteria lastSeal = DetachedCriteria.forClass(Seal.class, "lastSeal"); lastSeal.add(Subqueries.propertyEq("lastSeal.date", maxSealDate)); lastSeal.add(Restrictions.eqProperty("lastSeal.bb", idPropertyName)); lastSeal.add(Restrictions.le("lastSeal.date", minusDays)); lastSeal.setProjection(Projections.distinct(Property.forName("lastSeal.bb"))); Criterion outdatedCriterion = Subqueries.propertyIn(idPropertyName, lastSeal); Criterion valid = Restrictions.eq(effectivePropertyName, SealState.VALID.toString()); return Restrictions.and(valid, outdatedCriterion); }
From source file:de.iteratec.iteraplan.businesslogic.service.InformationSystemReleaseServiceImpl.java
License:Open Source License
/** {@inheritDoc} */ @Override/* ww w . ja va2 s .c om*/ public List<InformationSystemRelease> findByNames(Set<String> names) { if (names.isEmpty()) { return Collections.emptyList(); } DetachedCriteria criteria = DetachedCriteria.forClass(InformationSystemRelease.class); criteria.createAlias("informationSystem", "informationSystem"); Disjunction disjunction = Restrictions.disjunction(); for (String name : names) { String[] partsOfReleaseName = GeneralHelper.getPartsOfReleaseName(name); //FIXME will eq do the trick here too or do we need like? //if like is needed we should use the IteraplanLikeExpression // SimpleExpression nameExpression = Restrictions.like("informationSystem.name", partsOfReleaseName[0], MatchMode.EXACT).ignoreCase(); Criterion nameExpression = new IteraplanLikeExpression("informationSystem.name", partsOfReleaseName[0], true); String version = "version"; if (partsOfReleaseName[1] != null) { //FIXME will eq do the trick here too or do we need like? //if like is needed we should use the IteraplanLikeExpression // SimpleExpression versionExpression = Restrictions.like(version, partsOfReleaseName[1], MatchMode.EXACT).ignoreCase(); Criterion versionExpression = new IteraplanLikeExpression(version, partsOfReleaseName[1], true); disjunction.add(Restrictions.and(nameExpression, versionExpression)); } else { Criterion versionExpression = Restrictions.or(Restrictions.isNull(version), Restrictions.eq(version, Constants.DB_NU1L)); disjunction.add(Restrictions.and(nameExpression, versionExpression)); } } criteria.add(disjunction); return informationSystemReleaseDAO.findByCriteria(criteria); }
From source file:de.iteratec.iteraplan.businesslogic.service.TechnicalComponentReleaseServiceImpl.java
License:Open Source License
/** {@inheritDoc} */ @Override//from ww w. jav a 2 s . c o m public List<TechnicalComponentRelease> findByNames(Set<String> names) { if (names.isEmpty()) { return Collections.emptyList(); } DetachedCriteria criteria = DetachedCriteria.forClass(TechnicalComponentRelease.class); criteria.createAlias("technicalComponent", "technicalComponent"); Disjunction disjunction = Restrictions.disjunction(); for (String name : names) { String[] partsOfReleaseName = GeneralHelper.getPartsOfReleaseName(name); //FIXME will eq do the trick here too or do we need like? //if like is needed we should use the IteraplanLikeExpression // SimpleExpression nameExpression = Restrictions.like("technicalComponent.name", partsOfReleaseName[0], MatchMode.EXACT).ignoreCase(); Criterion nameExpression = new IteraplanLikeExpression("technicalComponent.name", partsOfReleaseName[0], true); if (partsOfReleaseName[1] != null) { //FIXME will eq do the trick here too or do we need like? //if like is needed we should use the IteraplanLikeExpression // SimpleExpression versionExpression = Restrictions.like(VERSION, partsOfReleaseName[1], MatchMode.EXACT).ignoreCase(); Criterion versionExpression = new IteraplanLikeExpression(VERSION, partsOfReleaseName[1], true); disjunction.add(Restrictions.and(nameExpression, versionExpression)); } else { Criterion versionExpression = Restrictions.or(Restrictions.isNull(VERSION), Restrictions.eq(VERSION, Constants.DB_NU1L)); disjunction.add(Restrictions.and(nameExpression, versionExpression)); } } criteria.add(disjunction); return technicalComponentReleaseDAO.findByCriteria(criteria); }
From source file:de.iteratec.iteraplan.persistence.dao.BusinessMappingDAOImpl.java
License:Open Source License
public BusinessMapping getBusinessMappingConnectedToProductAndBUAndBPAndISR(final Integer prodId, final Integer buId, final Integer bpId, final Integer isrId) { Criterion c = Restrictions.and(Restrictions.eq("product.id", prodId), Restrictions.and(Restrictions.eq("businessUnit.id", buId), Restrictions.and(Restrictions.eq("businessProcess.id", bpId), Restrictions.eq("informationSystemRelease.id", isrId)))); List<BusinessMapping> mappings = getBusinessMappings(c); if (mappings.size() > 1) { LOGGER.error("Found more than one assigned business mapping with product id '" + prodId + "' and business unit id '" + buId + "' and business process id '" + bpId + "' and information system release id '" + isrId + "'. A maximum of one business mapping is logically allowed."); throw new IteraplanTechnicalException(IteraplanErrorMessages.INTERNAL_ERROR); }//w w w .jav a 2 s.c o m return mappings.isEmpty() ? null : mappings.get(0); }