Example usage for org.hibernate.criterion Restrictions and

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

Introduction

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

Prototype

public static LogicalExpression and(Criterion lhs, Criterion rhs) 

Source Link

Document

Return the conjuction of two expressions

Usage

From source file:com.negocio.dao.UsuarioDaoImpl.java

@Override
public Usuarios buscarPassUser(String username, String pass) {
    Criteria crit = createEntityCriteria();
    crit.add(Restrictions.and(Restrictions.eq("usuUsername", username), Restrictions.eq("usuPass", pass)));
    Usuarios usu = (Usuarios) crit.uniqueResult();
    if (usu != null) {
        Hibernate.initialize(usu.getUsuId());
    }//from ww w .j a v a 2 s  . c om
    return usu;
}

From source file:com.pmo.pmoitserv.Dao.ActionDao.java

public long getEnCoursActionCount_byCompte(int compteId) {
    Long result = 0L;//from  w  w w .  ja  v a  2  s  . c  om
    ;
    Compte cpte = null;
    List<Projet> pjts = new ArrayList<Projet>();
    List<Sousprojet> souspjts = new ArrayList<Sousprojet>();
    List<Chantier> chantiers = new ArrayList<Chantier>();
    try {
        this.session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        cpte = (Compte) session.get(Compte.class, compteId);
        pjts = session.createCriteria(Projet.class).add(Restrictions.eq("compte", cpte)).list();
        souspjts = session.createCriteria(Sousprojet.class).add(Restrictions.in("projet", pjts)).list();
        chantiers = session.createCriteria(Chantier.class).add(Restrictions.in("sousprojet", souspjts)).list();
        Criteria cr = session.createCriteria(Action.class);
        Criterion c1 = Restrictions.ilike("actionStatut", "cours", MatchMode.ANYWHERE);
        Criterion c2 = Restrictions.in("chantier", chantiers);
        cr.add(Restrictions.and(c1, c2));
        cr.setProjection(Projections.rowCount());
        result = (Long) cr.uniqueResult();
        tx.commit();
        session.flush();
        session.close();
        return result;

    } catch (Exception e) {
        e.printStackTrace();
        session.close();
    }
    return result;
}

From source file:com.pmo.pmoitserv.Dao.ProjetDao.java

public long getEnCoursProjetCount() {
    Long result = 0L;//from  ww w . ja  va  2 s  .c o m
    try {
        this.session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();

        Criteria cr = session.createCriteria(Projet.class);
        Criterion c1 = Restrictions.ilike("projetStatut", "en", MatchMode.ANYWHERE);
        Criterion c2 = Restrictions.ilike("projetStatut", "cours", MatchMode.ANYWHERE);
        cr.add(Restrictions.and(c1, c2));
        cr.setProjection(Projections.rowCount());
        result = (Long) cr.uniqueResult();
        tx.commit();
        session.flush();
        session.close();
        return result;

    } catch (Exception e) {
        e.printStackTrace();
        session.close();
    }
    return result;
}

From source file:com.qfix.vms.dao.impl.RequestDaoImpl.java

@Override
public List<Request> getMyRequestList(User user) {
    Session session = sessionFactory.openSession();
    Transaction tx = null;/*  ww w. j  a va  2s . co m*/

    tx = session.beginTransaction();
    Criteria cr = session.createCriteria(Request.class);

    cr.add(Restrictions.and(Restrictions.eq("user", user), Restrictions.eq("user", user)));

    List requests = cr.list();
    return requests;
}

From source file:com.reignite.parser.QueryParser.java

License:Open Source License

private Criterion createAnd(JSONArray ands, int index) throws ParserException {
    if (ands.length() == (index + 1)) {
        try {/*from   w w w  .j av a 2s .  co m*/
            return createCriterion(ands.getJSONObject(index));
        } catch (JSONException e) {
            throw new ParserException(
                    "and clauses must be arrays with at least two elements: " + ands.toString());
        }
    }
    JSONObject andObj = null;
    try {
        andObj = ands.getJSONObject(index);
    } catch (JSONException e) {
        throw new ParserException("each element of an and clause must be a JSON Object. " + query.toString());
    }
    return Restrictions.and(createCriterion(andObj), createAnd(ands, index + 1));
}

From source file:com.seedboxer.seedboxer.core.persistence.impl.HibernateContentDao.java

License:Open Source License

@Override
public <T extends Content> List<T> getHistoryContentFilteredByNameAndUser(Class<T> clazz, String name,
        User user) {/*from w  w w . ja  v a 2s  .  c  o m*/
    Criteria criteria = getCurrentSession().createCriteria(clazz);
    Criterion rest1 = Restrictions.and(Restrictions.eq("name", name), Restrictions.eq("history", true));
    rest1 = Restrictions.and(rest1, Restrictions.eq("user", user));
    criteria.add(rest1);
    return criteria.list();
}

