List of usage examples for org.hibernate Query setBoolean
@Deprecated @SuppressWarnings("unchecked") default Query<R> setBoolean(String name, boolean val)
From source file:com.ocare.UMS.dao.imp.MyUserDaoImp.java
@SuppressWarnings("unchecked") @Override/*from www . j av a 2 s . c om*/ public List<MyUser> getAdminsWithPattern(final String pattern) { return getHibernateTemplate().execute(new HibernateCallback<List<MyUser>>() { @Override public List<MyUser> doInHibernate(Session sn) throws HibernateException { Query query = sn.createQuery( "select u from MyUser u inner join u.auth a inner join u.roles r where u.deleted =:deleted AND r.name = :roleName " + " and ( u.firstName like :firstName OR u.middleName like :middleName OR u.lastName like :lastName OR a.userName like :userName)"); query.setBoolean("deleted", false); query.setString("roleName", "ADMIN"); query.setString("firstName", "%" + pattern + "%"); query.setString("middleName", "%" + pattern + "%"); query.setString("lastName", "%" + pattern + "%"); query.setString("userName", "%" + pattern + "%"); List<MyUser> users = query.list(); //return result return users; } }); }
From source file:com.ocare.UMS.dao.imp.MyUserDaoImp.java
@SuppressWarnings("unchecked") @Override/*w w w.j a va 2 s . co m*/ public List<MyUser> getUsersWithPattern(final String pattern) { return getHibernateTemplate().execute(new HibernateCallback<List<MyUser>>() { @Override public List<MyUser> doInHibernate(Session sn) throws HibernateException { Query query = sn.createQuery( "select u from MyUser u inner join u.auth a inner join u.roles r where u.deleted =:deleted AND r.name <> :superAdminRole AND r.name <> :adminRole " + " and ( u.firstName like :firstName OR u.middleName like :middleName OR u.lastName like :lastName OR a.userName like :userName)"); query.setBoolean("deleted", false); query.setString("superAdminRole", "SUPER_ADMIN"); query.setString("adminRole", "ADMIN"); query.setString("firstName", "%" + pattern + "%"); query.setString("middleName", "%" + pattern + "%"); query.setString("lastName", "%" + pattern + "%"); query.setString("userName", "%" + pattern + "%"); List<MyUser> users = query.list(); //return result return users; } }); }
From source file:com.ocare.UMS.dao.imp.MyUserDaoImp.java
@Override public MyUser getByUserName(final String userName) { return getHibernateTemplate().execute(new HibernateCallback<MyUser>() { @Override//from w ww . java2 s .c o m public MyUser doInHibernate(Session sn) throws HibernateException { Query query = sn.createQuery( "select u from MyUser u inner join u.auth a where u.deleted =:deleted AND a.userName = :userName"); query.setBoolean("deleted", false); query.setString("userName", userName); //return result return (MyUser) query.uniqueResult(); } }); }
From source file:com.openkm.dao.AuthDAO.java
License:Open Source License
/** * Active user in database/*from w w w .j ava 2 s . c o m*/ */ public static void activeUser(String usrId, boolean active) throws DatabaseException, AccessDeniedException { log.debug("activeUser({}, {})", usrId, active); // Check if user has enought grants for the action checkAccessGrants(null); String qs = "update User u set u.active=:active where u.id=:id"; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Query q = session.createQuery(qs); q.setBoolean("active", active); q.setString("id", usrId); q.executeUpdate(); HibernateUtil.commit(tx); } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } log.debug("activeUser: void"); }
From source file:com.openkm.dao.AuthDAO.java
License:Open Source License
/** * Active role in database//w ww . ja va 2 s . co m */ public static void activeRole(String rolId, boolean active) throws DatabaseException, AccessDeniedException { log.debug("activeRole({}, {})", rolId, active); // Check if user has enought grants for the action checkAccessGrants(null); String qs = "update Role r set r.active=:active where r.id=:id"; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Query q = session.createQuery(qs); q.setBoolean("active", active); q.setString("id", rolId); q.executeUpdate(); HibernateUtil.commit(tx); } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } log.debug("activeRole: void"); }
From source file:com.openkm.dao.CssDAO.java
License:Open Source License
/** * Find all styles//from w w w.ja v a2 s .c om */ @SuppressWarnings("unchecked") public List<Css> findAll(boolean filterByActive) throws DatabaseException { log.debug("findAll({})", filterByActive); String qs = "from Css c " + (filterByActive ? "where c.active=:active" : "") + " order by c.context, c.name asc"; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs).setCacheable(true); if (filterByActive) { q.setBoolean("active", true); } List<Css> ret = q.list(); log.debug("findAll: {}", ret); return ret; } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.openkm.dao.DocumentFilterDAO.java
License:Open Source License
/** * find all document filter//from w w w. ja va 2 s.co m */ @SuppressWarnings("unchecked") public static List<DocumentFilter> findAll(boolean filterByActive) throws DatabaseException { log.debug("findAll({})", filterByActive); String qs = "from DocumentFilter df " + (filterByActive ? "where df.active=:active" : "") + " order by df.id"; Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs); if (filterByActive) { q.setBoolean("active", true); } List<DocumentFilter> ret = q.list(); log.debug("findAll: {}", ret); return ret; } catch (HibernateException e) { throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.openkm.dao.MimeTypeDAO.java
License:Open Source License
/** * Find by search./* www . j a va 2 s.c o m*/ */ @SuppressWarnings("unchecked") public static List<MimeType> findBySearch() throws DatabaseException { log.debug("findAll()"); String qs = "from MimeType mt where mt.search=:search order by mt.description"; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Query q = session.createQuery(qs).setCacheable(true); q.setBoolean("search", true); List<MimeType> ret = q.list(); HibernateUtil.commit(tx); log.debug("findAll: {}", ret); return ret; } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.openkm.dao.NodeDocumentDAO.java
License:Open Source License
/** * Get document node size./* w w w .j av a2 s.c o m*/ * * @see com.openkm.module.nr.NrStatsModule */ public long getSize(String context) throws PathNotFoundException, DatabaseException { log.debug("getSize({})", context); String qs = "select coalesce(sum(ndv.size), 0) from NodeDocumentVersion ndv " + "where ndv.current = :current and ndv.parent in " + "(select nd.uuid from NodeDocument nd where nd.context = :context)"; Session session = null; Transaction tx = null; long total = 0; try { long begin = System.currentTimeMillis(); session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Query q = session.createQuery(qs); q.setBoolean("current", true); q.setString("context", PathUtils.fixContext(context)); total = (Long) q.setMaxResults(1).uniqueResult(); HibernateUtil.commit(tx); SystemProfiling.log(context, System.currentTimeMillis() - begin); log.trace("getSize.Context: {}, Time: {}", context, System.currentTimeMillis() - begin); log.debug("getSize: {}", total); return total; } catch (HibernateException e) { HibernateUtil.rollback(tx); throw e; } finally { HibernateUtil.close(session); } }
From source file:com.openkm.dao.NodeDocumentDAO.java
License:Open Source License
/** * Get pending extraction queue/*w w w . jav a 2s. c o m*/ */ @SuppressWarnings("unchecked") public List<TextExtractorWork> getPendingExtractions(int maxResults) throws DatabaseException { log.debug("getPendingExtractions({})", maxResults); String qsDoc = "select nd.uuid from NodeDocument nd where nd.textExtracted=:extracted"; String qsDocVer = "from NodeDocumentVersion ndv where ndv.parent=:parent and ndv.current=:current"; Session session = null; Transaction tx = null; List<TextExtractorWork> ret = new ArrayList<TextExtractorWork>(); try { long begin = System.currentTimeMillis(); session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Query qDoc = session.createQuery(qsDoc); qDoc.setBoolean("extracted", false); qDoc.setMaxResults(maxResults); for (String docUuid : (List<String>) qDoc.list()) { Query qDocVer = session.createQuery(qsDocVer); qDocVer.setString("parent", docUuid); qDocVer.setBoolean("current", true); NodeDocumentVersion nDocVer = (NodeDocumentVersion) qDocVer.uniqueResult(); String docPath = NodeBaseDAO.getInstance().getPathFromUuid(session, docUuid); TextExtractorWork work = new TextExtractorWork(); work.setDocUuid(docUuid); work.setDocPath(docPath); work.setDocVerUuid(nDocVer.getUuid()); work.setDate(nDocVer.getCreated()); ret.add(work); } HibernateUtil.commit(tx); SystemProfiling.log(String.valueOf(maxResults), System.currentTimeMillis() - begin); log.trace("getPendingExtractions.MaxResults: {}, Time: {}", maxResults, System.currentTimeMillis() - begin); log.debug("getPendingExtractions: {}", ret); return ret; } catch (PathNotFoundException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }