Example usage for org.hibernate Query setLong

List of usage examples for org.hibernate Query setLong

Introduction

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

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setLong(String name, long val) 

Source Link

Document

Bind a named long-valued parameter.

Usage

From source file:com.zutubi.pulse.master.model.persistence.hibernate.HibernateBuildResultDao.java

License:Apache License

public List<BuildResult> findSinceByProject(final Project project, final Date since) {
    return getHibernateTemplate().execute(new HibernateCallback<List<BuildResult>>() {
        public List<BuildResult> doInHibernate(Session session) throws HibernateException {
            Query queryObject = session.createQuery(
                    "from BuildResult model where model.project = :project and model.user = null and model.stamps.endTime > :since order by model.number desc");
            queryObject.setEntity("project", project);
            queryObject.setLong("since", since.getTime());
            return queryObject.list();
        }//from w w w.  j  a  va 2  s .co  m
    });
}

From source file:com.zutubi.pulse.master.model.persistence.hibernate.HibernateBuildResultDao.java

License:Apache License

public BuildResult findPreviousBuildResult(final BuildResult result) {
    return getHibernateTemplate().execute(new HibernateCallback<BuildResult>() {
        public BuildResult doInHibernate(Session session) throws HibernateException {
            Query queryObject = session.createQuery(
                    "from BuildResult model where model.user = null and model.project = :project and model.number < :number order by model.number desc");
            queryObject.setEntity("project", result.getProject());
            queryObject.setLong("number", result.getNumber());
            queryObject.setMaxResults(1);
            return (BuildResult) queryObject.uniqueResult();
        }// w  ww . ja  v  a  2  s .  c o  m
    });
}

From source file:com.zutubi.pulse.master.model.persistence.hibernate.HibernateBuildResultDao.java

License:Apache License

public BuildResult findByProjectAndNumber(final long projectId, final long number) {
    List<BuildResult> results = getHibernateTemplate().execute(new HibernateCallback<List<BuildResult>>() {
        public List<BuildResult> doInHibernate(Session session) throws HibernateException {
            Query queryObject = session.createQuery(
                    "from BuildResult model where model.user = null and model.project.id = :project and model.number = :number");
            queryObject.setLong("project", projectId);
            queryObject.setParameter("number", number);
            return queryObject.list();
        }/*from w ww.  j  a v  a2 s . co  m*/
    });

    if (results.size() > 1) {
        LOG.warning("findByProjectNameAndNumber has returned " + results.size()
                + " results when expecting at most one.");
    }
    if (results.size() > 0) {
        return results.get(0);
    }
    return null;
}

From source file:com.zutubi.pulse.master.model.persistence.hibernate.HibernateBuildResultDao.java

License:Apache License

public CommandResult findCommandResultByArtifact(final long artifactId) {
    return getHibernateTemplate().execute(new HibernateCallback<CommandResult>() {
        public CommandResult doInHibernate(Session session) throws HibernateException {
            Query queryObject = session.createQuery("SELECT result " + "FROM CommandResult result "
                    + "JOIN result.artifacts artifact " + "WHERE artifact.id = :id");
            queryObject.setLong("id", artifactId);
            queryObject.setMaxResults(1);
            return (CommandResult) queryObject.uniqueResult();
        }//from   www .j a v a  2s.  com
    });
}

From source file:controller.DepartmentDAOImpl.java

@Override
public List<Department> getDepartmentByCompany(Company com) {
    Session s = HibernateUtil.getSessionFactory().openSession();
    Transaction t = s.beginTransaction();
    Query query = s.createQuery("from Department where COMPANY_ID = :COMPANY");
    query.setLong("COMPANY", com.getId());
    List<Department> list = query.list();
    t.commit();//www.  j  a  v a 2 s.  co  m
    s.close();
    return list;
}

From source file:cz.nkp.urnnbn.processmanager.persistence.XmlTransformationDAOImpl.java

License:Open Source License

public void deleteTransformation(Long transformationId) {
    Session session = factory.openSession();
    session.beginTransaction();/*w  ww .  j  ava  2  s .  c  o  m*/
    Query query = session.createQuery("delete from XmlTransformation where id = :id ");
    query.setLong("id", transformationId);
    query.executeUpdate();
    session.getTransaction().commit();
    session.close();
}

From source file:cz.zcu.pia.social.network.backend.services.dao.impl.CommentsDAO.java

@Override
public List<Comments> getCommentsForPost(Long postId) {
    Session session = getCurrentSession();
    try {/*  w  ww . ja  va  2  s .  c  om*/
        Query query = session.createQuery("from " + this.genericType.getName()
                + " comment where comment.post.id = :postId ORDER BY comment.dateSent DESC");
        return query.setLong("postId", postId).list();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return new ArrayList();
    } finally {
        closeSession(session);
    }

}

From source file:cz.zcu.pia.social.network.backend.services.dao.impl.FollowingDAO.java

@Override
public void removeFollow(Users follower, Users feeder) {
    Session session = getCurrentSessionWithTransaction();
    try {/*ww w .  j a v  a  2 s.c om*/
        Query query = session.createQuery("delete from " + this.genericType.getName()
                + " f WHERE f.follower.id = :followerId AND f.feeder.id = :feederId ORDER BY f.followingSince DESC");
        query.setLong("followerId", follower.getId()).setLong("feederId", feeder.getId());
        query.executeUpdate();
        this.currentTransaction.commit();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        this.currentTransaction.rollback();
    } finally {
        closeSession(session);
    }

}

From source file:cz.zcu.pia.social.network.backend.services.dao.impl.FollowingDAO.java

@Override
public Following getFollower(Users follower, Users feeder) {
    Session session = getCurrentSession();
    try {/*from   w  w w . j  ava  2  s . c om*/
        Query query = session.createQuery("from " + this.genericType.getName()
                + " f WHERE f.follower.id = :followerId AND f.feeder.id = :feederId");
        query.setLong("followerId", follower.getId()).setLong("feederId", feeder.getId());
        return (Following) query.uniqueResult();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return null;
    } finally {
        closeSession(session);
    }
}

From source file:cz.zcu.pia.social.network.backend.services.dao.impl.FollowingDAO.java

@Override
public List<Following> getUserFeeders(Users logedInUser) {
    Session session = getCurrentSession();
    try {//from w w  w. j a v  a 2s .  com
        Query query = session
                .createQuery("from " + this.genericType.getName() + " f WHERE f.follower.id = :followerId");
        query.setLong("followerId", logedInUser.getId());
        return (List<Following>) query.list();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return new ArrayList();
    } finally {
        closeSession(session);
    }
}