From source file:com.telefonica.euro_iaas.paasmanager.dao.impl.ProductInstanceDaoJpaImpl.java

License:Apache License

public Criterion getVMCriteria(Criteria baseCriteria, VM vm) {
    if (!StringUtils.isEmpty(vm.getFqn()) && !StringUtils.isEmpty(vm.getIp())
            && !StringUtils.isEmpty(vm.getDomain()) && !StringUtils.isEmpty(vm.getHostname())) {
        return Restrictions.eq(ProductInstance.VM_FIELD, vm);
    } else if (!StringUtils.isEmpty(vm.getFqn())) {
        return Restrictions.eq("vm.fqn", vm.getFqn());
    } else if (!StringUtils.isEmpty(vm.getIp())) {
        return Restrictions.eq("vm.ip", vm.getIp());
    } else if (!StringUtils.isEmpty(vm.getDomain()) && !StringUtils.isEmpty(vm.getHostname())) {
        return Restrictions.and(Restrictions.eq("vm.hostname", vm.getHostname()),
                Restrictions.eq("vm.domain", vm.getDomain()));
    } else {// ww w  . j a v a2  s .  c o m
        throw new PaasManagerServerRuntimeException("Invalid VM while finding products by criteria");
    }
}

From source file:com.telefonica.euro_iaas.sdc.dao.impl.AbstractInstallableInstanceDaoJpaIml.java

License:Apache License

public Criterion getVMCriteria(Criteria baseCriteria, VM vm) {
    if (!StringUtils.isEmpty(vm.getFqn()) && !StringUtils.isEmpty(vm.getIp())
            && !StringUtils.isEmpty(vm.getDomain()) && !StringUtils.isEmpty(vm.getHostname())) {
        return Restrictions.eq(InstallableInstance.VM_FIELD, vm);
    } else if (!StringUtils.isEmpty(vm.getFqn())) {
        return Restrictions.eq("vm.fqn", vm.getFqn());
    } else if (!StringUtils.isEmpty(vm.getIp())) {
        return Restrictions.eq("vm.ip", vm.getIp());
    } else if (!StringUtils.isEmpty(vm.getDomain()) && !StringUtils.isEmpty(vm.getHostname())) {
        return Restrictions.and(Restrictions.eq("vm.hostname", vm.getHostname()),
                Restrictions.eq("vm.domain", vm.getDomain()));
    } else {/* w  w  w.  j av a2 s.  c om*/
        throw new SdcRuntimeException("Invalid VM while finding products by criteria");
    }
}

From source file:com.thoughtworks.go.server.persistence.MaterialRepository.java

License:Apache License

private void loadModificationsForPMR(List<PipelineMaterialRevision> pmrs) {
    List<Criterion> criterions = new ArrayList<>();
    for (PipelineMaterialRevision pmr : pmrs) {
        if (goCache.get(pmrModificationsKey(pmr)) != null) {
            continue;
        }/*ww  w .j  a  va  2 s  . c o m*/
        final Criterion modificationClause = Restrictions.between("id", pmr.getFromModification().getId(),
                pmr.getToModification().getId());
        final SimpleExpression idClause = Restrictions.eq("materialInstance", pmr.getMaterialInstance());
        criterions.add(Restrictions.and(idClause, modificationClause));
    }
    List<Modification> modifications = (List<Modification>) getHibernateTemplate()
            .findByCriteria(buildModificationDetachedQuery(criterions));
    sortPersistentObjectsById(modifications, false);
    for (Modification modification : modifications) {
        List<String> cacheKeys = pmrModificationsKey(modification, pmrs);
        for (String cacheKey : cacheKeys) {
            List<Modification> modificationList = (List<Modification>) goCache.get(cacheKey);
            if (modificationList == null) {
                modificationList = new ArrayList<>();
                goCache.put(cacheKey, modificationList);
            }
            modificationList.add(modification);
        }
    }
}

From source file:com.vmware.appfactory.application.dao.ApplicationDaoImpl.java

License:Open Source License

/**
 * Get all other applications that match the passed app name and are marked
 * for inclusion.//from   w ww  .  j a  v  a  2  s .c o  m
 *
 * @param app
 * @return
 */
@Override
public List<Application> findOtherVersionsIncluded(Application app) {
    Criterion c1 = Restrictions.eq("_name", app.getName()).ignoreCase();
    Criterion c2 = Restrictions.ne("_id", app.getId());
    Criterion c3 = Restrictions.eq("_skipped", false);
    return findByCriterion(Restrictions.and(Restrictions.and(c1, c2), c3));
}