Example usage for org.hibernate.criterion Restrictions not

List of usage examples for org.hibernate.criterion Restrictions not

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions not.

Prototype

public static Criterion not(Criterion expression) 

Source Link

Document

Return the negation of an expression

Usage

From source file:org.dspace.content.dao.impl.MetadataSchemaDAOImpl.java

License:BSD License

/**
 * Return true if and only if the passed name appears within the allowed
 * number of times in the current schema.
 *
 * @param context DSpace context/*w  ww  .  j  a v  a2  s.com*/
 * @param namespace namespace URI to match
 * @return true of false
 * @throws java.sql.SQLException
 */
@Override
public boolean uniqueNamespace(Context context, int metadataSchemaId, String namespace) throws SQLException {
    Criteria criteria = createCriteria(context, MetadataSchema.class);
    criteria.add(Restrictions.and(Restrictions.not(Restrictions.eq("id", metadataSchemaId)),
            Restrictions.eq("namespace", namespace)));
    criteria.setCacheable(true);

    return uniqueResult(criteria) == null;
}

From source file:org.dspace.content.dao.impl.MetadataSchemaDAOImpl.java

License:BSD License

/**
 * Return true if and only if the passed name is unique.
 *
 * @param context DSpace context//from  w  w w .  ja  va2 s .  c o m
 * @param name  short name of schema
 * @return true of false
 * @throws java.sql.SQLException
 */
@Override
public boolean uniqueShortName(Context context, int metadataSchemaId, String name) throws SQLException {
    Criteria criteria = createCriteria(context, MetadataSchema.class);
    criteria.add(Restrictions.and(Restrictions.not(Restrictions.eq("id", metadataSchemaId)),
            Restrictions.eq("name", name)));
    criteria.setCacheable(true);

    return uniqueResult(criteria) == null;
}

From source file:org.dspace.identifier.dao.impl.DOIDAOImpl.java

License:BSD License

@Override
public DOI findDOIByDSpaceObject(Context context, DSpaceObject dso, List<Integer> statusToExclude)
        throws SQLException {
    //SELECT * FROM Doi WHERE resource_type_id = ? AND resource_id = ? AND resource_id = ? AND ((status != ? AND status != ?) OR status IS NULL)
    Criteria criteria = createCriteria(context, DOI.class);
    Disjunction statusQuery = Restrictions.or();
    Conjunction statusConjunctionAnd = Restrictions.and();
    for (Integer status : statusToExclude) {
        statusConjunctionAnd.add(Restrictions.not(Restrictions.eq("status", status)));
    }//from   ww  w  . j a v a 2s  . co  m
    statusQuery.add(statusConjunctionAnd);
    statusQuery.add(Restrictions.isNull("status"));
    criteria.add(Restrictions.and(Restrictions.eq("dSpaceObject", dso), statusQuery

    ));
    return singleResult(criteria);
}

From source file:org.egov.api.controller.EmployeeController.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<StateAware> getWorkflowItemsByUserAndWFType(final Long userId, final List<Long> owners,
        final String workFlowType, final int resultsFrom, final int resultsTo, String priority)
        throws ClassNotFoundException {

    if (!owners.isEmpty()) {
        Criterion criterion = Restrictions
                .not(Restrictions.conjunction().add(Restrictions.eq("state.status", StateStatus.STARTED))
                        .add(Restrictions.eq("createdBy.id", userId)));

        criterion = addPriorityCondition(criterion, priority);

        return entityQueryService.getSession()
                .createCriteria(Class
                        .forName(workflowTypeService.getEnabledWorkflowTypeByType(workFlowType).getTypeFQN()))
                .setFirstResult(resultsFrom).setMaxResults(resultsTo).setFetchMode("state", FetchMode.JOIN)
                .createAlias("state", "state").setFlushMode(FlushMode.MANUAL).setReadOnly(true)
                .setCacheable(true).add(Restrictions.eq("state.type", workFlowType))
                .add(Restrictions.in("state.ownerPosition.id", owners))
                .add(Restrictions.ne("state.status", StateStatus.ENDED)).add(criterion)
                .addOrder(Order.desc("state.createdDate")).list();
    }/*from w ww  .  ja  v  a 2  s .  c o m*/

    return Collections.emptyList();

}

From source file:org.egov.api.controller.EmployeeController.java

License:Open Source License

