Example usage for org.hibernate Query setFlushMode

List of usage examples for org.hibernate Query setFlushMode

Introduction

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

Prototype

@Override
    Query<R> setFlushMode(FlushModeType flushMode);

Source Link

Usage

From source file:org.osaf.cosmo.dao.hibernate.ItemDaoImpl.java

License:Apache License

protected Item findItemByParentAndNameMinusItem(Long userDbId, Long parentDbId, String name, Long itemId) {
    Query hibQuery = null;
    if (parentDbId != null) {
        hibQuery = getSession().getNamedQuery("item.by.ownerId.parentId.name.minusItem")
                .setParameter("itemid", itemId).setParameter("ownerid", userDbId)
                .setParameter("parentid", parentDbId).setParameter("name", name);
    } else {/* www  .j  av a 2 s. c  o m*/
        hibQuery = getSession().getNamedQuery("item.by.ownerId.nullParent.name.minusItem")
                .setParameter("itemid", itemId).setParameter("ownerid", userDbId).setParameter("name", name);
    }
    hibQuery.setFlushMode(FlushMode.MANUAL);
    return (Item) hibQuery.uniqueResult();
}

From source file:org.osaf.cosmo.dao.hibernate.ItemDaoImpl.java

License:Apache License

protected HomeCollectionItem findRootItem(Long dbUserId) {
    Query hibQuery = getSession().getNamedQuery("homeCollection.by.ownerId").setParameter("ownerid", dbUserId);
    hibQuery.setCacheable(true);//from   w w  w. j  a v a  2s  .co  m
    hibQuery.setFlushMode(FlushMode.MANUAL);

    return (HomeCollectionItem) hibQuery.uniqueResult();
}

From source file:org.osaf.cosmo.dao.hibernate.ItemDaoImpl.java

License:Apache License

protected void checkForDuplicateUid(Item item) {
    // verify uid not in use
    if (item.getUid() != null) {

        // Lookup item by uid
        Query hibQuery = getSession().getNamedQuery("itemid.by.uid").setParameter("uid", item.getUid());
        hibQuery.setFlushMode(FlushMode.MANUAL);

        Long itemId = (Long) hibQuery.uniqueResult();

        // if uid is in use throw exception
        if (itemId != null) {
            throw new UidInUseException(item.getUid(), "uid " + item.getUid() + " already in use");
        }/*from   ww  w.j  av a  2 s . c o m*/
    }
}

From source file:org.osaf.cosmo.dao.hibernate.UserDaoImpl.java

License:Apache License

private User findUserByUsernameIgnoreCase(String username) {
    Session session = getSession();//from  w w  w.  ja  v a  2 s . com
    Query hibQuery = session.getNamedQuery("user.byUsername.ignorecase").setParameter("username", username);
    hibQuery.setCacheable(true);
    hibQuery.setFlushMode(FlushMode.MANUAL);
    List users = hibQuery.list();
    if (users.size() > 0)
        return (User) users.get(0);
    else
        return null;
}

From source file:org.osaf.cosmo.dao.hibernate.UserDaoImpl.java

License:Apache License

private User findUserByUsernameOrEmailIgnoreCaseAndId(Long userId, String username, String email) {
    Session session = getSession();//w  w  w .j ava  2 s  .  co  m
    Query hibQuery = session.getNamedQuery("user.byUsernameOrEmail.ignorecase.ingoreId")
            .setParameter("username", username).setParameter("email", email).setParameter("userid", userId);
    hibQuery.setCacheable(true);
    hibQuery.setFlushMode(FlushMode.MANUAL);
    List users = hibQuery.list();
    if (users.size() > 0)
        return (User) users.get(0);
    else
        return null;
}

From source file:org.osaf.cosmo.dao.hibernate.UserDaoImpl.java

License:Apache License

private User findUserByEmail(String email) {
    Session session = getSession();//from  w w w  .  j a  va2  s .  c  o  m
    Query hibQuery = session.getNamedQuery("user.byEmail").setParameter("email", email);
    hibQuery.setCacheable(true);
    hibQuery.setFlushMode(FlushMode.MANUAL);
    List users = hibQuery.list();
    if (users.size() > 0)
        return (User) users.get(0);
    else
        return null;
}

