Example usage for org.hibernate.type LongType INSTANCE

List of usage examples for org.hibernate.type LongType INSTANCE

Introduction

In this page you can find the example usage for org.hibernate.type LongType INSTANCE.

Prototype

LongType INSTANCE

To view the source code for org.hibernate.type LongType INSTANCE.

Click Source Link

Usage

From source file:org.squashtest.tm.service.security.acls.jdbc.DerivedPermissionsManager.java

License:Open Source License

private Collection<Long> findMembers(long partyId) {

    Query query = em.unwrap(Session.class).createSQLQuery(FIND_TEAM_MEMBERS_OR_USER);
    query.setParameter("id", partyId, LongType.INSTANCE);
    query.setResultTransformer(new SqLIdResultTransformer());
    return query.list();

}

From source file:org.squashtest.tm.service.security.acls.jdbc.DerivedPermissionsManager.java

License:Open Source License

private Collection<Long> findUsers(ObjectIdentity identity) {

    // first find the parties managing that thing
    Query query = em.unwrap(Session.class).createSQLQuery(FIND_PARTIES_USING_IDENTITY);
    query.setParameter("id", identity.getIdentifier(), LongType.INSTANCE);
    query.setParameter("class", identity.getType(), StringType.INSTANCE);
    query.setResultTransformer(new SqLIdResultTransformer());

    Collection<Long> partyIds = query.list();

    // then find the corresponding users
    Collection<Long> userIds = new HashSet<>();
    for (Long id : partyIds) {
        userIds.addAll(findMembers(id));
    }/*from  w w w. java2 s .  c o  m*/

    return userIds;

}

From source file:org.squashtest.tm.service.security.acls.jdbc.DerivedPermissionsManager.java

License:Open Source License

private void removeProjectManagerAuthorities(Collection<Long> ids) {
    if (!ids.isEmpty()) {
        Query query = em.unwrap(Session.class).createSQLQuery(REMOVE_CORE_PARTY_MANAGER_AUTHORITY);
        query.setParameterList("ids", ids, LongType.INSTANCE);
        query.executeUpdate();//from w  w w.  j av  a2 s .  c  o m
    }
}

From source file:org.squashtest.tm.service.security.acls.jdbc.DerivedPermissionsManager.java

License:Open Source License

private Collection<Long> retainUsersManagingAnything(Collection<Long> ids) {
    if (!ids.isEmpty()) {

        Set<Long> userIds = new HashSet<>();
        Collection<Long> buffer;

        // first, get users directly managing anything
        Query query = em.unwrap(Session.class).createSQLQuery(RETAIN_USERS_MANAGING_ANYTHING);
        query.setParameterList("ids", ids, LongType.INSTANCE);
        query.setResultTransformer(new SqLIdResultTransformer());

        buffer = query.list();// w w w .  j a  v  a  2  s .co m
        userIds.addAll(buffer);

        // second, get users managing through teams or project leaders (which sounds quite silly I agree)
        query = em.unwrap(Session.class).createSQLQuery(RETAIN_MEMBERS_OF_TEAMS_MANAGING_ANYTHING);
        query.setParameterList("ids", ids, LongType.INSTANCE);
        query.setResultTransformer(new SqLIdResultTransformer());

        buffer = query.list();
        userIds.addAll(buffer);

        return userIds;
    } else {
        return Collections.emptyList();
    }
}

From source file:org.squashtest.tm.service.security.acls.jdbc.DerivedPermissionsManager.java

License:Open Source License

private void grantProjectManagerAuthorities(Collection<Long> ids) {
    Query query;//from  w  w w  .j a  va  2  s  .c o  m
    for (Long id : ids) {
        query = em.unwrap(Session.class).createSQLQuery(INSERT_CORE_PARTY_MANAGER_AUTHORITY);
        query.setParameter("id", id, LongType.INSTANCE);
        query.executeUpdate();
    }

}

