Example usage for org.hibernate SQLQuery list

List of usage examples for org.hibernate SQLQuery list

Introduction

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

Prototype

List<R> list();

Source Link

Document

Return the query results as a List.

Usage

From source file:com.krawler.customFieldMaster.fieldManager.java

License:Open Source License

public ArrayList getColumnModel(String moduleid, String companyid) {
    ArrayList colmodel = new ArrayList();
    Session session = HibernateUtil.getCurrentSession();
    try {/*from w  w w .j av a 2s. c om*/
        String query = "SELECT fieldname,fieldlabel,isessential,maxlength,validationtype,id,fieldtype,iseditable FROM fieldparams where moduleid = ? and companyid = ? ";
        SQLQuery sql = session.createSQLQuery(query);
        sql.setParameter(0, moduleid);
        sql.setParameter(1, companyid);
        colmodel = (ArrayList) sql.list();
    } catch (Exception e) {

    } finally {
        HibernateUtil.closeSession(session);
    }

    return colmodel;
}

From source file:com.krawler.customFieldMaster.fieldManager.java

License:Open Source License

public ArrayList getComboData(String fieldid, String companyid) {
    ArrayList colmodel = new ArrayList();
    Session session = HibernateUtil.getCurrentSession();
    try {//from  w w  w . j a v  a2 s .c  om
        String query = "SELECT `id`,`name` from fieldComboData  where fieldid = ?";
        SQLQuery sql = session.createSQLQuery(query);
        sql.setParameter(0, fieldid);
        colmodel = (ArrayList) sql.list();
    } catch (Exception e) {

    } finally {
        HibernateUtil.closeSession(session);
    }

    return colmodel;

}

From source file:com.krawler.spring.importFunctionality.ImportImpl.java

License:Open Source License

@Override
public List getCustomComboID(String fetchColumn, ArrayList filterNames, ArrayList filterValues)
        throws ServiceException, DataInvalidateException {
    try {// ww  w . j  a  va  2s.c  o  m
        //            "SELECT id FROM fieldComboData where name = ? and fieldid = ?"
        String query = "SELECT " + fetchColumn + " FROM fieldComboData ";
        String filter = StringUtil.filterQuery(filterNames, "where");
        query += filter;
        SQLQuery sql = hibernateTemplate.getSessionFactory().getCurrentSession().createSQLQuery(query);
        if (filterValues != null) {
            for (int i = 0; i < filterValues.size(); i++) {
                sql.setParameter(i, filterValues.get(i));
            }
        }
        return sql.list();
    } catch (Exception e) {
        throw ServiceException.FAILURE("ImportImpl. : getCustomComboID" + e.getMessage(), e);
    }
}

From source file:com.laborun.dao.QueueDaoImp.java

public List<Integer> getTraineeInQueue(QueueD queue) {
    Session session = Connection.getConnection();
    List<Trainee> Trainees = null;
    String sql = "select trainee_id from trainee_in_queue where queue_id = " + queue.getId();
    SQLQuery query = session.createSQLQuery(sql);

    List results = query.list();

    return results;
}

From source file:com.liferay.jbpm.db.GraphSession.java

License:Open Source License

