Example usage for org.hibernate.criterion DetachedCriteria createCriteria

List of usage examples for org.hibernate.criterion DetachedCriteria createCriteria

Introduction

In this page you can find the example usage for org.hibernate.criterion DetachedCriteria createCriteria.

Prototype

public DetachedCriteria createCriteria(String associationPath) 

Source Link

Document

Creates a nested DetachedCriteria representing the association path.

Usage

From source file:dk.teachus.backend.dao.hibernate.HibernateBookingDAO.java

License:Apache License

@SuppressWarnings("unchecked")
@Transactional(readOnly = true)//  w  ww . j  ava  2  s.c  o  m
public Bookings getBookings(Teacher teacher, DateMidnight fromDate, DateMidnight toDate) {
    DetachedCriteria c = DetachedCriteria.forClass(BookingImpl.class);

    DateTime start = fromDate.toDateTime().withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0)
            .withMillisOfSecond(0);
    DateTime end = toDate.toDateTime().withHourOfDay(23).withMinuteOfHour(59).withSecondOfMinute(59)
            .withMillisOfSecond(999);

    c.createCriteria("period").add(Restrictions.eq("status", Status.FINAL));
    c.createCriteria("teacher").add(Restrictions.eq("active", true));
    c.add(Restrictions.eq("teacher", teacher));
    c.add(Restrictions.between("date", start, end));
    c.add(Restrictions.eq("active", true));

    c.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE);

    List<Booking> bookings = getHibernateTemplate().findByCriteria(c);
    List<Booking> filteredBookings = filterBookings(bookings);

    return new BookingsImpl(filteredBookings);
}

From source file:dk.teachus.backend.dao.hibernate.HibernateBookingDAO.java

License:Apache License

@SuppressWarnings("unchecked")
@Transactional(readOnly = true)/*from   w  w w  .j  a  va 2 s . c  o m*/
public Bookings getBookings(Pupil pupil, DateMidnight fromDate, DateMidnight toDate) {
    DetachedCriteria c = DetachedCriteria.forClass(BookingImpl.class);

    DateTime start = new DateTime(fromDate).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0)
            .withMillisOfSecond(0);
    DateTime end = new DateTime(toDate).withHourOfDay(23).withMinuteOfHour(59).withSecondOfMinute(59)
            .withMillisOfSecond(999);

    c.createCriteria("period").add(Restrictions.eq("status", Status.FINAL));
    c.createCriteria("teacher").add(Restrictions.eq("active", true));
    c.add(Restrictions.eq("pupil", pupil));
    c.add(Restrictions.between("date", start, end));
    c.add(Restrictions.eq("active", true));

    c.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE);

    List<Booking> bookings = getHibernateTemplate().findByCriteria(c);
    List<Booking> filteredBookings = filterBookings(bookings);

    return new BookingsImpl(filteredBookings);
}

From source file:dk.teachus.backend.dao.hibernate.HibernateBookingDAO.java

License:Apache License

@SuppressWarnings("unchecked")
@Transactional(readOnly = true)//from w  w  w . j  a  va2  s .  c o  m
public DateTime getLastBookingDate(Period period) {
    DetachedCriteria c = DetachedCriteria.forClass(BookingImpl.class);
    c.createCriteria("pupil").add(Restrictions.eq("active", true));
    c.add(Restrictions.eq("period", period));
    c.add(Restrictions.eq("active", true));
    c.addOrder(Order.desc("date"));

    List<Booking> list = getHibernateTemplate().findByCriteria(c, 0, 1);

    DateTime lastBookingDate = null;
    if (list.size() == 1) {
        Booking booking = list.get(0);
        lastBookingDate = booking.getDate();
    }

    return lastBookingDate;
}

From source file:dk.teachus.backend.dao.hibernate.HibernatePeriodDAO.java

License:Apache License

@SuppressWarnings("unchecked")
@Transactional(readOnly = true)/* ww w .  j  a va2 s. co m*/
public Period get(Long id) {
    DetachedCriteria c = DetachedCriteria.forClass(PeriodImpl.class);

    c.add(Restrictions.eq("id", id));
    c.createCriteria("teacher").add(Restrictions.eq("active", true));

    Period period = null;
    List<Period> result = getHibernateTemplate().findByCriteria(c);
    if (result.size() == 1) {
        period = result.get(0);
    }

    return period;
}

From source file:dk.teachus.backend.dao.hibernate.HibernatePeriodDAO.java

License:Apache License

@SuppressWarnings("unchecked")
@Transactional(readOnly = true)//from   w w w  .  j av  a  2 s. c om
public Periods getPeriods(Teacher teacher, boolean onlyFinal) {
    DetachedCriteria c = DetachedCriteria.forClass(PeriodImpl.class);

    c.add(Restrictions.eq("teacher", teacher));
    c.createCriteria("teacher").add(Restrictions.eq("active", true));
    if (onlyFinal) {
        c.add(Restrictions.eq("status", Status.FINAL));
    } else {
        c.add(Restrictions.ne("status", Status.DELETED));
    }

    c.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE);

    List<Period> result = getHibernateTemplate().findByCriteria(c);

    Periods periods = new PeriodsImpl();
    periods.setPeriods(result);
    return periods;
}

From source file:dk.teachus.backend.dao.hibernate.HibernatePersonDAO.java

License:Apache License

@SuppressWarnings("unchecked")
@Transactional(readOnly = true)//from w ww.  ja  v a  2 s.  co m
public List<Pupil> getPupils(Teacher teacher) {
    DetachedCriteria c = DetachedCriteria.forClass(PupilImpl.class);

    c.add(Restrictions.eq("active", true));
    c.createCriteria("teacher").add(Restrictions.eq("active", true));
    c.add(Restrictions.eq("teacher", teacher));

    c.addOrder(Order.asc("name"));

    c.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE);

    return getHibernateTemplate().findByCriteria(c);
}

From source file:dk.teachus.backend.dao.hibernate.HibernatePersonDAO.java

License:Apache License

@SuppressWarnings("unchecked")
@Transactional(readOnly = true)/*from w  w  w  . j a va2  s. c  o  m*/
public List<TeacherAttribute> getAttributes(Teacher teacher) {
    DetachedCriteria c = DetachedCriteria.forClass(AbstractTeacherAttribute.class);

    c.add(Restrictions.eq("teacher", teacher));
    c.createCriteria("teacher").add(Restrictions.eq("active", true));

    return getHibernateTemplate().findByCriteria(c);
}

From source file:dk.teachus.backend.dao.hibernate.HibernateStatisticsDAO.java

License:Apache License

@SuppressWarnings("unchecked")
@Transactional(readOnly = true)/*from   w  w  w. jav a  2  s  .  c  o m*/
public List<PupilBooking> getAllBookings(DateMidnight fromDate, DateMidnight toDate) {
    DetachedCriteria c = DetachedCriteria.forClass(PupilBookingImpl.class);
    c.createCriteria("pupil").add(Restrictions.eq("active", true));
    c.createCriteria("teacher").add(Restrictions.eq("active", true));
    c.createCriteria("period").add(Restrictions.eq("status", Status.FINAL));
    Disjunction disjunction = Restrictions.disjunction();
    disjunction.add(Restrictions.and(Restrictions.ge("createDate", fromDate.toDateTime()),
            Restrictions.le("createDate", toDate.toDateTime())));
    disjunction.add(Restrictions.and(Restrictions.ge("updateDate", fromDate.toDateTime()),
            Restrictions.le("updateDate", toDate.toDateTime())));
    c.add(disjunction);

    c.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE);

    List<PupilBooking> bookings = getHibernateTemplate().findByCriteria(c);

    return bookings;
}

From source file:edu.wustl.geneconnect.bizlogic.ResultProcessor.java

License:BSD License

/**
 * Create new DetachedCriteria from old one excluding confidence and frequency
 * @return// w w w.j  av a  2  s  . c  o m
 * @throws Exception
 */