From source file:org.unitime.timetable.dataexchange.CourseOfferingExport.java

License:Apache License

public void saveXml(Document document, Session session, Properties parameters) throws Exception {
    try {//from   www.j  a v  a 2  s .  c  om
        beginTransaction();

        iExportGroupInfos = ApplicationProperty.DataExchangeIncludeStudentGroups.isTrue();
        iExportAssignments = "true".equals(parameters.getProperty("tmtbl.export.timetable", "true"));
        boolean examsOnly = "true".equals(parameters.getProperty("tmtbl.export.exam"));
        Element root = document.addElement(examsOnly ? "exams" : "offerings");
        root.addAttribute("campus", session.getAcademicInitiative());
        root.addAttribute("year", session.getAcademicYear());
        root.addAttribute("term", session.getAcademicTerm());
        root.addAttribute("dateFormat", sDateFormat.toPattern());
        root.addAttribute("timeFormat", sTimeFormat.toPattern());
        root.addAttribute("created", new Date().toString());
        if (examsOnly)
            root.addAttribute("type", parameters.getProperty("tmtbl.export.exam.type", "all"));
        root.addAttribute("includeExams", parameters.getProperty("tmtbl.export.exam.type", "all"));

        document.addDocType(examsOnly ? "exams" : "offerings",
                "-//UniTime//DTD University Course Timetabling/EN",
                "http://www.unitime.org/interface/CourseOfferingExport.dtd");

        SolverParameterDef maxRoomsParam = SolverParameterDef.findByNameType(getHibSession(), "Exams.MaxRooms",
                SolverParameterGroup.SolverType.EXAM);
        if (maxRoomsParam != null && maxRoomsParam.getDefault() != null)
            iDefaultMaxNbrRooms = Integer.valueOf(maxRoomsParam.getDefault());

        if (iExportAssignments && ApplicationProperty.DataExchangeIncludeMeetings.isTrue()) {
            iClassEvents = new HashMap<Long, ClassEvent>();
            for (ClassEvent e : (List<ClassEvent>) getHibSession().createQuery(
                    "from ClassEvent e where e.clazz.schedulingSubpart.instrOfferingConfig.instructionalOffering.session.uniqueId = :sessionId")
                    .setLong("sessionId", session.getUniqueId()).list()) {
                iClassEvents.put(e.getClazz().getUniqueId(), e);
            }
            iMeetingLocations = new HashMap<Long, Location>();
            for (Location l : (List<Location>) getHibSession()
                    .createQuery("from Location l where l.session.uniqueId = :sessionId")
                    .setLong("sessionId", session.getUniqueId()).list()) {
                iMeetingLocations.put(l.getPermanentId(), l);
            }
        }

        if (examsOnly) {
            if ("all".equals(parameters.getProperty("tmtbl.export.exam.type", "all"))
                    || "final".equals(parameters.getProperty("tmtbl.export.exam.type", "all"))) {
                for (Iterator i = new TreeSet(Exam.findAllFinal(session.getUniqueId())).iterator(); i
                        .hasNext();) {
                    Exam exam = (Exam) i.next();
                    exportExam(root, null, exam, session);
                }
            }
            if ("all".equals(parameters.getProperty("tmtbl.export.exam.type", "all"))
                    || "midterm".equals(parameters.getProperty("tmtbl.export.exam.type", "all"))) {
                for (Iterator i = new TreeSet(Exam.findAllMidterm(session.getUniqueId())).iterator(); i
                        .hasNext();) {
                    Exam exam = (Exam) i.next();
                    exportExam(root, null, exam, session);
                }
            }
        } else {
            info("Loading offerings...");
            String subjects = parameters.getProperty("tmtbl.export.subjects");

            List offerings = null;
            if (subjects == null || subjects.isEmpty()) {
                offerings = getHibSession().createQuery("select distinct io from InstructionalOffering io "
                        + "inner join fetch io.courseOfferings as co inner join fetch co.subjectArea sa "
                        + "left join fetch io.instrOfferingConfigs as ioc "
                        + "left join fetch ioc.schedulingSubparts as ss " + "left join fetch ss.classes as c "
                        + "where " + "io.session.uniqueId=:sessionId "
                        + "order by sa.subjectAreaAbbreviation, co.courseNbr")
                        .setLong("sessionId", session.getUniqueId().longValue()).setFetchSize(1000).list();
            } else {
                List<Long> subjectIds = new ArrayList<Long>();
                for (String id : subjects.split(","))
                    subjectIds.add(Long.valueOf(id));
                offerings = getHibSession().createQuery("select distinct io from InstructionalOffering io "
                        + "inner join fetch io.courseOfferings as co inner join fetch co.subjectArea sa "
                        + "left join fetch io.instrOfferingConfigs as ioc "
                        + "left join fetch ioc.schedulingSubparts as ss " + "left join fetch ss.classes as c "
                        + "where " + "io.session.uniqueId=:sessionId "
                        + "and io.uniqueId in (select x.instructionalOffering.uniqueId from CourseOffering x where x.isControl = true and x.subjectArea.uniqueId in (:subjects)) "
                        + "order by sa.subjectAreaAbbreviation, co.courseNbr")
                        .setLong("sessionId", session.getUniqueId().longValue())
                        .setParameterList("subjects", subjectIds, LongType.INSTANCE).setFetchSize(1000).list();
            }

            if (!"none".equals(parameters.getProperty("tmtbl.export.exam.type", "all"))) {
                info("Loading exams...");
                List allExams = getHibSession()
                        .createQuery("select x from Exam x left join fetch x.owners o "
                                + "where x.session.uniqueId=:sessionId"
                                + ("midterm".equals(parameters.getProperty("tmtbl.export.exam.type", "all"))
                                        ? " and x.examType.type=" + ExamType.sExamTypeMidterm
                                        : "")
                                + ("final".equals(parameters.getProperty("tmtbl.export.exam.type", "all"))
                                        ? " and x.examType.type=" + ExamType.sExamTypeFinal
                                        : ""))
                        .setLong("sessionId", session.getUniqueId().longValue()).setFetchSize(1000).list();

                iExams = new Hashtable();
                info("Checking exams...");
                for (Iterator i = allExams.iterator(); i.hasNext();) {
                    Exam exam = (Exam) i.next();
                    for (Iterator j = exam.getOwners().iterator(); j.hasNext();) {
                        ExamOwner owner = (ExamOwner) j.next();
                        Long offeringId = owner.getCourse().getInstructionalOffering().getUniqueId();
                        TreeSet<Exam> exams = iExams.get(offeringId);
                        if (exams == null) {
                            exams = new TreeSet();
                            iExams.put(offeringId, exams);
                        }
                        exams.add(exam);
                    }
                }
            }

            info("Exporting " + offerings.size() + " offerings ...");
            for (Iterator i = offerings.iterator(); i.hasNext();) {
                InstructionalOffering io = (InstructionalOffering) i.next();
                exportInstructionalOffering(root, io, session);
            }
        }

        commitTransaction();
    } catch (Exception e) {
        fatal("Exception: " + e.getMessage(), e);
        rollbackTransaction();
    }
}