@SuppressWarnings("unchecked")
public Number getWorkflowItemsCountByWFType(final Long userId, final List<Long> owners,
        final String workFlowType, final String priority) throws ClassNotFoundException {

    if (!owners.isEmpty()) {
        Criterion criterion = Restrictions
                .not(Restrictions.conjunction().add(Restrictions.eq("state.status", StateStatus.STARTED))
                        .add(Restrictions.eq("createdBy.id", userId)));
        criterion = addPriorityCondition(criterion, priority);

        return (Number) entityQueryService.getSession()
                .createCriteria(Class
                        .forName(workflowTypeService.getEnabledWorkflowTypeByType(workFlowType).getTypeFQN()))
                .setFetchMode("state", FetchMode.JOIN).createAlias("state", "state")
                .setFlushMode(FlushMode.MANUAL).setReadOnly(true).setCacheable(true)
                .setProjection(Projections.rowCount()).add(Restrictions.eq("state.type", workFlowType))
                .add(Restrictions.in("state.ownerPosition.id", owners))
                .add(Restrictions.ne("state.status", StateStatus.ENDED)).add(criterion).uniqueResult();
    }/*from w  ww  .  j a v  a  2  s . c  om*/
    return 0;
}

From source file:org.egov.egf.web.actions.masters.JQueryGridActionSupport.java

License:Open Source License

/**
 * Used to convert jqgrid search operator to hibernate restriction.
 **//*from   w  w  w.j a va 2 s . c o  m*/
private Criterion applyRestriction() {
    final Object convertedValue = convertValueType(searchField, searchString);

    if ("eq".equals(searchOper))
        return Restrictions.eq(searchField, convertedValue);
    else if ("ne".equals(searchOper))
        return Restrictions.ne(searchField, convertedValue);

    if (convertedValue instanceof String) {
        if ("bw".equals(searchOper))
            return Restrictions.ilike(searchField, searchString + "%");
        else if ("cn".equals(searchOper))
            return Restrictions.ilike(searchField, "%" + searchString + "%");
        else if ("ew".equals(searchOper))
            return Restrictions.ilike(searchField, "%" + searchString);
        else if ("bn".equals(searchOper))
            return Restrictions.not(Restrictions.ilike(searchField, searchString + "%"));
        else if ("en".equals(searchOper))
            return Restrictions.not(Restrictions.ilike(searchField, "%" + searchString));
        else if ("nc".equals(searchOper))
            return Restrictions.not(Restrictions.ilike(searchField, "%" + searchString + "%"));
        else if ("in".equals(searchOper))
            return Restrictions.in(searchField, searchString.split(","));
        else if ("ni".equals(searchOper))
            return Restrictions.not(Restrictions.in(searchField, searchString.split(",")));
    } else if ("lt".equals(searchOper))
        return Restrictions.lt(searchField, convertedValue);
    else if ("le".equals(searchOper))
        return Restrictions.le(searchField, convertedValue);
    else if ("gt".equals(searchOper))
        return Restrictions.gt(searchField, convertedValue);
    else if ("ge".equals(searchOper))
        return Restrictions.ge(searchField, convertedValue);
    return null;
}

From source file:org.egov.works.letterofacceptance.service.LetterOfAcceptanceService.java

License:Open Source License

public List<WorkOrder> searchLetterOfAcceptanceForContractorBill(
        final SearchRequestLetterOfAcceptance searchRequestLetterOfAcceptance) {
    final List<String> estimateNumbers = lineEstimateService
            .getEstimateNumberForDepartment(searchRequestLetterOfAcceptance.getDepartmentName());
    if (estimateNumbers.isEmpty())
        estimateNumbers.add("");
    // TODO: replace fetching workorders by query with criteria alias
    final List<String> workOrderNumbers = letterOfAcceptanceRepository
            .getDistinctNonCancelledWorkOrderNumbersByBillType(
                    ContractorBillRegister.BillStatus.CANCELLED.toString(), BillTypes.Final_Bill.toString());
    final Criteria criteria = entityManager.unwrap(Session.class).createCriteria(WorkOrder.class, "wo")
            .createAlias("contractor", "woc").createAlias("egwStatus", "status");

    if (searchRequestLetterOfAcceptance != null) {
        if (searchRequestLetterOfAcceptance.getWorkOrderNumber() != null)
            criteria.add(Restrictions//  ww  w  .  ja v a  2  s  . com
                    .eq("workOrderNumber", searchRequestLetterOfAcceptance.getWorkOrderNumber()).ignoreCase());
        if (searchRequestLetterOfAcceptance.getFromDate() != null)
            criteria.add(Restrictions.ge("workOrderDate", searchRequestLetterOfAcceptance.getFromDate()));
        if (searchRequestLetterOfAcceptance.getToDate() != null)
            criteria.add(Restrictions.le("workOrderDate", searchRequestLetterOfAcceptance.getToDate()));
        if (searchRequestLetterOfAcceptance.getName() != null)
            criteria.add(Restrictions.eq("woc.name", searchRequestLetterOfAcceptance.getName()).ignoreCase());
        if (searchRequestLetterOfAcceptance.getFileNumber() != null)
            criteria.add(Restrictions.ilike("fileNumber", searchRequestLetterOfAcceptance.getFileNumber(),
                    MatchMode.ANYWHERE));
        if (searchRequestLetterOfAcceptance.getEstimateNumber() != null)
            criteria.add(Restrictions.eq("estimateNumber", searchRequestLetterOfAcceptance.getEstimateNumber())
                    .ignoreCase());
        if (searchRequestLetterOfAcceptance.getDepartmentName() != null)
            criteria.add(Restrictions.in("estimateNumber", estimateNumbers));
        if (workOrderNumbers != null && !workOrderNumbers.isEmpty())
            criteria.add(Restrictions.not(Restrictions.in("workOrderNumber", workOrderNumbers)));
    }
    criteria.add(Restrictions.eq("status.code", WorksConstants.APPROVED));
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    return criteria.list();
}

