Example usage for org.hibernate Session getNamedQuery

List of usage examples for org.hibernate Session getNamedQuery

Introduction

In this page you can find the example usage for org.hibernate Session getNamedQuery.

Prototype

org.hibernate.Query getNamedQuery(String queryName);

Source Link

Document

Create a Query instance for the named query.

Usage

From source file:com.autentia.wuija.persistence.impl.hibernate.HibernateDao.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from   w w  w  .ja v a 2 s  .c o m*/
public <T> Pair<List<T>, Long> findAndCountByNamedQueryWithInStatements(final String namedQuery,
        final String countNamedQuery, final int firstResult, final int maxResults, final Object... params) {
    return (Pair<List<T>, Long>) getHibernateTemplate().execute(new HibernateCallback() {

        @Override
        public Object doInHibernate(Session session) throws HibernateException {
            final Query countQuery = session.getNamedQuery(countNamedQuery);
            addParamsToQueryCheckingIfIsListType(countQuery, params);
            final Long countResult = (Long) countQuery.list().get(0);
            final Query query = session.getNamedQuery(namedQuery);
            addParamsToQueryCheckingIfIsListType(query, params);
            query.setFirstResult(firstResult);
            query.setMaxResults(maxResults);
            return new Pair<List<T>, Long>(query.list(), countResult);
        }

    });
}

From source file:com.bloatit.data.DaoTeam.java

License:Open Source License

/**
 * Get a team using its name.// w  w  w.  ja va 2  s .com
 * 
 * @param name the name of the team we are lookong for.
 * @return the team named <code>name<code> or null if not found.
 */
public static DaoTeam getByName(final String name) {
    final Session session = SessionManager.getSessionFactory().getCurrentSession();
    final Query q = session.getNamedQuery("team.byName");
    q.setString("login", name);
    return (DaoTeam) q.uniqueResult();
}

From source file:com.bloatit.data.DaoTeamMembership.java

License:Open Source License

/**
 * Get a TeamMembership line using its composite key. (HQL request)
 *//*from ww w .  j a  v a 2  s  .  c om*/
protected static DaoTeamMembership get(final DaoTeam team, final DaoMember member) {
    final Session session = SessionManager.getSessionFactory().getCurrentSession();
    final Query q = session.getNamedQuery("teamMembership.byTeamMember");
    q.setEntity("bloatitTeam", team);
    q.setEntity("member", member);
    return (DaoTeamMembership) q.uniqueResult();
}

From source file:com.bluexml.side.Framework.alfresco.jbpm.CustomJBPMEngine.java

License:Open Source License

@SuppressWarnings("unchecked")
private List<WorkflowTask> findActiveTaskInstances(final String authority, JbpmContext context) {
    Session session = context.getSession();
    Query query = session.getNamedQuery("org.alfresco.repo.workflow.findTaskInstancesByActorId");
    query.setString("actorId", authority);
    query.setBoolean("true", true);
    List<WorkflowTask> workflowTasks = getWorkflowTasks(session, query.list());
    // Do we need to clear a session here? It takes 3 seconds with 2000 workflows.
    // session.clear();
    return workflowTasks;
}

From source file:com.bluexml.side.Framework.alfresco.jbpm.CustomJBPMEngine.java

License:Open Source License

@SuppressWarnings({ "unchecked", "cast" })
private void cacheVariablesNoBatch(Session session, List<Long> contextInstanceIds,
        Map<Long, TokenVariableMap> variablesCache) {
    Query query = session.getNamedQuery("org.alfresco.repo.workflow.cacheInstanceVariables");
    query.setParameterList("ids", contextInstanceIds);
    query.setCacheMode(CacheMode.PUT);//from  w  ww  .  j  a  v a2 s .  co m
    query.setFlushMode(FlushMode.MANUAL);
    query.setCacheable(true);

    List<TokenVariableMap> results = (List<TokenVariableMap>) query.list();
    for (TokenVariableMap tokenVariableMap : results) {
        variablesCache.put(tokenVariableMap.getContextInstance().getId(), tokenVariableMap);
    }
}