From source file:org.unitime.timetable.onlinesectioning.custom.purdue.UCCCoursesLookup.java

License:Apache License

@Override
public List<CourseOffering> getCourses(AcademicSessionInfo session, Session hibSession, String query,
        boolean allowPartialMatch) {
    String q = fixQuery(query);/*from   w  ww.  ja  va 2s  . com*/
    if (q == null)
        return null;
    if (useCache()) {
        List<Long> courseIds = new ArrayList<Long>();
        boolean fullMatch = false;
        for (CourseAttribute ca : getCourseAttributes(session, hibSession)) {
            if (ca.isFullMatch(q)) {
                if (!fullMatch) {
                    fullMatch = true;
                    courseIds.clear();
                }
                courseIds.addAll(ca.getCourseIds());
            } else if (allowPartialMatch && !fullMatch && ca.isPartialMatch(q)) {
                courseIds.addAll(ca.getCourseIds());
            }
        }
        if (courseIds == null || courseIds.isEmpty())
            return null;
        return (List<CourseOffering>) hibSession
                .createQuery(
                        "from CourseOffering where uniqueId in :courseIds order by subjectAreaAbbv, courseNbr")
                .setParameterList("courseIds", courseIds, LongType.INSTANCE).setCacheable(true).list();
    } else {
        List courseIds = hibSession.createSQLQuery(getCourseLookupFullSQL())
                .setLong("sessionId", session.getUniqueId()).setString("term", getBannerTerm(session))
                .setString("query", q).list();
        if (allowPartialMatch && (courseIds == null || courseIds.isEmpty())) {
            courseIds = hibSession.createSQLQuery(getCourseLookupPartialSQL())
                    .setLong("sessionId", session.getUniqueId()).setString("term", getBannerTerm(session))
                    .setString("query", q).list();
        }
        if (courseIds == null || courseIds.isEmpty())
            return null;
        return (List<CourseOffering>) hibSession
                .createQuery(
                        "from CourseOffering where uniqueId in :courseIds order by subjectAreaAbbv, courseNbr")
                .setParameterList("courseIds", courseIds, BigDecimalType.INSTANCE).setCacheable(true).list();
    }
}

