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.webical.dao.hibernateImpl.EventDaoWebDavHibernateBufferedImpl.java

License:Open Source License

@Transaction(readOnly = false)
@SuppressWarnings("unchecked")
public void storeEvent(Event updatedEvent)
        throws DaoException, DeleteConflictException, UpdateConflictException {
    if (updatedEvent == null)
        return;//  w  w  w .  j a v  a2 s  .  c  o m

    try {
        boolean update = (updatedEvent.getUid() != null);

        // Create a new WebDavCalendarSynchronisation util
        WebDavCalendarSynchronisation calendarSynchronisation = new WebDavCalendarSynchronisation();
        if (update) {
            if (log.isDebugEnabled()) {
                log.debug("Merging existing Event: " + updatedEvent.getUid());
            }

            //Remove the old events (except the updated event)
            Criteria criteria = getSession().createCriteria(Event.class);
            criteria.add(Restrictions.eq(Calendar.CALENDAR_PROPERTY_NAME, updatedEvent.getCalendar()));
            criteria.add(Restrictions.not(Restrictions.idEq(updatedEvent.getEventId())));
            List<Event> eventsToRemove = criteria.list();
            if (eventsToRemove != null) {
                deleteAll(eventsToRemove);
            }

            // Synchronize the updated event
            List<Event> newEvents = calendarSynchronisation.updateEvent(updatedEvent,
                    updatedEvent.getCalendar());

            //Store the new events
            if (newEvents != null) {
                for (Event event : newEvents) {
                    saveOrUpdate(event);
                }
            }

            // Write changes to remote calendar
            calendarSynchronisation.writeToRemoteCalendarFile(updatedEvent.getCalendar(), newEvents);
        } else {
            updatedEvent.setUid(generateUid());

            if (log.isDebugEnabled()) {
                log.debug("Storing new Event: " + updatedEvent.getUid());
            }

            saveOrUpdate(updatedEvent);

            // Calendar Ical4J over webdav has its own transactions?
            calendarSynchronisation.writeToRemoteCalendarFile(updatedEvent.getCalendar(),
                    getEventsForCalendar(updatedEvent.getCalendar()));
        }
    } catch (Exception e) {
        log.error(e, e);
        throw new DaoException("Could not store Event", e);
    }
}

From source file:org.yes.cart.payment.service.impl.PaymentGatewayParameterServiceImpl.java

License:Apache License

/**
 * {@inheritDoc}// ww w .j  av  a  2 s  .co  m
 */
public Collection<PaymentGatewayParameter> findAll(final String label, final String shopCode) {
    if (shopCode != null && !"DEFAULT".equals(shopCode)) {
        return getGenericDao().findByCriteria(Restrictions.and(Restrictions.eq("pgLabel", label),
                Restrictions.or(Restrictions.not(Restrictions.like("label", "#", MatchMode.START)),
                        Restrictions.like("label", "#" + shopCode + "_", MatchMode.START))));
    }
    return getGenericDao().findByCriteria(Restrictions.and(Restrictions.eq("pgLabel", label),
            Restrictions.not(Restrictions.like("label", "#", MatchMode.START))));
}

From source file:pe.gob.onpe.rae.dao.hibernate.ExpedientePadronDAOH.java

@Override
public ExpedientePadron fetchListaPadronByDni(String numele) {
    Criteria criteria = this.getSession().createCriteria(ExpedientePadron.class);
    criteria.add(Restrictions.eq("dni", numele));
    criteria.add(/*w  w w.  j  ava 2s  .  c om*/
            Restrictions.not(Restrictions.in("estado", new Integer[] { Parametros.ESTADO_ELECTOR_REG_OTRA_LISTA,
                    Parametros.ESTADO_ELECTOR_ELIMINADO, Parametros.ESTADO_ELECTOR_RECHAZADO })));
    return (ExpedientePadron) criteria.uniqueResult();
}

From source file:pe.gob.onpe.rae.dao.hibernate.ExpedientePadronDAOH.java