From source file:com.bluexml.side.Framework.alfresco.jbpm.CustomJBPMEngine.java

License:Open Source License

@SuppressWarnings({ "unchecked", "cast" })
private void cacheTasksNoBatch(Session session, List<Long> taskInstanceIds, Map<Long, TaskInstance> returnMap) {
    Query query = session.getNamedQuery("org.alfresco.repo.workflow.cacheTaskInstanceProperties");
    query.setParameterList("ids", taskInstanceIds);
    query.setCacheMode(CacheMode.PUT);/*from w  w w.jav  a  2s  . c o  m*/
    query.setFlushMode(FlushMode.MANUAL);
    query.setCacheable(true);

    List<TaskInstance> results = (List<TaskInstance>) query.list();
    for (TaskInstance taskInstance : results) {
        returnMap.put(taskInstance.getId(), taskInstance);
    }
}

From source file:com.cis.paseaproduccionweb.dao.ArchivoPaseDao.java

public int PasarProduccion() {

    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = null;// w  w  w.j av a  2s .c om
    Integer resultado = -1;

    try {
        tx = session.getTransaction();
        tx.begin();
        Query q = session.getNamedQuery("SP_PASE_PRODUCCION");
        resultado = (Integer) q.uniqueResult();
        tx.commit();
    } catch (Exception e) {
        if (tx != null)
            tx.rollback();
        ErroresDao dError = new ErroresDao();
        PpErrores error = new PpErrores();
        Date date = new Date();

        error.setStacktrace(e.toString());
        error.setFecha(date);
        dError.insertarError(error);
    } finally {
        session.close();
    }

    return resultado;

}

From source file:com.cis.paseaproduccionweb.dao.ArchivoPaseDao.java

public void PasarProduccionServicios() {

    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = null;//from   w  w  w.  ja v  a 2  s . c o m

    try {
        tx = session.getTransaction();
        tx.begin();
        Query q = session.getNamedQuery("SP_PASE_PRODUCCION_SERVICIOS");
        Object resultado = q.uniqueResult();
        tx.commit();
    } catch (Exception e) {
        if (tx != null)
            tx.rollback();
        ErroresDao dError = new ErroresDao();
        PpErrores error = new PpErrores();
        Date date = new Date();

        error.setStacktrace(e.toString());
        error.setFecha(date);
        dError.insertarError(error);
    } finally {
        session.close();
    }

}

From source file:com.cis.paseaproduccionweb.dao.HistorialesDao.java

public Integer getLastVersion(String nombre, BigDecimal sistemaId) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = null;//from  w  w  w  .j a v  a 2 s .  c  o m
    Object resultado;

    try {
        tx = session.getTransaction();
        tx.begin();
        Query q = session.getNamedQuery("SP_ULTIMA_VERSION_HISTORIAL");
        q.setString(0, nombre);
        q.setBigDecimal(1, sistemaId);
        resultado = q.uniqueResult();
        tx.commit();
        return (Integer) resultado;
    } catch (Exception e) {
        if (tx != null)
            tx.rollback();
        ErroresDao dError = new ErroresDao();
        PpErrores error = new PpErrores();
        Date date = new Date();

        error.setStacktrace(e.toString());
        error.setFecha(date);
        dError.insertarError(error);
    } finally {
        session.close();
    }
    return 0;
}

From source file:com.DaoImp.LoginDaoImp.java

@Override
public Usuarios ObtenerDatosUsr(Usuarios usuario) {

    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction t = session.beginTransaction();
    Query q = session.getNamedQuery("Usr.Login");
    q.setParameter("alias", usuario.getAliass()).setParameter("passUsr", usuario.getPassUsr());
    return (Usuarios) q.uniqueResult();
}