List of usage examples for org.hibernate Session clear
void clear();
From source file:de.fhdo.terminologie.ws.administration._import.ImportMeSH.java
License:Apache License
private void loadMeSH(byte[] bytes, Session hb_session) throws Exception { if (logger.isDebugEnabled()) logger.debug("bytes length: " + bytes.length); // check if zip file /*try/*from ww w.j a v a 2 s . c om*/ { logger.debug("check for zip file"); ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(bytes)); ZipEntry ze = zis.getNextEntry(); if (ze != null) { byte[] buffer = new byte[1024]; ByteArrayOutputStream baos = new ByteArrayOutputStream(); int anzahl; while ((anzahl = zis.read(buffer)) != -1) { // -1 = Stream-Ende baos.write(buffer, 0, anzahl); // Nur die gelesene Zahl von Bytes schreiben } baos.close(); bytes = baos.toByteArray(); zis.closeEntry(); zis.close(); if (logger.isDebugEnabled()) logger.debug("ZIP loaded, length of file: " + bytes.length); //logger.debug("FILE: " + new String(bytes)); } } catch (Exception ex) { logger.debug("no zip file detected"); ex.printStackTrace(); } ByteArrayInputStream input = new ByteArrayInputStream(bytes);*/ InputStream input = getInputStream(bytes); /*logger.debug("SAVE FILE"); //File file = new File("C:/temp/test_mesh.xml"); OutputStream outputStream = null; try { // write the inputStream to a FileOutputStream outputStream = new FileOutputStream(new File("C:/temp/test_mesh.xml")); int read = 0; byte[] bytes2 = new byte[1024]; while ((read = input.read(bytes2)) != -1) { outputStream.write(bytes2, 0, read); } System.out.println("Done!"); } catch (IOException e) { e.printStackTrace(); } finally { if (outputStream != null) { try { // outputStream.flush(); outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } logger.debug("SAVE FILE FINISH");*/ JAXBContext jc = JAXBContext.newInstance("mesh"); //JAXBContext jc = JAXBContext.newInstance(DescriptorRecordSet.class); //Unmarshaller u = jc.createUnmarshaller(); //u.set //Object rootObject = u.unmarshal(input); XMLInputFactory xif = XMLInputFactory.newFactory(); xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); //XMLStreamReader xsr = xif.createXMLStreamReader(input, "UTF-8"); //XMLStreamReader xsr = xif.createXMLStreamReader(input, "ISO-8859-1"); XMLStreamReader xsr = xif.createXMLStreamReader(input); Unmarshaller unmarshaller = jc.createUnmarshaller(); DescriptorRecordSet descriptorRecordSet = (DescriptorRecordSet) unmarshaller.unmarshal(xsr); languageCode = descriptorRecordSet.getLanguageCode(); if (logger.isDebugEnabled()) logger.debug("Language-Code: " + languageCode); codeSystem = createCodeSystem(hb_session, descriptorRecordSet.getLanguageCode()); if (codeSystem != null) { if (logger.isDebugEnabled()) logger.debug("codesystem created, begin import"); StaticStatus.importTotal = descriptorRecordSet.getDescriptorRecord().size(); if (logger.isDebugEnabled()) logger.debug("Count entries: " + StaticStatus.importTotal); long countEvery = 0; for (DescriptorRecord record : descriptorRecordSet.getDescriptorRecord()) { if (StaticStatus.cancel) break; if (importRecord(hb_session, record)) { StaticStatus.importCount++; countImported++; } else { } // memory garbage collection if (countEvery % 500 == 0) { // wichtig, sonst kommt es bei greren Dateien zum Java-Heapspace-Fehler hb_session.flush(); hb_session.clear(); if (countEvery % 1000 == 0) { // sicherheitshalber aufrufen System.gc(); } } countEvery++; } // import associations from Treenumbers logger.info("=================================================="); logger.info("import associations from Treenumbers, count: " + treeNumberMap.size()); logger.info("=================================================="); long countAssociationsImported = 0; for (String treenumber : treeNumberMap.keySet()) { long ev_id1 = 0, ev_id2 = treeNumberMap.get(treenumber); String upperNumber = ""; String[] s = treenumber.split("\\."); if (s != null && s.length > 0) { //for(String s2 : s) for (int i = 0; i < s.length - 1; ++i) { if (upperNumber.length() > 0) upperNumber += "."; upperNumber += s[i]; } } logger.debug("treenumber: " + treenumber + ", upper: " + upperNumber); if (upperNumber.length() > 0) { if (treeNumberMap.containsKey(upperNumber)) { ev_id1 = treeNumberMap.get(upperNumber); } } logger.debug("ev_id1: " + ev_id1 + ", ev_id2: " + ev_id2); if (ev_id1 > 0 && ev_id2 > 0) { // add association (taxonomy) createAssociationTaxonomy(hb_session, ev_id1, ev_id2); countAssociationsImported++; } } if (countAssociationsImported == 0 && treeNumberMap.size() > 0) { throw new Exception("No associations could be imported. Import cancelled."); } // import other associations AssociationType assTypeSeeRelated = null; for (String descriptorUI : relationSeeRelatedMap.keySet()) { long ev_id1 = relationSeeRelatedMap.get(descriptorUI), ev_id2 = 0; if (entityVersionIdMap.containsKey(descriptorUI)) ev_id2 = entityVersionIdMap.get(descriptorUI); logger.debug("SEE RELATED: ev_id1: " + ev_id1 + ", ev_id2: " + ev_id2); if (ev_id1 > 0 && ev_id2 > 0) { // add association if (assTypeSeeRelated == null) assTypeSeeRelated = CreateAssociationType(hb_session, "see related", "see related (backwards)"); createAssociation(hb_session, ev_id1, ev_id2, Definitions.ASSOCIATION_KIND.ONTOLOGY, assTypeSeeRelated); countAssociationsImported++; } } AssociationType assTypePharma = null; for (String descriptorUI : relationPharmacologicalActionMap.keySet()) { long ev_id1 = relationPharmacologicalActionMap.get(descriptorUI), ev_id2 = 0; if (entityVersionIdMap.containsKey(descriptorUI)) ev_id2 = entityVersionIdMap.get(descriptorUI); logger.debug("PHARMA: ev_id1: " + ev_id1 + ", ev_id2: " + ev_id2); if (ev_id1 > 0 && ev_id2 > 0) { // add association if (assTypePharma == null) assTypePharma = CreateAssociationType(hb_session, "pharmacological action", "pharmacological action (backwards)"); createAssociation(hb_session, ev_id1, ev_id2, Definitions.ASSOCIATION_KIND.ONTOLOGY, assTypePharma); countAssociationsImported++; } } // TODO relationEntryCombinationMap = new HashMap<String, Long>(); if (input != null) input.close(); } else { if (input != null) input.close(); throw new Exception("Codesystem could not be created or loaded, name: " + CODESYSTEM_NAME); } }
From source file:de.innovationgate.webgate.api.jdbc.WGDatabaseImpl.java
License:Open Source License
public void refresh() throws WGAPIException { Session session = getSession(); session.flush(); session.clear(); }
From source file:de.innovationgate.webgate.api.jdbc.WGDatabaseImpl.java
License:Open Source License
@Override public void clearSessionCache() throws WGAPIException { Session session = getSessionStatus().getSession(); if (session != null) { session.flush();/*from w w w.java2s . co m*/ session.clear(); } else { throw new WGClosedSessionException(); } }
From source file:de.lemo.dms.connectors.clix2010.ClixImporter.java
License:Open Source License
/** * Loads all necessary tables from the Clix2010 database. *//*from ww w .j av a2s . c o m*/ @SuppressWarnings("unchecked") private void loadData(final DBConfigObject dbConfig, List<Long> courses, List<String> logins, long startTime) { // accessing DB by creating a session and a transaction using HibernateUtil final Session session = ClixHibernateUtil.getSessionFactory(dbConfig).openSession(); boolean hasCR = false; if (courses != null && courses.size() > 0) hasCR = true; boolean empty = false; if (logins != null && !logins.isEmpty()) { List<Long> newCourses = new ArrayList<Long>(); Criteria criteria = session.createCriteria(Person.class, "obj"); criteria.add(CriteriaHelper.in("obj.login", logins)); List<Long> usId = new ArrayList<Long>(); for (Person p : (List<Person>) criteria.list()) usId.add(p.getId()); if (!usId.isEmpty()) { criteria = session.createCriteria(PersonComponentAssignment.class, "obj"); criteria.add(CriteriaHelper.in("obj.person", usId)); for (PersonComponentAssignment pca : (List<PersonComponentAssignment>) criteria.list()) newCourses.add(pca.getComponent()); courses.addAll(newCourses); hasCR = true; logger.info(newCourses.toString()); } } this.logger.info("Starting data extraction."); // The Clix database uses date representation of the type varchar, so the unix-timestamp has to be converted // to a string String startStr = TimeConverter.getStringRepresentation(startTime); //Get QTiTestPlayerResp tables this.tQtiTestPlayerResp = new ArrayList<TQtiTestPlayerResp>(); Criteria criteria = session.createCriteria(TQtiTestPlayerResp.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.container", courses)); } criteria.add(Restrictions.gt("obj.evaluationDate", startStr)); criteria.addOrder(Property.forName("obj.id").asc()); this.tQtiTestPlayerResp = criteria.list(); logger.info("TQtiTestPlayerResp tables: " + this.tQtiTestPlayerResp.size()); //Get QTiTestPlayer tables this.tQtiTestPlayer = new ArrayList<TQtiTestPlayer>(); criteria = session.createCriteria(TQtiTestPlayer.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.container", courses)); } criteria.add(Restrictions.gt("obj.created", startStr)); criteria.addOrder(Property.forName("obj.id").asc()); this.tQtiTestPlayer = criteria.list(); logger.info("TQtiTestPlayer tables: " + this.tQtiTestPlayer.size()); //Get EComposing tables this.eComposing = new ArrayList<EComposing>(); criteria = session.createCriteria(EComposing.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.composing", courses)); } criteria.add(Restrictions.gt("obj.lastUpdated", startStr)); criteria.addOrder(Property.forName("obj.id").asc()); this.eComposing = criteria.list(); this.eComposingMap = new HashMap<Long, EComposing>(); for (int i = 0; i < this.eComposing.size(); i++) { this.eComposingMap.put(this.eComposing.get(i).getComponent(), this.eComposing.get(i)); } logger.info("EComposing tables: " + this.eComposing.size()); //Get ExerciseGroup tables this.exerciseGroup = new ArrayList<ExerciseGroup>(); criteria = session.createCriteria(ExerciseGroup.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.associatedCourse", courses)); } criteria.addOrder(Property.forName("obj.id").asc()); this.exerciseGroup = criteria.list(); this.logger.info("ExerciseGroup tables: " + this.exerciseGroup.size()); //Get ExercisePersonalised tables this.exercisePersonalised = new ArrayList<ExercisePersonalised>(); criteria = session.createCriteria(ExercisePersonalised.class, "obj"); if (hasCR) { Set<Long> ids = new HashSet<Long>(); for (ExerciseGroup eg : this.exerciseGroup) ids.add(eg.getId()); if (!(empty = ids.isEmpty())) criteria.add(CriteriaHelper.in("obj.community", ids)); } criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.exercisePersonalised = criteria.list(); else this.exercisePersonalised = new ArrayList<ExercisePersonalised>(); this.logger.info("ExercisePersonalised tables: " + this.exercisePersonalised.size()); Set<Long> tmpComp = new HashSet<Long>(); //Get EComponent tables criteria = session.createCriteria(EComponent.class, "obj"); if (hasCR) { tmpComp.addAll(this.eComposingMap.keySet()); tmpComp.addAll(courses); for (ExercisePersonalised eP : this.exercisePersonalised) tmpComp.add(eP.getExercise()); if (!(empty = tmpComp.isEmpty())) { criteria.add(CriteriaHelper.in("obj.id", new ArrayList<Long>(tmpComp))); //criteria.add(CriteriaHelper.in("obj.id", tmpComp)); } } criteria.add(Restrictions.gt("obj.lastUpdated", startStr)); criteria.addOrder(Property.forName("obj.id").asc()); final List<EComponent> tmp; if (!(hasCR && empty)) tmp = criteria.list(); else tmp = new ArrayList<EComponent>(); this.eComponentMap = new HashMap<Long, EComponent>(); for (final EComponent c : tmp) { this.eComponentMap.put(c.getId(), c); } tmp.clear(); this.logger.info("EComponent tables: " + this.eComponentMap.values().size()); //Get TQtiContentStructure tables criteria = session.createCriteria(TQtiContentStructure.class, "obj"); if (hasCR) { ArrayList<Long> newKeys = new ArrayList<Long>(this.eComposingMap.keySet()); HashSet<Long> allKeys = new HashSet<Long>(); while (!newKeys.isEmpty()) { criteria = session.createCriteria(TQtiContentStructure.class, "obj"); criteria.add(CriteriaHelper.in("obj.container", newKeys)); List<TQtiContentStructure> t = criteria.list(); newKeys.clear(); for (TQtiContentStructure tqs : t) { newKeys.add(tqs.getContent()); allKeys.add(tqs.getContainer()); } allKeys.addAll(newKeys); } criteria = session.createCriteria(TQtiContentStructure.class, "obj"); if (!(empty = allKeys.isEmpty())) criteria.add(CriteriaHelper.in("obj.container", allKeys)); } criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.tQtiContentStructure = criteria.list(); else this.tQtiContentStructure = new ArrayList<TQtiContentStructure>(); this.logger.info("TQtiContentStructure tables: " + this.tQtiContentStructure.size()); //Get TQtiContentComposing tables criteria = session.createCriteria(TQtiContentComposing.class, "obj"); if (hasCR) { HashSet<Long> tmp1 = new HashSet<Long>(); for (TQtiContentStructure tqs : this.tQtiContentStructure) tmp1.add(tqs.getContent()); if (!(empty = tmp1.isEmpty())) criteria.add(CriteriaHelper.in("obj.container", tmp1)); } criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.tQtiContentComposing = criteria.list(); else this.tQtiContentComposing = new ArrayList<TQtiContentComposing>(); logger.info("TQtiContentComposing tables: " + this.tQtiContentComposing.size()); //Get TQtiContent tables criteria = session.createCriteria(TQtiContent.class, "obj"); if (hasCR) { HashSet<Long> ids = new HashSet<Long>(); for (TQtiContentStructure tqs : this.tQtiContentStructure) { ids.add(tqs.getContainer()); ids.add(tqs.getContent()); } for (TQtiContentComposing tqs : this.tQtiContentComposing) { ids.add(tqs.getContainer()); ids.add(tqs.getContent()); } if (!(empty = ids.isEmpty())) criteria.add(CriteriaHelper.in("obj.id", ids)); } criteria.add(Restrictions.gt("obj.lastUpdated", startStr)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.tQtiContent = criteria.list(); else this.tQtiContent = new ArrayList<TQtiContent>(); this.logger.info("TQtiContent tables: " + this.tQtiContent.size()); //Get ChatProtocol tables criteria = session.createCriteria(ChatProtocol.class, "obj"); if (hasCR) { HashSet<Long> tmp1 = new HashSet<Long>(this.eComposingMap.keySet()); if (!(empty = tmp1.isEmpty())) criteria.add(CriteriaHelper.in("obj.chatroom", tmp1)); } criteria.add(Restrictions.gt("obj.lastUpdated", startStr)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.chatProtocol = criteria.list(); else this.chatProtocol = new ArrayList<ChatProtocol>(); logger.info("ChatProtocol tables: " + this.chatProtocol.size()); //Get EComponentType tables criteria = session.createCriteria(EComponentType.class, "obj"); if (hasCR) { Set<Long> ids = new HashSet<Long>(); for (EComponent eg : this.eComponentMap.values()) { ids.add(eg.getType()); } //if(!(empty = ids.isEmpty())) //criteria.add(CriteriaHelper.in("obj.id", ids)); } criteria.add(Restrictions.gt("obj.lastUpdated", startStr)); criteria.addOrder(Property.forName("obj.id").asc()); this.eComponentType = criteria.list(); this.logger.info("EComponentType tables: " + this.eComponentType.size()); //Get ForumEntry tables criteria = session.createCriteria(ForumEntry.class, "obj"); if (hasCR) { if (!(empty = this.eComposingMap.isEmpty())) { criteria.add(CriteriaHelper.in("obj.forum", this.eComposingMap.keySet())); } } criteria.add(Restrictions.gt("obj.lastUpdated", startStr)); criteria.addOrder(Property.forName("obj.id").asc()); if (!empty) { this.forumEntry = criteria.list(); } else this.forumEntry = new ArrayList<ForumEntry>(); this.logger.info("ForumEntry tables: " + this.forumEntry.size()); //Get ForumEntryState tables /*criteria = session.createCriteria(ForumEntryState.class, "obj"); if(hasCR) { if(!(empty = this.eComposingMap.isEmpty())) { criteria.add(CriteriaHelper.in("obj.forum", this.eComposingMap.keySet())); } } criteria.add(Restrictions.gt("obj.lastUpdated", startStr)); criteria.addOrder(Property.forName("obj.id").asc()); if(!hasCR || !empty) { this.forumEntryState = criteria.list(); } else*/ this.forumEntryState = new ArrayList<ForumEntryState>(); this.logger.info("ForumEntryState tables: " + this.forumEntryState.size()); //Get LearningLog tables criteria = session.createCriteria(LearningLog.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.course", courses)); } criteria.add(Restrictions.gt("obj.lastUpdated", startStr)); criteria.addOrder(Property.forName("obj.id").asc()); this.learningLog = criteria.list(); this.logger.info("LearningLog tables: " + this.learningLog.size()); //Get Portfolio tables criteria = session.createCriteria(Portfolio.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.component", courses)); } criteria.add(Restrictions.gt("obj.lastUpdated", startStr)); criteria.addOrder(Property.forName("obj.id").asc()); this.portfolio = criteria.list(); this.logger.info("Portfolio tables: " + this.portfolio.size()); //Get PortfolioLog tables criteria = session.createCriteria(PortfolioLog.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.component", courses)); } criteria.add(Restrictions.gt("obj.lastUpdated", startStr)); criteria.addOrder(Property.forName("obj.id").asc()); this.portfolioLog = criteria.list(); this.logger.info("PortfolioLog tables: " + this.portfolioLog.size()); //Get PersonComponentAssignment tables criteria = session.createCriteria(PersonComponentAssignment.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.component", courses)); } criteria.addOrder(Property.forName("obj.id").asc()); this.personComponentAssignment = criteria.list(); this.logger.info("PersonComponentAssignment tables: " + this.personComponentAssignment.size()); //Get Person tables criteria = session.createCriteria(Person.class, "obj"); if (hasCR) { Set<Long> ids = new HashSet<Long>(); for (Portfolio eg : this.portfolio) ids.add(eg.getPerson()); for (ExercisePersonalised eP : this.exercisePersonalised) ids.add(eP.getUser()); for (PersonComponentAssignment eP : this.personComponentAssignment) ids.add(eP.getPerson()); if (!(empty = ids.isEmpty())) criteria.add(CriteriaHelper.in("obj.id", ids)); } criteria.add(Restrictions.gt("obj.lastUpdated", startStr)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.person = criteria.list(); else this.person = new ArrayList<Person>(); this.logger.info("Person tables: " + this.person.size()); //Get PlatformGroupSpecification tables /*criteria = session.createCriteria(PlatformGroupSpecification.class, "obj"); if(hasCR) { Set<Long> ids = new HashSet<Long>(); for(Person eg : this.person) ids.add(eg.getId()); if(!(empty = ids.isEmpty())) criteria.add(CriteriaHelper.in("obj.person", ids)); } criteria.addOrder(Property.forName("obj.id").asc()); if(!(hasCR && empty)) this.platformGroupSpecification = criteria.list(); else*/ this.platformGroupSpecification = new ArrayList<PlatformGroupSpecification>(); this.logger.info("PlatformGroupSpecification tables: " + this.platformGroupSpecification.size()); //Get PlatformGroup tables criteria = session.createCriteria(PlatformGroup.class, "obj"); if (hasCR) { Set<Long> ids = new HashSet<Long>(); for (PlatformGroupSpecification eg : this.platformGroupSpecification) ids.add(eg.getGroup()); if (!(empty = ids.isEmpty())) criteria.add(CriteriaHelper.in("obj.id", ids)); } criteria.add(Restrictions.gt("obj.lastUpdated", startStr)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.platformGroup = criteria.list(); else this.platformGroup = new ArrayList<PlatformGroup>(); this.logger.info("PlatformGroup tables: " + this.platformGroup.size()); //Get ScormSessionTimes tables criteria = session.createCriteria(ScormSessionTimes.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.component", courses)); } criteria.add(Restrictions.gt("obj.lastUpdated", startStr)); criteria.addOrder(Property.forName("obj.id").asc()); this.scormSessionTimes = criteria.list(); this.logger.info("ScormSessionTimes tables: " + this.scormSessionTimes.size()); //Get TeamExerciseGroup tables criteria = session.createCriteria(TeamExerciseGroup.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.component", courses)); } criteria.addOrder(Property.forName("obj.id").asc()); this.teamExerciseGroup = criteria.list(); this.logger.info("TeamExerciseGroup tables: " + this.teamExerciseGroup.size()); //Get TQtiTestItemD tables criteria = session.createCriteria(TQtiTestItemD.class, "obj"); if (hasCR) { HashSet<Long> ids = new HashSet<Long>(); for (TQtiContent tc : this.tQtiContent) { ids.add(tc.getId()); } if (!(empty = ids.isEmpty())) { criteria.add(CriteriaHelper.in("obj.content", ids)); } } criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.tQtiTestItemD = criteria.list(); else this.tQtiTestItemD = new ArrayList<TQtiTestItemD>(); this.logger.info("TQtiTestItemD tables: " + this.tQtiTestItemD.size()); //Get TGroupFullSpecification tables criteria = session.createCriteria(TGroupFullSpecification.class, "obj"); if (hasCR) { Set<Long> ids = new HashSet<Long>(); for (TeamExerciseGroup eg : this.teamExerciseGroup) ids.add(eg.getId()); if (!(empty = ids.isEmpty())) criteria.add(CriteriaHelper.in("obj.group", ids)); } criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.tGroupFullSpecification = criteria.list(); else this.tGroupFullSpecification = new ArrayList<TGroupFullSpecification>(); this.logger.info("TGroupFullSpecification tables: " + this.tGroupFullSpecification.size()); //Get TQtiEvalAssessment tables criteria = session.createCriteria(TQtiEvalAssessment.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.component", courses)); } criteria.add(Restrictions.gt("obj.lastInvocation", startStr)); criteria.addOrder(Property.forName("obj.id").asc()); this.tQtiEvalAssessment = criteria.list(); this.logger.info("TQtiEvalAssessment tables: " + this.tQtiEvalAssessment.size()); //Get WikiEntry tables criteria = session.createCriteria(WikiEntry.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.component", courses)); } criteria.add(Restrictions.gt("obj.lastUpdated", startStr)); criteria.addOrder(Property.forName("obj.id").asc()); this.wikiEntry = criteria.list(); this.logger.info("WikiEntry tables: " + this.wikiEntry.size()); startStr = startStr.substring(0, startStr.indexOf(' ')); //Get BiTrackContentImpressions tables criteria = session.createCriteria(BiTrackContentImpressions.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.container", courses)); } criteria.add(Restrictions.gt("obj.dayOfAccess", startStr)); criteria.addOrder(Property.forName("obj.id").asc()); this.biTrackContentImpressions = criteria.list(); logger.info("BiTrackContentImpressions tables: " + this.biTrackContentImpressions.size()); session.clear(); session.close(); }
From source file:de.lemo.dms.connectors.clix2010.ClixImporter.java
License:Open Source License
/** * Loads all tables needed for the data-extraction from the Clix database. * //from w w w . j a va 2s . co m * @param start * the start * @param end * the end */ @SuppressWarnings("unchecked") private void loadData(final DBConfigObject dbConfig, final Long start, final Long end, List<Long> courses, List<String> logins) { // accessing DB by creating a session and a transaction using HibernateUtil final Session session = ClixHibernateUtil.getSessionFactory(dbConfig).openSession(); boolean hasCR = false; if (courses != null && courses.size() > 0) hasCR = true; boolean empty = true; if (logins != null && !logins.isEmpty()) { List<Long> newCourses = new ArrayList<Long>(); Criteria criteria = session.createCriteria(Person.class, "obj"); criteria.add(CriteriaHelper.in("obj.login", logins)); List<Long> usId = new ArrayList<Long>(); for (Person p : (List<Person>) criteria.list()) usId.add(p.getId()); if (!usId.isEmpty()) { criteria = session.createCriteria(PersonComponentAssignment.class, "obj"); criteria.add(CriteriaHelper.in("obj.person", usId)); for (PersonComponentAssignment pca : (List<PersonComponentAssignment>) criteria.list()) newCourses.add(pca.getComponent()); courses.addAll(newCourses); hasCR = true; } } this.logger.info("Starting data extraction."); Criteria criteria; // The Clix database uses date representation of the type varchar, so the unix-timestamp has to be converted // to a string String startStr = TimeConverter.getStringRepresentation(start); String endStr = TimeConverter.getStringRepresentation(end); // Read the tables that don't refer to log-entries once if (this.userMining == null) { //Get EComposing tables criteria = session.createCriteria(EComposing.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.composing", courses)); } criteria.addOrder(Property.forName("obj.id").asc()); this.eComposing = criteria.list(); this.eComposingMap = new HashMap<Long, EComposing>(); for (int i = 0; i < this.eComposing.size(); i++) { this.eComposingMap.put(this.eComposing.get(i).getComponent(), this.eComposing.get(i)); } logger.info("EComposing tables: " + this.eComposing.size()); criteria = session.createCriteria(Portfolio.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.component", courses)); } criteria.addOrder(Property.forName("obj.id").asc()); this.portfolio = criteria.list(); this.logger.info("Portfolio tables: " + this.portfolio.size()); //Get PersonComponentAssignment tables criteria = session.createCriteria(PersonComponentAssignment.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.component", courses)); } criteria.addOrder(Property.forName("obj.id").asc()); this.personComponentAssignment = criteria.list(); this.logger.info("PersonComponentAssignment tables: " + this.personComponentAssignment.size()); //Get ExerciseGroup tables criteria = session.createCriteria(ExerciseGroup.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.associatedCourse", courses)); } criteria.addOrder(Property.forName("obj.id").asc()); this.exerciseGroup = criteria.list(); this.logger.info("ExerciseGroup tables: " + this.exerciseGroup.size()); //Get ExercisePersonalised tables criteria = session.createCriteria(ExercisePersonalised.class, "obj"); if (hasCR) { Set<Long> ids = new HashSet<Long>(); for (ExerciseGroup eg : this.exerciseGroup) ids.add(eg.getId()); if (!(empty = ids.isEmpty())) criteria.add(CriteriaHelper.in("obj.community", ids)); } criteria.add(Restrictions.between("obj.uploadDate", startStr, endStr)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.exercisePersonalised = criteria.list(); else this.exercisePersonalised = new ArrayList<ExercisePersonalised>(); this.logger.info("ExercisePersonalised tables: " + this.exercisePersonalised.size()); //Get EComponent tables Set<Long> tmpComp = new HashSet<Long>(); criteria = session.createCriteria(EComponent.class, "obj"); if (hasCR) { tmpComp.addAll(this.eComposingMap.keySet()); tmpComp.addAll(courses); for (ExercisePersonalised eP : this.exercisePersonalised) tmpComp.add(eP.getExercise()); if (!(empty = tmpComp.isEmpty())) criteria.add(CriteriaHelper.in("obj.id", tmpComp)); } criteria.addOrder(Property.forName("obj.id").asc()); final List<EComponent> tmp; if (!(hasCR && empty)) tmp = criteria.list(); else tmp = new ArrayList<EComponent>(); this.eComponentMap = new HashMap<Long, EComponent>(); for (final EComponent c : tmp) { this.eComponentMap.put(c.getId(), c); } tmp.clear(); this.logger.info("EComponent tables: " + this.eComponentMap.values().size()); //Get EComponentType tables criteria = session.createCriteria(EComponentType.class, "obj"); if (hasCR) { Set<Long> ids = new HashSet<Long>(); for (EComponent eg : this.eComponentMap.values()) { ids.add(eg.getType()); } //if(!(empty = ids.isEmpty())) //criteria.add(CriteriaHelper.in("obj.id", ids)); } criteria.addOrder(Property.forName("obj.id").asc()); this.eComponentType = criteria.list(); this.logger.info("EComponentType tables: " + this.eComponentType.size()); //Get TQtiContentStructure tables criteria = session.createCriteria(TQtiContentStructure.class, "obj"); if (hasCR) { ArrayList<Long> newKeys = new ArrayList<Long>(this.eComposingMap.keySet()); HashSet<Long> allKeys = new HashSet<Long>(); while (!newKeys.isEmpty()) { criteria = session.createCriteria(TQtiContentStructure.class, "obj"); criteria.add(CriteriaHelper.in("obj.container", newKeys)); List<TQtiContentStructure> t = criteria.list(); newKeys.clear(); for (TQtiContentStructure tqs : t) { newKeys.add(tqs.getContent()); allKeys.add(tqs.getContainer()); } allKeys.addAll(newKeys); } criteria = session.createCriteria(TQtiContentStructure.class, "obj"); if (!(empty = allKeys.isEmpty())) criteria.add(CriteriaHelper.in("obj.container", allKeys)); } criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.tQtiContentStructure = criteria.list(); else this.tQtiContentStructure = new ArrayList<TQtiContentStructure>(); this.logger.info("TQtiContentStructure tables: " + this.tQtiContentStructure.size()); //Get TQtiContentComposing tables criteria = session.createCriteria(TQtiContentComposing.class, "obj"); if (hasCR) { HashSet<Long> tmp1 = new HashSet<Long>(); for (TQtiContentStructure tqs : this.tQtiContentStructure) tmp1.add(tqs.getContent()); if (!(empty = tmp1.isEmpty())) criteria.add(CriteriaHelper.in("obj.container", tmp1)); } criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.tQtiContentComposing = criteria.list(); else this.tQtiContentComposing = new ArrayList<TQtiContentComposing>(); logger.info("TQtiContentComposing tables: " + this.tQtiContentComposing.size()); //Get Person tables criteria = session.createCriteria(Person.class, "obj"); if (hasCR) { Set<Long> ids = new HashSet<Long>(); for (Portfolio eg : this.portfolio) ids.add(eg.getPerson()); for (ExercisePersonalised eP : this.exercisePersonalised) ids.add(eP.getUser()); for (PersonComponentAssignment eP : this.personComponentAssignment) ids.add(eP.getPerson()); if (!(empty = ids.isEmpty())) criteria.add(CriteriaHelper.in("obj.id", ids)); } criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.person = criteria.list(); else this.person = new ArrayList<Person>(); this.logger.info("Person tables: " + this.person.size()); //Get PlatformGroupSpecification tables /*criteria = session.createCriteria(PlatformGroupSpecification.class, "obj"); if(hasCR) { Set<Long> ids = new HashSet<Long>(); for(Person eg : this.person) ids.add(eg.getId()); if(!(empty = ids.isEmpty())) criteria.add(CriteriaHelper.in("obj.person", ids)); } criteria.addOrder(Property.forName("obj.id").asc()); if(!hasCR || !empty) this.platformGroupSpecification = criteria.list(); else*/ this.platformGroupSpecification = new ArrayList<PlatformGroupSpecification>(); this.logger.info("PlatformGroupSpecification tables: " + this.platformGroupSpecification.size()); //Get PlatformGroup tables criteria = session.createCriteria(PlatformGroup.class, "obj"); if (hasCR) { Set<Long> ids = new HashSet<Long>(); for (PlatformGroupSpecification eg : this.platformGroupSpecification) ids.add(eg.getGroup()); if (!(empty = ids.isEmpty())) criteria.add(CriteriaHelper.in("obj.id", ids)); } criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.platformGroup = criteria.list(); else this.platformGroup = new ArrayList<PlatformGroup>(); this.logger.info("PlatformGroup tables: " + this.platformGroup.size()); //Get TQtiContent tables criteria = session.createCriteria(TQtiContent.class, "obj"); if (hasCR) { HashSet<Long> ids = new HashSet<Long>(); for (TQtiContentStructure tqs : this.tQtiContentStructure) { ids.add(tqs.getContainer()); ids.add(tqs.getContent()); } for (TQtiContentComposing tqs : this.tQtiContentComposing) { ids.add(tqs.getContainer()); ids.add(tqs.getContent()); } if (!(empty = ids.isEmpty())) criteria.add(CriteriaHelper.in("obj.id", ids)); } criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.tQtiContent = criteria.list(); else this.tQtiContent = new ArrayList<TQtiContent>(); this.logger.info("TQtiContent tables: " + this.tQtiContent.size()); } //Get TQtiTestItemD tables criteria = session.createCriteria(TQtiTestItemD.class, "obj"); if (hasCR) { HashSet<Long> ids = new HashSet<Long>(); for (TQtiContent tc : this.tQtiContent) { ids.add(tc.getId()); } if (!(empty = ids.isEmpty())) { criteria.add(CriteriaHelper.in("obj.content", ids)); } } criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.tQtiTestItemD = criteria.list(); else this.tQtiTestItemD = new ArrayList<TQtiTestItemD>(); this.logger.info("TQtiTestItemD tables: " + this.tQtiTestItemD.size()); //Get TeamExerciseGroup tables criteria = session.createCriteria(TeamExerciseGroup.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.component", courses)); } criteria.addOrder(Property.forName("obj.id").asc()); this.teamExerciseGroup = criteria.list(); this.logger.info("TeamExerciseGroup tables: " + this.teamExerciseGroup.size()); //Get TGroupFullSpecification tables criteria = session.createCriteria(TGroupFullSpecification.class, "obj"); if (hasCR) { Set<Long> ids = new HashSet<Long>(); for (TeamExerciseGroup eg : this.teamExerciseGroup) ids.add(eg.getId()); if (!(empty = ids.isEmpty())) criteria.add(CriteriaHelper.in("obj.group", ids)); } criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.tGroupFullSpecification = criteria.list(); else this.tGroupFullSpecification = new ArrayList<TGroupFullSpecification>(); this.logger.info("TGroupFullSpecification tables: " + this.tGroupFullSpecification.size()); // Read log-data successively, using the time stamps //Get QTiTestPlayerResp tables criteria = session.createCriteria(TQtiTestPlayerResp.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.container", courses)); } criteria.addOrder(Property.forName("obj.id").asc()); this.tQtiTestPlayerResp = criteria.list(); logger.info("TQtiTestPlayerResp tables: " + this.tQtiTestPlayerResp.size()); //Get LearningLog tables criteria = session.createCriteria(LearningLog.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.course", courses)); } criteria.add(Restrictions.between("obj.lastUpdated", startStr, endStr)); criteria.addOrder(Property.forName("obj.id").asc()); this.learningLog = criteria.list(); this.logger.info("LearningLog tables: " + this.learningLog.size()); //Get Portfolio tables criteria = session.createCriteria(Portfolio.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.component", courses)); } criteria.add(Restrictions.between("obj.lastUpdated", startStr, endStr)); criteria.addOrder(Property.forName("obj.id").asc()); this.portfolio = criteria.list(); this.logger.info("Portfolio tables: " + this.portfolio.size()); //Get PortfolioLog tables criteria = session.createCriteria(PortfolioLog.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.component", courses)); } criteria.add(Restrictions.between("obj.lastUpdated", startStr, endStr)); criteria.addOrder(Property.forName("obj.id").asc()); this.portfolioLog = criteria.list(); this.logger.info("PortfolioLog tables: " + this.portfolioLog.size()); //Get ChatProtocol tables criteria = session.createCriteria(ChatProtocol.class, "obj"); if (hasCR) { HashSet<Long> tmp1 = new HashSet<Long>(this.eComposingMap.keySet()); if (!(empty = tmp1.isEmpty())) criteria.add(CriteriaHelper.in("obj.chatroom", tmp1)); } criteria.add(Restrictions.between("obj.lastUpdated", startStr, endStr)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.chatProtocol = criteria.list(); else this.chatProtocol = new ArrayList<ChatProtocol>(); this.logger.info("ChatProtocol tables: " + this.chatProtocol.size()); //Get ForumEntry tables criteria = session.createCriteria(ForumEntry.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.forum", this.eComposingMap.keySet())); } criteria.add(Restrictions.between("obj.lastUpdated", startStr, endStr)); criteria.addOrder(Property.forName("obj.id").asc()); this.forumEntry = criteria.list(); this.logger.info("ForumEntry tables: " + this.forumEntry.size()); //Get ForumEntryState tables criteria = session.createCriteria(ForumEntryState.class, "obj"); if (hasCR) { if (!this.eComposingMap.isEmpty()) criteria.add(CriteriaHelper.in("obj.forum", this.eComposingMap.keySet())); } criteria.add(Restrictions.between("obj.lastUpdated", startStr, endStr)); criteria.addOrder(Property.forName("obj.id").asc()); if (!this.eComposingMap.isEmpty()) this.forumEntryState = criteria.list(); else this.forumEntryState = new ArrayList<ForumEntryState>(); this.logger.info("ForumEntryState tables: " + this.forumEntryState.size()); //Get TQtiEvalAssessment tables criteria = session.createCriteria(TQtiEvalAssessment.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.component", courses)); } criteria.add(Restrictions.between("obj.lastInvocation", startStr, endStr)); criteria.addOrder(Property.forName("obj.id").asc()); this.tQtiEvalAssessment = criteria.list(); this.logger.info("TQtiEvalAssessment tables: " + this.tQtiEvalAssessment.size()); //Get ScormSessionTimes tables criteria = session.createCriteria(ScormSessionTimes.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.component", courses)); } criteria.add(Restrictions.between("obj.lastUpdated", startStr, endStr)); criteria.addOrder(Property.forName("obj.id").asc()); this.scormSessionTimes = criteria.list(); this.logger.info("ScormSessionTimes tables: " + this.scormSessionTimes.size()); //Get WikiEntry tables criteria = session.createCriteria(WikiEntry.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.component", courses)); } criteria.add(Restrictions.between("obj.lastUpdated", startStr, endStr)); criteria.addOrder(Property.forName("obj.id").asc()); this.wikiEntry = criteria.list(); this.logger.info("WikiEntry tables: " + this.wikiEntry.size()); //Get QTiTestPlayer tables criteria = session.createCriteria(TQtiTestPlayer.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.container", courses)); } criteria.add(Restrictions.between("obj.created", startStr, endStr)); criteria.addOrder(Property.forName("obj.id").asc()); this.tQtiTestPlayer = criteria.list(); logger.info("TQtiTestPlayer tables: " + this.tQtiTestPlayer.size()); // The date-strings have to be modified, because the date format of the table BiTrackContentImpressions is // different startStr = startStr.substring(0, startStr.indexOf(' ')); endStr = endStr.substring(0, endStr.indexOf(' ')); //Get BiTrackContentImpressions tables criteria = session.createCriteria(BiTrackContentImpressions.class, "obj"); if (hasCR) { criteria.add(CriteriaHelper.in("obj.container", courses)); } criteria.add(Restrictions.between("obj.dayOfAccess", startStr, endStr)); criteria.addOrder(Property.forName("obj.id").asc()); this.biTrackContentImpressions = criteria.list(); this.logger.info("BiTrackContentImpressions tables: " + this.biTrackContentImpressions.size()); session.clear(); session.close(); }
From source file:de.lemo.dms.connectors.lemo_0_8.ExtractAndMapLeMo.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public void getLMStables(final DBConfigObject dbConfig, final long readingfromtimestamp, List<Long> courses, List<String> logins) { // accessing DB by creating a session and a transaction using HibernateUtil final Session session = HibernateUtil.getSessionFactory(dbConfig).openSession(); session.clear(); final Transaction tx = session.beginTransaction(); Criteria criteria = session.createCriteria(CourseLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.courseLms = criteria.list(); logger.info("CourseLMS tables: " + this.courseLms.size()); criteria = session.createCriteria(UserLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.userLms = criteria.list(); logger.info("UserLMS tables: " + this.courseLms.size()); criteria = session.createCriteria(RoleLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.roleLms = criteria.list(); logger.info("RoleLMS tables: " + this.roleLms.size()); criteria = session.createCriteria(AssignmentLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.assignmentLms = criteria.list(); logger.info("AssignmentLMS tables: " + this.assignmentLms.size()); criteria = session.createCriteria(ChatLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.chatLms = criteria.list(); logger.info("ChatLMS tables: " + this.chatLms.size()); criteria = session.createCriteria(ForumLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.forumLms = criteria.list(); logger.info("ForumLMS tables: " + this.forumLms.size()); criteria = session.createCriteria(QuizLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.quizLms = criteria.list(); logger.info("QuizLMS tables: " + this.quizLms.size()); criteria = session.createCriteria(ResourceLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.resourceLms = criteria.list(); logger.info("ResourceLMS tables: " + this.resourceLms.size()); criteria = session.createCriteria(ScormLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.scormLms = criteria.list(); logger.info("ScormLMS tables: " + this.scormLms.size()); criteria = session.createCriteria(WikiLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.wikiLms = criteria.list(); logger.info("WikiLMS tables: " + this.wikiLms.size()); criteria = session.createCriteria(WikiLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.wikiLms = criteria.list(); logger.info("WikiLMS tables: " + this.wikiLms.size()); criteria = session.createCriteria(CourseAssignmentLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.courseAssignmentLms = criteria.list(); logger.info("CourseAssignmentLMS tables: " + this.courseAssignmentLms.size()); criteria = session.createCriteria(CourseChatLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.courseChatLms = criteria.list(); logger.info("CourseChatLMS tables: " + this.courseChatLms.size()); criteria = session.createCriteria(CourseForumLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.courseForumLms = criteria.list(); logger.info("CourseForumLMS tables: " + this.courseForumLms.size()); criteria = session.createCriteria(CourseQuizLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.courseQuizLms = criteria.list(); logger.info("CourseQuizLMS tables: " + this.courseQuizLms.size()); criteria = session.createCriteria(CourseResourceLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.courseResourceLms = criteria.list(); logger.info("CourseResourceLMS tables: " + this.courseResourceLms.size()); criteria = session.createCriteria(CourseScormLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.courseScormLms = criteria.list(); logger.info("CourseScormLMS tables: " + this.courseScormLms.size()); criteria = session.createCriteria(CourseWikiLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.courseWikiLms = criteria.list(); logger.info("CourseWikiLMS tables: " + this.courseWikiLms.size()); criteria = session.createCriteria(CourseUserLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.courseUserLms = criteria.list(); logger.info("CourseUserLMS tables: " + this.courseUserLms.size()); criteria = session.createCriteria(AssignmentLogLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.assignmentLogLms = criteria.list(); logger.info("AssignmentLogLMS tables: " + this.assignmentLogLms.size()); criteria = session.createCriteria(ChatLogLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.chatLogLms = criteria.list(); logger.info("ChatLogLMS tables: " + this.chatLogLms.size()); criteria = session.createCriteria(ForumLogLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.forumLogLms = criteria.list(); logger.info("ForumLogLMS tables: " + this.forumLogLms.size()); criteria = session.createCriteria(QuizLogLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.quizLogLms = criteria.list(); logger.info("QuizLogLMS tables: " + this.quizLogLms.size()); criteria = session.createCriteria(ResourceLogLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.resourceLogLms = criteria.list(); logger.info("ResourceLogLMS tables: " + this.resourceLogLms.size()); criteria = session.createCriteria(ScormLogLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.scormLogLms = criteria.list(); logger.info("ScormLogLMS tables: " + this.scormLogLms.size()); criteria = session.createCriteria(WikiLogLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.wikiLogLms = criteria.list(); logger.info("WikiLogLMS tables: " + this.wikiLogLms.size()); criteria = session.createCriteria(QuizUserLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.quizUserLms = criteria.list(); logger.info("QuizUserLMS tables: " + this.quizUserLms.size()); // hibernate session finish and close tx.commit();/*from w w w . j a va 2 s.co m*/ session.close(); }
From source file:de.lemo.dms.connectors.lemo_0_8.ExtractAndMapLeMo.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public void getLMStables(final DBConfigObject dbConf, final long readingfromtimestamp, final long readingtotimestamp, List<Long> courses, List<String> logins) { // accessing DB by creating a session and a transaction using HibernateUtil final Session session = HibernateUtil.getSessionFactory(dbConf).openSession(); session.clear(); final Transaction tx = session.beginTransaction(); Criteria criteria = session.createCriteria(CourseLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.courseLms = criteria.list(); logger.info("CourseLMS tables: " + this.courseLms.size()); criteria = session.createCriteria(UserLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.userLms = criteria.list(); logger.info("UserLMS tables: " + this.courseLms.size()); criteria = session.createCriteria(RoleLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.roleLms = criteria.list(); logger.info("RoleLMS tables: " + this.roleLms.size()); criteria = session.createCriteria(AssignmentLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.assignmentLms = criteria.list(); logger.info("AssignmentLMS tables: " + this.assignmentLms.size()); criteria = session.createCriteria(ChatLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.chatLms = criteria.list(); logger.info("ChatLMS tables: " + this.chatLms.size()); criteria = session.createCriteria(ForumLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.forumLms = criteria.list(); logger.info("ForumLMS tables: " + this.forumLms.size()); criteria = session.createCriteria(QuizLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.quizLms = criteria.list(); logger.info("QuizLMS tables: " + this.quizLms.size()); criteria = session.createCriteria(ResourceLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.resourceLms = criteria.list(); logger.info("ResourceLMS tables: " + this.resourceLms.size()); criteria = session.createCriteria(ScormLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.scormLms = criteria.list(); logger.info("ScormLMS tables: " + this.scormLms.size()); criteria = session.createCriteria(WikiLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.wikiLms = criteria.list(); logger.info("WikiLMS tables: " + this.wikiLms.size()); criteria = session.createCriteria(WikiLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.wikiLms = criteria.list(); logger.info("WikiLMS tables: " + this.wikiLms.size()); criteria = session.createCriteria(CourseAssignmentLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.courseAssignmentLms = criteria.list(); logger.info("CourseAssignmentLMS tables: " + this.courseAssignmentLms.size()); criteria = session.createCriteria(CourseChatLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.courseChatLms = criteria.list(); logger.info("CourseChatLMS tables: " + this.courseChatLms.size()); criteria = session.createCriteria(CourseForumLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.courseForumLms = criteria.list(); logger.info("CourseForumLMS tables: " + this.courseForumLms.size()); criteria = session.createCriteria(CourseQuizLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.courseQuizLms = criteria.list(); logger.info("CourseQuizLMS tables: " + this.courseQuizLms.size()); criteria = session.createCriteria(CourseResourceLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.courseResourceLms = criteria.list(); logger.info("CourseResourceLMS tables: " + this.courseResourceLms.size()); criteria = session.createCriteria(CourseScormLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.courseScormLms = criteria.list(); logger.info("CourseScormLMS tables: " + this.courseScormLms.size()); criteria = session.createCriteria(CourseUserLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.courseUserLms = criteria.list(); logger.info("CourseUserLMS tables: " + this.courseUserLms.size()); criteria = session.createCriteria(CourseWikiLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.courseWikiLms = criteria.list(); logger.info("CourseWikiLMS tables: " + this.courseWikiLms.size()); criteria = session.createCriteria(AssignmentLogLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.assignmentLogLms = criteria.list(); logger.info("AssignmentLogLMS tables: " + this.assignmentLogLms.size()); criteria = session.createCriteria(ChatLogLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.chatLogLms = criteria.list(); logger.info("ChatLogLMS tables: " + this.chatLogLms.size()); criteria = session.createCriteria(ForumLogLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.forumLogLms = criteria.list(); logger.info("ForumLogLMS tables: " + this.forumLogLms.size()); criteria = session.createCriteria(QuizLogLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.quizLogLms = criteria.list(); logger.info("QuizLogLMS tables: " + this.quizLogLms.size()); criteria = session.createCriteria(ResourceLogLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.resourceLogLms = criteria.list(); logger.info("ResourceLogLMS tables: " + this.resourceLogLms.size()); criteria = session.createCriteria(ScormLogLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.scormLogLms = criteria.list(); logger.info("ScormLogLMS tables: " + this.scormLogLms.size()); criteria = session.createCriteria(WikiLogLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.wikiLogLms = criteria.list(); logger.info("WikiLogLMS tables: " + this.wikiLogLms.size()); criteria = session.createCriteria(QuizUserLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.quizUserLms = criteria.list(); logger.info("QuizUserLMS tables: " + this.quizUserLms.size()); // hibernate session finish and close tx.commit();/*w w w.j a v a2s. c o m*/ session.close(); }
From source file:de.lemo.dms.connectors.moodle_1_9.ExtractAndMapMoodle.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public void getLMStables(final DBConfigObject dbConf, final long readingfromtimestamp, final long readingtotimestamp, List<Long> courses, List<String> logins) { final Session session = HibernateUtil.getSessionFactory(dbConf).openSession(); final Transaction tx = session.beginTransaction(); boolean hasCR = false; if (courses != null && courses.size() > 0) hasCR = true;/*from w w w .j ava 2s .c o m*/ boolean empty = false; // reading the LMS Database, create tables as lists of instances of the DB-table classes Criteria criteria; if (this.userLms == null) { criteria = session.createCriteria(ResourceLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); criteria.addOrder(Property.forName("obj.id").asc()); this.resourceLms = criteria.list(); logger.info("ResourceLMS tables: " + this.resourceLms.size()); criteria = session.createCriteria(CourseLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.id", courses)); criteria.addOrder(Property.forName("obj.id").asc()); this.courseLms = criteria.list(); logger.info("CourseLMS tables: " + this.courseLms.size()); criteria = session.createCriteria(ChatLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); criteria.addOrder(Property.forName("obj.id").asc()); this.chatLms = criteria.list(); logger.info("ChatLMS tables: " + this.chatLms.size()); criteria = session.createCriteria(CourseCategoriesLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.courseCategoriesLms = criteria.list(); logger.info("CourseCategoriesLMS tables: " + this.courseCategoriesLms.size()); criteria = session.createCriteria(ForumLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); criteria.addOrder(Property.forName("obj.id").asc()); this.forumLms = criteria.list(); logger.info("ForumLMS tables: " + this.forumLms.size()); criteria = session.createCriteria(CourseModulesLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); criteria.addOrder(Property.forName("obj.id").asc()); this.courseModulesLms = criteria.list(); logger.info("CourseModulesLMS tables: " + this.courseModulesLms.size()); criteria = session.createCriteria(GroupsLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.courseid", courses)); criteria.addOrder(Property.forName("obj.id").asc()); this.groupLms = criteria.list(); logger.info("GroupsLMS tables: " + this.groupLms.size()); criteria = session.createCriteria(QuizLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); criteria.addOrder(Property.forName("obj.id").asc()); this.quizLms = criteria.list(); logger.info("QuizLMS tables: " + this.quizLms.size()); criteria = session.createCriteria(WikiLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); criteria.addOrder(Property.forName("obj.id").asc()); this.wikiLms = criteria.list(); logger.info("WikiLMS tables: " + this.wikiLms.size()); criteria = session.createCriteria(QuizQuestionInstancesLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (QuizLMS e : this.quizLms) ids.add(e.getId()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.quiz", ids)); } criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.quizQuestionInstancesLms = criteria.list(); else this.quizQuestionInstancesLms = new ArrayList<QuizQuestionInstancesLMS>(); logger.info("QuizQuestionInstancesLMS tables: " + this.quizQuestionInstancesLms.size()); criteria = session.createCriteria(QuestionLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (QuizQuestionInstancesLMS e : this.quizQuestionInstancesLms) ids.add(e.getQuestion()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.id", ids)); } criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.questionLms = criteria.list(); else this.questionLms = new ArrayList<QuestionLMS>(); empty = false; logger.info("QuestionLMS tables: " + this.questionLms.size()); criteria = session.createCriteria(RoleLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.roleLms = criteria.list(); logger.info("RoleLMS tables: " + this.roleLms.size()); session.clear(); criteria = session.createCriteria(ContextLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.instanceid", courses)); criteria.addOrder(Property.forName("obj.id").asc()); this.contextLms = criteria.list(); logger.info("ContextLMS tables: " + this.contextLms.size()); criteria = session.createCriteria(AssignmentLMS.class, "obj"); if (hasCR) { criteria.add(Restrictions.in("obj.course", courses)); } criteria.addOrder(Property.forName("obj.id").asc()); this.assignmentLms = criteria.list(); logger.info("AssignmentLMS tables: " + this.assignmentLms.size()); criteria = session.createCriteria(ScormLMS.class, "obj"); if (hasCR) { criteria.add(Restrictions.in("obj.course", courses)); } criteria.addOrder(Property.forName("obj.id").asc()); this.scormLms = criteria.list(); logger.info("ScormLMS tables: " + this.scormLms.size()); criteria = session.createCriteria(GradeItemsLMS.class, "obj"); if (hasCR) { criteria.add(Restrictions.in("obj.courseid", courses)); } criteria.addOrder(Property.forName("obj.id").asc()); this.gradeItemsLms = criteria.list(); logger.info("GradeItemsLMS tables: " + this.gradeItemsLms.size()); } criteria = session.createCriteria(LogLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); criteria.add(Restrictions.le("obj.time", readingtotimestamp)); criteria.add(Restrictions.ge("obj.time", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); this.logLms = criteria.list(); logger.info("LogLMS tables: " + this.logLms.size()); criteria = session.createCriteria(ChatLogLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (ChatLMS e : this.chatLms) ids.add(e.getId()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.chat", ids)); } criteria.add(Restrictions.le("obj.timestamp", readingtotimestamp)); criteria.add(Restrictions.ge("obj.timestamp", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.chatLogLms = criteria.list(); else this.chatLogLms = new ArrayList<ChatLogLMS>(); empty = false; logger.info("ChatLogLMS tables: " + this.chatLogLms.size()); final Query forumPosts; if (!hasCR) { forumPosts = session.createQuery( "from ForumPostsLMS x where x.created>=:readingtimestamp and x.created<=:ceiling order by x.id asc"); forumPosts.setParameter("readingtimestamp", readingfromtimestamp); forumPosts.setParameter("ceiling", readingtotimestamp); this.forumPostsLms = forumPosts.list(); } else { String courseClause = "("; for (int i = 0; i < courses.size(); i++) { courseClause += courses.get(i); if (i < courses.size() - 1) courseClause += ","; else courseClause += ")"; } forumPosts = session.createSQLQuery( "SELECT posts.id,posts.userid,posts.created,posts.modified,posts.subject,posts.message,posts.discussion from forum_posts as posts JOIN log as logs ON posts.userid = logs.userid Where logs.course in " + courseClause + " and (posts.created = logs.time or posts.modified = logs.time) AND posts.created>=:readingtimestamp and posts.created<=:ceiling"); forumPosts.setParameter("readingtimestamp", readingfromtimestamp); forumPosts.setParameter("ceiling", readingtotimestamp); List<Object[]> tmpl = forumPosts.list(); if (this.forumPostsLms == null) this.forumPostsLms = new ArrayList<ForumPostsLMS>(); for (Object[] obj : tmpl) { ForumPostsLMS p = new ForumPostsLMS(); if (obj[0].getClass().equals(BigInteger.class)) { p.setId(((BigInteger) obj[0]).longValue()); } else { p.setId(((Integer) obj[0]).longValue()); } if (obj[0].getClass().equals(BigInteger.class)) { p.setUserid(((BigInteger) obj[1]).longValue()); } else { p.setUserid(((Integer) obj[1]).longValue()); } if (obj[0].getClass().equals(BigInteger.class)) { p.setCreated(((BigInteger) obj[2]).longValue()); } else { p.setCreated(((Integer) obj[2]).longValue()); } if (obj[0].getClass().equals(BigInteger.class)) { p.setModified(((BigInteger) obj[3]).longValue()); } else { p.setModified(((Integer) obj[3]).longValue()); } p.setSubject((String) obj[4]); p.setMessage((String) obj[5]); if (obj[0].getClass().equals(BigInteger.class)) { p.setDiscussion(((BigInteger) obj[6]).longValue()); } else { p.setDiscussion(((Integer) obj[6]).longValue()); } this.forumPostsLms.add(p); this.forumPostsLms.add(p); } } logger.info("ForumPostsLMS tables: " + this.forumPostsLms.size()); final Query forumPostsModified; if (!hasCR) { forumPostsModified = session.createQuery( "from ForumPostsLMS x where x.modified>=:readingtimestamp and x.modified<=:ceiling order by x.id asc"); forumPostsModified.setParameter("readingtimestamp", readingfromtimestamp); forumPostsModified.setParameter("ceiling", readingtotimestamp); this.forumPostsLms.addAll(forumPostsModified.list()); } else { String courseClause = "("; for (int i = 0; i < courses.size(); i++) { courseClause += courses.get(i); if (i < courses.size() - 1) courseClause += ","; else courseClause += ")"; } forumPostsModified = session.createSQLQuery( "SELECT posts.id,posts.userid,posts.created,posts.modified,posts.subject,posts.message from forum_posts as posts JOIN log as logs ON posts.userid = logs.userid Where logs.course in " + courseClause + " and (posts.created = logs.time or posts.modified = logs.time) AND posts.modified>=:readingtimestamp and posts.modified<=:ceiling"); forumPostsModified.setParameter("readingtimestamp", readingfromtimestamp); forumPostsModified.setParameter("ceiling", readingtotimestamp); List<Object[]> tmpl = forumPostsModified.list(); if (this.forumPostsLms == null) this.forumPostsLms = new ArrayList<ForumPostsLMS>(); for (Object[] obj : tmpl) { ForumPostsLMS p = new ForumPostsLMS(); p.setId(((Integer) obj[0]).longValue()); p.setUserid(((Integer) obj[1]).longValue()); p.setCreated(((Integer) obj[2]).longValue()); p.setModified(((Integer) obj[3]).longValue()); p.setSubject((String) obj[4]); p.setMessage((String) obj[5]); this.forumPostsLms.add(p); } } logger.info("ForumPostsLMS tables: " + this.forumPostsLms.size()); session.clear(); criteria = session.createCriteria(GroupsMembersLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (GroupsLMS e : this.groupLms) ids.add(e.getId()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.groupid", ids)); } criteria.add(Restrictions.le("obj.timeadded", readingtotimestamp)); criteria.add(Restrictions.ge("obj.timeadded", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.groupMembersLms = criteria.list(); else this.groupMembersLms = new ArrayList<GroupsMembersLMS>(); empty = false; logger.info("GroupsMembersLMS tables: " + this.groupMembersLms.size()); criteria = session.createCriteria(QuestionStatesLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (QuizQuestionInstancesLMS e : this.quizQuestionInstancesLms) ids.add(e.getQuestion()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.question", ids)); } criteria.add(Restrictions.le("obj.timestamp", readingtotimestamp)); criteria.add(Restrictions.ge("obj.timestamp", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.questionStatesLms = criteria.list(); else this.questionStatesLms = new ArrayList<QuestionStatesLMS>(); empty = false; logger.info("QuestionStatesLMS tables: " + this.questionStatesLms.size()); if (this.userLms == null) { criteria = session.createCriteria(RoleAssignmentsLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (ContextLMS c : this.contextLms) { if (c.getContextlevel() == 50 && courses.contains(c.getInstanceid())) ids.add(c.getId()); } if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.contextid", ids)); } criteria.addOrder(Property.forName("obj.id").asc()); if (!empty) this.roleAssignmentsLms = criteria.list(); else this.roleAssignmentsLms = new ArrayList<RoleAssignmentsLMS>(); criteria = session.createCriteria(UserLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (RoleAssignmentsLMS e : this.roleAssignmentsLms) ids.add(e.getUserid()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.id", ids)); } criteria.addOrder(Property.forName("obj.id").asc()); if (!empty) this.userLms = criteria.list(); else this.userLms = new ArrayList<UserLMS>(); logger.info("UserLMS tables: " + this.userLms.size()); this.roleAssignmentsLms = null; } criteria = session.createCriteria(RoleAssignmentsLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (ContextLMS c : this.contextLms) { if (c.getContextlevel() == 50 && courses.contains(c.getInstanceid())) ids.add(c.getId()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.contextid", ids)); } } criteria.add(Restrictions.le("obj.timemodified", readingtotimestamp)); criteria.add(Restrictions.ge("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.roleAssignmentsLms = criteria.list(); else this.roleAssignmentsLms = new ArrayList<RoleAssignmentsLMS>(); empty = false; logger.info("RoleAssignmentsLMS tables: " + this.roleAssignmentsLms.size()); criteria = session.createCriteria(AssignmentSubmissionsLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (AssignmentLMS e : this.assignmentLms) ids.add(e.getId()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.assignment", ids)); } criteria.add(Restrictions.le("obj.timemodified", readingtotimestamp)); criteria.add(Restrictions.ge("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.assignmentSubmissionLms = criteria.list(); else this.assignmentSubmissionLms = new ArrayList<AssignmentSubmissionsLMS>(); empty = false; logger.info("AssignmentSubmissionsLMS tables: " + this.assignmentSubmissionLms.size()); criteria = session.createCriteria(QuizGradesLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (QuizLMS e : this.quizLms) ids.add(e.getId()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.quiz", ids)); } criteria.add(Restrictions.le("obj.timemodified", readingtotimestamp)); criteria.add(Restrictions.ge("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.quizGradesLms = criteria.list(); else this.quizGradesLms = new ArrayList<QuizGradesLMS>(); empty = false; logger.info("QuizGradesLMS tables: " + this.quizGradesLms.size()); criteria = session.createCriteria(ForumDiscussionsLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (ForumLMS e : this.forumLms) ids.add(e.getId()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.forum", ids)); } criteria.add(Restrictions.le("obj.timemodified", readingtotimestamp)); criteria.add(Restrictions.ge("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.forumDiscussionsLms = criteria.list(); else this.forumDiscussionsLms = new ArrayList<ForumDiscussionsLMS>(); empty = false; logger.info("ForumDiscussionsLMS tables: " + this.forumDiscussionsLms.size()); criteria = session.createCriteria(GradeGradesLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (GradeItemsLMS e : this.gradeItemsLms) ids.add(e.getId()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.itemid", ids)); } criteria.add(Restrictions.le("obj.timemodified", readingtotimestamp)); criteria.add(Restrictions.ge("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.gradeGradesLms = criteria.list(); else this.gradeGradesLms = new ArrayList<GradeGradesLMS>(); empty = false; logger.info("GradeGradesLMS tables: " + this.gradeGradesLms.size()); session.clear(); // hibernate session finish and close tx.commit(); session.close(); }
From source file:de.lemo.dms.connectors.moodle_2_3.ExtractAndMapMoodle.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public void getLMStables(final DBConfigObject dbConfig, final long readingfromtimestamp, List<Long> courses, List<String> logins) { // accessing DB by creating a session and a transaction using HibernateUtil final Session session = HibernateUtil.getSessionFactory(dbConfig).openSession(); session.clear(); final Transaction tx = session.beginTransaction(); boolean hasCR = false; if (courses != null && courses.size() > 0) hasCR = true;/* w w w . j av a 2 s . c o m*/ else courses = new ArrayList<Long>(); boolean empty = false; //Read Context Criteria criteria = session.createCriteria(ContextLMS.class, "obj"); List<Long> contextLevels = new ArrayList<Long>(); contextLevels.add(40L); contextLevels.add(50L); //Read ContextLevels criteria.add(Restrictions.in("obj.contextlevel", contextLevels)); criteria.addOrder(Property.forName("obj.id").asc()); this.contextLms = criteria.list(); logger.info("ContextLMS tables: " + this.contextLms.size()); if (logins != null && !logins.isEmpty()) { List<String> archetypes = new ArrayList<String>(); List<Long> roleIds = new ArrayList<Long>(); List<String> userIds = new ArrayList<String>(); archetypes.add("manager"); archetypes.add("coursecreator"); archetypes.add("teacher"); archetypes.add("editingteacher"); criteria = session.createCriteria(RoleLMS.class, "obj"); criteria.add(Restrictions.in("obj.archetype", archetypes)); for (RoleLMS role : (List<RoleLMS>) criteria.list()) roleIds.add(role.getId()); criteria = session.createCriteria(UserLMS.class, "obj"); criteria.add(Restrictions.in("obj.username", logins)); for (UserLMS user : (List<UserLMS>) criteria.list()) userIds.add(user.getId() + ""); criteria = session.createCriteria(RoleAssignmentsLMS.class, "obj"); criteria.add(Restrictions.in("obj.userid", userIds)); criteria.add(Restrictions.in("obj.roleid", roleIds)); for (ContextLMS c : this.contextLms) { for (RoleAssignmentsLMS ra : (List<RoleAssignmentsLMS>) criteria.list()) { if (c.getContextlevel() == 50 && c.getId() == ra.getContextid()) { courses.add(c.getInstanceid()); hasCR = true; } } } } // reading the LMS Database, create tables as lists of instances of the DB-table classes criteria = session.createCriteria(AssignLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); criteria.addOrder(Property.forName("obj.id").asc()); this.assignLms = criteria.list(); logger.info("AssignLMS tables: " + this.assignLms.size()); //Read RoleAssignments criteria = session.createCriteria(RoleAssignmentsLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (ContextLMS c : this.contextLms) { if (c.getContextlevel() == 50 && courses.contains(c.getInstanceid())) ids.add(c.getId()); } if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.contextid", ids)); } //criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.roleAssignmentsLms = criteria.list(); else this.roleAssignmentsLms = new ArrayList<RoleAssignmentsLMS>(); logger.info("RoleAssignmentsLMS tables: " + this.roleAssignmentsLms.size()); //Read AssignGrades criteria = session.createCriteria(AssignGradesLMS.class, "obj"); if (hasCR) { List<Long> tmp = new ArrayList<Long>(); for (AssignLMS assign : assignLms) { tmp.add(assign.getId()); } if (!(empty = tmp.isEmpty())) criteria.add(Restrictions.in("obj.assignment", tmp)); } criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.assignGradesLms = criteria.list(); else this.assignGradesLms = new ArrayList<AssignGradesLMS>(); logger.info("AssignGradesLMS tables: " + this.assignGradesLms.size()); //Read Enrol criteria = session.createCriteria(EnrolLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.courseid", courses)); criteria.addOrder(Property.forName("obj.id").asc()); this.enrolLms = criteria.list(); logger.info("EnrolLMS tables: " + this.enrolLms.size()); //Read Modules criteria = session.createCriteria(ModulesLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.modulesLms = criteria.list(); logger.info("ModulesLMS tables: " + this.modulesLms.size()); //Read UserEnrolments criteria = session.createCriteria(UserEnrolmentsLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (EnrolLMS e : this.enrolLms) ids.add(e.getId()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.enrolid", ids)); } criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.userEnrolmentsLms = criteria.list(); else this.userEnrolmentsLms = new ArrayList<UserEnrolmentsLMS>(); logger.info("UserEnrolmentsLMS tables: " + this.userEnrolmentsLms.size()); //Read CourseModules criteria = session.createCriteria(CourseModulesLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); criteria.addOrder(Property.forName("obj.id").asc()); this.courseModulesLms = criteria.list(); logger.info("CourseModulesLMS tables: " + this.courseModulesLms.size()); //Read Log criteria = session.createCriteria(LogLMS.class, "obj"); if (hasCR) { criteria.add(Restrictions.in("obj.course", courses)); } criteria.add(Restrictions.gt("obj.time", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); this.logLms = criteria.list(); logger.info("LogLMS tables: " + this.logLms.size()); //Read Resource criteria = session.createCriteria(ResourceLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); //criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); this.resourceLms = criteria.list(); logger.info("ResourceLMS tables: " + this.resourceLms.size()); //Read Urls criteria = session.createCriteria(UrlLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); //criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); this.urlLms = criteria.list(); logger.info("UrlLMS tables: " + this.urlLms.size()); //Read Pages criteria = session.createCriteria(PageLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); //criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); this.pageLms = criteria.list(); logger.info("UrlLMS tables: " + this.pageLms.size()); //Read Quiz criteria = session.createCriteria(QuizLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); //criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); this.quizLms = criteria.list(); logger.info("QuizLMS tables: " + this.quizLms.size()); //Read QuizAttempts criteria = session.createCriteria(QuizAttemptsLMS.class, "obj"); if (hasCR) if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (QuizLMS e : this.quizLms) ids.add(e.getId()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.quiz", ids)); } criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.quizAttemptsLms = criteria.list(); else this.quizAttemptsLms = new ArrayList<QuizAttemptsLMS>(); logger.info("QuizAttemptsLMS tables: " + this.quizAttemptsLms.size()); //Read Chats criteria = session.createCriteria(ChatLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); //criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); this.chatLms = criteria.list(); logger.info("ChatLMS tables: " + this.chatLms.size()); //Read ChatLog criteria = session.createCriteria(ChatLogLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (ChatLMS e : this.chatLms) ids.add(e.getId()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.chat", ids)); } criteria.add(Restrictions.gt("obj.timestamp", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.chatLogLms = criteria.list(); else this.chatLogLms = new ArrayList<ChatLogLMS>(); logger.info("ChatLogLMS tables: " + this.chatLogLms.size()); criteria = session.createCriteria(CourseCategoriesLMS.class, "obj"); //criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); this.courseCategoriesLms = criteria.list(); logger.info("CourseCategoriesLMS tables: " + this.courseCategoriesLms.size()); criteria = session.createCriteria(CourseLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.id", courses)); criteria.addOrder(Property.forName("obj.id").asc()); this.courseLms = criteria.list(); logger.info("CourseLMS tables: " + this.courseLms.size()); final Query forumPosts; if (!hasCR) { forumPosts = session .createQuery("from ForumPostsLMS x where x.modified>=:readingtimestamp order by x.id asc"); forumPosts.setParameter("readingtimestamp", readingfromtimestamp); this.forumPostsLms = forumPosts.list(); } else { String courseClause = "("; for (int i = 0; i < courses.size(); i++) { courseClause += courses.get(i); if (i < courses.size() - 1) courseClause += ","; else courseClause += ")"; } forumPosts = session.createSQLQuery( "SELECT posts.id,posts.userid,posts.created,posts.modified,posts.subject,posts.message,posts.discussion from mdl_forum_posts as posts JOIN mdl_log as logs ON posts.userid = logs.userid Where logs.course in " + courseClause + " and (posts.created = logs.time or posts.modified = logs.time) AND posts.modified>=:readingtimestamp"); forumPosts.setParameter("readingtimestamp", readingfromtimestamp); List<Object[]> tmpl = forumPosts.list(); this.forumPostsLms = new ArrayList<ForumPostsLMS>(); for (Object[] obj : tmpl) { ForumPostsLMS p = new ForumPostsLMS(); if (obj[0].getClass().equals(BigInteger.class)) { p.setId(((BigInteger) obj[0]).longValue()); } else { p.setId(((Integer) obj[0]).longValue()); } if (obj[0].getClass().equals(BigInteger.class)) { p.setUserid(((BigInteger) obj[1]).longValue()); } else { p.setUserid(((Integer) obj[1]).longValue()); } if (obj[0].getClass().equals(BigInteger.class)) { p.setCreated(((BigInteger) obj[2]).longValue()); } else { p.setCreated(((Integer) obj[2]).longValue()); } if (obj[0].getClass().equals(BigInteger.class)) { p.setModified(((BigInteger) obj[3]).longValue()); } else { p.setModified(((Integer) obj[3]).longValue()); } p.setSubject((String) obj[4]); p.setMessage((String) obj[5]); if (obj[0].getClass().equals(BigInteger.class)) { p.setDiscussion(((BigInteger) obj[6]).longValue()); } else { p.setDiscussion(((Integer) obj[6]).longValue()); } this.forumPostsLms.add(p); } } logger.info("ForumPostsLMS tables: " + this.forumPostsLms.size()); criteria = session.createCriteria(ForumLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); //criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); this.forumLms = criteria.list(); logger.info("ForumLMS tables: " + this.forumLms.size()); criteria = session.createCriteria(GroupsLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.courseid", courses)); //criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); this.groupLms = criteria.list(); logger.info("GroupsLMS tables: " + this.groupLms.size()); criteria = session.createCriteria(WikiLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); //criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); this.wikiLms = criteria.list(); logger.info("WikiLMS tables: " + this.wikiLms.size()); criteria = session.createCriteria(GroupsMembersLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (GroupsLMS e : this.groupLms) ids.add(e.getId()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.groupid", ids)); } //criteria.add(Restrictions.gt("obj.timeadded", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.groupMembersLms = criteria.list(); else this.groupMembersLms = new ArrayList<GroupsMembersLMS>(); logger.info("GroupsMembersLMS tables: " + this.groupMembersLms.size()); criteria = session.createCriteria(QuizQuestionInstancesLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (QuizLMS e : this.quizLms) ids.add(e.getId()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.quiz", ids)); } criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.quizQuestionInstancesLms = criteria.list(); else this.quizQuestionInstancesLms = new ArrayList<QuizQuestionInstancesLMS>(); logger.info("QuizQuestionInstancesLMS tables: " + this.quizQuestionInstancesLms.size()); criteria = session.createCriteria(QuestionStatesLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (QuizQuestionInstancesLMS e : this.quizQuestionInstancesLms) ids.add(e.getQuestion()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.question", ids)); } criteria.add(Restrictions.gt("obj.timestamp", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.questionStatesLms = criteria.list(); else this.questionStatesLms = new ArrayList<QuestionStatesLMS>(); logger.info("QuestionStatesLMS tables: " + this.questionStatesLms.size()); criteria = session.createCriteria(QuestionLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (QuizQuestionInstancesLMS e : this.quizQuestionInstancesLms) ids.add(e.getQuestion()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.id", ids)); } //criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.questionLms = criteria.list(); else this.questionLms = new ArrayList<QuestionLMS>(); logger.info("QuestionLMS tables: " + this.questionLms.size()); criteria = session.createCriteria(UserLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (RoleAssignmentsLMS e : this.roleAssignmentsLms) ids.add(Long.valueOf(e.getUserid())); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.id", ids)); } criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.userLms = criteria.list(); else this.userLms = new ArrayList<UserLMS>(); logger.info("UserLMS tables: " + this.userLms.size()); criteria = session.createCriteria(RoleLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.roleLms = criteria.list(); logger.info("RoleLMS tables: " + this.roleLms.size()); criteria = session.createCriteria(QuizGradesLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (QuizLMS e : this.quizLms) ids.add(e.getId()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.quiz", ids)); } criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.quizGradesLms = criteria.list(); else this.quizGradesLms = new ArrayList<QuizGradesLMS>(); logger.info("QuizGradesLMS tables: " + this.quizGradesLms.size()); criteria = session.createCriteria(ForumDiscussionsLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (ForumLMS e : this.forumLms) ids.add(e.getId()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.forum", ids)); } criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.forumDiscussionsLms = criteria.list(); else this.forumDiscussionsLms = new ArrayList<ForumDiscussionsLMS>(); logger.info("ForumDiscussionsLMS tables: " + this.forumDiscussionsLms.size()); criteria = session.createCriteria(ScormLMS.class, "obj"); if (hasCR) { criteria.add(Restrictions.in("obj.course", courses)); } //criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); this.scormLms = criteria.list(); logger.info("ScormLMS tables: " + this.scormLms.size()); criteria = session.createCriteria(GradeItemsLMS.class, "obj"); if (hasCR) { criteria.add(Restrictions.in("obj.courseid", courses)); } //criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); this.gradeItemsLms = criteria.list(); logger.info("GradeItemsLMS tables: " + this.gradeItemsLms.size()); criteria = session.createCriteria(GradeGradesLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (GradeItemsLMS e : this.gradeItemsLms) ids.add(e.getId()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.itemid", ids)); } //criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.gradeGradesLms = criteria.list(); else this.gradeGradesLms = new ArrayList<GradeGradesLMS>(); logger.info("GradeGradesLMS tables: " + this.gradeGradesLms.size()); // hibernate session finish and close tx.commit(); session.close(); }
From source file:de.lemo.dms.connectors.moodle_2_3.ExtractAndMapMoodle.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public void getLMStables(final DBConfigObject dbConf, final long readingfromtimestamp, final long readingtotimestamp, List<Long> courses, List<String> logins) { // accessing DB by creating a session and a transaction using HibernateUtil final Session session = HibernateUtil.getSessionFactory(dbConf).openSession(); // Session session = HibernateUtil.getDynamicSourceDBFactoryMoodle("jdbc:mysql://localhost/moodle19", session.clear(); final Transaction tx = session.beginTransaction(); // reading the LMS Database, create tables as lists of instances of the DB-table classes Criteria criteria;//from w w w.jav a2s . co m boolean hasCR = false; if (courses != null && courses.size() > 0) hasCR = true; boolean empty = false; if (this.userLms == null) { //Read Context criteria = session.createCriteria(ContextLMS.class, "obj"); List<Long> contextLevels = new ArrayList<Long>(); contextLevels.add(40L); contextLevels.add(50L); criteria.add(Restrictions.in("obj.contextlevel", contextLevels)); criteria.addOrder(Property.forName("obj.id").asc()); this.contextLms = criteria.list(); logger.info("ContextLMS tables: " + this.contextLms.size()); if (logins != null && !logins.isEmpty()) { List<String> archetypes = new ArrayList<String>(); List<Long> roleIds = new ArrayList<Long>(); List<String> userIds = new ArrayList<String>(); archetypes.add("manager"); archetypes.add("coursecreator"); archetypes.add("teacher"); archetypes.add("editingteacher"); criteria = session.createCriteria(RoleLMS.class, "obj"); criteria.add(Restrictions.in("obj.archetype", archetypes)); for (RoleLMS role : (List<RoleLMS>) criteria.list()) roleIds.add(role.getId()); criteria = session.createCriteria(UserLMS.class, "obj"); criteria.add(Restrictions.in("obj.username", logins)); for (UserLMS user : (List<UserLMS>) criteria.list()) userIds.add(user.getId() + ""); criteria = session.createCriteria(RoleAssignmentsLMS.class, "obj"); criteria.add(Restrictions.in("obj.userid", userIds)); criteria.add(Restrictions.in("obj.roleid", roleIds)); for (ContextLMS c : this.contextLms) { for (RoleAssignmentsLMS ra : (List<RoleAssignmentsLMS>) criteria.list()) { if (c.getContextlevel() == 50 && c.getId() == ra.getContextid()) { courses.add(c.getInstanceid()); hasCR = true; } } } } criteria = session.createCriteria(AssignLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); criteria.addOrder(Property.forName("obj.id").asc()); this.assignLms = criteria.list(); logger.info("AssignLMS tables: " + this.assignLms.size()); criteria = session.createCriteria(EnrolLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.courseid", courses)); criteria.addOrder(Property.forName("obj.id").asc()); this.enrolLms = criteria.list(); logger.info("EnrolLMS tables: " + this.enrolLms.size()); criteria = session.createCriteria(ModulesLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.modulesLms = criteria.list(); logger.info("ModulesLMS tables: " + this.modulesLms.size()); criteria = session.createCriteria(UserEnrolmentsLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (EnrolLMS e : this.enrolLms) ids.add(e.getId()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.enrolid", ids)); } criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.userEnrolmentsLms = criteria.list(); else this.userEnrolmentsLms = new ArrayList<UserEnrolmentsLMS>(); logger.info("UserEnrolmentsLMS tables: " + this.userEnrolmentsLms.size()); criteria = session.createCriteria(CourseModulesLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); criteria.addOrder(Property.forName("obj.id").asc()); this.courseModulesLms = criteria.list(); logger.info("CourseModulesLMS tables: " + this.courseModulesLms.size()); criteria = session.createCriteria(ResourceLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); criteria.addOrder(Property.forName("obj.id").asc()); this.resourceLms = criteria.list(); logger.info("ResourceLMS tables: " + this.resourceLms.size()); //Read Urls criteria = session.createCriteria(UrlLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); this.urlLms = criteria.list(); logger.info("UrlLMS tables: " + this.urlLms.size()); //Read Pages criteria = session.createCriteria(PageLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); this.pageLms = criteria.list(); logger.info("UrlLMS tables: " + this.pageLms.size()); criteria = session.createCriteria(CourseLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.id", courses)); criteria.addOrder(Property.forName("obj.id").asc()); this.courseLms = criteria.list(); logger.info("CourseLMS tables: " + this.courseLms.size()); criteria = session.createCriteria(ChatLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); criteria.addOrder(Property.forName("obj.id").asc()); this.chatLms = criteria.list(); logger.info("ChatLMS tables: " + this.chatLms.size()); criteria = session.createCriteria(CourseCategoriesLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.courseCategoriesLms = criteria.list(); logger.info("CourseCategoriesLMS tables: " + this.courseCategoriesLms.size()); criteria = session.createCriteria(ForumLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); criteria.addOrder(Property.forName("obj.id").asc()); this.forumLms = criteria.list(); logger.info("ForumLMS tables: " + this.forumLms.size()); criteria = session.createCriteria(GroupsLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.courseid", courses)); criteria.addOrder(Property.forName("obj.id").asc()); this.groupLms = criteria.list(); logger.info("GroupsLMS tables: " + this.groupLms.size()); criteria = session.createCriteria(QuizLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); criteria.addOrder(Property.forName("obj.id").asc()); this.quizLms = criteria.list(); logger.info("QuizLMS tables: " + this.quizLms.size()); criteria = session.createCriteria(WikiLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); criteria.addOrder(Property.forName("obj.id").asc()); this.wikiLms = criteria.list(); logger.info("WikiLMS tables: " + this.wikiLms.size()); criteria = session.createCriteria(QuizQuestionInstancesLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (QuizLMS e : this.quizLms) ids.add(e.getId()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.quiz", ids)); } criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.quizQuestionInstancesLms = criteria.list(); else this.quizQuestionInstancesLms = new ArrayList<QuizQuestionInstancesLMS>(); logger.info("QuizQuestionInstancesLMS tables: " + this.quizQuestionInstancesLms.size()); criteria = session.createCriteria(QuestionLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (QuizQuestionInstancesLMS e : this.quizQuestionInstancesLms) ids.add(e.getQuestion()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.id", ids)); } criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.questionLms = criteria.list(); else this.questionLms = new ArrayList<QuestionLMS>(); logger.info("QuestionLMS tables: " + this.questionLms.size()); criteria = session.createCriteria(RoleLMS.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); this.roleLms = criteria.list(); logger.info("RoleLMS tables: " + this.roleLms.size()); session.clear(); /* criteria = session.createCriteria(AssignmentLMS.class, "obj"); if(hasCR) { criteria.add(Restrictions.in("obj.course", courses)); } criteria.addOrder(Property.forName("obj.id").asc()); this.assignmentLms = criteria.list(); logger.info("AssignmentLMS tables: " + this.assignmentLms.size()); */ criteria = session.createCriteria(ScormLMS.class, "obj"); if (hasCR) { criteria.add(Restrictions.in("obj.course", courses)); } criteria.addOrder(Property.forName("obj.id").asc()); this.scormLms = criteria.list(); logger.info("ScormLMS tables: " + this.scormLms.size()); criteria = session.createCriteria(GradeItemsLMS.class, "obj"); if (hasCR) { criteria.add(Restrictions.in("obj.courseid", courses)); } criteria.addOrder(Property.forName("obj.id").asc()); this.gradeItemsLms = criteria.list(); logger.info("GradeItemsLMS tables: " + this.gradeItemsLms.size()); criteria = session.createCriteria(RoleAssignmentsLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (ContextLMS c : this.contextLms) { if (c.getContextlevel() == 50 && courses.contains(c.getInstanceid())) ids.add(c.getId()); } if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.contextid", ids)); } criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.roleAssignmentsLms = criteria.list(); else this.roleAssignmentsLms = new ArrayList<RoleAssignmentsLMS>(); logger.info("RoleAssignmentsLMS tables: " + this.roleAssignmentsLms.size()); criteria = session.createCriteria(UserLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (RoleAssignmentsLMS e : this.roleAssignmentsLms) ids.add(Long.valueOf(e.getUserid())); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.id", ids)); } criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.userLms = criteria.list(); else this.userLms = new ArrayList<UserLMS>(); logger.info("UserLMS tables: " + this.userLms.size()); } criteria = session.createCriteria(QuizAttemptsLMS.class, "obj"); if (hasCR) if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (QuizLMS e : this.quizLms) ids.add(e.getId()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.quiz", ids)); } criteria.add(Restrictions.lt("obj.timemodified", readingtotimestamp)); criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.quizAttemptsLms = criteria.list(); else this.quizAttemptsLms = new ArrayList<QuizAttemptsLMS>(); logger.info("QuizAttemptsLMS tables: " + this.quizAttemptsLms.size()); criteria = session.createCriteria(LogLMS.class, "obj"); if (hasCR) criteria.add(Restrictions.in("obj.course", courses)); criteria.add(Restrictions.lt("obj.time", readingtotimestamp)); criteria.add(Restrictions.gt("obj.time", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); this.logLms = criteria.list(); logger.info("LogLMS tables: " + this.logLms.size()); criteria = session.createCriteria(ChatLogLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (ChatLMS e : this.chatLms) ids.add(e.getId()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.chat", ids)); } criteria.add(Restrictions.lt("obj.timestamp", readingtotimestamp)); criteria.add(Restrictions.gt("obj.timestamp", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.chatLogLms = criteria.list(); else this.chatLogLms = new ArrayList<ChatLogLMS>(); logger.info("ChatLogLMS tables: " + this.chatLogLms.size()); final Query forumPosts; if (!hasCR) { forumPosts = session.createQuery( "from ForumPostsLMS x where x.created>=:readingtimestamp and x.created<=:ceiling order by x.id asc"); forumPosts.setParameter("readingtimestamp", readingfromtimestamp); forumPosts.setParameter("ceiling", readingtotimestamp); this.forumPostsLms = forumPosts.list(); } else { String courseClause = "("; for (int i = 0; i < courses.size(); i++) { courseClause += courses.get(i); if (i < courses.size() - 1) courseClause += ","; else courseClause += ")"; } forumPosts = session.createSQLQuery( "SELECT posts.id,posts.userid,posts.created,posts.modified,posts.subject,posts.message,posts.discussion from forum_posts as posts JOIN log as logs ON posts.userid = logs.userid Where logs.course in " + courseClause + " and (posts.created = logs.time or posts.modified = logs.time) AND posts.created>=:readingtimestamp and posts.created<=:ceiling"); forumPosts.setParameter("readingtimestamp", readingfromtimestamp); forumPosts.setParameter("ceiling", readingtotimestamp); List<Object[]> tmpl = forumPosts.list(); if (this.forumPostsLms == null) this.forumPostsLms = new ArrayList<ForumPostsLMS>(); for (Object[] obj : tmpl) { ForumPostsLMS p = new ForumPostsLMS(); if (obj[0].getClass().equals(BigInteger.class)) { p.setId(((BigInteger) obj[0]).longValue()); } else { p.setId(((Integer) obj[0]).longValue()); } if (obj[0].getClass().equals(BigInteger.class)) { p.setUserid(((BigInteger) obj[1]).longValue()); } else { p.setUserid(((Integer) obj[1]).longValue()); } if (obj[0].getClass().equals(BigInteger.class)) { p.setCreated(((BigInteger) obj[2]).longValue()); } else { p.setCreated(((Integer) obj[2]).longValue()); } if (obj[0].getClass().equals(BigInteger.class)) { p.setModified(((BigInteger) obj[3]).longValue()); } else { p.setModified(((Integer) obj[3]).longValue()); } p.setSubject((String) obj[4]); p.setMessage((String) obj[5]); if (obj[0].getClass().equals(BigInteger.class)) { p.setDiscussion(((BigInteger) obj[6]).longValue()); } else { p.setDiscussion(((Integer) obj[6]).longValue()); } this.forumPostsLms.add(p); } } logger.info("ForumPostsLMS tables: " + this.forumPostsLms.size()); final Query forumPostsModified; if (!hasCR) { forumPostsModified = session.createQuery( "from ForumPostsLMS x where x.modified>=:readingtimestamp and x.modified<=:ceiling order by x.id asc"); this.forumPostsLms.addAll(forumPostsModified.list()); } else { String courseClause = "("; for (int i = 0; i < courses.size(); i++) { courseClause += courses.get(i); if (i < courses.size() - 1) courseClause += ","; else courseClause += ")"; } forumPostsModified = session.createSQLQuery( "SELECT posts.id,posts.userid,posts.created,posts.modified,posts.subject,posts.message from mdl_forum_posts as posts JOIN mdl_log as logs ON posts.userid = logs.userid Where logs.course in " + courseClause + " and (posts.created = logs.time or posts.modified = logs.time) AND posts.modified>=:readingtimestamp and posts.modified<=:ceiling"); forumPostsModified.setParameter("readingtimestamp", readingfromtimestamp); forumPostsModified.setParameter("ceiling", readingtotimestamp); List<Object[]> tmpl = forumPostsModified.list(); if (this.forumPostsLms == null) this.forumPostsLms = new ArrayList<ForumPostsLMS>(); for (Object[] obj : tmpl) { ForumPostsLMS p = new ForumPostsLMS(); p.setId(((Integer) obj[0]).longValue()); p.setUserid(((Integer) obj[1]).longValue()); p.setCreated(((Integer) obj[2]).longValue()); p.setModified(((Integer) obj[3]).longValue()); p.setSubject((String) obj[4]); p.setMessage((String) obj[5]); this.forumPostsLms.add(p); } } logger.info("ForumPostsModifiedLMS tables: " + this.forumPostsLms.size()); session.clear(); criteria = session.createCriteria(AssignGradesLMS.class, "obj"); if (hasCR) { List<Long> tmp = new ArrayList<Long>(); for (AssignLMS assign : assignLms) { tmp.add(assign.getId()); } if (!(empty = tmp.isEmpty())) criteria.add(Restrictions.in("obj.assignment", tmp)); } criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.add(Restrictions.lt("obj.timemodified", readingtotimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.assignGradesLms = criteria.list(); else this.assignGradesLms = new ArrayList<AssignGradesLMS>(); logger.info("AssignGradesLMS tables: " + this.assignGradesLms.size()); criteria = session.createCriteria(GroupsMembersLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (GroupsLMS e : this.groupLms) ids.add(e.getId()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.groupid", ids)); } criteria.add(Restrictions.lt("obj.timeadded", readingtotimestamp)); criteria.add(Restrictions.gt("obj.timeadded", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.groupMembersLms = criteria.list(); else this.groupMembersLms = new ArrayList<GroupsMembersLMS>(); logger.info("GroupsMembersLMS tables: " + this.groupMembersLms.size()); criteria = session.createCriteria(QuestionStatesLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (QuizQuestionInstancesLMS e : this.quizQuestionInstancesLms) ids.add(e.getQuestion()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.question", ids)); } criteria.add(Restrictions.lt("obj.timestamp", readingtotimestamp)); criteria.add(Restrictions.gt("obj.timestamp", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.questionStatesLms = criteria.list(); else this.questionStatesLms = new ArrayList<QuestionStatesLMS>(); logger.info("QuestionStatesLMS tables: " + this.questionStatesLms.size()); /* criteria = session.createCriteria(AssignmentSubmissionsLMS.class, "obj"); if(hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for(AssignmentLMS e : this.assignmentLms) ids.add(e.getId()); if(!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.id", ids)); } criteria.add(Restrictions.lt("obj.timecreated", readingtotimestamp)); criteria.add(Restrictions.gt("obj.timecreated", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if(!(hasCR && empty)) this.assignmentSubmissionLms = criteria.list(); else this.assignmentSubmissionLms = new ArrayList<AssignmentSubmissionsLMS>(); logger.info("AssignmentSubmissionsLMS tables: " + this.userLms.size()); */ criteria = session.createCriteria(QuizGradesLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (QuizLMS e : this.quizLms) ids.add(e.getId()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.quiz", ids)); } criteria.add(Restrictions.lt("obj.timemodified", readingtotimestamp)); criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.quizGradesLms = criteria.list(); else this.quizGradesLms = new ArrayList<QuizGradesLMS>(); logger.info("QuizGradesLMS tables: " + this.quizGradesLms.size()); criteria = session.createCriteria(ForumDiscussionsLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (ForumLMS e : this.forumLms) ids.add(e.getId()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.forum", ids)); } criteria.add(Restrictions.lt("obj.timemodified", readingtotimestamp)); criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.forumDiscussionsLms = criteria.list(); else this.forumDiscussionsLms = new ArrayList<ForumDiscussionsLMS>(); logger.info("ForumDiscussionsLMS tables: " + this.forumDiscussionsLms.size()); criteria = session.createCriteria(GradeGradesLMS.class, "obj"); if (hasCR) { ArrayList<Long> ids = new ArrayList<Long>(); for (GradeItemsLMS e : this.gradeItemsLms) ids.add(e.getId()); if (!(empty = ids.isEmpty())) criteria.add(Restrictions.in("obj.itemid", ids)); } //criteria.add(Restrictions.lt("obj.timemodified", readingtotimestamp)); //criteria.add(Restrictions.gt("obj.timemodified", readingfromtimestamp)); criteria.addOrder(Property.forName("obj.id").asc()); if (!(hasCR && empty)) this.gradeGradesLms = criteria.list(); else this.gradeGradesLms = new ArrayList<GradeGradesLMS>(); logger.info("GradeGradesLMS tables: " + this.gradeGradesLms.size()); session.clear(); // hibernate session finish and close tx.commit(); session.close(); }