public DetachedCriteria createNewCriteria() throws Exception {
    /**
     * Create root DetachedCriteria for GenomicIdentifierSet
     */
    DetachedCriteria genomicIdSetCriteria = DetachedCriteria.forClass(GenomicIdentifierSet.class);
    //System.out.println("caCore deprepnputDsList.size() :  " + inputDsList.size());
    Map addedAssociation = new HashMap();
    for (int i = 0; i < selectedInputValueList.size(); i++) {
        String predicate = (String) selectedInputValueList.get(i);
        int ind = predicate.indexOf("=");
        String dsName = predicate.substring(0, ind);

        String dsValue = predicate.substring(ind + 1, predicate.length());

        // Get Class of data source i.e Gene,MRNA or Protein
        String className = MetadataManager.getDataSourceAttribute(Constants.DATASOURCE_NAME, dsName,
                Constants.CLASS);

        String roleName = MetadataManager.getRoleName("GenomicIdentifierSet", className);

        // get attribute name of Gene.MRNA or protein representing data source 
        String classAttribute = MetadataManager.getDataSourceAttribute(Constants.DATASOURCE_NAME, dsName,
                Constants.ATTRIBUTE);
        // get type of attribute
        String attributeType = MetadataManager.getDataSourceAttribute(Constants.DATASOURCE_NAME, dsName,
                Constants.TYPE);

        log.info("Adding " + roleName + ":" + classAttribute);
        /**
         * Create DetachedCriteria for search on given datasource and its genomicId
         */
        /**
         * Check if Criteria already created.IF yed teh get teh DetachedCriteria object from Map
         * else crete new DetachedCriteria 
         */
        DetachedCriteria genomicCriteria = (DetachedCriteria) addedAssociation.get(roleName);
        if (genomicCriteria == null) {
            genomicCriteria = genomicIdSetCriteria.createCriteria(roleName);
            addedAssociation.put(roleName, genomicCriteria);
        }
        if (attributeType.equalsIgnoreCase("java.lang.Long")) {
            Long longValue = null;
            try {
                longValue = new Long(dsValue);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                throw new Exception("Genomic Identifier for DataSource " + dsName + " must be Integer");
            }
            genomicCriteria.add(Restrictions.eq(classAttribute, longValue));
        } else {
            genomicCriteria.add(Restrictions.eq(classAttribute, dsValue));
        }
    }

    for (int j = 0; j < selectedOutputDataSourceList.size(); j++) {
        String outputDSName = (String) selectedOutputDataSourceList.get(j);
        String outputClassName = MetadataManager.getDataSourceAttribute(Constants.DATASOURCE_NAME, outputDSName,
                Constants.CLASS);
        String roleName = MetadataManager.getRoleName("GenomicIdentifierSet", outputClassName);
        DetachedCriteria outputGenomicCriteria = (DetachedCriteria) addedAssociation.get(roleName);
        if (outputGenomicCriteria == null) {
            outputGenomicCriteria = genomicIdSetCriteria.createCriteria(roleName);
            addedAssociation.put(roleName, outputGenomicCriteria);
        }

        String outputAttribute = MetadataManager.getDataSourceAttribute(Constants.DATASOURCE_NAME, outputDSName,
                Constants.OUTPUT_ATTRIBUTE);
        log.info("Adding " + roleName + ":" + outputAttribute);
        outputGenomicCriteria.add(Restrictions.eq(outputAttribute, new Boolean(true)));
    }
    Map currentNode = new HashMap();

    if (ontList.size() > 0) {
        DetachedCriteria ontCrit = genomicIdSetCriteria.createCriteria("orderOfNodeTraversalCollection");
        currentNode.put(CURRENT_NODE, ontCrit);
    }
    for (int i = 0; i < ontList.size(); i++) {

        DetachedCriteria ontCrit = (DetachedCriteria) currentNode.get(CURRENT_NODE);
        GCCriteria f = (GCCriteria) ontList.get(i);
        String ds = f.getDataSource();
        List type = f.getType();
        String linkType = null;
        if (type.size() > 0)
            linkType = (String) type.get(0);
        ontCrit.createCriteria("sourceDataSource").add(Restrictions.eq("name", ds));
        log.info("Adding ONT ds " + ds);
        DetachedCriteria ontCritF1 = null;
        if (linkType != null) {
            ontCrit.createCriteria("linkType").add(Restrictions.eq("type", linkType));
            ontCritF1 = ontCrit.createCriteria("childOrderOfNodeTraversal");
            currentNode.remove(CURRENT_NODE);
            currentNode.put(CURRENT_NODE, ontCritF1);
            log.info("Adding ONT link " + linkType);
        } else {
            ontCrit.add(Restrictions.isNull("childOrderOfNodeTraversal"));
            log.info("Adding ISNULL next ");
        }
    }
    return genomicIdSetCriteria;
}

From source file:gov.nih.nci.cabig.caaers.dao.AdverseEventDao.java

License:BSD License

public List<AdverseEvent> getByParticipant(Participant participant) {
    DetachedCriteria criteria = DetachedCriteria.forClass(AdverseEvent.class);
    criteria.createCriteria("reportingPeriod").createCriteria("assignment").createCriteria("participant")
            .add(getParticipantExample(participant));

    //.createCriteria("identifiers").add(getIdentifierExample(participant));
    return getHibernateTemplate().findByCriteria(criteria);
}