List of usage examples for org.hibernate.criterion ProjectionList add
public ProjectionList add(Projection projection)
From source file:de.lemo.dms.connectors.moodle_1_9.ExtractAndMap.java
License:Open Source License
/** * Reads the Mining Database.//from w w w.ja va 2 s .c o m * 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.// w w w.j av a2 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 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.//from ww w. j a v a 2s . 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.powerstaff.business.dao.hibernate.PersonDAOHibernateImpl.java
License:Open Source License
protected Collection<GenericSearchResult> performSearchByContact(final String aContact, final ContactType aContactType, final String[] aDisplayProperties, final String[] aOrderByProperties, final int aMax) { return (Collection<GenericSearchResult>) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session aSession) throws SQLException { Criteria theCriteria = aSession.createCriteria(getEntityClass()); ProjectionList theList = Projections.projectionList(); theList.add(Projections.property("id")); for (String theProperty : aDisplayProperties) { theList.add(Projections.property(theProperty)); }/*from w ww .ja v a 2 s.co m*/ theCriteria.setProjection(theList); for (String theProperty : aOrderByProperties) { theCriteria.addOrder(Order.asc(theProperty)); } Criteria theContacts = theCriteria.createCriteria("contacts"); theContacts.add(Restrictions.eq("type", aContactType)); theContacts.add(Restrictions.ilike("value", "%" + aContact + "%")); Collection<GenericSearchResult> theResult = new ArrayList<GenericSearchResult>(); theCriteria.setMaxResults(aMax); for (Iterator it = theCriteria.list().iterator(); it.hasNext();) { Object[] theRow = (Object[]) it.next(); GenericSearchResult theRowObject = new GenericSearchResult(); theRowObject.put(GenericSearchResult.OBJECT_ID_KEY, theRow[0]); for (int i = 0; i < aDisplayProperties.length; i++) { theRowObject.put(aDisplayProperties[i], theRow[i + 1]); } theResult.add(theRowObject); } return theResult; } }); }
From source file:de.powerstaff.business.dao.hibernate.StatistikDAOHibernateImpl.java
License:Open Source License
@Override public List<KontakthistorieEntry> kontakthistorie(final Date aDatumVon, final Date aDatumBis, final User aBenutzer) { return (List<KontakthistorieEntry>) getHibernateTemplate().execute(new HibernateCallback() { @Override/*from w ww . j av a 2 s. c o m*/ public Object doInHibernate(Session aSession) throws SQLException { List<KontakthistorieEntry> theResult = new ArrayList<KontakthistorieEntry>(); Conjunction theRestrictions = Restrictions.conjunction(); if (aDatumVon != null) { theRestrictions.add(Restrictions.ge("h.creationDate", aDatumVon)); } if (aDatumBis != null) { theRestrictions.add(Restrictions.le("h.creationDate", aDatumBis)); } if (aBenutzer != null) { theRestrictions.add(Restrictions.eq("h.creationUserID", aBenutzer.getUsername())); } // Freiberufler Criteria theCriteria = aSession.createCriteria(Freelancer.class, "p"); theCriteria.createCriteria("history", "h"); theCriteria.add(theRestrictions); ProjectionList theProjections = Projections.projectionList(); theProjections.add(Projections.property("p.name1")); theProjections.add(Projections.property("p.name2")); theProjections.add(Projections.property("p.code")); theProjections.add(Projections.property("h.creationDate")); theProjections.add(Projections.property("h.creationUserID")); theProjections.add(Projections.property("h.type")); theProjections.add(Projections.property("h.description")); theCriteria.setProjection(theProjections); for (Object theResultObject : theCriteria.list()) { Object[] theResultArray = (Object[]) theResultObject; KontakthistorieEntry theEntry = new KontakthistorieEntry(); theEntry.setName1((String) theResultArray[0]); theEntry.setName2((String) theResultArray[1]); theEntry.setCode((String) theResultArray[2]); Timestamp theTimestamp = (Timestamp) theResultArray[3]; theEntry.setDatum(new Date(theTimestamp.getTime())); theEntry.setUserid((String) theResultArray[4]); theEntry.setType((HistoryType) theResultArray[5]); theEntry.setDescription((String) theResultArray[6]); theResult.add(theEntry); } // Partner theCriteria = aSession.createCriteria(Partner.class, "p"); theCriteria.createCriteria("history", "h"); theCriteria.add(theRestrictions); theProjections = Projections.projectionList(); theProjections.add(Projections.property("p.name1")); theProjections.add(Projections.property("p.name2")); theProjections.add(Projections.property("h.creationDate")); theProjections.add(Projections.property("h.creationUserID")); theProjections.add(Projections.property("h.type")); theProjections.add(Projections.property("h.description")); theCriteria.setProjection(theProjections); for (Object theResultObject : theCriteria.list()) { Object[] theResultArray = (Object[]) theResultObject; KontakthistorieEntry theEntry = new KontakthistorieEntry(); theEntry.setName1((String) theResultArray[0]); theEntry.setName2((String) theResultArray[1]); Timestamp theTimestamp = (Timestamp) theResultArray[2]; theEntry.setDatum(new Date(theTimestamp.getTime())); theEntry.setUserid((String) theResultArray[3]); theEntry.setType((HistoryType) theResultArray[4]); theEntry.setDescription((String) theResultArray[5]); theResult.add(theEntry); } // Kunden theCriteria = aSession.createCriteria(Customer.class, "p"); theCriteria.createCriteria("history", "h"); theCriteria.add(theRestrictions); theProjections = Projections.projectionList(); theProjections.add(Projections.property("p.name1")); theProjections.add(Projections.property("p.name2")); theProjections.add(Projections.property("h.creationDate")); theProjections.add(Projections.property("h.creationUserID")); theProjections.add(Projections.property("h.type")); theProjections.add(Projections.property("h.description")); theCriteria.setProjection(theProjections); for (Object theResultObject : theCriteria.list()) { Object[] theResultArray = (Object[]) theResultObject; KontakthistorieEntry theEntry = new KontakthistorieEntry(); theEntry.setName1((String) theResultArray[0]); theEntry.setName2((String) theResultArray[1]); Timestamp theTimestamp = (Timestamp) theResultArray[2]; theEntry.setDatum(new Date(theTimestamp.getTime())); theEntry.setUserid((String) theResultArray[3]); theEntry.setType((HistoryType) theResultArray[4]); theEntry.setDescription((String) theResultArray[5]); theResult.add(theEntry); } Collections.sort(theResult, new ReverseComparator(new BeanComparator("datum"))); return theResult; } }); }
From source file:de.sub.goobi.forms.ProjekteForm.java
License:Open Source License
/** * generates values for count of volumes and images for statistics. *//*from w w w .j a va 2 s. co m*/ @SuppressWarnings("rawtypes") public void GenerateValuesForStatistics() { Criteria crit = Helper.getHibernateSession().createCriteria(Process.class) .add(Restrictions.eq("projekt", this.myProjekt)); ProjectionList pl = Projections.projectionList(); pl.add(Projections.sum("sortHelperImages")); pl.add(Projections.count("sortHelperImages")); crit.setProjection(pl); List list = crit.list(); Long images = 0l; Long volumes = 0l; for (Object obj : list) { Object[] row = (Object[]) obj; images = (Long) row[0]; volumes = (Long) row[1]; } this.myProjekt.setNumberOfPages(images.intValue()); this.myProjekt.setNumberOfVolumes(volumes.intValue()); }
From source file:de.sub.goobi.helper.ProjectHelper.java
License:Open Source License
/** * static to reduce load/*w w w. ja v a 2s. c om*/ * * @param project * object * @return a GoobiCollection of the following structure: GoobiCollection 1-n * representing the steps each step has the following properties @ * stepTitle, stepOrder, * stepCount,stepImageCount,totalProcessCount,totalImageCount which * can get extracted by the IGoobiCollection Interface using the * getItem(<name>) method standard workflow of the project * according to the definition that only steps shared by all * processes are returned. The workflow order is returned according * to the average order return by a grouping by step title consider * workflow structure to be a prototype, it would probably make * things easier, to either assemble the underlying construction in * separate classes or to create a new class with these properties */ @SuppressWarnings("unchecked") public static synchronized List<StepInformation> getProjectWorkFlowOverview(Project project) { Long totalNumberOfProc = 0l; Long totalNumberOfImages = 0l; Session session = Helper.getHibernateSession(); Criteria critTotals = session.createCriteria(Process.class, "proc"); critTotals.add(Restrictions.eq("proc.template", Boolean.FALSE)); critTotals.add(Restrictions.eq("proc.project", project)); ProjectionList proList = Projections.projectionList(); proList.add(Projections.count("proc.id")); proList.add(Projections.sum("proc.sortHelperImages")); critTotals.setProjection(proList); List<Object> list = critTotals.list(); for (Object obj : list) { Object[] row = (Object[]) obj; totalNumberOfProc = (Long) row[FieldList.totalProcessCount.fieldLocation]; totalNumberOfImages = (Long) row[FieldList.totalImageCount.fieldLocation]; ; } proList = null; list = null; Criteria critSteps = session.createCriteria(Task.class); critSteps.createCriteria("process", "proc"); critSteps.addOrder(Order.asc("ordering")); critSteps.add(Restrictions.eq("proc.template", Boolean.FALSE)); critSteps.add(Restrictions.eq("proc.project", project)); proList = Projections.projectionList(); proList.add(Projections.groupProperty(("title"))); proList.add(Projections.count("id")); proList.add(Projections.avg("ordering")); critSteps.setProjection(proList); // now we have to discriminate the hits where the max number of hits // doesn't reach numberOfProcs // and extract a workflow, which is the workflow common for all // processes according to its titel // the position will be calculated by the average of 'reihenfolge' of // steps list = critSteps.list(); String title; Double averageStepOrder; Long numberOfSteps; Long numberOfImages; List<StepInformation> workFlow = new ArrayList<>(); for (Object obj : list) { Object[] row = (Object[]) obj; title = (String) (row[FieldList.stepName.fieldLocation]); numberOfSteps = (Long) (row[FieldList.stepCount.fieldLocation]); averageStepOrder = (Double) (row[FieldList.stepOrder.fieldLocation]); // in this step we only take the steps which are present in each of // the workflows if (numberOfSteps.equals(totalNumberOfProc)) { StepInformation newStep = new StepInformation(title, averageStepOrder); newStep.setNumberOfTotalImages(totalNumberOfImages.intValue()); newStep.setNumberOfTotalSteps(totalNumberOfProc.intValue()); workFlow.add(newStep); } } Criteria critStepDone = session.createCriteria(Task.class, "step"); critStepDone.createCriteria("process", "proc"); critStepDone.add(Restrictions.eq("step.processingStatus", TaskStatus.DONE.getValue())); critStepDone.add(Restrictions.eq("proc.template", Boolean.FALSE)); critStepDone.add(Restrictions.eq("proc.project", project)); ProjectionList proCount = Projections.projectionList(); proCount.add(Projections.groupProperty(("step.title"))); proCount.add(Projections.count("proc.id")); proCount.add(Projections.sum("proc.sortHelperImages")); critStepDone.setProjection(proCount); list = critStepDone.list(); for (Object obj : list) { Object[] row = (Object[]) obj; title = (String) (row[FieldList.stepName.fieldLocation]); numberOfSteps = (Long) (row[FieldList.stepCount.fieldLocation]); numberOfImages = (Long) (row[FieldList.imageCount.fieldLocation]); // getting from the workflow collection the collection which // represents step <title> // we only created one for each step holding the counts of processes for (StepInformation currentStep : workFlow) { if (currentStep.getTitle().equals(title)) { currentStep.setNumberOfStepsDone(numberOfSteps.intValue()); currentStep.setNumberOfImagesDone(numberOfImages.intValue()); } } } Comparator<StepInformation> comp = new compareWorkflowSteps(); Collections.sort(workFlow, comp); return workFlow; }
From source file:edu.utah.further.core.data.util.HibernateUtil.java
License:Apache License
/** * @deprecated This method does not work well due to Hibernate bug HHH-817, nor does * AliasToBeanResultTransformer handle multi-level property values. * Therefore it should not be used. * @see http://opensource.atlassian.com/projects/hibernate/browse/HHH-817 *//*from w w w . j a v a2 s .c om*/ @Deprecated public static Projection createProjectionList(final String identifierProperty, final Type identifierType, final String[] propertyNames, final Class<?> domainClass) { final ProjectionList projectionList = Projections.projectionList(); if (identifierType.isComponentType()) { final String[] idProperties = ((ComponentType) (identifierType)).getPropertyNames(); for (final String idProperty : idProperties) { final String idPath = identifierProperty + "." + idProperty; projectionList.add(Projections.property(idPath)); } } else { projectionList.add(Projections.id()); } for (final String propertyName : propertyNames) { final Field field = ReflectionUtils.findField(domainClass, propertyName); if (!hasAssociationAnnotation(field)) { projectionList.add(Projections.property(propertyName), propertyName); } } return projectionList; }
From source file:es.sm2.openppm.core.dao.TimesheetDAO.java
License:Open Source License
/** * Get Hours resource//from www .j a va 2 s .co m * @param idEmployee * @param id * @param initDate * @param endDate * @param minStatus * @param maxStatus * @return */ public double getHoursResource(Integer idEmployee, Integer id, Date initDate, Date endDate, String minStatus, Employee filterUser) { ProjectionList proList = Projections.projectionList(); proList.add(Projections.sum(Timesheet.HOURSDAY1)); proList.add(Projections.sum(Timesheet.HOURSDAY2)); proList.add(Projections.sum(Timesheet.HOURSDAY3)); proList.add(Projections.sum(Timesheet.HOURSDAY4)); proList.add(Projections.sum(Timesheet.HOURSDAY5)); proList.add(Projections.sum(Timesheet.HOURSDAY6)); proList.add(Projections.sum(Timesheet.HOURSDAY7)); Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(proList) .add(Restrictions.disjunction().add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP1)) .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP2)) .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3))) .add(Restrictions.eq(Timesheet.INITDATE, initDate)).add(Restrictions.eq(Timesheet.ENDDATE, endDate)) .add(Restrictions.eq(Timesheet.EMPLOYEE, new Employee(idEmployee))); if (Constants.TIMESTATUS_APP1.equals(minStatus)) { crit.createCriteria(Timesheet.PROJECTACTIVITY) .add(Restrictions.eq(Projectactivity.PROJECT, new Project(id))); } else if (Constants.TIMESTATUS_APP2.equals(minStatus)) { // Filter by User. Settings by company for last approval. Criteria critFilter = crit.createCriteria(Timesheet.PROJECTACTIVITY) .createCriteria(Projectactivity.PROJECT); Resourceprofiles profile = filterUser.getResourceprofiles(); if (profile.getIdProfile() == Constants.ROLE_FM) { critFilter.add(Restrictions.eq(Project.EMPLOYEEBYFUNCTIONALMANAGER, filterUser)); } else if (profile.getIdProfile() == Constants.ROLE_PMO) { critFilter.add(Restrictions.eq(Project.PERFORMINGORG, filterUser.getPerformingorg())); } } Object[] hoursList = (Object[]) crit.uniqueResult(); double hours = 0; if (hoursList != null) { hours += (hoursList[0] == null ? 0 : (Double) hoursList[0]); hours += (hoursList[1] == null ? 0 : (Double) hoursList[1]); hours += (hoursList[2] == null ? 0 : (Double) hoursList[2]); hours += (hoursList[3] == null ? 0 : (Double) hoursList[3]); hours += (hoursList[4] == null ? 0 : (Double) hoursList[4]); hours += (hoursList[5] == null ? 0 : (Double) hoursList[5]); hours += (hoursList[6] == null ? 0 : (Double) hoursList[6]); } return hours; }
From source file:es.sm2.openppm.core.dao.TimesheetDAO.java
License:Open Source License
/** * Get Hours resource by operation//from w ww . ja va2 s. co m * @param idEmployee * @param initDate * @param endDate * @return */ public double getHoursResourceOpeartion(Integer idEmployee, Date initDate, Date endDate) { ProjectionList proList = Projections.projectionList(); proList.add(Projections.sum(Timesheet.HOURSDAY1)); proList.add(Projections.sum(Timesheet.HOURSDAY2)); proList.add(Projections.sum(Timesheet.HOURSDAY3)); proList.add(Projections.sum(Timesheet.HOURSDAY4)); proList.add(Projections.sum(Timesheet.HOURSDAY5)); proList.add(Projections.sum(Timesheet.HOURSDAY6)); proList.add(Projections.sum(Timesheet.HOURSDAY7)); Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(proList) .add(Restrictions.disjunction().add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP1)) .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP2)) .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3))) .add(Restrictions.eq(Timesheet.INITDATE, initDate)).add(Restrictions.eq(Timesheet.ENDDATE, endDate)) .add(Restrictions.eq(Timesheet.EMPLOYEE, new Employee(idEmployee))) .add(Restrictions.isNotNull(Timesheet.OPERATION)); Object[] hoursList = (Object[]) crit.uniqueResult(); double hours = 0; if (hoursList != null) { hours += (hoursList[0] == null ? 0 : (Double) hoursList[0]); hours += (hoursList[1] == null ? 0 : (Double) hoursList[1]); hours += (hoursList[2] == null ? 0 : (Double) hoursList[2]); hours += (hoursList[3] == null ? 0 : (Double) hoursList[3]); hours += (hoursList[4] == null ? 0 : (Double) hoursList[4]); hours += (hoursList[5] == null ? 0 : (Double) hoursList[5]); hours += (hoursList[6] == null ? 0 : (Double) hoursList[6]); } return hours; }