Example usage for org.hibernate Query setCalendarDate

List of usage examples for org.hibernate Query setCalendarDate

Introduction

In this page you can find the example usage for org.hibernate Query setCalendarDate.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setCalendarDate(String name, Calendar value) 

Source Link

Document

Bind a named Calendar-valued parameter using just the Date portion.

Usage

From source file:com.cloud.bridge.util.QueryHelper.java

License:Open Source License

public static void bindParameters(Query query, Object[] params) {
    int pos = 0;/*from  w ww  .  ja v a2s.c  om*/
    if (params != null && params.length > 0) {
        for (Object param : params) {
            if (param instanceof Byte)
                query.setByte(pos++, ((Byte) param).byteValue());
            else if (param instanceof Short)
                query.setShort(pos++, ((Short) param).shortValue());
            else if (param instanceof Integer)
                query.setInteger(pos++, ((Integer) param).intValue());
            else if (param instanceof Long)
                query.setLong(pos++, ((Long) param).longValue());
            else if (param instanceof Float)
                query.setFloat(pos++, ((Float) param).floatValue());
            else if (param instanceof Double)
                query.setDouble(pos++, ((Double) param).doubleValue());
            else if (param instanceof Boolean)
                query.setBoolean(pos++, ((Boolean) param).booleanValue());
            else if (param instanceof Character)
                query.setCharacter(pos++, ((Character) param).charValue());
            else if (param instanceof Date)
                query.setDate(pos++, (Date) param);
            else if (param instanceof Calendar)
                query.setCalendar(pos++, (Calendar) param);
            else if (param instanceof CalendarDateParam)
                query.setCalendarDate(pos++, ((CalendarDateParam) param).dateValue());
            else if (param instanceof TimestampParam)
                query.setTimestamp(pos++, ((TimestampParam) param).timestampValue());
            else if (param instanceof TimeParam)
                query.setTime(pos++, ((TimeParam) param).timeValue());
            else if (param instanceof String)
                query.setString(pos++, (String) param);
            else if (param instanceof TextParam)
                query.setText(pos++, ((TextParam) param).textValue());
            else if (param instanceof byte[])
                query.setBinary(pos++, (byte[]) param);
            else if (param instanceof BigDecimal)
                query.setBigDecimal(pos++, (BigDecimal) param);
            else if (param instanceof BigInteger)
                query.setBigInteger(pos++, (BigInteger) param);
            else if (param instanceof Locale)
                query.setLocale(pos++, (Locale) param);
            else if (param instanceof EntityParam)
                query.setEntity(pos++, ((EntityParam) param).entityValue());
            else if (param instanceof Serializable)
                query.setSerializable(pos++, (Serializable) param);
            else
                query.setEntity(pos++, param);
        }
    }
}

From source file:d4n1x.photosocial.DAO.impl.PhotoDAOImpl.java

License:Open Source License

@Override
public List<Photo> getPopularPhotos() throws Exception {
    Query query = null;
    List<Photo> new_photos = null;
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR_OF_DAY, -24);
    String HQL = "FROM Photo p WHERE p.upload_data >= :cal ORDER BY p.photo_likes DESC";
    Session session = factory.openSession();

    try {/* ww w . j av a2s.  c  o m*/
        query = session.createQuery(HQL);
        query.setCalendarDate("cal", cal);
        new_photos = (List<Photo>) query.list();
    } catch (RuntimeException e) {

    } finally {
        session.close();
    }
    return new_photos;
}

From source file:org.ednovo.gooru.infrastructure.persistence.hibernate.classplan.LearnguideRepositoryHibernate.java

License:Open Source License

public List<Learnguide> findRecentlyModifiedLearnguides() {

    String hql = "SELECT l from Learnguide l  where l.lastModified >= :date AND " + generateAuthQuery("l.");

    Query q = getSession().createQuery(hql);

    Calendar current = Calendar.getInstance();
    current.add(Calendar.DATE, -1); // reducing by one day
    q.setCalendarDate("date", current);
    addAuthParameters(q);//from   w w  w.j  ava  2 s .  co  m
    return q.list();

}

From source file:org.jasig.portlet.announcements.service.HibernateAnnouncementService.java

License:Apache License

@SuppressWarnings("unchecked")
public void deleteAnnouncementsPastExpirationThreshold(int numDays) {
    try {/*from   w w  w .  ja va 2s.  c  o m*/
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, (numDays * -1));

        Query q = this.getSession().createQuery("delete from Announcement where END_DISPLAY < :date");
        q.setCalendarDate("date", cal);
        int count = q.executeUpdate();
        getHibernateTemplate().flush();
        log.info("Deleted " + count + " expired announcements that stopped displaying prior to "
                + cal.getTime());
    } catch (HibernateException ex) {
        throw convertHibernateAccessException(ex);
    }
}

From source file:us.mn.state.health.lims.sample.daoimpl.SampleDAOImpl.java

License:Mozilla Public License

/**
 * @see us.mn.state.health.lims.sample.dao.SampleDAO#getSamplesReceivedWithin(java.lang.String, java.lang.String)
 *//* w  w w .  j ava 2s  . c o m*/
@SuppressWarnings("unchecked")
@Override
public List<Sample> getSamplesReceivedInDateRange(String receivedDateStart, String receivedDateEnd)
        throws LIMSRuntimeException {
    List<Sample> list = null;

    Calendar start = getCalendarForDateString(receivedDateStart);
    if (GenericValidator.isBlankOrNull(receivedDateEnd)) {
        receivedDateEnd = receivedDateStart;
    }
    Calendar end = getCalendarForDateString(receivedDateEnd);
    // worried about time stamps including time information, so might be missed comparing to midnight (00:00:00.00) on the last day of range.
    end.add(Calendar.DAY_OF_YEAR, 1);
    end.set(Calendar.HOUR_OF_DAY, 0);
    end.set(Calendar.MINUTE, 0);
    end.set(Calendar.SECOND, 0);
    try {
        String sql = "from Sample as s where s.receivedTimestamp >= :start AND s.receivedTimestamp < :end";
        Query query = HibernateUtil.getSession().createQuery(sql);
        query.setCalendarDate("start", start);
        query.setCalendarDate("end", end);
        list = query.list();
        HibernateUtil.getSession().flush();
        HibernateUtil.getSession().clear();
    } catch (HibernateException he) {
        LogEvent.logError("SampleDAOImpl", "getSamplesReceivedInDateRange()", he.toString());
        throw new LIMSRuntimeException("Error in Sample getSamplesReceivedInDateRange()", he);
    }
    return list;
}

From source file:us.mn.state.health.lims.sample.daoimpl.SampleDAOImpl.java

License:Mozilla Public License

@SuppressWarnings("unchecked")
public List<Sample> getSamplesCollectedOn(String collectionDate) throws LIMSRuntimeException {
    List<Sample> list = null;

    Calendar calendar = getCalendarForDateString(collectionDate);

    try {//  w  w w.  j  av a  2  s .  c  o m
        String sql = "from Sample as sample where sample.collectionDate = :date";
        Query query = HibernateUtil.getSession().createQuery(sql);
        query.setCalendarDate("date", calendar);
        list = query.list();
        HibernateUtil.getSession().flush();
        HibernateUtil.getSession().clear();

    } catch (HibernateException he) {
        LogEvent.logError("SampleDAOImpl", "getSamplesRecievedOn()", he.toString());
        throw new LIMSRuntimeException("Error in Sample getSamplesRecievedOn()", he);
    }

    return list;
}