List of usage examples for org.hibernate Session createSQLQuery
@Override NativeQuery createSQLQuery(String queryString);
From source file:com.globalsight.calendar.CalendarManagerLocal.java
License:Apache License
private Collection getAllCalendarsByHolidayId(Session session, long p_holidayId) throws CalendarManagerException { try {//from ww w . jav a2 s . com 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 {/*from w ww.jav a 2s.com*/ 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. * //from ww w . j av a2s . 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 v a 2 s . c om 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) */// www .ja va 2 s. co m 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 www .j a v a2 s.co m long mtId = ((BigInteger) session.createSQLQuery(sql).list().get(0)).longValue(); return mtId; }
From source file:com.globalsight.everest.webapp.pagehandler.administration.mtprofile.MTProfileHandlerHelper.java
License:Apache License
public static String isAble2Delete(long id) { Session session = HibernateUtil.getSession(); String sql = "SELECT lp.NAME FROM l10n_profile lp " + " WHERE lp.ID IN(SELECT lpwi.L10N_PROFILE_ID FROM l10n_profile_wftemplate_info lpwi WHERE lpwi.MT_PROFILE_ID=" + id + " ) " + " AND lp.IS_ACTIVE='y' "; SQLQuery query = session.createSQLQuery(sql); if (query.list() == null || query.list().size() == 0) { return null; } else {//from w w w .ja v a 2 s .com StringBuffer lpnames = new StringBuffer(); List<String> names = query.list(); for (String name : names) { lpnames.append("," + name); } return lpnames.toString(); } }
From source file:com.globalsight.everest.workflow.WorkflowJbpmPersistenceHandler.java
License:Apache License
/** * Gets the task instances in all status. * //from ww w . j a va 2s .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 task instances in all status. */ @SuppressWarnings("unchecked") private static List<TaskInstance> allTaskInstances(String p_userId, Session p_session, boolean p_pm) { SQLQuery query = null; if (p_pm) { query = p_session.createSQLQuery(ALL_TASK_INSTANCES_PM); query.setString(PM, p_userId); } else { query = p_session.createSQLQuery(SqlHolder.allTask); 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 completed task instances./*from www. 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 completed task instances. */ @SuppressWarnings("unchecked") private static List<TaskInstance> completedTaskInstances(String p_userId, Session p_session, boolean p_pm) { SQLQuery query = null; if (p_pm) { query = p_session.createSQLQuery(COMPLETED_TASK_INSTANCES_PM); query.setString(PM, p_userId); } else { query = p_session.createSQLQuery(COMPLETED_TASK_INSTANCES); query.setString(ACTOR_ID, p_userId); } query.addEntity(TaskInstance.class); return query.list(); }
From source file:com.globalsight.everest.workflow.WorkflowJbpmPersistenceHandler.java
License:Apache License
/** * Gets the accepted task instances.//from www .j av a2 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 accepted task instances. */ @SuppressWarnings("unchecked") private static List<TaskInstance> acceptedTaskInstances(String p_userId, Session p_session, boolean p_pm) { SQLQuery query = null; if (p_pm) { query = p_session.createSQLQuery(ACCEPTED_TASK_INSTANCES_PM); query.setString(PM, p_userId); } else { query = p_session.createSQLQuery(ACCEPTED_TASK_INSTANCES); query.setString(ACTOR_ID, p_userId); } query.addEntity(TaskInstance.class); return query.list(); }