public int countProcessInstancesBySearchTerms(String definitionName, String definitionVersion,
        String startDateGT, String startDateLT, String endDateGT, String endDateLT, boolean hideEndedTasks,
        String assignedUserId, boolean andOperator) {

    try {/*from  www .  ja  v a2s  . c o m*/
        int definitionVersionInt = 0;

        if (!Validator.isNumber(definitionVersion)) {
            definitionVersion = null;
        } else {
            definitionVersionInt = GetterUtil.getInteger(definitionVersion);
        }

        String assignedUserIdInnerJoin = StringPool.BLANK;
        String assignedUserIdCheck = StringPool.BLANK;

        if (Validator.isNotNull(assignedUserId)) {
            assignedUserIdInnerJoin = "INNER JOIN JBPM_TOKEN ON JBPM_TOKEN.PROCESSINSTANCE_ = "
                    + "JBPM_PROCESSINSTANCE.ID_ INNER JOIN "
                    + "JBPM_TASKINSTANCE ON JBPM_TASKINSTANCE.TOKEN_ = " + "JBPM_TOKEN.ID_ ";
            assignedUserIdCheck = "(JBPM_TASKINSTANCE.ACTORID_ = ?) AND ";
        }

        String endDateCheck = "(JBPM_PROCESSINSTANCE.END_ IS NULL) ";

        if (!hideEndedTasks) {
            endDateCheck = "((JBPM_PROCESSINSTANCE.END_ >= ? [$AND_OR_NULL_CHECK$]) "
                    + "AND (JBPM_PROCESSINSTANCE.END_ <= ? " + "[$AND_OR_NULL_CHECK$])) ";
        }

        String sql = CustomSQLUtil.get(COUNT_PROCESS_INSTANCES_BY_SEARCH_TERMS);

        sql = StringUtil.replace(sql, "[$ASSIGNED_USER_ID_INNER_JOIN$]", assignedUserIdInnerJoin);
        sql = StringUtil.replace(sql, "[$ASSIGNED_USER_ID_CHECK$]", assignedUserIdCheck);
        sql = StringUtil.replace(sql, "[$END_DATE_CHECK$]", endDateCheck);
        sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);

        SQLQuery q = _session.createSQLQuery(sql);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(definitionName);
        qPos.add(definitionName);
        qPos.add(definitionVersionInt);
        qPos.add(definitionVersion);
        qPos.add(_getDate(startDateGT, true));
        qPos.add(_getDate(startDateGT, true));
        qPos.add(_getDate(startDateLT, false));
        qPos.add(_getDate(startDateLT, false));

        if (assignedUserId != null) {
            qPos.add(assignedUserId);
        }

        if (!hideEndedTasks) {
            qPos.add(_getDate(endDateGT, true));
            qPos.add(_getDate(endDateGT, true));
            qPos.add(_getDate(endDateLT, false));
            qPos.add(_getDate(endDateLT, false));
        }

        Iterator itr = q.list().iterator();

        if (itr.hasNext()) {
            Number count = (Number) itr.next();

            if (count != null) {
                return count.intValue();
            }
        }

        return 0;
    } catch (Exception e) {
        _log.error(e, e);

        throw new RuntimeException(e.getMessage());
    }
}

From source file:com.liferay.jbpm.db.GraphSession.java

License:Open Source License

public int countTaskInstancesBySearchTerms(String taskName, String definitionName, String assignedTo,
        String createDateGT, String createDateLT, String startDateGT, String startDateLT, String endDateGT,
        String endDateLT, boolean hideEndedTasks, boolean andOperator) {

    try {/*from w  ww  .  j av  a  2 s .  c  om*/
        String sql = "";

        int index = 0;

        if (Validator.isNull(assignedTo) || assignedTo.equals("all")) {
            sql += "(";
            sql += CustomSQLUtil.get(COUNT_TASK_INSTANCES_BY_ACTOR);
            sql += ") ";
            sql += "UNION ";
            sql += "(";
            sql += CustomSQLUtil.get(COUNT_TASK_INSTANCES_BY_POOL);
            sql += ") ";

            index = 2;
        } else if (assignedTo.equals("me")) {
            sql += CustomSQLUtil.get(COUNT_TASK_INSTANCES_BY_ACTOR);

            index = 1;
        } else if (assignedTo.equals("pool")) {
            sql += CustomSQLUtil.get(COUNT_TASK_INSTANCES_BY_POOL);

            index = 1;
        }

        String endDateCheck = "(JBPM_TASKINSTANCE.END_ IS NULL) ";

        if (!hideEndedTasks) {
            endDateCheck = "((JBPM_TASKINSTANCE.END_ >= ? " + "[$AND_OR_NULL_CHECK$]) AND "
                    + "(JBPM_TASKINSTANCE.END_ <= ? [$AND_OR_NULL_CHECK$])) ";
        }

        sql = StringUtil.replace(sql, "[$END_DATE_CHECK$]", endDateCheck);
        sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);

        SQLQuery q = _session.createSQLQuery(sql);

        QueryPos qPos = QueryPos.getInstance(q);

        for (int i = 0; i < index; i++) {
            qPos.add(taskName);
            qPos.add(taskName);
            qPos.add(definitionName);
            qPos.add(definitionName);
            qPos.add(_getDate(createDateGT, true));
            qPos.add(_getDate(createDateGT, true));
            qPos.add(_getDate(createDateLT, false));
            qPos.add(_getDate(createDateLT, false));
            qPos.add(_getDate(startDateGT, true));
            qPos.add(_getDate(startDateGT, true));
            qPos.add(_getDate(startDateLT, false));
            qPos.add(_getDate(startDateLT, false));

            if (!hideEndedTasks) {
                qPos.add(_getDate(endDateGT, true));
                qPos.add(_getDate(endDateGT, true));
                qPos.add(_getDate(endDateLT, false));
                qPos.add(_getDate(endDateLT, false));
            }

            qPos.add(_userId);
        }

        int count = 0;

        Iterator itr = q.list().iterator();

        while (itr.hasNext()) {
            Number i = (Number) itr.next();

            if (i != null) {
                count += i.intValue();
            }
        }

        return count;
    } catch (Exception e) {
        _log.error(e, e);

        throw new RuntimeException(e.getMessage());
    }
}

