Example usage for org.hibernate SQLQuery addEntity

List of usage examples for org.hibernate SQLQuery addEntity

Introduction

In this page you can find the example usage for org.hibernate SQLQuery addEntity.

Prototype

SQLQuery<T> addEntity(Class entityType);

Source Link

Document

Declare a "root" entity, without specifying an alias.

Usage

From source file:com.globalsight.everest.workflow.WorkflowJbpmPersistenceHandler.java

License:Apache License

/**
  * Gets the active(available) task instances.
  * /*from  w  w  w . j av a 2 s .c o m*/
  * @param p_userId
  *            the user id.
  * @param p_session
  *            the hibernate session.
  * @param p_pm
  *            is pm or not (true:PM|false:user).
  * 
  * @return the active(available) task instances.
  */
@SuppressWarnings("unchecked")
private static List<TaskInstance> activeTaskInstances(String p_userId, Session p_session, boolean p_pm) {
    SQLQuery query = null;
    if (p_pm) {
        query = p_session.createSQLQuery(SqlHolder.activeTaskPm);
        query.setString(PM, p_userId);
        if (c_logger.isDebugEnabled()) {
            c_logger.debug("The query sql is " + SqlHolder.activeTaskPm);
        }
    } else {
        query = p_session.createSQLQuery(SqlHolder.activeTask);
        if (c_logger.isDebugEnabled()) {
            c_logger.debug("The query sql is " + SqlHolder.activeTask);
        }
        query.setString(ACTOR_ID, p_userId);
    }

    query.setString(VARIABLE_NAME, WorkflowConstants.VARIABLE_IS_REJECTED);
    query.setString(CATEGORY, VARIABLE_CATEGORY_REJECT);
    query.addEntity(TaskInstance.class);

    return query.list();
}

From source file:com.globalsight.everest.workflow.WorkflowJbpmPersistenceHandler.java

License:Apache License

/**
  * Gets the rejected task instances.//from  w  ww .  j a v  a 2  s .c om
  * 
  * @param p_userId
  *            the user id.
  * @param p_session
  *            the hibernate session.
  * @param p_pm
  *            is pm or not (true:PM|false:user).
  * 
  * @return the rejected task instances.
  */
@SuppressWarnings("unchecked")
private static List<TaskInstance> rejectedTaskInstances(String p_userId, Session p_session, boolean p_pm) {
    SQLQuery query = null;
    if (p_pm) {
        query = p_session.createSQLQuery(SqlHolder.rejectTaskPm);
        query.setString(PM, p_userId);
    } else {
        query = p_session.createSQLQuery(SqlHolder.rejectTask);
        query.setString(USER_ID, p_userId);
    }
    query.setString(VARIABLE_NAME, WorkflowConstants.VARIABLE_IS_REJECTED);
    query.setString(CATEGORY, VARIABLE_CATEGORY_REJECT);
    query.addEntity(TaskInstance.class);

    return query.list();
}

From source file:com.globalsight.everest.workflow.WorkflowJbpmPersistenceHandler.java

License:Apache License

/**
  * Gets the task instances with specified task node id.
  * /*from  www. j  av a 2 s.c om*/
  * @param p_taskId -
  *            The task node id.
  * @param p_ctx
  *            the JbpmContext.
  * 
  * @return a list of the task instances.
  */
public static List getTaskInstancesById(long p_taskId, JbpmContext p_ctx) {
    Session session = p_ctx.getSession();
    SQLQuery query = session.createSQLQuery(TASK_INSTANCE_BY_ID);
    query.addEntity(TaskInstance.class);
    query.setLong(TASK_ID, p_taskId);
    List result = query.list();
    return result;
}

From source file:com.globalsight.persistence.hibernate.HibernateUtil.java

License:Apache License

@SuppressWarnings("unchecked")
public static <T> List<T> searchWithSql(Class<T> entityClass, String sql) throws HibernateException {
    Session session = getSession();//  ww  w  .  j  ava2s.  c  o m

    SQLQuery query = session.createSQLQuery(sql);
    query.addEntity(entityClass);
    List<T> result = query.list();

    return result;
}

