Example usage for org.hibernate.criterion Projections projectionList

List of usage examples for org.hibernate.criterion Projections projectionList

Introduction

In this page you can find the example usage for org.hibernate.criterion Projections projectionList.

Prototype

public static ProjectionList projectionList() 

Source Link

Document

Create a new projection list.

Usage

From source file:com.ut.tekir.tender.TenderBrowseBean.java

License:LGPL

private void addProjections(DetachedCriteria crit) {
    crit.setProjection(Projections.projectionList().add(Projections.property("id"), "id")
            .add(Projections.property("serial"), "serial").add(Projections.property("reference"), "reference")
            .add(Projections.property("status"), "status")
            .add(Projections.property("referenceSuffix"), "referenceSuffix")
            .add(Projections.property("code"), "code").add(Projections.property("date"), "date")
            .add(Projections.property("info1"), "info1").add(Projections.property("info2"), "info2")
            .add(Projections.property("contact.fullname"), "contactName")
            .add(Projections.property("contact.code"), "contactCode")
            .add(Projections.property("totalAmount.value"), "totalAmountValue")
            .add(Projections.property("totalAmount.currency"), "totalAmountCurrency")
            .add(Projections.property("totalDiscount.value"), "totalDiscountValue")
            .add(Projections.property("totalDiscount.currency"), "totalDiscountCurrency")
            .add(Projections.property("totalExpense.value"), "totalExpenseValue")
            .add(Projections.property("totalExpense.currency"), "totalExpenseCurrency")
            .add(Projections.property("totalFee.value"), "totalFeeValue")
            .add(Projections.property("totalFee.currency"), "totalFeeCurrency")
            .add(Projections.property("totalTax.value"), "totalTaxValue")
            .add(Projections.property("totalTax.currency"), "totalTaxCurrency"))
            .setResultTransformer(Transformers.aliasToBean(TenderFilterModel.class));
}

From source file:control.dao.StaffDAO.java

public List<Object> getStaffList(String key, int type, int page) {
    int firstResult = (page - 1) * 20;
    int totalSize;
    Session session = utils.HibernateUtils.getSessionFactory().getCurrentSession();
    List<Object> resultSet = new ArrayList<>();
    boolean searchByFirstName = true;
    try {//  w  w  w .j  a  v  a 2s.  com
        session.beginTransaction();
        //            Query qr =session.createQuery("from "
        //                    +Staff.class.getName() 
        //                    + " s left join fetch s.roleCollection");
        //            session.createQuery(")
        Criteria crit = session.createCriteria(Staff.class);
        crit.setFetchMode("roleCollection", FetchMode.SELECT);
        crit.addOrder(Order.asc("id"));
        crit.setProjection(Projections.projectionList().add(Projections.property("id"))
                .add(Projections.property("userName")).add(Projections.property("firstName"))
                .add(Projections.property("lastName")).add(Projections.property("phone"))
                .add(Projections.property("email")).add(Projections.property("status")));

        switch (type) {
        case 0:
            break;

        case 1:
            crit.add(Restrictions.ilike("userName", "%" + key + "%"));
            break;

        case 2:
            while (true) {
                if (searchByFirstName) {
                    crit.add(Restrictions.ilike("firstName", "%" + key + "%"));
                    searchByFirstName = crit.list().isEmpty();
                    if (searchByFirstName) {
                        break;
                    }
                } else {
                    crit.add(Restrictions.ilike("lastName", "%" + key + "%"));
                    break;
                }
            }
            break;

        case 3:
            crit.add(Restrictions.ilike("phone", "%" + key + "%"));
            break;

        case 4:
            crit.add(Restrictions.ilike("email", "%" + key + "%"));
            break;

        case 5:
            crit.add(Restrictions.ilike("adress", "%" + key + "%"));
            break;
        }

        totalSize = crit.list().size();
        crit.setFirstResult(firstResult);
        crit.setMaxResults(20);
        resultSet = crit.list();
        resultSet.add(totalSize);
        return resultSet == null ? new ArrayList<>() : resultSet;
    } catch (Exception e) {
        e.printStackTrace();
        return new ArrayList<>();
    } finally {
        if (session.getTransaction().isActive()) {
            session.getTransaction().commit();
        }
    }
}