From source file:org.unitime.timetable.server.solver.AssignedClassesBackend.java

License:Apache License

public static void addCrosslistedNames(TableInterface table, boolean showClassSuffix, boolean showConfigNames) {
    Map<Long, TableInterface.TableRowInterface> id2row = new HashMap<Long, TableInterface.TableRowInterface>();
    for (TableInterface.TableRowInterface row : table.getRows()) {
        if (row.hasId())
            id2row.put(row.getId(), row);
    }/*from   www  .j  a v  a 2  s .c o  m*/
    if (id2row.isEmpty())
        return;
    if (id2row.size() <= 1000) {
        for (Object[] o : (List<Object[]>) Class_DAO.getInstance().getSession().createQuery(
                "select c, co from Class_ c inner join c.schedulingSubpart.instrOfferingConfig.instructionalOffering.courseOfferings co where "
                        + "co.isControl = false and c.uniqueId in :classIds order by co.subjectAreaAbbv, co.courseNbr")
                .setParameterList("classIds", id2row.keySet(), LongType.INSTANCE).setCacheable(true).list()) {
            Class_ clazz = (Class_) o[0];
            CourseOffering course = (CourseOffering) o[1];
            TableInterface.TableRowInterface row = id2row.get(clazz.getUniqueId());
            if (row != null)
                ((TableInterface.TableCellClassName) row.getCell(0))
                        .addAlternative(clazz.getClassLabel(course, showClassSuffix, showConfigNames));
        }
    } else {
        List<Long> ids = new ArrayList<Long>(1000);
        for (Long id : id2row.keySet()) {
            ids.add(id);
            if (ids.size() == 1000) {
                for (Object[] o : (List<Object[]>) Class_DAO.getInstance().getSession().createQuery(
                        "select c, co from Class_ c inner join c.schedulingSubpart.instrOfferingConfig.instructionalOffering.courseOfferings co where "
                                + "co.isControl = false and c.uniqueId in :classIds order by co.subjectAreaAbbv, co.courseNbr")
                        .setParameterList("classIds", ids, LongType.INSTANCE).setCacheable(true).list()) {
                    Class_ clazz = (Class_) o[0];
                    CourseOffering course = (CourseOffering) o[1];
                    TableInterface.TableRowInterface row = id2row.get(clazz.getUniqueId());
                    if (row != null)
                        ((TableInterface.TableCellClassName) row.getCell(0))
                                .addAlternative(clazz.getClassLabel(course, showClassSuffix, showConfigNames));
                }
                ids.clear();
            }
        }
        if (!ids.isEmpty()) {
            for (Object[] o : (List<Object[]>) Class_DAO.getInstance().getSession().createQuery(
                    "select c, co from Class_ c inner join c.schedulingSubpart.instrOfferingConfig.instructionalOffering.courseOfferings co where "
                            + "co.isControl = false and c.uniqueId in :classIds order by co.subjectAreaAbbv, co.courseNbr")
                    .setParameterList("classIds", ids, LongType.INSTANCE).setCacheable(true).list()) {
                Class_ clazz = (Class_) o[0];
                CourseOffering course = (CourseOffering) o[1];
                TableInterface.TableRowInterface row = id2row.get(clazz.getUniqueId());
                if (row != null)
                    ((TableInterface.TableCellClassName) row.getCell(0))
                            .addAlternative(clazz.getClassLabel(course, showClassSuffix, showConfigNames));
            }
        }
    }
}