From source file:com.liferay.samplehibernate.util.FoodItemUtil.java

License:Open Source License

public static List getFoodItems() throws Exception {
    Session session = null;//www. ja  va 2 s .  c o  m

    try {
        session = HibernateUtil.openSession();

        session.beginTransaction();

        SQLQuery q = session.createSQLQuery(_GET_FOOD_ITEMS);

        q.addEntity("FoodItem", FoodItem.class);

        List list = q.list();

        session.getTransaction().commit();

        return list;
    } catch (Exception e) {
        throw new Exception(e);
    } finally {
        HibernateUtil.closeSession(session);
    }
}

From source file:com.lighting.platform.base.dao.HibernateDao.java

License:Apache License

public <K> Page<K> pageSQLQuery(PageConfig pageConfig, SQLQuery sqlQuery, Object... values) {
    Page<K> page = new Page<K>(pageConfig);
    String totalSql = "select count(*) as total from(" + sqlQuery.getQueryString() + ")";
    Query countQuery = this.getSession().createSQLQuery(totalSql);
    setParams(countQuery, values);//  w ww . jav  a2  s .c  o  m
    Number total = (Number) countQuery.uniqueResult();
    if (total != null) {
        page.setTotal(total.longValue());
        sqlQuery.setFirstResult(page.getOffset()).setMaxResults(page.getPageSize());
        setParams(sqlQuery, values);
        List<K> list = sqlQuery.list();
        page.setRows(list);
    } else {
        page.setTotal(0);
        page.setRows(new ArrayList<K>());
    }
    return page;
}

From source file:com.liusoft.dlog4j.dao.DlogDAO.java

License:Open Source License

/**
 * ?,(site=-1)/*from w w  w. j  ava2s.  com*/
 * @param site
 * @param count
 * @return
 */
public static List listHotTags(int site, int count) {
    Session ssn = getSession();
    StringBuffer sql = new StringBuffer("SELECT tag_name,COUNT(*) FROM dlog_tag");
    if (site > 0)
        sql.append(" WHERE site_id=?");
    sql.append(" GROUP BY tag_name ORDER BY 2 DESC");
    SQLQuery query = ssn.createSQLQuery(sql.toString());
    if (site > 0)
        query.setInteger(0, site);
    query.setMaxResults(count);
    List tags = new ArrayList();
    List results = query.list();
    for (int i = 0; results != null && i < results.size(); i++) {
        tags.add(((Object[]) results.get(i))[0]);
    }
    return tags;
}

From source file:com.liyablieva.jaxws.dao.EmployeeDAOImpl.java

@SuppressWarnings("unchecked")
@Override// w  ww.j a  v  a 2 s.c  o m
@Transactional(value = "transactionManager")
public List<Employee> getEmployees(String department) {

    System.out.println("In get employees DAO");
    int departmentId = getDepartmentId(department);
    System.out.println("Department = " + department + ", departmentId = " + departmentId);

    List<Employee> employees = Collections.emptyList();

    String sql = "SELECT * FROM employee WHERE department_id = :department_id";
    SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery(sql);
    query.addEntity(Employee.class);
    query.setParameter("department_id", departmentId);
    employees = query.list();

    return employees;
}