From source file:corner.orm.tapestry.component.prototype.autocompleter.AbstractSelectModel.java

License:Apache License

/**
 * ?/*  ww w. ja v a2  s  .c om*/
 * @param criteria
 */
protected void appendProjection(Criteria criteria) {
    criteria.setProjection(Projections.projectionList().add(Projections.property(INDEX_CODE_FIELD))
            .add(Projections.property(ABC_FIELD)).add(Projections.property(CHN_FIELD)));
}

From source file:dao.DaoImplementProductos.java

public int getUltimoProducto() {
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();//from  w  w w  .j  av  a2  s . com
    Criteria criteria = session.createCriteria(Productos.class);
    ProjectionList projList = Projections.projectionList();
    projList.add(Projections.max("idproducto"));
    criteria.setProjection(projList);
    List results = criteria.list();
    Iterator iterator = results.iterator();
    int ultReg = 0;
    while (iterator.hasNext()) {
        ultReg = Integer.parseInt(iterator.next().toString());
    }
    session.close();
    return ultReg;
}

From source file:de.erdesignerng.model.serializer.repository.DictionaryModelSerializer.java

License:Open Source License

/**
 * Get the available repository entries.
 *
 * @param aDialectClass the hibernate dialect class
 * @param aConnection   the jdbc connection
 * @return list of entries//  w  ww . ja  v  a 2  s.  c  o  m
 * @throws Exception will be thrown in case of an exception
 */
public List<RepositoryEntryDescriptor> getRepositoryEntries(Class aDialectClass, Connection aConnection)
        throws Exception {
    return (List<RepositoryEntryDescriptor>) new HibernateTemplate(aDialectClass, aConnection) {
        @Override
        public Object doInSession(Session aSession) {
            List<RepositoryEntryDescriptor> theResult = new ArrayList<>();

            Criteria theCriteria = aSession.createCriteria(RepositoryEntity.class);
            theCriteria.setProjection(Projections.projectionList().add(Projections.property("id"))
                    .add(Projections.property("name")));
            theCriteria.addOrder(Order.asc("name"));

            for (Object theObject : theCriteria.list()) {
                Object[] theArray = (Object[]) theObject;

                RepositoryEntryDescriptor theEntry = new RepositoryEntryDescriptor();
                theEntry.setId((Long) theArray[0]);
                theEntry.setName((String) theArray[1]);
                theResult.add(theEntry);
            }
            return theResult;
        }
    }.execute();
}

From source file:de.forsthaus.backend.dao.impl.CustomerDAOImpl.java

License:Open Source License

@Override
public int getMaxCustomerId() {
    DetachedCriteria criteria = DetachedCriteria.forClass(Customer.class);
    criteria.setProjection(Projections.projectionList().add(Projections.max("id")));

    long max = DataAccessUtils.longResult(getHibernateTemplate().findByCriteria(criteria));
    return (int) max;
}

From source file:de.iew.framework.persistence.hibernate.HbmMessageBundleDaoImpl.java

License:Apache License

public List<Locale> getSupportedLocales() {
    Criteria crit = getCurrentSession().createCriteria(TextItem.class).setCacheable(true)
            .setProjection(Projections.distinct(Projections.projectionList()
                    .add(Projections.property("languageCode")).add(Projections.property("countryCode"))));
    crit.setCacheable(true);//  ww  w.  ja v  a2 s. co  m
    crit.setResultTransformer(LocaleTupleResultTransformer.DEFAULT);
    return crit.list();
}

From source file:de.lemo.dms.connectors.lemo_0_8.ExtractAndMap.java

License:Open Source License

/**
 * Reads the Mining Database./*  w ww .j  ava2 s.  c o 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;
    }
    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.//  ww  w.jav a2 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.//from   www  . j  a  v  a 2 s . c o  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;
}