From source file:org.emonocot.persistence.dao.hibernate.ResourceDaoImpl.java

License:Open Source License

@Override
public boolean isHarvesting() {
    Criteria criteria = getSession().createCriteria(type);
    criteria.add(Restrictions.isNotNull("resourceType"));
    criteria.add(Restrictions.not(Restrictions.in("status", Arrays.asList(new BatchStatus[] {
            BatchStatus.COMPLETED, BatchStatus.FAILED, BatchStatus.ABANDONED, BatchStatus.STOPPED }))));
    criteria.setProjection(Projections.rowCount());
    return (Long) criteria.uniqueResult() > 0;
}

From source file:org.encuestame.persistence.dao.imp.HashTagDao.java

License:Apache License

public List<HashTagRanking> getHashTagRankingLastPosition(final Date maxDate) {
    DetachedCriteria criteria = DetachedCriteria.forClass(HashTagRanking.class);
    criteria.add(Restrictions.not(Restrictions.eq("rankingDate", maxDate)));
    criteria.addOrder(Order.desc("average"));
    @SuppressWarnings("unchecked")
    List<HashTagRanking> results = (List<HashTagRanking>) getHibernateTemplate().findByCriteria(criteria);
    return results;
}

From source file:org.eulerframework.web.core.base.dao.impl.hibernate5.BaseDao.java

License:Apache License

protected Criterion generateRestriction(String property, String value, QueryMode queryMode) {
    Field field;//www .j av a2s  .c o m
    try {
        String fieldName = property;
        if (property.indexOf('.') > 0) {
            fieldName = property.substring(0, property.indexOf('.'));
        }
        field = this.entityClass.getDeclaredField(fieldName);
    } catch (NoSuchFieldException e) {
        throw new IllegalArgumentException("Property '" + property + "' not exist");
    }

    if (BaseEmbeddable.class.isAssignableFrom(field.getType())) {
        try {
            field = field.getType().getDeclaredField(property.substring(property.indexOf('.') + 1));
        } catch (NoSuchFieldException e) {
            throw new IllegalArgumentException("Property '" + property + "' not exist");
        }
    }

    switch (queryMode) {
    case ANYWHERE:
        return RestrictionsX.like(property, value, MatchMode.ANYWHERE);
    case START:
        return RestrictionsX.like(property, value, MatchMode.START);
    case END:
        return RestrictionsX.like(property, value, MatchMode.END);
    case EXACT:
        return RestrictionsX.like(property, value, MatchMode.EXACT);
    case GE:
        return Restrictions.ge(property, JavaObjectUtils.analyzeStringValueToObject(value, field.getType()));
    case GT:
        return Restrictions.gt(property, JavaObjectUtils.analyzeStringValueToObject(value, field.getType()));
    case LE:
        return Restrictions.le(property, JavaObjectUtils.analyzeStringValueToObject(value, field.getType()));
    case LT:
        return Restrictions.lt(property, JavaObjectUtils.analyzeStringValueToObject(value, field.getType()));
    case IN:
        return Restrictions.in(property, this.analyzeInterval(value, field.getType()));
    case NOTIN:
        return Restrictions.not(RestrictionsX.in(property, this.analyzeInterval(value, field.getType())));
    case IS:
        return Restrictions.eq(property, JavaObjectUtils.analyzeStringValueToObject(value, field.getType()));
    case NOT:
        return Restrictions.ne(property, JavaObjectUtils.analyzeStringValueToObject(value, field.getType()));
    case BETWEEN:
        Object[] array1 = this.analyzeInterval(value, field.getType());
        return Restrictions.between(property, array1[0], array1[1]);
    case OUTSIDE:
        Object[] array2 = this.analyzeInterval(value, field.getType());
        return Restrictions.not(Restrictions.between(property, array2[0], array2[1]));
    default:
        throw new IllegalArgumentException("Unknown query mode: " + queryMode);
    }
}