@Override
public List<ExpedientePadron> fetchByRangoInicialInd(Expediente expediente, int indicador, int desde) {

    Criteria criteria = this.getSession().createCriteria(ExpedientePadron.class);
    criteria.add(Restrictions.eq("expediente", expediente));
    criteria.add(Restrictions.not(Restrictions.in("estado",
            new Integer[] { Parametros.ESTADO_ELECTOR_ELIMINADO, Parametros.ESTADO_ELECTOR_RECHAZADO })));
    criteria.add(Restrictions.eq("indicador", indicador));
    criteria.add(Restrictions.gt("ordenRegistro", desde));
    criteria.addOrder(Order.asc("ordenRegistro"));
    return (List<ExpedientePadron>) criteria.list();
}

From source file:pe.gob.onpe.rae.dao.hibernate.ExpedientePadronDAOH.java

@Override
public List<ExpedientePadron> getByCompaginado(ExpedienteImpresion expImpresion) {
    Criteria criteria = this.getSession().createCriteria(ExpedientePadron.class);
    criteria.add(Restrictions.eq("expediente", expImpresion.getExpediente()));
    criteria.add(Restrictions.not(Restrictions.in("estado",
            new Integer[] { Parametros.ESTADO_ELECTOR_ELIMINADO, Parametros.ESTADO_ELECTOR_RECHAZADO })));
    criteria.add(Restrictions.eq("indicador", expImpresion.getIndicador()));
    criteria.add(Restrictions.gt("ordenRegistro", expImpresion.getRegistroInicial() - 1));
    criteria.add(Restrictions.lt("ordenRegistro", expImpresion.getResgitroFinal() + 1));
    criteria.addOrder(Order.asc("ordenRegistro"));
    return (List<ExpedientePadron>) criteria.list();
}

From source file:pe.gob.onpe.rae.dao.hibernate.ExpedientePadronDAOH.java

@Override
public List<ExpedientePadron> getByExpedienteIndicador(Expediente expediente, int indicador) {
    Criteria criteria = this.getSession().createCriteria(ExpedientePadron.class);
    criteria.add(Restrictions.eq("expediente", expediente));
    criteria.add(Restrictions.not(Restrictions.in("estado",
            new Integer[] { Parametros.ESTADO_ELECTOR_ELIMINADO, Parametros.ESTADO_ELECTOR_RECHAZADO })));
    criteria.add(Restrictions.eq("indicador", indicador));
    criteria.addOrder(Order.asc("ordenRegistro"));
    return (List<ExpedientePadron>) criteria.list();
}

From source file:pl.touk.wonderfulsecurity.dao.WsecBaseDaoImpl.java

License:Apache License

