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.xpn.xwiki.store.XWikiHibernateStore.java

License:Open Source License

public List<XWikiLink> loadLinks(long docId, XWikiContext context, boolean bTransaction) throws XWikiException {
    List<XWikiLink> links = new ArrayList<XWikiLink>();
    try {/*from  ww  w.  j a  v  a2  s  .  c om*/
        if (bTransaction) {
            checkHibernate(context);
            bTransaction = beginTransaction(false, context);
        }
        Session session = getSession(context);

        Query query = session.createQuery(" from XWikiLink as link where link.id.docId = :docId");
        query.setLong("docId", docId);

        links = query.list();

        if (bTransaction) {
            endTransaction(context, false, false);
            bTransaction = false;
        }
    } catch (Exception e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE,
                XWikiException.ERROR_XWIKI_STORE_HIBERNATE_LOADING_LINKS, "Exception while loading links", e);
    } finally {
        try {
            if (bTransaction) {
                endTransaction(context, false, false);
            }
        } catch (Exception e) {
        }
    }
    return links;
}

From source file:com.xpn.xwiki.store.XWikiHibernateStore.java

License:Open Source License

public void deleteLinks(long docId, XWikiContext context, boolean bTransaction) throws XWikiException {
    try {/*from w ww .  j  ava  2 s . c  o m*/
        if (bTransaction) {
            checkHibernate(context);
            bTransaction = beginTransaction(context);
        }
        Session session = getSession(context);

        Query query = session.createQuery("delete from XWikiLink as link where link.id.docId = :docId");
        query.setLong("docId", docId);
        query.executeUpdate();

        if (bTransaction) {
            endTransaction(context, true);
            bTransaction = false;
        }
    } catch (Exception e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE,
                XWikiException.ERROR_XWIKI_STORE_HIBERNATE_DELETING_LINKS, "Exception while deleting links", e);
    } finally {
        try {
            if (bTransaction) {
                endTransaction(context, false);
            }
        } catch (Exception e) {
        }
    }
}

From source file:com.zhengxuetao.gupiao.dao.impl.DayDAOImpl.java

@Override
public List<DayData> findDayDataList(Long id, Timestamp startDate, Timestamp endDate) {
    Query query = getSession().createQuery("FROM DayData d WHERE d.financeId=:id AND d.time>=:startDate "
            + "AND d.time <=:endDate ORDER BY d.time ASC");
    query.setLong("id", id);
    query.setTimestamp("startDate", startDate);
    query.setTimestamp("endDate", endDate);
    return query.list();
}

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

License:Apache License

public List<AgentDailyStatistics> findByAgent(final long agentId) {
    return getHibernateTemplate().execute(new HibernateCallback<List<AgentDailyStatistics>>() {
        public List<AgentDailyStatistics> doInHibernate(Session session) throws HibernateException {
            Query queryObject = session.createQuery("from AgentDailyStatistics where agentId = :agentId");
            queryObject.setLong("agentId", agentId);
            return queryObject.list();
        }/* w ww. jav a2s . co m*/
    });
}

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

License:Apache License

public AgentDailyStatistics findByAgentAndDaySafe(final long agentId, final long dayStamp) {
    List<AgentDailyStatistics> results = getHibernateTemplate()
            .execute(new HibernateCallback<List<AgentDailyStatistics>>() {
                public List<AgentDailyStatistics> doInHibernate(Session session) throws HibernateException {
                    Query queryObject = session.createQuery(
                            "from AgentDailyStatistics where agentId = :agentId and dayStamp = :dayStamp");
                    queryObject.setLong("agentId", agentId);
                    queryObject.setLong("dayStamp", dayStamp);
                    return queryObject.list();
                }/*from   w  ww  .  j av  a  2 s .  com*/
            });

    if (results.size() == 0) {
        return null;
    } else if (results.size() == 1) {
        return results.get(0);
    } else {
        LOG.warning("Expected unique result for agent id '" + agentId + "' and day '" + dayStamp + "', but got "
                + results.size() + " results.  Resetting statistics for this day.");
        for (AgentDailyStatistics stats : results) {
            delete(stats);
        }

        return null;
    }
}

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

License:Apache License

public int deleteByDayStampBefore(final long dayStamp) {
    return getHibernateTemplate().execute(new HibernateCallback<Integer>() {
        public Integer doInHibernate(Session session) throws HibernateException {
            Query queryObject = session
                    .createQuery("delete from AgentDailyStatistics where dayStamp < :dayStamp");
            queryObject.setLong("dayStamp", dayStamp);
            return queryObject.executeUpdate();
        }/*from w w w.  ja  v a 2 s  .  c  om*/
    });
}

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

License:Apache License

public List<BuildDependencyLink> findAllDependencies(final long buildId) {
    return getHibernateTemplate().execute(new HibernateCallback<List<BuildDependencyLink>>() {
        public List<BuildDependencyLink> doInHibernate(Session session) throws HibernateException {
            Query query = session.createQuery(
                    "from BuildDependencyLink where downstreamBuildId = :build or upstreamBuildId = :build");
            query.setLong("build", buildId);
            return query.list();
        }//from  w ww  .jav  a  2 s  .c  o  m
    });
}

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

License:Apache License

public List<BuildDependencyLink> findAllUpstreamDependencies(final long buildId) {
    return getHibernateTemplate().execute(new HibernateCallback<List<BuildDependencyLink>>() {
        public List<BuildDependencyLink> doInHibernate(Session session) throws HibernateException {
            Query query = session.createQuery("from BuildDependencyLink where downstreamBuildId = :build");
            query.setLong("build", buildId);
            return query.list();
        }/*from   ww w . ja v  a 2  s . c  o  m*/
    });
}

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

License:Apache License

public List<BuildDependencyLink> findAllDownstreamDependencies(final long buildId) {
    return getHibernateTemplate().execute(new HibernateCallback<List<BuildDependencyLink>>() {
        public List<BuildDependencyLink> doInHibernate(Session session) throws HibernateException {
            Query query = session.createQuery("from BuildDependencyLink where upstreamBuildId = :build");
            query.setLong("build", buildId);
            return query.list();
        }/*  ww  w .  j a  v  a 2  s .c o m*/
    });
}

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

License:Apache License

public int deleteDependenciesByBuild(final long buildId) {
    return getHibernateTemplate().execute(new HibernateCallback<Integer>() {
        public Integer doInHibernate(Session session) throws HibernateException {
            Query queryObject = session.createQuery(
                    "delete from BuildDependencyLink where upstreamBuildId = :build or downstreamBuildId = :build");
            queryObject.setLong("build", buildId);
            return queryObject.executeUpdate();
        }/*w w  w.ja  v  a 2  s  .  c  o  m*/
    });
}