Example usage for org.hibernate Criteria createCriteria

List of usage examples for org.hibernate Criteria createCriteria

Introduction

In this page you can find the example usage for org.hibernate Criteria createCriteria.

Prototype

public Criteria createCriteria(String associationPath) throws HibernateException;

Source Link

Document

Create a new Criteria, "rooted" at the associated entity.

Usage

From source file:edu.ur.hibernate.ir.researcher.db.HbResearcherPublicationDAO.java

License:Apache License

/**
 * Get researcher publications for specified researcher and specified parent folder
 * //from ww  w.j  a v  a2  s.  c om
 * @see edu.ur.ir.researcher.ResearcherPublicationDAO#getSubResearcherPublications(Long, Long)
 */
@SuppressWarnings("unchecked")
public List<ResearcherPublication> getSubResearcherPublications(final Long researcherId,
        final Long parentCollectionId) {
    log.debug("getSubResearcherPublications::");
    Criteria criteria = hbCrudDAO.getSessionFactory().getCurrentSession().createCriteria(hbCrudDAO.getClazz());
    criteria.createCriteria("researcher").add(Restrictions.idEq(researcherId));
    criteria.createCriteria("parentFolder").add(Restrictions.idEq(parentCollectionId));
    return criteria.list();
}

From source file:edu.ur.hibernate.ir.researcher.db.HbResearcherPublicationDAO.java

License:Apache License

/**
 * Find the specified items for the given researcher.
 * // w  ww.j a v  a  2  s.co m
 * @see edu.ur.ir.researcher.ResearcherPublicationDAO#getResearcherPublications(java.lang.Long, java.util.List)
 */
@SuppressWarnings("unchecked")
public List<ResearcherPublication> getResearcherPublications(final Long researcherId,
        final List<Long> itemIds) {
    List<ResearcherPublication> foundItems = new LinkedList<ResearcherPublication>();
    if (itemIds.size() > 0) {
        Criteria criteria = hbCrudDAO.getSessionFactory().getCurrentSession()
                .createCriteria(hbCrudDAO.getClazz());
        criteria.createCriteria("researcher").add(Restrictions.idEq(researcherId));
        criteria.add(Restrictions.in("id", itemIds));
        foundItems = criteria.list();
    }
    return foundItems;
}

From source file:edu.ur.hibernate.ir.user.db.HbSharedInboxFileDAO.java

License:Apache License

/**
 * Find the specified files./*from www.  ja  v a  2  s  . c o m*/
 * 
 * @see edu.ur.ir.user.PersonalFolderDAO#getSharedInboxFiles(java.lang.Long, java.util.List)
 */
@SuppressWarnings("unchecked")
public List<SharedInboxFile> getSharedInboxFiles(final Long userId, final List<Long> fileIds) {
    List<SharedInboxFile> foundFiles = new LinkedList<SharedInboxFile>();
    if (fileIds.size() > 0) {
        foundFiles = (List<SharedInboxFile>) hbCrudDAO.getHibernateTemplate().execute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException, SQLException {
                Criteria criteria = session.createCriteria(hbCrudDAO.getClazz());
                criteria.createCriteria("sharedWithUser").add(Restrictions.idEq(userId));
                criteria.add(Restrictions.in("id", fileIds));
                return criteria.list();
            }
        });
    }
    return foundFiles;
}

From source file:ee.ria.xroad.common.conf.serverconf.dao.ClientDAOImpl.java

License:Open Source License

/**
 * Returns true, if client with specified identifier exists.
 * @param session the session//from  w  w  w.ja  v a 2s  . com
 * @param id the identifier
 * @param includeSubsystems if true and identifier is not subsystem,
 * also looks for clients whose identifier is a subsystem
 * @return true, if client with specified identifier exists
 */
public boolean clientExists(Session session, ClientId id, boolean includeSubsystems) {
    Example ex = Example.create(id);

    if (includeSubsystems) {
        ex.excludeProperty("type").excludeZeroes();
    }

    Criteria criteria = session.createCriteria(ClientType.class);
    criteria.createCriteria("identifier").add(ex);
    return criteria.list().size() > 0;
}

From source file:ee.ria.xroad.common.conf.serverconf.dao.ClientDAOImpl.java

License:Open Source License

/**
 * Returns the client for the given client identifier.
 * @param session the session//  w  w w. j  ava2 s.c o  m
 * @param id the client identifier
 * @return the client
 */
public ClientType getClient(Session session, ClientId id) {
    Criteria criteria = session.createCriteria(ClientType.class);
    criteria.createCriteria("identifier").add(Example.create(id));
    return findOne(criteria);
}

From source file:ee.ria.xroad.common.conf.serverconf.dao.ClientDAOImpl.java

License:Open Source License

/**
 * Returns the information system certificates of the specified client.
 * @param session the session/* w  w  w  .  j  a  v a  2 s . c  o m*/
 * @param id the client identifier
 * @return the information system certificates of the specified client
 */
public List<CertificateType> getIsCerts(Session session, ClientId id) {
    Criteria criteria = session.createCriteria(ClientType.class);
    criteria.createCriteria("identifier").add(Example.create(id));

    ClientType client = findOne(criteria);
    if (client != null) {
        return client.getIsCert();
    }

    return emptyList();
}

From source file:es.emergya.bbdd.dao.CapaInformacionHome.java

License:Open Source License

@SuppressWarnings("unchecked")
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public List<CapaInformacion> getAll(boolean base, Boolean historico) {
    List<CapaInformacion> res = new LinkedList<CapaInformacion>();
    try {//from w w w.ja  v  a2  s.  c o  m
        Session currentSession = getSession();
        currentSession.clear();
        Criteria criteria = currentSession.createCriteria(CapaInformacion.class).addOrder(Order.desc("orden"))
                .add(Restrictions.eq("opcional", (!base))).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

        if (!base) {
            if (historico != null) {
                criteria = criteria.createCriteria("capasInformacion");
                if (!historico) {
                    criteria.add(Restrictions.eq("visibleGPS", true));
                } else {
                    criteria.add(Restrictions.eq("visibleHistorico", true));
                }
                criteria = criteria.add(Restrictions
                        .sqlRestriction("{alias}.fk_usuarios = " + Authentication.getUsuario().getId()));
            }
        }

        res = (List<CapaInformacion>) criteria.list();
    } catch (Throwable t) {
        log.error(t, t);
    }
    return res;
}

From source file:es.emergya.bbdd.dao.UsuarioHome.java

License:Open Source License

@SuppressWarnings("unchecked")
@Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW)
public List<Usuario> getByFilter(Usuario u) {
    List<Usuario> res = new ArrayList<Usuario>(0);

    org.hibernate.Session currentSession = getSession();
    currentSession.clear();//from w ww.ja va  2s  .  c  o m
    Criteria criteria = currentSession.createCriteria(Usuario.class).addOrder(Order.asc("nombreUsuario"));

    if (u.getInfoAdicional() != null)
        criteria = criteria.add(
                Restrictions.ilike("infoAdicional", LogicConstants.getGenericString(u.getInfoAdicional())));
    if (u.getAdministrador() != null)
        criteria = criteria.add(Restrictions.eq("administrador", u.getAdministrador()));
    if (u.getHabilitado() != null)
        criteria = criteria.add(Restrictions.eq("habilitado", u.getHabilitado()));
    if (u.getNombreUsuario() != null)
        criteria = criteria.add(
                Restrictions.ilike("nombreUsuario", LogicConstants.getGenericString(u.getNombreUsuario())));
    if (u.getNombre() != null)
        criteria = criteria.add(Restrictions.ilike("nombre", LogicConstants.getGenericString(u.getNombre())));
    if (u.getApellidos() != null)
        criteria = criteria
                .add(Restrictions.ilike("apellidos", LogicConstants.getGenericString(u.getApellidos())));
    if (u.getRoles() != null)
        criteria = criteria.createCriteria("roles")
                .add(Restrictions.ilike("nombre", LogicConstants.getGenericString(u.getRoles().getNombre())));

    res = criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();

    for (Usuario usu : res)
        if (usu != null) {
            if (usu.getRoles() != null)
                usu.getRoles().getId();
        }

    return res;
}

From source file:es.pode.auditoria.CriteriaSearch.java

/**
 * Locates a <code>Criteria</code> for a <code>childEntityName</code>. If a
 * <code>Criteria</code> exists for the <code>childEntityName</code>, it is returned. If
 * not, one is created and referenced in the <code>childCriteriaMap</code> under the
 * <code>childEntityName</code>.
 *
 * @param childEntityName//from  w ww  . j  a  va 2s .c  o  m
 * @param parentCriteria
 * @return criteria The Criteria for the childEntityName.
 * @throws org.hibernate.HibernateException
 */
private org.hibernate.Criteria locateCriteria(String childEntityName, org.hibernate.Criteria parentCriteria)
        throws org.hibernate.HibernateException {
    if (this.childCriteriaMap.containsKey(childEntityName)) {
        return (org.hibernate.Criteria) this.childCriteriaMap.get(childEntityName);
    }
    org.hibernate.Criteria childCriteria = parentCriteria.createCriteria(childEntityName);
    if (this.configuration.isForceEagerLoading()) {
        parentCriteria.setFetchMode(childEntityName, org.hibernate.FetchMode.JOIN);
    }
    this.childCriteriaMap.put(childEntityName, childCriteria);
    return childCriteria;
}

From source file:es.sm2.openppm.core.dao.ActivitysellerDAO.java

License:Open Source License

/**
 * Find by seller and project/*from   w ww. ja  v  a  2  s. c om*/
 * 
 * @param seller
 * @param project
 * @return
 */
@SuppressWarnings("unchecked")
public List<Activityseller> findBySellerAndProject(Seller seller, Project project) {

    Criteria crit = getSession().createCriteria(getPersistentClass());

    // Filter by seller
    crit.add(Restrictions.eq(Activityseller.SELLER, seller))
            .add(Restrictions.isNotNull(Activityseller.INDIRECT));

    Criteria critProjectActivity = crit.createCriteria(Activityseller.PROJECTACTIVITY);

    // Filter by project
    critProjectActivity.add(Restrictions.eq(Projectactivity.PROJECT, project));

    return crit.list();
}