From source file:com.globalsight.persistence.hibernate.HibernateUtil.java

License:Apache License

@SuppressWarnings("unchecked")
public static <T> List<T> searchWithSql(Class<T> entityClass, String sql, Object param1)
        throws HibernateException {
    Session session = getSession();/*from  w w w.  j  a v  a2  s . c o m*/

    SQLQuery query = session.createSQLQuery(sql);
    query.addEntity(entityClass);
    query.setParameter(0, param1);
    List<T> result = query.list();

    return result;
}

From source file:com.globalsight.persistence.hibernate.HibernateUtil.java

License:Apache License

@SuppressWarnings("unchecked")
public static <T> List<T> searchWithSql(Class<T> entityClass, String sql, Object param1, Object param2)
        throws HibernateException {
    Session session = getSession();/*from  w w  w.  j a v  a2 s .  co m*/

    SQLQuery query = session.createSQLQuery(sql);
    query.addEntity(entityClass);
    query.setParameter(0, param1);
    query.setParameter(1, param2);
    List<T> result = query.list();

    return result;
}

From source file:com.globalsight.persistence.hibernate.HibernateUtil.java

License:Apache License

@SuppressWarnings("unchecked")
public static <T> List<T> searchWithSql(Class<T> entityClass, String sql, Object param1, Object param2,
        Object param3) throws HibernateException {
    Session session = getSession();/*from   w  w  w.ja va2s.  com*/

    SQLQuery query = session.createSQLQuery(sql);
    query.addEntity(entityClass);
    query.setParameter(0, param1);
    query.setParameter(1, param2);
    query.setParameter(2, param3);
    List<T> result = query.list();

    return result;
}

From source file:com.globalsight.persistence.hibernate.HibernateUtil.java

License:Apache License

@SuppressWarnings("unchecked")
public static <T> List<T> searchWithSql(Class<T> entityClass, String sql, Object param1, Object param2,
        Object param3, Object param4) throws HibernateException {
    Session session = getSession();/*from ww w .  j  a v a2s .c  om*/

    SQLQuery query = session.createSQLQuery(sql);
    query.addEntity(entityClass);
    query.setParameter(0, param1);
    query.setParameter(1, param2);
    query.setParameter(2, param3);
    query.setParameter(3, param4);
    List<T> result = query.list();

    return result;
}

From source file:com.globalsight.persistence.hibernate.HibernateUtil.java

License:Apache License

/**
 * Execute sql, return the result./*from  w ww  .  ja  v  a  2 s  .  co m*/
 * 
 * @param sql
 * @param params
 * @return
 */
@SuppressWarnings("unchecked")
public static <T> List<T> searchWithSql(String sql, Map<String, ?> params, Class<T> clazz)
        throws HibernateException {
    Session session = getSession();
    SQLQuery query = session.createSQLQuery(sql);
    query.addEntity(clazz);

    if (params != null) {
        Iterator<String> iterator = params.keySet().iterator();
        while (iterator.hasNext()) {
            String key = iterator.next();
            query.setParameter(key, params.get(key));
        }
    }

    List<T> result = query.list();

    return result;
}

From source file:com.induscorp.prime.testing.ui.core.config.database.DatabaseQueryHandler.java

License:Open Source License

@SuppressWarnings("unchecked")
public <T> List<T> executeSearchQuery(String query, Class<T> entityClass) {
    List<T> foundRecords = null;
    Session hibSession = null;//from w  ww  .j  a  v  a 2 s .  co  m
    try {
        Thread.sleep(5000);

        hibSession = hibernateSessionFactory.openSession();

        SQLQuery sqlQuery = hibSession.createSQLQuery(query);
        sqlQuery.addEntity(entityClass);
        foundRecords = sqlQuery.list();

    } catch (Exception ex) {
        Reporter.log("Error in executing query '" + query + "'.");
        Assert.fail("Error in executing query '" + query + "'.", ex);
    } finally {
        if (hibSession != null) {
            hibSession.close();
        }
    }

    return foundRecords;
}