Example usage for org.hibernate Query setTimestamp

List of usage examples for org.hibernate Query setTimestamp

Introduction

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

Prototype

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

Source Link

Document

Bind the value and the time of a given Date object to a named query parameter.

Usage

From source file:org.headsupdev.agile.app.history.HistoryApplication.java

License:Open Source License

public List<Event> getEvents(long before, List<String> types, int count) {
    if (types == null || types.size() == 0) {
        return new LinkedList<Event>();
    }//ww  w. j  ava  2  s.  c o m

    Session session = ((HibernateStorage) Manager.getStorageInstance()).getHibernateSession();

    Query q = session.createQuery(
            "from StoredEvent e where e.class in (:types) and e.time < :before order by time desc");
    q.setParameterList("types", types);
    q.setTimestamp("before", new Date(before));
    q.setMaxResults(count);
    return q.list();
}

From source file:org.headsupdev.agile.app.history.HistoryApplication.java

License:Open Source License

public List<Event> getEventsForProject(Project project, long before, List<String> types, int count) {
    if (types == null || types.size() == 0) {
        return new LinkedList<Event>();
    }/*from   w w w .  j ava2 s.c  om*/

    Session session = ((HibernateStorage) Manager.getStorageInstance()).getHibernateSession();

    Query q = session.createQuery(
            "from StoredEvent e where e.class in (:types) and project.id = :pid and e.time < :before order by time desc");
    q.setParameterList("types", types);
    q.setString("pid", project.getId());
    q.setTimestamp("before", new Date(before));
    q.setMaxResults(count);
    return q.list();
}

From source file:org.headsupdev.agile.app.history.rest.ActivityApi.java

License:Open Source License

protected Query createQuery(Date before, Session session) {
    Query q;
    if (getProject().equals(StoredProject.getDefault())) {
        q = session.createQuery("from StoredEvent e where e.time < :before order by time desc");
        q.setTimestamp("before", before);
    } else {// w  w w .j ava  2s . c  om
        q = session.createQuery(
                "from StoredEvent e where project.id = :pid and e.time < :before order by time desc");
        q.setString("pid", getProject().getId());
        q.setTimestamp("before", before);
    }
    q.setMaxResults(50);

    return q;
}

From source file:org.headsupdev.agile.storage.dao.MilestonesDAO.java

License:Open Source License

public List<Milestone> findAllActiveDuring(Date startDate, Date endDate) {
    Query q = getSession().createQuery("from " + persistentClass.getSimpleName()
            + " o where o.start <= :endDate " + "and o.due >= :startDate");
    q.setTimestamp("startDate", startDate);
    q.setTimestamp("endDate", endDate);

    return (List<Milestone>) q.list();
}

From source file:org.headsupdev.agile.storage.HibernateStorage.java

License:Open Source License

public List<Event> getEvents(Application app, Date start, Date end) {
    Session session = getHibernateSession();
    Query q = session.createQuery(
            "from StoredEvent e where applicationId = :appId and time >= :start and time < :end order by time desc");
    q.setString("appId", app.getApplicationId());
    q.setTimestamp("start", start);
    q.setTimestamp("end", end);

    q.setReadOnly(true);//from  w  w w  . j  av  a 2  s.c  o  m
    return (List<Event>) q.list();
}

From source file:org.headsupdev.agile.storage.HibernateStorage.java

License:Open Source License

private List<Event> doGetEventsForProject(Project project, Application app, Date start, Date end,
        boolean tree) {
    String query = "from StoredEvent e where project.id = :pid";
    if (tree) {/*from   w  w w  . j a v  a2  s. c om*/
        query = "from StoredEvent e where project.id in (:pids)";
    }

    if (app != null) {
        query += " and applicationId = :appId";
    }

    if (start != null) {
        query += " and time >= :start and time < :end";
    }
    query += " order by time desc";

    Session session = getHibernateSession();
    Transaction tx = session.beginTransaction();
    Query q = session.createQuery(query);

    if (tree) {
        project = (Project) session.merge(project);
        List<String> projects = new LinkedList<String>();
        doListProjectIds(project, projects);
        q.setParameterList("pids", projects);
    } else {
        q.setString("pid", project.getId());
    }

    if (app != null) {
        q.setString("appId", app.getApplicationId());
    }

    if (start != null) {
        q.setTimestamp("start", start);
        q.setTimestamp("end", end);
    }

    q.setReadOnly(true);
    List<Event> list = q.list();
    tx.commit();

    return list;
}

From source file:org.headsupdev.agile.storage.HibernateStorage.java

License:Open Source License

public List<Event> getEventsForUser(User user, Date start, Date stop) {
    Session session = getHibernateSession();
    Transaction tx = session.beginTransaction();

    Query q = session.createQuery("from StoredEvent e where time >= :start and time < :end and "
            + "(username = :username or username like :emailLike or username like :nameLike) order by time desc");
    q.setTimestamp("start", start);
    q.setTimestamp("end", stop);
    q.setString("username", user.getUsername());

    if (!StringUtil.isEmpty(user.getEmail())) {
        q.setString("emailLike", "%<" + user.getEmail() + ">");
    } else {/*from  w w  w.j  a va  2s  . c om*/
        // a silly fallback for now
        q.setString("emailLike", user.getUsername());
    }

    if (!StringUtil.isEmpty(user.getFullname())) {
        q.setString("nameLike", user.getFullname() + " <%");
    } else {
        // a silly fallback for now
        q.setString("nameLike", user.getUsername());
    }

    q.setReadOnly(true);
    List<Event> list = q.list();
    tx.commit();

    return list;
}

From source file:org.hoteia.qalingo.core.dao.EmailDao.java

License:Apache License

public int deleteSendedEmail(final Timestamp before) {
    Session session = (Session) em.getDelegate();
    String sql = "FROM Email WHERE dateCreate <= :before AND status = '" + Email.EMAIl_STATUS_SENDED + "'";
    Query query = session.createQuery(sql);
    query.setTimestamp("before", before);
    List<Email> emails = (List<Email>) query.list();
    if (emails != null) {
        for (Iterator<Email> iterator = emails.iterator(); iterator.hasNext();) {
            Email email = (Email) iterator.next();
            deleteEmail(email);//  ww  w .j a v a2 s.  co m
        }
        return emails.size();
    }
    return 0;
}

From source file:org.hoteia.qalingo.core.dao.impl.ServerDaoImpl.java

License:Apache License

public int deleteSendedServerStatus(final Timestamp before) {
    Session session = (Session) em.getDelegate();
    String sql = "FROM ServerStatus WHERE lastCheckReceived <= :before";
    Query query = session.createQuery(sql);
    query.setTimestamp("before", before);
    List<ServerStatus> serverStatusList = (List<ServerStatus>) query.list();
    if (serverStatusList != null) {
        for (Iterator<ServerStatus> iterator = serverStatusList.iterator(); iterator.hasNext();) {
            ServerStatus serverStatus = (ServerStatus) iterator.next();
            deleteServerStatus(serverStatus);
        }//  ww w  .j a v  a2 s.  c o  m
        return serverStatusList.size();
    }
    return 0;
}

From source file:org.jahia.services.workflow.jbpm.HistoryProcessInstanceByVariableQuery.java

License:Open Source License

protected void applyParameters(Query query) {
    if (endedBefore != null) {
        query.setTimestamp("before", endedBefore);
    }/*w  w  w  .j ava  2s .  c o m*/
    if (endedAfter != null) {
        query.setTimestamp("after", endedAfter);
    }
}