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.ghy.common.orm.hibernate.HibernateDao.java

License:Apache License

/**
 * ?sql???map??/*w w  w .  j  a v  a  2  s . c o m*/
 * @param sql
 * @param params
 * @return
 */
public Integer findBySqlCount(String sql, Map<String, ?> params) {
    SQLQuery queryObject = getSession().createSQLQuery(sql);
    if (params != null && params.size() > 0)
        queryObject.setProperties(params);
    List<BigDecimal> qlist = queryObject.list();
    if (qlist != null && qlist.size() > 0) {
        BigDecimal obj = qlist.get(0);
        return obj.intValue();
    }
    return 0;
}

From source file:com.ghy.common.orm.hibernate.HibernateDao.java

License:Apache License

/**
 * //from   www  .j  a  v  a2s. c  o m
 * @param sql
 * @param params
 * @return
 */
public Float findBySqlFloat(String sql, Map<String, ?> params) {
    SQLQuery queryObject = getSession().createSQLQuery(sql);
    if (params != null && params.size() > 0)
        queryObject.setProperties(params);
    List<BigDecimal> qlist = queryObject.list();
    if (qlist != null && qlist.size() > 0) {
        BigDecimal obj = qlist.get(0);
        return obj.floatValue();
    }
    return Float.valueOf(0);
}

From source file:com.ghy.common.orm.hibernate.HibernateDao.java

License:Apache License

/**
 * ?sql???map?map??//from w  ww  .j ava  2 s.c o m
 * @param sql
 * @param params
 * @return
 */
public Integer findBySqlCount(String sql, Map<String, ?> params, Map<String, ?> params2) {
    SQLQuery queryObject = getSession().createSQLQuery(sql);
    if (params != null && params.size() > 0) {
        queryObject.setProperties(params);
    }
    if (params2 != null && params2.size() > 0) {
        queryObject.setProperties(params2);
    }
    List<BigDecimal> qlist = queryObject.list();
    if (qlist != null && qlist.size() > 0) {
        BigDecimal obj = qlist.get(0);
        return obj.intValue();
    }
    return 0;
}

From source file:com.globalsight.calendar.CalendarManagerLocal.java

License:Apache License

/**
 * @see CalendarManager.removeScheduledActivities(long);
 *//*www  .jav a2s  .  c  om*/
public void removeScheduledActivities(long p_taskId) throws RemoteException, CalendarManagerException {
    String ownerId = "";

    Session session = HibernateUtil.getSession();

    try {
        String sql = "select r.* from RESERVED_TIME r, USER_CALENDAR u "
                + " where r.TASK_ID = :TASK_ID and r.USER_CALENDAR_ID = u.ID ";

        SQLQuery query = session.createSQLQuery(sql).addEntity(ReservedTime.class);
        query.setParameter("TASK_ID", new Long(p_taskId));

        Object[] rts = query.list().toArray();

        HashMap map = new HashMap(4);

        for (int i = 0; i < rts.length; i++) {
            ReservedTime rt = (ReservedTime) rts[i];

            Long calId = rt.getUserFluxCalendar().getIdAsLong();
            UserFluxCalendar cal = (UserFluxCalendar) map.get(calId);
            if (cal == null) {
                cal = rt.getUserFluxCalendar();
                map.put(calId, cal);
            }

            ownerId = cal.getOwnerUserId();

            cal.getCollectionByType(rt.getType()).remove(rt);

            HibernateUtil.saveOrUpdate(cal);
        }

        HibernateUtil.delete(Arrays.asList(rts));
    } catch (Exception e) {
        String[] args = { ownerId, String.valueOf(p_taskId) };
        throw new CalendarManagerException(CalendarManagerException.MSG_REMOVE_RESERVED_TIME_FAILED, args, e);
    }
}

From source file:com.globalsight.calendar.CalendarManagerLocal.java

License:Apache License

private Collection getAllCalendarsByHolidayId(Session session, long p_holidayId)
        throws CalendarManagerException {
    try {//from   w  w  w . j  av  a2 s. c  o m
        String sql = " select c.* from CALENDAR c, CALENDAR_HOLIDAY ch "
                + " where ch.HOLIDAY_ID = ? and c.ID = ch.CALENDAR_ID ";

        String currentCompanyId = CompanyThreadLocal.getInstance().getValue();
        if (CompanyWrapper.SUPER_COMPANY_ID.equals(currentCompanyId)) {
            SQLQuery query = session.createSQLQuery(sql).addEntity(FluxCalendar.class);
            query.setParameter(0, new Long(p_holidayId));
            return query.list();
        } else {
            sql += " and c.COMPANY_ID = ? ";
            SQLQuery query = session.createSQLQuery(sql).addEntity(FluxCalendar.class);
            query.setParameter(0, new Long(p_holidayId));
            query.setParameter(1, Long.parseLong(currentCompanyId));
            return query.list();
        }
    } catch (Exception e) {
        String[] arg = { String.valueOf(p_holidayId) };
        throw new CalendarManagerException(CalendarManagerException.MSG_GET_CALENDARS_BY_HOLIDAY_ID_FAILED, arg,
                null);
    }
}

From source file:com.globalsight.cxe.persistence.fileprofile.FileProfilePersistenceManagerLocal.java

License:Apache License