From source file:org.unitime.timetable.server.solver.TimetableGridSolverHelper.java

License:Apache License

public static void addCrosslistedNames(TimetableGridModel model, TimetableGridContext context) {
    Map<Long, List<TimetableGridCell>> id2cells = new HashMap<Long, List<TimetableGridCell>>();
    for (TimetableGridCell cell : model.getCells()) {
        if (cell.getType() != Type.Class || cell.getId() == null || cell.getId() < 0)
            continue;
        List<TimetableGridCell> cells = id2cells.get(cell.getId());
        if (cells == null) {
            cells = new ArrayList<TimetableGridCell>();
            id2cells.put(cell.getId(), cells);
        }/*from  w w  w . ja  v  a  2 s. com*/
        cells.add(cell);
    }
    if (id2cells.isEmpty())
        return;
    if (id2cells.size() <= 1000) {
        for (Object[] o : (List<Object[]>) Class_DAO.getInstance().getSession().createQuery(
                "select c, co from Class_ c inner join c.schedulingSubpart.instrOfferingConfig.instructionalOffering.courseOfferings co where "
                        + "co.isControl = false and c.uniqueId in :classIds order by co.subjectAreaAbbv, co.courseNbr")
                .setParameterList("classIds", id2cells.keySet(), LongType.INSTANCE).setCacheable(true).list()) {
            Class_ clazz = (Class_) o[0];
            CourseOffering course = (CourseOffering) o[1];
            for (TimetableGridCell cell : id2cells.get(clazz.getUniqueId()))
                cell.addName(
                        clazz.getClassLabel(course, context.isShowClassSuffix(), context.isShowConfigName()));
        }
    } else {
        List<Long> ids = new ArrayList<Long>(1000);
        for (Long id : id2cells.keySet()) {
            ids.add(id);
            if (ids.size() == 1000) {
                for (Object[] o : (List<Object[]>) Class_DAO.getInstance().getSession().createQuery(
                        "select c, co from Class_ c inner join c.schedulingSubpart.instrOfferingConfig.instructionalOffering.courseOfferings co where "
                                + "co.isControl = false and c.uniqueId in :classIds order by co.subjectAreaAbbv, co.courseNbr")
                        .setParameterList("classIds", ids, LongType.INSTANCE).setCacheable(true).list()) {
                    Class_ clazz = (Class_) o[0];
                    CourseOffering course = (CourseOffering) o[1];
                    for (TimetableGridCell cell : id2cells.get(clazz.getUniqueId()))
                        cell.addName(clazz.getClassLabel(course, context.isShowClassSuffix(),
                                context.isShowConfigName()));
                }
                ids.clear();
            }
        }
        if (!ids.isEmpty()) {
            for (Object[] o : (List<Object[]>) Class_DAO.getInstance().getSession().createQuery(
                    "select c, co from Class_ c inner join c.schedulingSubpart.instrOfferingConfig.instructionalOffering.courseOfferings co where "
                            + "co.isControl = false and c.uniqueId in :classIds order by co.subjectAreaAbbv, co.courseNbr")
                    .setParameterList("classIds", ids, LongType.INSTANCE).setCacheable(true).list()) {
                Class_ clazz = (Class_) o[0];
                CourseOffering course = (CourseOffering) o[1];
                for (TimetableGridCell cell : id2cells.get(clazz.getUniqueId()))
                    cell.addName(clazz.getClassLabel(course, context.isShowClassSuffix(),
                            context.isShowConfigName()));
            }
        }
    }
}

