List of usage examples for java.util Hashtable elements
public synchronized Enumeration<V> elements()
From source file:org.unitime.timetable.test.BatchStudentSectioningLoader.java
public void load(Session session) { org.hibernate.Session hibSession = new SessionDAO().getSession(); Transaction tx = hibSession.beginTransaction(); try {// www. j av a2s . c o m Hashtable courseTable = new Hashtable(); Hashtable classTable = new Hashtable(); List offerings = hibSession .createQuery("select distinct io from InstructionalOffering io " + "left join fetch io.courseOfferings as co " + "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.notOffered=false") .setLong("sessionId", session.getUniqueId().longValue()).setFetchSize(1000).list(); for (Iterator i = offerings.iterator(); i.hasNext();) { InstructionalOffering io = (InstructionalOffering) i.next(); Offering offering = loadOffering(io, courseTable, classTable); if (offering != null) getModel().addOffering(offering); } HashSet loadedStudentIds = new HashSet(); if (iIncludeCourseDemands) { List students = hibSession .createQuery("select distinct s from Student s " + "left join fetch s.courseDemands as cd " + "left join fetch cd.courseRequests as cr " + "where s.session.uniqueId=:sessionId") .setLong("sessionId", session.getUniqueId().longValue()).setFetchSize(1000).list(); for (Iterator i = students.iterator(); i.hasNext();) { org.unitime.timetable.model.Student s = (org.unitime.timetable.model.Student) i.next(); if (s.getCourseDemands().isEmpty()) continue; Student student = loadStudent(s, courseTable, classTable); if (student != null) getModel().addStudent(student); if (s.getExternalUniqueId() != null) loadedStudentIds.add(s.getExternalUniqueId()); } } if (iIncludeLastLikeStudents) { Hashtable classAssignments = null; if (iIncludeUseCommittedAssignments) { classAssignments = new Hashtable(); for (Iterator i = hibSession.createQuery( "select distinct se.studentId, se.clazz.uniqueId from StudentEnrollment se where " + "se.solution.commited=true and se.solution.owner.session.uniqueId=:sessionId") .setLong("sessionId", session.getUniqueId().longValue()).iterate(); i.hasNext();) { Object[] o = (Object[]) i.next(); Long studentId = (Long) o[0]; Long classId = (Long) o[1]; HashSet classIds = (HashSet) classAssignments.get(studentId); if (classIds == null) { classIds = new HashSet(); classAssignments.put(studentId, classIds); } classIds.add(classId); } } Hashtable lastLikeStudentTable = new Hashtable(); for (Iterator i = hibSession.createQuery( "select d, c.uniqueId from LastLikeCourseDemand d left join fetch d.student s, CourseOffering c left join c.demandOffering cx " + "where d.subjectArea.session.uniqueId=:sessionId and c.subjectArea.session.uniqueId=:sessionId and " + "((c.permId=null and d.subjectArea=c.subjectArea and d.courseNbr=c.courseNbr ) or " + " (c.permId!=null and c.permId=d.coursePermId) or " + " (cx.permId=null and d.subjectArea=cx.subjectArea and d.courseNbr=cx.courseNbr) or " + " (cx.permId!=null and cx.permId=d.coursePermId)) " + "order by s.uniqueId, d.priority, d.uniqueId") .setLong("sessionId", session.getUniqueId().longValue()).list().iterator(); i.hasNext();) { Object[] o = (Object[]) i.next(); LastLikeCourseDemand d = (LastLikeCourseDemand) o[0]; org.unitime.timetable.model.Student s = (org.unitime.timetable.model.Student) d.getStudent(); Long courseOfferingId = (Long) o[1]; if (s.getExternalUniqueId() != null && loadedStudentIds.contains(s.getExternalUniqueId())) continue; loadLastLikeStudent(hibSession, d, s, courseOfferingId, lastLikeStudentTable, courseTable, classTable, classAssignments); } for (Enumeration e = lastLikeStudentTable.elements(); e.hasMoreElements();) { Student student = (Student) e.nextElement(); getModel().addStudent(student); } if (classAssignments != null && !classAssignments.isEmpty()) { for (Request request : getModel().variables()) { if (request.getInitialAssignment() == null) continue; Set conflicts = getModel().conflictValues(getAssignment(), request.getInitialAssignment()); if (conflicts.isEmpty()) getAssignment().assign(0, request.getInitialAssignment()); else sLog.debug("Unable to assign " + request.getInitialAssignment() + ", conflicts: " + conflicts); } } fixWeights(); } tx.commit(); } catch (Exception e) { tx.rollback(); throw new RuntimeException(e); } finally { hibSession.close(); } }
From source file:org.unitime.timetable.test.UpdateExamConflicts.java
public TreeSet<ExamAssignmentInfo> loadExams(Long sessionId, Long examTypeId) throws Exception { info("Loading exams..."); long t0 = System.currentTimeMillis(); Hashtable<Long, Exam> exams = new Hashtable(); for (Iterator i = new ExamDAO().getSession().createQuery( "select x from Exam x where x.session.uniqueId=:sessionId and x.examType.uniqueId=:examTypeId") .setLong("sessionId", sessionId).setLong("examTypeId", examTypeId).setCacheable(true).list() .iterator(); i.hasNext();) { Exam exam = (Exam) i.next();/* ww w.ja v a 2 s. c o m*/ exams.put(exam.getUniqueId(), exam); } info(" Fetching related objects (class)..."); new ExamDAO().getSession().createQuery( "select c from Class_ c, ExamOwner o where o.exam.session.uniqueId=:sessionId and o.exam.examType.uniqueId=:examTypeId and o.ownerType=:classType and c.uniqueId=o.ownerId") .setLong("sessionId", sessionId).setLong("examTypeId", examTypeId) .setInteger("classType", ExamOwner.sOwnerTypeClass).setCacheable(true).list(); info(" Fetching related objects (config)..."); new ExamDAO().getSession().createQuery( "select c from InstrOfferingConfig c, ExamOwner o where o.exam.session.uniqueId=:sessionId and o.exam.examType.uniqueId=:examTypeId and o.ownerType=:configType and c.uniqueId=o.ownerId") .setLong("sessionId", sessionId).setLong("examTypeId", examTypeId) .setInteger("configType", ExamOwner.sOwnerTypeConfig).setCacheable(true).list(); info(" Fetching related objects (course)..."); new ExamDAO().getSession().createQuery( "select c from CourseOffering c, ExamOwner o where o.exam.session.uniqueId=:sessionId and o.exam.examType.uniqueId=:examTypeId and o.ownerType=:courseType and c.uniqueId=o.ownerId") .setLong("sessionId", sessionId).setLong("examTypeId", examTypeId) .setInteger("courseType", ExamOwner.sOwnerTypeCourse).setCacheable(true).list(); info(" Fetching related objects (offering)..."); new ExamDAO().getSession().createQuery( "select c from InstructionalOffering c, ExamOwner o where o.exam.session.uniqueId=:sessionId and o.exam.examType.uniqueId=:examTypeId and o.ownerType=:offeringType and c.uniqueId=o.ownerId") .setLong("sessionId", sessionId).setLong("examTypeId", examTypeId) .setInteger("offeringType", ExamOwner.sOwnerTypeOffering).setCacheable(true).list(); Hashtable<Long, Set<Long>> owner2students = new Hashtable(); Hashtable<Long, Set<Exam>> student2exams = new Hashtable(); Hashtable<Long, Hashtable<Long, Set<Long>>> owner2course2students = new Hashtable(); info(" Loading students (class)..."); for (Iterator i = new ExamDAO().getSession() .createQuery("select x.uniqueId, o.uniqueId, e.student.uniqueId, e.courseOffering.uniqueId from " + "Exam x inner join x.owners o, " + "StudentClassEnrollment e inner join e.clazz c " + "where x.session.uniqueId=:sessionId and x.examType.uniqueId=:examTypeId and " + "o.ownerType=" + org.unitime.timetable.model.ExamOwner.sOwnerTypeClass + " and " + "o.ownerId=c.uniqueId") .setLong("sessionId", sessionId).setLong("examTypeId", examTypeId).setCacheable(true).list() .iterator(); i.hasNext();) { Object[] o = (Object[]) i.next(); Long examId = (Long) o[0]; Long ownerId = (Long) o[1]; Long studentId = (Long) o[2]; Set<Long> studentsOfOwner = owner2students.get(ownerId); if (studentsOfOwner == null) { studentsOfOwner = new HashSet<Long>(); owner2students.put(ownerId, studentsOfOwner); } studentsOfOwner.add(studentId); Set<Exam> examsOfStudent = student2exams.get(studentId); if (examsOfStudent == null) { examsOfStudent = new HashSet<Exam>(); student2exams.put(studentId, examsOfStudent); } examsOfStudent.add(exams.get(examId)); Long courseId = (Long) o[3]; Hashtable<Long, Set<Long>> course2students = owner2course2students.get(ownerId); if (course2students == null) { course2students = new Hashtable<Long, Set<Long>>(); owner2course2students.put(ownerId, course2students); } Set<Long> studentsOfCourse = course2students.get(courseId); if (studentsOfCourse == null) { studentsOfCourse = new HashSet<Long>(); course2students.put(courseId, studentsOfCourse); } studentsOfCourse.add(studentId); } info(" Loading students (config)..."); for (Iterator i = new ExamDAO().getSession() .createQuery("select x.uniqueId, o.uniqueId, e.student.uniqueId, e.courseOffering.uniqueId from " + "Exam x inner join x.owners o, " + "StudentClassEnrollment e inner join e.clazz c " + "inner join c.schedulingSubpart.instrOfferingConfig ioc " + "where x.session.uniqueId=:sessionId and x.examType.uniqueId=:examTypeId and " + "o.ownerType=" + org.unitime.timetable.model.ExamOwner.sOwnerTypeConfig + " and " + "o.ownerId=ioc.uniqueId") .setLong("sessionId", sessionId).setLong("examTypeId", examTypeId).setCacheable(true).list() .iterator(); i.hasNext();) { Object[] o = (Object[]) i.next(); Long examId = (Long) o[0]; Long ownerId = (Long) o[1]; Long studentId = (Long) o[2]; Set<Long> studentsOfOwner = owner2students.get(ownerId); if (studentsOfOwner == null) { studentsOfOwner = new HashSet<Long>(); owner2students.put(ownerId, studentsOfOwner); } studentsOfOwner.add(studentId); Set<Exam> examsOfStudent = student2exams.get(studentId); if (examsOfStudent == null) { examsOfStudent = new HashSet<Exam>(); student2exams.put(studentId, examsOfStudent); } examsOfStudent.add(exams.get(examId)); Long courseId = (Long) o[3]; Hashtable<Long, Set<Long>> course2students = owner2course2students.get(ownerId); if (course2students == null) { course2students = new Hashtable<Long, Set<Long>>(); owner2course2students.put(ownerId, course2students); } Set<Long> studentsOfCourse = course2students.get(courseId); if (studentsOfCourse == null) { studentsOfCourse = new HashSet<Long>(); course2students.put(courseId, studentsOfCourse); } studentsOfCourse.add(studentId); } info(" Loading students (course)..."); for (Iterator i = new ExamDAO().getSession() .createQuery("select x.uniqueId, o.uniqueId, e.student.uniqueId, e.courseOffering.uniqueId from " + "Exam x inner join x.owners o, " + "StudentClassEnrollment e inner join e.courseOffering co " + "where x.session.uniqueId=:sessionId and x.examType.uniqueId=:examTypeId and " + "o.ownerType=" + org.unitime.timetable.model.ExamOwner.sOwnerTypeCourse + " and " + "o.ownerId=co.uniqueId") .setLong("sessionId", sessionId).setLong("examTypeId", examTypeId).setCacheable(true).list() .iterator(); i.hasNext();) { Object[] o = (Object[]) i.next(); Long examId = (Long) o[0]; Long ownerId = (Long) o[1]; Long studentId = (Long) o[2]; Set<Long> studentsOfOwner = owner2students.get(ownerId); if (studentsOfOwner == null) { studentsOfOwner = new HashSet<Long>(); owner2students.put(ownerId, studentsOfOwner); } studentsOfOwner.add(studentId); Set<Exam> examsOfStudent = student2exams.get(studentId); if (examsOfStudent == null) { examsOfStudent = new HashSet<Exam>(); student2exams.put(studentId, examsOfStudent); } examsOfStudent.add(exams.get(examId)); Long courseId = (Long) o[3]; Hashtable<Long, Set<Long>> course2students = owner2course2students.get(ownerId); if (course2students == null) { course2students = new Hashtable<Long, Set<Long>>(); owner2course2students.put(ownerId, course2students); } Set<Long> studentsOfCourse = course2students.get(courseId); if (studentsOfCourse == null) { studentsOfCourse = new HashSet<Long>(); course2students.put(courseId, studentsOfCourse); } studentsOfCourse.add(studentId); } info(" Loading students (offering)..."); for (Iterator i = new ExamDAO().getSession() .createQuery("select x.uniqueId, o.uniqueId, e.student.uniqueId, e.courseOffering.uniqueId from " + "Exam x inner join x.owners o, " + "StudentClassEnrollment e inner join e.courseOffering.instructionalOffering io " + "where x.session.uniqueId=:sessionId and x.examType.uniqueId=:examTypeId and " + "o.ownerType=" + org.unitime.timetable.model.ExamOwner.sOwnerTypeOffering + " and " + "o.ownerId=io.uniqueId") .setLong("sessionId", sessionId).setLong("examTypeId", examTypeId).setCacheable(true).list() .iterator(); i.hasNext();) { Object[] o = (Object[]) i.next(); Long examId = (Long) o[0]; Long ownerId = (Long) o[1]; Long studentId = (Long) o[2]; Set<Long> studentsOfOwner = owner2students.get(ownerId); if (studentsOfOwner == null) { studentsOfOwner = new HashSet<Long>(); owner2students.put(ownerId, studentsOfOwner); } studentsOfOwner.add(studentId); Set<Exam> examsOfStudent = student2exams.get(studentId); if (examsOfStudent == null) { examsOfStudent = new HashSet<Exam>(); student2exams.put(studentId, examsOfStudent); } examsOfStudent.add(exams.get(examId)); Long courseId = (Long) o[3]; Hashtable<Long, Set<Long>> course2students = owner2course2students.get(ownerId); if (course2students == null) { course2students = new Hashtable<Long, Set<Long>>(); owner2course2students.put(ownerId, course2students); } Set<Long> studentsOfCourse = course2students.get(courseId); if (studentsOfCourse == null) { studentsOfCourse = new HashSet<Long>(); course2students.put(courseId, studentsOfCourse); } studentsOfCourse.add(studentId); } Hashtable<Long, Set<Meeting>> period2meetings = new Hashtable(); Parameters p = new Parameters(sessionId, examTypeId); info(" Creating exam assignments..."); TreeSet<ExamAssignmentInfo> ret = new TreeSet(); for (Enumeration<Exam> e = exams.elements(); e.hasMoreElements();) { Exam exam = (Exam) e.nextElement(); ExamAssignmentInfo info = new ExamAssignmentInfo(exam, owner2students, owner2course2students, student2exams, period2meetings, p); ret.add(info); } long t1 = System.currentTimeMillis(); info("Exams loaded in " + sDF.format((t1 - t0) / 1000.0) + "s."); return ret; }
From source file:org.webical.plugin.classloading.PluginClassLoader.java
@Override protected Enumeration<URL> findResources(String name) throws IOException { Hashtable<String, URL> resources = new Hashtable<String, URL>(); resources.put(name, findResource(name)); return resources.elements(); }
From source file:org.xmlblackbox.test.infrastructure.FlowControl.java
public void execute(String fileConfigTest, Properties prop) throws TestException, Exception { int step = 1; Object obj = null;// w w w. java 2s. c o m try { log.info("execute fileConfigTest, prop, genericConnection"); log.info("[ START TEST CASE : " + fileConfigTest.substring(0, fileConfigTest.indexOf(".")) + " ]"); Properties xmlBlackboxProp = Configurator.getProperties("xmlBlackbox.properties"); log.info("xmlBlackbox.properties " + xmlBlackboxProp); log.debug("[Starting Memory & File Properties]"); memory.overrideRepository(Repository.FILE_PROPERTIES, xmlBlackboxProp); memory.addToRepository(Repository.FILE_PROPERTIES, prop); log.debug("[Starting Memory & File Properties][OK]"); //conn = new DatabaseConnection(genericConn); // log.debug("System.getProperty(\"XBB_STEP\") "+System.getProperty("XBB_STEP")); // log.debug("System.getenv(\"XBB_STEP\") "+System.getenv("XBB_STEP")); // log.debug("System.getProperties() "+System.getProperties()); // log.debug("System.getenv() "+System.getenv()); String stepConfig = System.getenv("XBB_STEP"); log.debug("[Reading XML TestCase]"); log.debug("[Reading XML TestCase]"); ReadXmlDocument readXmlDocument = null; try { readXmlDocument = new ReadXmlDocument(fileConfigTest); } catch (DataSetException e1) { log.error("[!] Unable to read test file ", e1); throw new TestException(e1, "Unable to read test file " + fileConfigTest); } catch (IOException e1) { log.error("[!] Unable to read test file ", e1); throw new TestException(e1, "Unable to read test file " + fileConfigTest); } catch (Exception e1) { log.error("[!] Unable to read test file ", e1); throw new TestException(e1, "Unable to read test file " + fileConfigTest); } nomeTestCase = readXmlDocument.getNomeTest(); log.info("[Preparing starting TestCase : " + nomeTestCase + "]"); log.debug("[Reading XML TestCase][OK]"); Iterator iterElement = readXmlDocument.getListaCompleta().iterator(); log.debug("[TestCase number of steps : " + readXmlDocument.getListaCompleta().size() + "]"); while (iterElement.hasNext()) { log.info("[*][Starting execution TestCase : " + nomeTestCase + " Step : " + step + "]"); obj = iterElement.next(); //memory.debugMemory(); log.info("[Identify type node & Replacing variable xml]"); replacingVariableXml(obj, memory); log.info("[Identify type node & Replacing variable xml][OK]"); log.info("[Executing node]"); executeNode((XmlElement) obj, step); log.info("[Executing node][OK]"); step++; if (stepConfig != null && stepConfig.equals("" + step)) { log.info("Exit configuration (-DXBB_STEP=" + stepConfig + ") a step " + stepConfig); break; } } } catch (TestException e) { if (memory != null) { memory.debugMemory(); } if (obj != null) { log.error("TestException in step " + step + " (" + obj.getClass() + ") of FlowControl.execute() ", e); } else { log.error("Exception in FlowControl.execute() ", e); } throw e; } catch (Exception e) { if (memory != null) { memory.debugMemory(); } if (obj != null) { log.error("Exception in in step " + step + " (" + obj.getClass() + ") FlowControl.execute() ", e); } else { log.error("Exception in FlowControl.execute() ", e); } throw e; } finally { Hashtable hashObject = memory.getAllObject(); Enumeration elements = hashObject.elements(); while (elements.hasMoreElements()) { Object objTmp = elements.nextElement(); log.info("objTmp " + objTmp); if (objTmp instanceof Connection) { Connection conn = (Connection) objTmp; try { if (conn != null) { conn.close(); conn = null; } } catch (Exception e) { log.error("Exception during database connection close", e); } } } } }