public HashMap<Long, String> getIdViewFileExtensions() throws FileProfileEntityException, RemoteException {
    String sql = "SELECT fp.ID fid,e.NAME ename FROM file_profile fp, extension e, file_profile_extension fpe "
            + "WHERE fp.ID=fpe.FILE_PROFILE_ID AND e.ID=fpe.EXTENSION_ID AND fp.IS_ACTIVE='Y' AND e.IS_ACTIVE='Y'";

    Session session = HibernateUtil.getSession();
    SQLQuery query = session.createSQLQuery(sql);
    Collection<Object[]> listo = query.list();
    HashMap<Long, String> result = new HashMap<Long, String>();
    try {/* w ww.  j a  v  a 2s  .  c o m*/
        for (Iterator<Object[]> a = listo.iterator(); a.hasNext();) {
            Object[] test = a.next();
            long key = ((BigInteger) test[0]).longValue();
            String value = result.get(key);
            if (value != null) {
                result.put(key, value + "<br>" + (String) test[1]);

            } else {
                result.put(key, (String) test[1]);

            }

        }
    }

    catch (Exception e) {
        throw new FileProfileEntityException(e);
    }
    return result;
}

From source file:com.globalsight.everest.permission.PermissionManagerLocal.java

License:Apache License

/**
 * Queries all permissiongroups for this user.
 * /*www . ja  v a 2  s.c o m*/
 * @param p_userId
 *            user
 * @return Collection of PermissionGroups
 */
@SuppressWarnings("unchecked")
public Collection<PermissionGroup> getAllPermissionGroupsForUser(String p_userId)
        throws PermissionException, RemoteException {
    String sql = "select p.* from permissiongroup p, "
            + " permissiongroup_user pu where p.id = pu.permissiongroup_id "
            + " and pu.user_id = :USER_ID_ARG ";

    Session session = HibernateUtil.getSession();
    SQLQuery query = session.createSQLQuery(sql);
    query.addEntity(PermissionGroupImpl.class);
    query.setString("USER_ID_ARG", p_userId);

    try {
        return query.list();
    } catch (Exception e) {
        throw new PermissionException(e);
    }
}

From source file:com.globalsight.everest.permission.PermissionManagerLocal.java

License:Apache License

@SuppressWarnings("unchecked")
public Collection<Object[]> getAlltableNameForUser(String tableName) throws RemoteException {
    String sql = "";
    if (tableName == "permissiongroup") {
        sql = "SELECT  peru.USER_ID uid, per.NAME pname  FROM permissiongroup per, permissiongroup_user peru WHERE per.ID=peru.PERMISSIONGROUP_ID";

    } else if (tableName == "project") {
        sql = "SELECT  peru.USER_ID uid, per.PROJECT_NAME pname  FROM project per, project_user peru WHERE per.PROJECT_SEQ=peru.PROJECT_ID and per.is_active = \"Y\"";

    }// w  w w.j a  va  2 s .  co  m

    Session session = HibernateUtil.getSession();
    SQLQuery query = session.createSQLQuery(sql);
    Collection<Object[]> l = query.list();

    try {
        return l;
    }

    catch (Exception e) {
        throw new PermissionException(e);
    }
}

From source file:com.globalsight.everest.taskmanager.TaskManagerLocal.java

License:Apache License

/**
 * @see TaskManager.removeUserAsTaskAcceptor(String)
 *//* w  ww.j  a v a2  s .com*/
public void removeUserAsTaskAcceptor(String p_userId) throws RemoteException, TaskException {
    // first reassign the user
    try {
        ServerProxy.getWorkflowServer().reassignUserActivitiesToPm(p_userId);
    } catch (Exception e) {
        CATEGORY.error(
                "Failed to reassign the user activities of user " + p_userId + " to the Project Manager.", e);
        return;
    }

    // now reset the acceptor, accepted_date, and task state
    // for all accepted task by this user
    Session session = HibernateUtil.getSession();
    Transaction tx = session.beginTransaction();
    try {
        SQLQuery query = session.createSQLQuery(TaskDescriptorModifier.ACCEPTED_TASK_BY_USER_ID_SQL);
        query.addEntity(TaskImpl.class);
        query.setParameter(TaskDescriptorModifier.TASK_USER_ID_ARG, p_userId);
        Collection col = query.list();

        if (col == null) {
            return;
        }

        Object[] tasks = col.toArray();

        for (int i = 0, size = tasks.length; i < size; i++) {
            Task task = (Task) tasks[i];
            task.setAcceptor(null);
            task.setAcceptedDate(null);
            task.setState(Task.STATE_ACTIVE);
            session.update(task);
        }
        tx.commit();
    } catch (Exception e) {
        tx.rollback();
        CATEGORY.error("Failed to reset task acceptor and state for the removed user " + p_userId + ".", e);
        return;
    }
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.mtprofile.MTProfileHandlerHelper.java

License:Apache License

public static long getMTProfileIdByRelation(long lpId, long wfId) {
    String sql = "SELECT lpwi.MT_PROFILE_ID FROM l10n_profile_wftemplate_info lpwi "
            + " WHERE lpwi.L10N_PROFILE_ID=" + lpId + " AND lpwi.WF_TEMPLATE_ID=" + wfId;
    Session session = HibernateUtil.getSession();
    SQLQuery query = session.createSQLQuery(sql);
    if (query.list() == null || query.list().size() == 0) {
        return -1;
    }/*from ww  w.  j ava  2s.c  om*/

    long mtId = ((BigInteger) session.createSQLQuery(sql).list().get(0)).longValue();
    return mtId;
}