List of usage examples for org.hibernate.criterion Projections max
public static AggregateProjection max(String propertyName)
From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.SealLeafNode.java
License:Open Source License
/** * Returns the Criterion for the outdated entities. * // w w w . j av a2s. co m * @param effectivePropertyName the field name representing the seal state * @return the Criterion for the outdated entities */ private Criterion getOutdatedCriterion(String effectivePropertyName) { int expirationInDays = IteraplanProperties.getIntProperty(IteraplanProperties.SEAL_EXPIRATION_DAYS); Date minusDays = new DateTime().minusDays(expirationInDays).toDate(); String idPropertyName = String.format("%s.%s", getResultTypeDBNameShortWithSuffix(), "id"); final DetachedCriteria maxSealDate = DetachedCriteria.forClass(Seal.class, "seal"); maxSealDate.setProjection(Projections.max("seal.date")); maxSealDate.add(Restrictions.eqProperty("seal.bb", idPropertyName)); final DetachedCriteria lastSeal = DetachedCriteria.forClass(Seal.class, "lastSeal"); lastSeal.add(Subqueries.propertyEq("lastSeal.date", maxSealDate)); lastSeal.add(Restrictions.eqProperty("lastSeal.bb", idPropertyName)); lastSeal.add(Restrictions.le("lastSeal.date", minusDays)); lastSeal.setProjection(Projections.distinct(Property.forName("lastSeal.bb"))); Criterion outdatedCriterion = Subqueries.propertyIn(idPropertyName, lastSeal); Criterion valid = Restrictions.eq(effectivePropertyName, SealState.VALID.toString()); return Restrictions.and(valid, outdatedCriterion); }
From source file:de.lemo.dms.connectors.ConnectorManager.java
License:Open Source License
private void saveOrUpdateConnectorInfo(final IConnector connector) { final IDBHandler dbHandler = ServerConfiguration.getInstance().getMiningDbHandler(); final Session session = dbHandler.getMiningSession(); PlatformMining platform = (PlatformMining) session.get(PlatformMining.class, connector.getPlatformId()); if (platform == null) { // save new platform final Criteria criteria = session.createCriteria(PlatformMining.class) .setProjection(Projections.max("prefix")); Long maxPrefix = (Long) criteria.uniqueResult(); if (maxPrefix == null) { maxPrefix = 10L;//from w w w.ja va2 s . c om } platform = new PlatformMining(); platform.setId(connector.getPlatformId()); platform.setPrefix(maxPrefix + 1); } final AbstractConnector ac = (AbstractConnector) connector; ac.setPrefix(platform.getPrefix()); // update name platform.setName(connector.getName()); platform.setType(connector.getPlattformType().name()); dbHandler.saveToDB(session, platform); dbHandler.closeSession(session); }
From source file:de.lemo.dms.connectors.lemo_0_8.ExtractAndMap.java
License:Open Source License
/** * Reads the Mining Database.// ww w . j a va2 s . c om * Initial informations needed to start the process of updating are collected here. * The Timestamp of the last run of the extractor is read from the config table * and the objects which might been needed to associate are read and saved here. * * @return The timestamp of the last run of the extractor. If this is the first run it will be set 0. **/ public long getMiningInitial() { final Session session = this.dbHandler.getMiningSession(); List<?> t; Long readingtimestamp; readingtimestamp = (Long) session .createQuery( "Select max(latestTimestamp) from Config where platform=" + this.connector.getPlatformId()) .uniqueResult(); if (readingtimestamp == null) { readingtimestamp = -1L; } Criteria criteria = session.createCriteria(PlatformLMS.class, "obj"); // load objects which are already in Mining DB for associations criteria = session.createCriteria(Course.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); t = criteria.list(); this.oldCourseMining = new HashMap<Long, Course>(); for (int i = 0; i < t.size(); i++) { this.oldCourseMining.put(((Course) (t.get(i))).getId(), (Course) t.get(i)); } logger.info("Loaded " + this.oldCourseMining.size() + " Course objects from the mining database."); criteria = session.createCriteria(User.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); t = criteria.list(); this.oldUserMining = new HashMap<Long, User>(); for (int i = 0; i < t.size(); i++) { this.oldUserMining.put(((User) (t.get(i))).getId(), (User) t.get(i)); } logger.info("Loaded " + this.oldUserMining.size() + " User objects from the mining database."); criteria = session.createCriteria(LearningObj.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); t = criteria.list(); this.oldLearningObjectMining = new HashMap<Long, LearningObj>(); for (int i = 0; i < t.size(); i++) { this.oldLearningObjectMining.put(((LearningObj) (t.get(i))).getId(), (LearningObj) t.get(i)); } logger.info( "Loaded " + this.oldLearningObjectMining.size() + " LearningObj objects from the mining database."); criteria = session.createCriteria(Attribute.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); t = criteria.list(); this.oldAttributeMining = new HashMap<String, Attribute>(); for (int i = 0; i < t.size(); i++) { this.oldAttributeMining.put(((Attribute) (t.get(i))).getName(), (Attribute) t.get(i)); } logger.info("Loaded " + this.oldAttributeMining.size() + " Attribute objects from the mining database."); criteria = session.createCriteria(Role.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); t = criteria.list(); this.oldRoleMining = new HashMap<Long, Role>(); for (int i = 0; i < t.size(); i++) { this.oldRoleMining.put(((Role) (t.get(i))).getId(), (Role) t.get(i)); } logger.info("Loaded " + this.oldRoleMining.size() + " Role objects from the mining database."); criteria = session.createCriteria(LearningType.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); t = criteria.list(); this.oldLearningTypeMining = new HashMap<String, LearningType>(); for (int i = 0; i < t.size(); i++) { this.oldLearningTypeMining.put(((LearningType) (t.get(i))).getType(), (LearningType) t.get(i)); } logger.info( "Loaded " + this.oldLearningTypeMining.size() + " LearningType objects from the mining database."); criteria = session.createCriteria(CourseAttribute.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); t = criteria.list(); this.oldCourseAttributeMining = new HashMap<Long, CourseAttribute>(); for (int i = 0; i < t.size(); i++) { this.oldCourseAttributeMining.put(((CourseAttribute) (t.get(i))).getId(), (CourseAttribute) t.get(i)); } logger.info("Loaded " + this.oldCourseAttributeMining.size() + " CourseAttribute objects from the mining database."); criteria = session.createCriteria(UserAttribute.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); t = criteria.list(); this.oldUserAttributeMining = new HashMap<Long, UserAttribute>(); for (int i = 0; i < t.size(); i++) { this.oldUserAttributeMining.put(((UserAttribute) (t.get(i))).getId(), (UserAttribute) t.get(i)); } logger.info("Loaded " + this.oldUserAttributeMining.size() + " UserAttribute objects from the mining database."); criteria = session.createCriteria(LearningAttribute.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); t = criteria.list(); this.oldLearningAttributeMining = new HashMap<Long, LearningAttribute>(); for (int i = 0; i < t.size(); i++) { this.oldLearningAttributeMining.put(((LearningAttribute) (t.get(i))).getId(), (LearningAttribute) t.get(i)); } logger.info("Loaded " + this.oldUserAttributeMining.size() + " LearningAttribute objects from the mining database."); criteria = session.createCriteria(CourseLearning.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); t = criteria.list(); this.oldCourseLearningObjectMining = new HashMap<Long, CourseLearning>(); for (int i = 0; i < t.size(); i++) { this.oldCourseLearningObjectMining.put(((CourseLearning) (t.get(i))).getId(), (CourseLearning) t.get(i)); } logger.info("Loaded " + this.oldCourseLearningObjectMining.size() + " CourseResource objects from the mining database."); criteria = session.createCriteria(UserAssessment.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); t = criteria.list(); this.oldUserAssessmentMining = new HashMap<Long, UserAssessment>(); for (int i = 0; i < t.size(); i++) { this.oldUserAssessmentMining.put(((UserAssessment) (t.get(i))).getId(), (UserAssessment) t.get(i)); } logger.info("Loaded " + this.oldUserAssessmentMining.size() + " UserAssessment objects from the mining database."); criteria = session.createCriteria(CourseUser.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); t = criteria.list(); this.oldCourseUserMining = new HashMap<Long, CourseUser>(); for (int i = 0; i < t.size(); i++) { this.oldCourseUserMining.put(((CourseUser) (t.get(i))).getId(), (CourseUser) t.get(i)); } logger.info("Loaded " + this.oldCourseUserMining.size() + " CourseUser objects from the mining database."); criteria = session.createCriteria(AccessLog.class); ProjectionList pl = Projections.projectionList(); pl.add(Projections.max("id")); criteria.setProjection(pl); this.accessLogMax = (Long) criteria.list().get(0); if (this.accessLogMax == null) { this.accessLogMax = 0L; } criteria = session.createCriteria(CollaborationLog.class); criteria.setProjection(pl); this.collaborationLogMax = (Long) criteria.list().get(0); if (this.collaborationLogMax == null) { this.collaborationLogMax = 0L; } criteria = session.createCriteria(AssessmentLog.class); criteria.setProjection(pl); this.assessmentLogMax = (Long) criteria.list().get(0); if (this.assessmentLogMax == null) { this.assessmentLogMax = 0L; } criteria = session.createCriteria(LearningType.class); criteria.setProjection(pl); this.learningObjectTypeMax = (Long) criteria.list().get(0); if (this.learningObjectTypeMax == null) { this.learningObjectTypeMax = 0L; } criteria = session.createCriteria(Attribute.class); criteria.setProjection(pl); this.attributeIdMax = (Long) criteria.list().get(0); if (this.attributeIdMax == null) { this.attributeIdMax = 0L; } criteria = session.createCriteria(CourseAttribute.class); criteria.setProjection(pl); this.courseAttributeIdMax = (Long) criteria.list().get(0); if (this.courseAttributeIdMax == null) { this.courseAttributeIdMax = 0L; } criteria = session.createCriteria(UserAttribute.class); criteria.setProjection(pl); this.userAttributeIdMax = (Long) criteria.list().get(0); if (this.userAttributeIdMax == null) { this.userAttributeIdMax = 0L; } criteria = session.createCriteria(LearningAttribute.class); criteria.setProjection(pl); this.learningAttributeIdMax = (Long) criteria.list().get(0); if (this.learningAttributeIdMax == null) { this.learningAttributeIdMax = 0L; } //this.dbHandler.closeSession(session); return readingtimestamp; }
From source file:de.lemo.dms.connectors.moodle_1_9.ExtractAndMap.java
License:Open Source License
/** * Reads the Mining Database./*from w w w . j a v a 2 s .c om*/ * Initial informations needed to start the process of updating are collected here. * The time stamp of the last run of the extractor is read from the config table * and the objects which might been needed to associate are read and saved here. * * @return The time stamp of the last run of the extractor. If this is the first run it will be set 0. **/ @SuppressWarnings("unchecked") public long getMiningInitial() { // open a DB connection final Session session = this.dbHandler.getMiningSession(); List<?> t; t = this.dbHandler.performQuery(session, EQueryType.HQL, "from PlatformMining x order by x.id asc"); this.oldPlatformMining = new HashMap<Long, PlatformMining>(); if (t != null) { for (int i = 0; i < t.size(); i++) { this.oldPlatformMining.put(((PlatformMining) (t.get(i))).getId(), (PlatformMining) t.get(i)); } } logger.info( "Loaded " + this.oldPlatformMining.size() + " PlatformMining objects from the mining database."); this.platformMining = new HashMap<Long, PlatformMining>(); Long readingtimestamp; readingtimestamp = (Long) session.createQuery( "Select max(latestTimestamp) from ConfigMining where platform=" + this.connector.getPlatformId()) .uniqueResult(); if (readingtimestamp == null) { readingtimestamp = -1L; } // load objects which are already in Mining DB for associations Query couCaCount = session.createQuery("select max(cc.id) from CourseChatMining cc"); this.courseChatMax = ((ArrayList<Long>) couCaCount.list()).get(0); if (this.courseChatMax == null) { this.courseChatMax = 0L; } t = this.dbHandler.performQuery(session, EQueryType.HQL, "from CourseMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldCourseMining = new HashMap<Long, CourseMining>(); for (int i = 0; i < t.size(); i++) { this.oldCourseMining.put(((CourseMining) (t.get(i))).getId(), (CourseMining) t.get(i)); } logger.info("Loaded " + this.oldCourseMining.size() + " CourseMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from QuizMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldQuizMining = new HashMap<Long, QuizMining>(); for (int i = 0; i < t.size(); i++) { this.oldQuizMining.put(((QuizMining) (t.get(i))).getId(), (QuizMining) t.get(i)); } logger.info("Loaded " + this.oldQuizMining.size() + " QuizMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from AssignmentMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldAssignmentMining = new HashMap<Long, AssignmentMining>(); for (int i = 0; i < t.size(); i++) { this.oldAssignmentMining.put(((AssignmentMining) (t.get(i))).getId(), (AssignmentMining) t.get(i)); } logger.info("Loaded " + this.oldAssignmentMining.size() + " AssignmentMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from ScormMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldScormMining = new HashMap<Long, ScormMining>(); for (int i = 0; i < t.size(); i++) { this.oldScormMining.put(((ScormMining) (t.get(i))).getId(), (ScormMining) t.get(i)); } logger.info("Loaded " + this.oldScormMining.size() + " ScormMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from ForumMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldForumMining = new HashMap<Long, ForumMining>(); for (int i = 0; i < t.size(); i++) { this.oldForumMining.put(((ForumMining) (t.get(i))).getId(), (ForumMining) t.get(i)); } logger.info("Loaded " + this.oldForumMining.size() + " ForumMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from ResourceMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldResourceMining = new HashMap<Long, ResourceMining>(); for (int i = 0; i < t.size(); i++) { this.oldResourceMining.put(((ResourceMining) (t.get(i))).getId(), (ResourceMining) t.get(i)); } logger.info( "Loaded " + this.oldResourceMining.size() + " ResourceMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from UserMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldUserMining = new HashMap<Long, UserMining>(); for (int i = 0; i < t.size(); i++) { this.oldUserMining.put(((UserMining) (t.get(i))).getId(), (UserMining) t.get(i)); } logger.info("Loaded " + this.oldUserMining.size() + " UserMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from WikiMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldWikiMining = new HashMap<Long, WikiMining>(); for (int i = 0; i < t.size(); i++) { this.oldWikiMining.put(((WikiMining) (t.get(i))).getId(), (WikiMining) t.get(i)); } logger.info("Loaded " + this.oldWikiMining.size() + " WikiMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from GroupMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldGroupMining = new HashMap<Long, GroupMining>(); for (int i = 0; i < t.size(); i++) { this.oldGroupMining.put(((GroupMining) (t.get(i))).getId(), (GroupMining) t.get(i)); } logger.info("Loaded " + this.oldGroupMining.size() + " GroupMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from QuestionMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldQuestionMining = new HashMap<Long, QuestionMining>(); for (int i = 0; i < t.size(); i++) { this.oldQuestionMining.put(((QuestionMining) (t.get(i))).getId(), (QuestionMining) t.get(i)); } logger.info("Loaded " + this.oldQuizMining.size() + " QuestionMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from RoleMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldRoleMining = new HashMap<Long, RoleMining>(); for (int i = 0; i < t.size(); i++) { this.oldRoleMining.put(((RoleMining) (t.get(i))).getId(), (RoleMining) t.get(i)); } logger.info("Loaded " + this.oldRoleMining.size() + " RoleMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from QuizQuestionMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldQuizQuestionMining = new HashMap<Long, QuizQuestionMining>(); for (int i = 0; i < t.size(); i++) { this.oldQuizQuestionMining.put(((QuizQuestionMining) (t.get(i))).getId(), (QuizQuestionMining) t.get(i)); } logger.info("Loaded " + this.oldQuizQuestionMining.size() + " QuizQuestionMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from LevelMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldLevelMining = new HashMap<Long, LevelMining>(); for (int i = 0; i < t.size(); i++) { this.oldLevelMining.put(((LevelMining) (t.get(i))).getId(), (LevelMining) t.get(i)); } logger.info("Loaded " + this.oldLevelMining.size() + " LevelMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from ChatMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldChatMining = new HashMap<Long, ChatMining>(); for (int i = 0; i < t.size(); i++) { this.oldChatMining.put(((ChatMining) (t.get(i))).getId(), (ChatMining) t.get(i)); } logger.info("Loaded " + this.oldChatMining.size() + " ChatMining objects from the mining database."); Criteria criteria = session.createCriteria(ResourceLogMining.class); ProjectionList pl = Projections.projectionList(); pl.add(Projections.max("id")); criteria.setProjection(pl); this.resourceLogMax = (Long) criteria.list().get(0); if (this.resourceLogMax == null) { this.resourceLogMax = 0L; } criteria = session.createCriteria(ChatLogMining.class); criteria.setProjection(pl); this.chatLogMax = (Long) criteria.list().get(0); if (this.chatLogMax == null) { this.chatLogMax = 0L; } criteria = session.createCriteria(AssignmentLogMining.class); criteria.setProjection(pl); this.assignmentLogMax = (Long) criteria.list().get(0); if (this.assignmentLogMax == null) { this.assignmentLogMax = 0L; } criteria = session.createCriteria(CourseLogMining.class); criteria.setProjection(pl); this.courseLogMax = (Long) criteria.list().get(0); if (this.courseLogMax == null) { this.courseLogMax = 0L; } criteria = session.createCriteria(ForumLogMining.class); criteria.setProjection(pl); this.forumLogMax = (Long) criteria.list().get(0); if (this.forumLogMax == null) { this.forumLogMax = 0L; } criteria = session.createCriteria(QuestionLogMining.class); criteria.setProjection(pl); this.questionLogMax = (Long) criteria.list().get(0); if (this.questionLogMax == null) { this.questionLogMax = 0L; } criteria = session.createCriteria(QuizLogMining.class); criteria.setProjection(pl); this.quizLogMax = (Long) criteria.list().get(0); if (this.quizLogMax == null) { this.quizLogMax = 0L; } criteria = session.createCriteria(ScormLogMining.class); criteria.setProjection(pl); this.scormLogMax = (Long) criteria.list().get(0); if (this.scormLogMax == null) { this.scormLogMax = 0L; } criteria = session.createCriteria(WikiLogMining.class); criteria.setProjection(pl); this.wikiLogMax = (Long) criteria.list().get(0); if (this.wikiLogMax == null) { this.wikiLogMax = 0L; } return readingtimestamp; }
From source file:de.lemo.dms.connectors.moodle_2_3.ExtractAndMap.java
License:Open Source License
/** * Reads the Mining Database./* www. jav a2 s . co m*/ * Initial informations needed to start the process of updating are collected here. * The Timestamp of the last run of the extractor is read from the config table * and the objects which might been needed to associate are read and saved here. * * @return The timestamp of the last run of the extractor. If this is the first run it will be set 0. **/ public long getMiningInitial() { final Session session = this.dbHandler.getMiningSession(); List<?> t; Long readingtimestamp; readingtimestamp = (Long) session.createQuery( "Select max(latestTimestamp) from ConfigMining where platform=" + this.connector.getPlatformId()) .uniqueResult(); if (readingtimestamp == null) { readingtimestamp = -1L; } // load objects which are already in Mining DB for associations t = this.dbHandler.performQuery(session, EQueryType.HQL, "from CourseMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldCourseMining = new HashMap<Long, CourseMining>(); for (int i = 0; i < t.size(); i++) { this.oldCourseMining.put(((CourseMining) (t.get(i))).getId(), (CourseMining) t.get(i)); } logger.info("Loaded " + this.oldCourseMining.size() + " CourseMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from QuizMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldQuizMining = new HashMap<Long, QuizMining>(); for (int i = 0; i < t.size(); i++) { this.oldQuizMining.put(((QuizMining) (t.get(i))).getId(), (QuizMining) t.get(i)); } logger.info("Loaded " + this.oldQuizMining.size() + " QuizMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from AssignmentMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldAssignmentMining = new HashMap<Long, AssignmentMining>(); for (int i = 0; i < t.size(); i++) { this.oldAssignmentMining.put(((AssignmentMining) (t.get(i))).getId(), (AssignmentMining) t.get(i)); } logger.info("Loaded " + this.oldAssignmentMining.size() + " AssignmentMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from ScormMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldScormMining = new HashMap<Long, ScormMining>(); for (int i = 0; i < t.size(); i++) { this.oldScormMining.put(((ScormMining) (t.get(i))).getId(), (ScormMining) t.get(i)); } logger.info("Loaded " + this.oldScormMining.size() + " ScormMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from ForumMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldForumMining = new HashMap<Long, ForumMining>(); for (int i = 0; i < t.size(); i++) { this.oldForumMining.put(((ForumMining) (t.get(i))).getId(), (ForumMining) t.get(i)); } logger.info("Loaded " + this.oldForumMining.size() + " ForumMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from ResourceMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldResourceMining = new HashMap<Long, ResourceMining>(); for (int i = 0; i < t.size(); i++) { this.oldResourceMining.put(((ResourceMining) (t.get(i))).getId(), (ResourceMining) t.get(i)); } logger.info( "Loaded " + this.oldResourceMining.size() + " ResourceMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from UserMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldUserMining = new HashMap<Long, UserMining>(); for (int i = 0; i < t.size(); i++) { this.oldUserMining.put(((UserMining) (t.get(i))).getId(), (UserMining) t.get(i)); } logger.info("Loaded " + this.oldUserMining.size() + " UserMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from WikiMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldWikiMining = new HashMap<Long, WikiMining>(); for (int i = 0; i < t.size(); i++) { this.oldWikiMining.put(((WikiMining) (t.get(i))).getId(), (WikiMining) t.get(i)); } logger.info("Loaded " + this.oldWikiMining.size() + " WikiMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from GroupMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldGroupMining = new HashMap<Long, GroupMining>(); for (int i = 0; i < t.size(); i++) { this.oldGroupMining.put(((GroupMining) (t.get(i))).getId(), (GroupMining) t.get(i)); } logger.info("Loaded " + this.oldGroupMining.size() + " GroupMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from QuestionMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldQuestionMining = new HashMap<Long, QuestionMining>(); for (int i = 0; i < t.size(); i++) { this.oldQuestionMining.put(((QuestionMining) (t.get(i))).getId(), (QuestionMining) t.get(i)); } logger.info("Loaded " + this.oldQuizMining.size() + " QuestionMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from RoleMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldRoleMining = new HashMap<Long, RoleMining>(); for (int i = 0; i < t.size(); i++) { this.oldRoleMining.put(((RoleMining) (t.get(i))).getId(), (RoleMining) t.get(i)); } logger.info("Loaded " + this.oldRoleMining.size() + " RoleMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from QuizQuestionMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldQuizQuestionMining = new HashMap<Long, QuizQuestionMining>(); for (int i = 0; i < t.size(); i++) { this.oldQuizQuestionMining.put(((QuizQuestionMining) (t.get(i))).getQuestion().getId(), (QuizQuestionMining) t.get(i)); } logger.info("Loaded " + this.oldQuizQuestionMining.size() + " QuizQuestionMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from LevelMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldLevelMining = new HashMap<Long, LevelMining>(); for (int i = 0; i < t.size(); i++) { this.oldLevelMining.put(((LevelMining) (t.get(i))).getId(), (LevelMining) t.get(i)); } logger.info("Loaded " + this.oldLevelMining.size() + " LevelMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from ChatMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldChatMining = new HashMap<Long, ChatMining>(); for (int i = 0; i < t.size(); i++) { this.oldChatMining.put(((ChatMining) (t.get(i))).getId(), (ChatMining) t.get(i)); } logger.info("Loaded " + this.oldChatMining.size() + " ChatMining objects from the mining database."); t = this.dbHandler.performQuery(session, EQueryType.HQL, "from ChatMining x where x.platform=" + this.connector.getPlatformId() + " order by x.id asc"); this.oldChatMining = new HashMap<Long, ChatMining>(); for (int i = 0; i < t.size(); i++) { this.oldChatMining.put(((ChatMining) (t.get(i))).getId(), (ChatMining) t.get(i)); } logger.info("Loaded " + this.oldChatMining.size() + " ChatMining objects from the mining database."); Criteria criteria = session.createCriteria(ResourceLogMining.class); ProjectionList pl = Projections.projectionList(); pl.add(Projections.max("id")); criteria.setProjection(pl); this.resourceLogMax = (Long) criteria.list().get(0); if (this.resourceLogMax == null) { this.resourceLogMax = 0L; } criteria = session.createCriteria(CourseChatMining.class); criteria.setProjection(pl); this.courseChatMax = (Long) criteria.list().get(0); if (this.courseChatMax == null) { this.courseChatMax = 0L; } criteria = session.createCriteria(ChatLogMining.class); criteria.setProjection(pl); this.chatLogMax = (Long) criteria.list().get(0); if (this.chatLogMax == null) { this.chatLogMax = 0L; } criteria = session.createCriteria(AssignmentLogMining.class); criteria.setProjection(pl); this.assignmentLogMax = (Long) criteria.list().get(0); if (this.assignmentLogMax == null) { this.assignmentLogMax = 0L; } criteria = session.createCriteria(CourseLogMining.class); criteria.setProjection(pl); this.courseLogMax = (Long) criteria.list().get(0); if (this.courseLogMax == null) { this.courseLogMax = 0L; } criteria = session.createCriteria(ForumLogMining.class); criteria.setProjection(pl); this.forumLogMax = (Long) criteria.list().get(0); if (this.forumLogMax == null) { this.forumLogMax = 0L; } criteria = session.createCriteria(QuestionLogMining.class); criteria.setProjection(pl); this.questionLogMax = (Long) criteria.list().get(0); if (this.questionLogMax == null) { this.questionLogMax = 0L; } criteria = session.createCriteria(QuizLogMining.class); criteria.setProjection(pl); this.quizLogMax = (Long) criteria.list().get(0); if (this.quizLogMax == null) { this.quizLogMax = 0L; } criteria = session.createCriteria(ScormLogMining.class); criteria.setProjection(pl); this.scormLogMax = (Long) criteria.list().get(0); if (this.scormLogMax == null) { this.scormLogMax = 0L; } criteria = session.createCriteria(WikiLogMining.class); criteria.setProjection(pl); this.wikiLogMax = (Long) criteria.list().get(0); if (this.wikiLogMax == null) { this.wikiLogMax = 0L; } //this.dbHandler.closeSession(session); return readingtimestamp; }
From source file:de.lemo.dms.connectors.moodle_2_7.ExtractAndMap.java
License:Open Source License
/** * Reads the Mining Database.//ww w . j a va 2 s .co m * Initial informations needed to start the process of updating are collected here. * The Timestamp of the last run of the extractor is read from the config table * and the objects which might been needed to associate are read and saved here. * * @return The timestamp of the last run of the extractor. If this is the first run it will be set 0. **/ public long getMiningInitial() { final Session session = this.dbHandler.getMiningSession(); List<?> t; Long readingtimestamp; readingtimestamp = (Long) session .createQuery( "Select max(latestTimestamp) from Config where platform=" + this.connector.getPlatformId()) .uniqueResult(); if (readingtimestamp == null) { readingtimestamp = -1L; } // load objects which are already in Mining DB for associations Criteria criteria = session.createCriteria(Course.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); t = criteria.list(); this.oldCourseMining = new HashMap<Long, Course>(); for (int i = 0; i < t.size(); i++) { this.oldCourseMining.put(((Course) (t.get(i))).getId(), (Course) t.get(i)); } logger.info("Loaded " + this.oldCourseMining.size() + " Course objects from the mining database."); criteria = session.createCriteria(User.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); t = criteria.list(); this.oldUserMining = new HashMap<Long, User>(); for (int i = 0; i < t.size(); i++) { this.oldUserMining.put(((User) (t.get(i))).getId(), (User) t.get(i)); } logger.info("Loaded " + this.oldUserMining.size() + " User objects from the mining database."); criteria = session.createCriteria(LearningObj.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); t = criteria.list(); this.oldLearningObjectMining = new HashMap<Long, LearningObj>(); for (int i = 0; i < t.size(); i++) { this.oldLearningObjectMining.put(((LearningObj) (t.get(i))).getId(), (LearningObj) t.get(i)); } logger.info( "Loaded " + this.oldLearningObjectMining.size() + " LearningObj objects from the mining database."); criteria = session.createCriteria(Attribute.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); t = criteria.list(); this.oldAttributeMining = new HashMap<String, Attribute>(); for (int i = 0; i < t.size(); i++) { this.oldAttributeMining.put(((Attribute) (t.get(i))).getName(), (Attribute) t.get(i)); } logger.info("Loaded " + this.oldAttributeMining.size() + " Attribute objects from the mining database."); criteria = session.createCriteria(Role.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); t = criteria.list(); this.oldRoleMining = new HashMap<Long, Role>(); for (int i = 0; i < t.size(); i++) { this.oldRoleMining.put(((Role) (t.get(i))).getId(), (Role) t.get(i)); } logger.info("Loaded " + this.oldRoleMining.size() + " Role objects from the mining database."); criteria = session.createCriteria(LearningType.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); t = criteria.list(); this.oldLearningTypeMining = new HashMap<String, LearningType>(); for (int i = 0; i < t.size(); i++) { this.oldLearningTypeMining.put(((LearningType) (t.get(i))).getType(), (LearningType) t.get(i)); } logger.info( "Loaded " + this.oldLearningTypeMining.size() + " LearningType objects from the mining database."); criteria = session.createCriteria(CourseAttribute.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); t = criteria.list(); this.oldCourseAttributeMining = new HashMap<Long, CourseAttribute>(); for (int i = 0; i < t.size(); i++) { this.oldCourseAttributeMining.put(((CourseAttribute) (t.get(i))).getId(), (CourseAttribute) t.get(i)); } logger.info("Loaded " + this.oldCourseAttributeMining.size() + " CourseAttribute objects from the mining database."); criteria = session.createCriteria(UserAttribute.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); t = criteria.list(); this.oldUserAttributeMining = new HashMap<Long, UserAttribute>(); for (int i = 0; i < t.size(); i++) { this.oldUserAttributeMining.put(((UserAttribute) (t.get(i))).getId(), (UserAttribute) t.get(i)); } logger.info("Loaded " + this.oldUserAttributeMining.size() + " UserAttribute objects from the mining database."); criteria = session.createCriteria(LearningAttribute.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); t = criteria.list(); this.oldLearningAttributeMining = new HashMap<Long, LearningAttribute>(); for (int i = 0; i < t.size(); i++) { this.oldLearningAttributeMining.put(((LearningAttribute) (t.get(i))).getId(), (LearningAttribute) t.get(i)); } logger.info("Loaded " + this.oldUserAttributeMining.size() + " LearningAttribute objects from the mining database."); criteria = session.createCriteria(CourseLearning.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); t = criteria.list(); this.oldCourseLearningObjectMining = new HashMap<Long, CourseLearning>(); for (int i = 0; i < t.size(); i++) { this.oldCourseLearningObjectMining.put(((CourseLearning) (t.get(i))).getId(), (CourseLearning) t.get(i)); } logger.info("Loaded " + this.oldCourseLearningObjectMining.size() + " CourseResource objects from the mining database."); criteria = session.createCriteria(UserAssessment.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); t = criteria.list(); this.oldUserAssessmentMining = new HashMap<Long, UserAssessment>(); for (int i = 0; i < t.size(); i++) { this.oldUserAssessmentMining.put(((UserAssessment) (t.get(i))).getId(), (UserAssessment) t.get(i)); } logger.info("Loaded " + this.oldUserAssessmentMining.size() + " UserAssessment objects from the mining database."); criteria = session.createCriteria(CourseUser.class, "obj"); criteria.addOrder(Property.forName("obj.id").asc()); t = criteria.list(); this.oldCourseUserMining = new HashMap<Long, CourseUser>(); for (int i = 0; i < t.size(); i++) { this.oldCourseUserMining.put(((CourseUser) (t.get(i))).getId(), (CourseUser) t.get(i)); } logger.info("Loaded " + this.oldCourseUserMining.size() + " CourseUser objects from the mining database."); criteria = session.createCriteria(AccessLog.class); ProjectionList pl = Projections.projectionList(); pl.add(Projections.max("id")); criteria.setProjection(pl); this.accessLogMax = (Long) criteria.list().get(0); if (this.accessLogMax == null) { this.accessLogMax = 0L; } criteria = session.createCriteria(CollaborationLog.class); criteria.setProjection(pl); this.collaborationLogMax = (Long) criteria.list().get(0); if (this.collaborationLogMax == null) { this.collaborationLogMax = 0L; } criteria = session.createCriteria(AssessmentLog.class); criteria.setProjection(pl); this.assessmentLogMax = (Long) criteria.list().get(0); if (this.assessmentLogMax == null) { this.assessmentLogMax = 0L; } criteria = session.createCriteria(LearningType.class); criteria.setProjection(pl); this.learningObjectTypeMax = (Long) criteria.list().get(0); if (this.learningObjectTypeMax == null) { this.learningObjectTypeMax = 0L; } criteria = session.createCriteria(Attribute.class); criteria.setProjection(pl); this.attributeIdMax = (Long) criteria.list().get(0); if (this.attributeIdMax == null) { this.attributeIdMax = 0L; } criteria = session.createCriteria(CourseAttribute.class); criteria.setProjection(pl); this.courseAttributeIdMax = (Long) criteria.list().get(0); if (this.courseAttributeIdMax == null) { this.courseAttributeIdMax = 0L; } criteria = session.createCriteria(UserAttribute.class); criteria.setProjection(pl); this.userAttributeIdMax = (Long) criteria.list().get(0); if (this.userAttributeIdMax == null) { this.userAttributeIdMax = 0L; } criteria = session.createCriteria(LearningAttribute.class); criteria.setProjection(pl); this.learningAttributeIdMax = (Long) criteria.list().get(0); if (this.learningAttributeIdMax == null) { this.learningAttributeIdMax = 0L; } //this.dbHandler.closeSession(session); return readingtimestamp; }
From source file:de.xatc.server.ShutdownHook.java
public static void attachShutDownHook() { LOG.info("Attaching ShutDownHook"); Runtime.getRuntime().addShutdownHook(new Thread() { @Override//w ww. j a v a2 s. com public void run() { LOG.info("ShutDownHook Running"); Session session = DBSessionManager.getSession(); DetachedCriteria maxId = DetachedCriteria.forClass(LastRun.class) .setProjection(Projections.max("id")); List<LastRun> lastRunList = session.createCriteria(LastRun.class) .add(Property.forName("id").eq(maxId)).list(); LastRun lr = lastRunList.get(0); LOG.info("SHUTDOWN HOOK: LastRun StartDate: " + lr.getStartDate()); lr.setEndDate(SQLDateTimeTools.getTimeStampOfNow()); session.saveOrUpdate(lr); DBSessionManager.closeSession(session); //shutdown all mq producers LOG.info("Shutting Down all Message Producers for MQ"); for (Map.Entry<String, MQMessageSender> entry : ServerConfig.getMessageSenders().entrySet()) { LOG.info("Shutting down messageSende: " + entry.getValue().getQueueName()); entry.getValue().shutdownProducer(); } //shutdown all Consumers for (Map.Entry<String, MQAbstractConsumer> entry : ServerConfig.getMessageReceivers().entrySet()) { LOG.info("Shutting down messageReceiver: " + entry.getValue().getQueueName()); entry.getValue().shutdownConsumer(); } //shutdown MQBroker if (ServerConfig.getMqBrokerManager() != null) { try { ServerConfig.getMqBrokerManager().shutdownBroker(); } catch (Exception ex) { LOG.error(ex.getLocalizedMessage()); ex.printStackTrace(System.err); } } DBSessionManager.shutdownDB(); } }); LOG.info("Shut Down Hook Attached."); }
From source file:edu.monash.merc.dao.DSVersionDAO.java
License:Open Source License
/** * {@inheritDoc}/*from ww w. j a v a2s . co m*/ */ @SuppressWarnings("unchecked") public List<DBVersionBean> getLatestDBSVersionByChromosome(ChromType chromType) { Criteria dsvCriteria = this.session().createCriteria(this.persistClass); dsvCriteria.add(Restrictions.eq("chromosome", chromType.chm())); dsvCriteria.setProjection( Projections.projectionList().add(Projections.groupProperty("dbSource").as("dbSource")) .add(Projections.max("id").as("id")).add(Projections.max("createdTime").as("createdTime")) .add(Projections.max("versionNo").as("versionNo"))); dsvCriteria.addOrder(Order.asc("dbSource")); return dsvCriteria.setResultTransformer(Transformers.aliasToBean(DBVersionBean.class)).list(); }
From source file:edu.monash.merc.dao.TPBVersionDAO.java
License:Open Source License
/** * {@inheritDoc}/*from ww w. j a v a 2 s .c om*/ */ @SuppressWarnings("unchecked") public List<MaxDsTPBVersion> getAllChromosomeTPBVersionByMaxCombinatedDs() { Criteria tpbVCriteria = this.session().createCriteria(this.persistClass); tpbVCriteria.setProjection( Projections.projectionList().add(Projections.groupProperty("chromosome").as("chromosome")) .add(Projections.max("id").as("id")).add(Projections.max("trackToken").as("trackToken")) .add(Projections.max("versionNo").as("versionNo"))); List<MaxDsTPBVersion> maxDsTPBVersions = tpbVCriteria .setResultTransformer(Transformers.aliasToBean(MaxDsTPBVersion.class)).list(); // System.out.println("======= max ds tpb versions size: " + maxDsTPBVersions.size()); // for(MaxDsTPBVersion maxDsTPBVersion : maxDsTPBVersions){ // System.out.println("========= > " +maxDsTPBVersion.getId() + " -- " + maxDsTPBVersion.getChromosome() + " -- " + maxDsTPBVersion.getTrackToken() + " -- " + maxDsTPBVersion.getVersionNo()); // } return maxDsTPBVersions; }
From source file:edu.nps.moves.mmowgli.cache.MCacheGameEventHelper.java
License:Open Source License
@SuppressWarnings("unchecked") private List<GameEvent> eventsQuery(Session sess) { // Attempt to speed up query Long num = (Long) sess.createCriteria(GameEvent.class) //.setProjection(Projections.rowCount()).uniqueResult(); .setProjection(Projections.max("id")).uniqueResult(); List<GameEvent> evs = null; if (num != null) { long lowlimit = Math.max(0L, num.longValue() - GAMEEVENTCAPACITY); evs = (List<GameEvent>) sess.createCriteria(GameEvent.class).add(Restrictions.gt("id", lowlimit)) .addOrder(Order.desc("dateTime")).list(); } else// www . j a va 2 s . com evs = new ArrayList<GameEvent>(); // Old version // List<GameEvent> evs = (List<GameEvent>) sess.createCriteria(GameEvent.class). // addOrder(Order.desc("dateTime")). // setMaxResults(GAMEEVENTCAPACITY).list(); return evs; }