From source file:org.unitime.timetable.server.solver.TimetableGridSolverHelper.java

License:Apache License

public static void fixClassNames(TimetableGridModel model, TimetableGridContext context) {
    Map<Long, List<TimetableGridCell>> id2cells = new HashMap<Long, List<TimetableGridCell>>();
    for (TimetableGridCell cell : model.getCells()) {
        if (cell.getType() != Type.Class || cell.getId() == null || cell.getId() < 0)
            continue;
        List<TimetableGridCell> cells = id2cells.get(cell.getId());
        if (cells == null) {
            cells = new ArrayList<TimetableGridCell>();
            id2cells.put(cell.getId(), cells);
        }//from w w w.  j  av  a 2  s.co m
        cells.add(cell);
    }
    if (id2cells.isEmpty())
        return;
    if (id2cells.size() <= 1000) {
        for (Object[] o : (List<Object[]>) Class_DAO.getInstance().getSession().createQuery(
                "select c, co from Class_ c inner join c.schedulingSubpart.instrOfferingConfig.instructionalOffering.courseOfferings co where "
                        + "co.isControl = true and c.uniqueId in :classIds order by co.subjectAreaAbbv, co.courseNbr")
                .setParameterList("classIds", id2cells.keySet(), LongType.INSTANCE).setCacheable(true).list()) {
            Class_ clazz = (Class_) o[0];
            CourseOffering course = (CourseOffering) o[1];
            for (TimetableGridCell cell : id2cells.get(clazz.getUniqueId()))
                fixClassName(context, cell, clazz, course);
        }
    } else {
        List<Long> ids = new ArrayList<Long>(1000);
        for (Long id : id2cells.keySet()) {
            ids.add(id);
            if (ids.size() == 1000) {
                for (Object[] o : (List<Object[]>) Class_DAO.getInstance().getSession().createQuery(
                        "select c, co from Class_ c inner join c.schedulingSubpart.instrOfferingConfig.instructionalOffering.courseOfferings co where "
                                + "co.isControl = true and c.uniqueId in :classIds order by co.subjectAreaAbbv, co.courseNbr")
                        .setParameterList("classIds", ids, LongType.INSTANCE).setCacheable(true).list()) {
                    Class_ clazz = (Class_) o[0];
                    CourseOffering course = (CourseOffering) o[1];
                    for (TimetableGridCell cell : id2cells.get(clazz.getUniqueId()))
                        fixClassName(context, cell, clazz, course);
                }
                ids.clear();
            }
        }
        if (!ids.isEmpty()) {
            for (Object[] o : (List<Object[]>) Class_DAO.getInstance().getSession().createQuery(
                    "select c, co from Class_ c inner join c.schedulingSubpart.instrOfferingConfig.instructionalOffering.courseOfferings co where "
                            + "co.isControl = true and c.uniqueId in :classIds order by co.subjectAreaAbbv, co.courseNbr")
                    .setParameterList("classIds", ids, LongType.INSTANCE).setCacheable(true).list()) {
                Class_ clazz = (Class_) o[0];
                CourseOffering course = (CourseOffering) o[1];
                for (TimetableGridCell cell : id2cells.get(clazz.getUniqueId()))
                    fixClassName(context, cell, clazz, course);
            }
        }
    }
}