private void applyFilters(String key, Object filter, DetachedCriteria criteria) {
    if (key.endsWith(LIKE_SUFFIX)) {
        criteria.add(//from   www  .  ja  v  a 2  s. c  o  m
                Restrictions.like(key.substring(0, key.length() - LIKE_SUFFIX.length()), "%" + filter + "%"));
    } else if (key.endsWith(I_LIKE_SUFFIX)) {
        criteria.add(Restrictions.ilike(key.substring(0, key.length() - I_LIKE_SUFFIX.length()),
                "%" + filter + "%"));
    } else if (key.endsWith(LIKE_DATE_SUFFIX)) {
        String realKey = key.substring(0, key.length() - LIKE_DATE_SUFFIX.length());
        Date dateFilter = ((Date) filter);
        Date plus24h = new Date();
        plus24h.setTime(dateFilter.getTime() + 86399999l);
        criteria.add(Restrictions.between(realKey, dateFilter, plus24h));
    } else if (key.endsWith(NULL_END_SUFFIX)) {
        criteria.add(Restrictions.isNull(key.substring(0, key.length() - NULL_END_SUFFIX.length())));
    } else if (key.endsWith(NOT_NULL_END_SUFFIX)) {
        criteria.add(Restrictions.isNotNull(key.substring(0, key.length() - NOT_NULL_END_SUFFIX.length())));
    } else if (key.endsWith(LIKE_MATCH_START_SUFFIX)) {
        criteria.add(Restrictions.like(key.substring(0, key.length() - LIKE_MATCH_START_SUFFIX.length()),
                filter + "%"));
    } else if (key.endsWith(I_LIKE_MATCH_START_SUFFIX)) {
        criteria.add(Restrictions.ilike(key.substring(0, key.length() - I_LIKE_MATCH_START_SUFFIX.length()),
                filter + "%"));
    } else if (key.endsWith(NOT_LIKE_END_SUFFIX)) {
        criteria.add(Restrictions.not(Restrictions
                .like(key.substring(0, key.length() - NOT_LIKE_END_SUFFIX.length()), "%" + filter + "%")));
    } else if (key.endsWith(LIKE_MATCH_END_SUFFIX)) {
        criteria.add(Restrictions.like(key.substring(0, key.length() - LIKE_MATCH_END_SUFFIX.length()),
                "%" + filter));
    } else if (key.endsWith(I_LIKE_MATCH_END_SUFFIX)) {
        criteria.add(Restrictions.ilike(key.substring(0, key.length() - I_LIKE_MATCH_END_SUFFIX.length()),
                "%" + filter));
    } else if (key.endsWith(BETWEEN_DATES_END_SUFFIX)) {
        String realKeyWithUpperLimit = key.substring(0, key.length() - BETWEEN_DATES_END_SUFFIX.length());
        String upperLimitAsStr = realKeyWithUpperLimit.substring(realKeyWithUpperLimit.indexOf("|") + 1);
        try {
            Date upperLimit = new Timestamp(dateFormat.parse(upperLimitAsStr).getTime());
            String realKey = realKeyWithUpperLimit.substring(0, realKeyWithUpperLimit.indexOf("|"));
            criteria.add(Restrictions.between(realKey, new Timestamp(((Date) filter).getTime()), upperLimit));
        } catch (ParseException e) {
            throw new IllegalArgumentException("for the key '" + key + "' the date '" + upperLimitAsStr
                    + "' can't be parsed according to the format '" + dateFormatAsStr, e);
        }
    } else if (key.endsWith(EVERYTHING_EXCEPT_END_SUFFIX)) {
        criteria.add(Restrictions.or(
                Restrictions.ne(key.substring(0, key.length() - EVERYTHING_EXCEPT_END_SUFFIX.length()), filter),
                Restrictions.isNull(key.substring(0, key.length() - EVERYTHING_EXCEPT_END_SUFFIX.length()))));
    } else if (filter == null) {
        criteria.add(Restrictions.isNull(key));
    } else if (filter instanceof Collection) {
        criteria.add(Restrictions.in(key, (Collection) filter));
    } else {
        criteria.add(Restrictions.eq(key, filter));
    }
}

From source file:podd.resources.util.view.ProjectListPopulator.java

License:Open Source License

public List<FreemarkerProjectHelper> getProjects(Project.ProjectPublicationStatus status,
        boolean includeUserProjects, User user, int max, int first) throws DataAccessException {
    // get all FreemarkerProjectHelper published projects which are not in the users' project list
    Set<Criterion> criteria = new HashSet<Criterion>();
    criteria.add(Restrictions.like("publicationStatus", status));
    // only return active projects
    criteria.add(Restrictions.eq("state", STATE_ACTIVE));
    if (!includeUserProjects) {
        for (String pid : getUserProjectPidList(user)) {
            criteria.add(Restrictions.not(Restrictions.like("pid", pid)));
        }/* w  w w .j  a  v  a 2  s .com*/
    }
    return getProjectList(user, pidHolderDao.getAll(Project.class, criteria, max, first));
}

From source file:podd.resources.util.view.ProjectListPopulator.java

License:Open Source License

public int getProjectCount(Project.ProjectPublicationStatus status, User user, boolean includeUserProjects)
        throws DataAccessException {
    Set<Criterion> criteria = new HashSet<Criterion>();
    criteria.add(Restrictions.like("publicationStatus", status));
    criteria.add(Restrictions.eq("state", STATE_ACTIVE));
    if (!includeUserProjects) {
        for (String pid : getUserProjectPidList(user)) {
            criteria.add(Restrictions.not(Restrictions.like("pid", pid)));
        }/*from  w w w. j  a va2s.c om*/
    }
    return pidHolderDao.getCount(Project.class, criteria);
}

From source file:py.una.pol.karaku.dao.helper.NotExpressionHelper.java

License:Open Source License

@Override
public Criterion getCriterion(@Nonnull Criteria criteria, @Nonnull Not clause,
        @Nonnull Map<String, String> aliases) {

    Criterion c = helper.getCriterion(clause.getClause(), criteria, aliases);
    return Restrictions.not(c);

}