From source file:org.osaf.cosmo.dao.hibernate.UserDaoImpl.java

License:Apache License

private User findUserByEmailIgnoreCase(String email) {
    Session session = getSession();//from   w w w.  ja  va  2 s  .  co  m
    Query hibQuery = session.getNamedQuery("user.byEmail.ignorecase").setParameter("email", email);
    hibQuery.setCacheable(true);
    hibQuery.setFlushMode(FlushMode.MANUAL);
    List users = hibQuery.list();
    if (users.size() > 0)
        return (User) users.get(0);
    else
        return null;
}

From source file:org.osaf.cosmo.dao.hibernate.UserDaoImpl.java

License:Apache License

private User findUserByUid(String uid) {
    Session session = getSession();//from   www  .j  a  v a 2s  .  c om
    Query hibQuery = session.getNamedQuery("user.byUid").setParameter("uid", uid);
    hibQuery.setCacheable(true);
    hibQuery.setFlushMode(FlushMode.MANUAL);
    return (User) hibQuery.uniqueResult();
}

From source file:org.sakaiproject.sitestats.impl.StatsManagerImpl.java

License:Educational Community License

public List<SiteActivity> getSiteActivityGrpByDate(final String siteId, final List<String> events,
        final Date iDate, final Date fDate) {
    if (siteId == null) {
        throw new IllegalArgumentException("Null siteId");
    } else {//from ww w .j a v  a 2s.com
        String iDateStr = "";
        String fDateStr = "";
        if (iDate != null)
            iDateStr = "and s.date >= :idate ";
        if (fDate != null)
            fDateStr = "and s.date < :fdate ";
        final String hql = "select s.siteId, sum(s.count),s.date " + "from SiteActivityImpl as s "
                + "where s.siteId = :siteid " + "and s.eventId in (:eventlist) " + iDateStr + fDateStr
                + "group by s.siteId, s.date";

        HibernateCallback hcb = new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException, SQLException {
                Query q = session.createQuery(hql);
                q.setFlushMode(FlushMode.NEVER);
                q.setString("siteid", siteId);
                if (events != null && events.size() > 0)
                    q.setParameterList("eventlist", events);
                else
                    q.setParameterList("eventlist", M_ers.getEventIds());
                if (iDate != null)
                    q.setDate("idate", iDate);
                if (fDate != null) {
                    // adjust final date
                    Calendar c = Calendar.getInstance();
                    c.setTime(fDate);
                    c.add(Calendar.DAY_OF_YEAR, 1);
                    Date fDate2 = c.getTime();
                    q.setDate("fdate", fDate2);
                }
                List<Object[]> records = q.list();
                List<SiteActivity> results = new ArrayList<SiteActivity>();
                if (records.size() > 0) {
                    for (Iterator<Object[]> iter = records.iterator(); iter.hasNext();) {
                        Object[] s = iter.next();
                        SiteActivity c = new SiteActivityImpl();
                        c.setSiteId((String) s[0]);
                        c.setCount(((Long) s[1]).longValue());
                        Date recDate = (Date) s[2];
                        c.setDate(recDate);
                        c.setEventId(null);
                        results.add(c);
                    }
                    return results;
                } else
                    return results;
            }
        };
        return (List<SiteActivity>) getHibernateTemplate().execute(hcb);
    }
}

From source file:org.unitedinternet.cosmo.dao.hibernate.ContentDaoImpl.java

License:Apache License

public Set<ContentItem> loadChildren(CollectionItem collection, Date timestamp) {
    try {/*from   w  w w .  j ava  2 s .co  m*/
        Set<ContentItem> children = new HashSet<ContentItem>();
        Query query = null;

        // use custom HQL query that will eager fetch all associations
        if (timestamp == null) {
            query = getSession().getNamedQuery("contentItem.by.parent").setParameter("parent", collection);
        } else {
            query = getSession().getNamedQuery("contentItem.by.parent.timestamp")
                    .setParameter("parent", collection).setParameter("timestamp", timestamp);
        }
        query.setFlushMode(FlushMode.MANUAL);
        List results = query.list();
        for (Iterator it = results.iterator(); it.hasNext();) {
            ContentItem content = (ContentItem) it.next();
            initializeItem(content);
            children.add(content);
        }

        return children;

    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}