List of usage examples for org.hibernate Query setBoolean
@Deprecated @SuppressWarnings("unchecked") default Query<R> setBoolean(String name, boolean val)
From source file:com.ikon.dao.AuthDAO.java
License:Open Source License
/** * Active role in database//ww w . j av a2 s .c o m */ public static void activeRole(String rolId, boolean active) throws DatabaseException { log.debug("activeRole({}, {})", rolId, active); 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.ikon.dao.CssDAO.java
License:Open Source License
/** * Find all styles/*from www . java2 s. c o m*/ */ @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); 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.ikon.dao.CssDAO.java
License:Open Source License
/** * Find by content and name/*from ww w . j av a2 s . c o m*/ */ public Css findByContextAndName(String context, String name) throws DatabaseException { log.debug("findByContextAndName({},{})", context, name); String qs = "from Css c where c.context=:context and c.name=:name and c.active=:active"; Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs); q.setString("context", context); q.setString("name", name); q.setBoolean("active", true); Css ret = (Css) q.setMaxResults(1).uniqueResult(); log.debug("findByContextAndName: {}", ret); return ret; } catch (HibernateException e) { throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.ikon.dao.MailAccountDAO.java
License:Open Source License
/** * Find by user//ww w . j a v a2 s . c o m */ @SuppressWarnings("unchecked") public static List<MailAccount> findByUser(String usrId, boolean filterByActive) throws DatabaseException { log.debug("findByUser({}, {})", usrId, filterByActive); String qs = "from MailAccount ma where ma.user=:user " + (filterByActive ? "and ma.active=:active" : "") + " order by ma.id"; Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs); q.setString("user", usrId); if (filterByActive) { q.setBoolean("active", true); } List<MailAccount> ret = q.list(); log.debug("findByUser: {}", ret); return ret; } catch (HibernateException e) { throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.ikon.dao.MailAccountDAO.java
License:Open Source License
/** * find all mail accounts//from w ww . ja v a 2s .co m */ @SuppressWarnings("unchecked") public static List<MailAccount> findAll(boolean filterByActive) throws DatabaseException { log.debug("findAll({})", filterByActive); String qs = "from MailAccount ma " + (filterByActive ? "where ma.active=:active" : "") + " order by ma.id"; Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs); if (filterByActive) { q.setBoolean("active", true); } List<MailAccount> 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.ikon.dao.NodeDocumentDAO.java
License:Open Source License
/** * Get document node size./*from w ww . ja v a 2 s .co m*/ * * @see com.ikon.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 { 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); log.debug("getSize: {}", total); return total; } catch (HibernateException e) { HibernateUtil.rollback(tx); throw e; } finally { HibernateUtil.close(session); } }
From source file:com.ikon.dao.NodeDocumentDAO.java
License:Open Source License
/** * Clear pending extraction queue//from w w w . j a v a2 s. c o m */ public int resetAllPendingExtractionFlags() throws DatabaseException { log.debug("resetAllPendingExtractionFlags()"); String qs = "update NodeDocument nd set nd.textExtracted=:extracted"; Session session = null; Transaction tx = null; int rowCount = 0; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Query q = session.createQuery(qs); q.setBoolean("extracted", false); rowCount = q.executeUpdate(); HibernateUtil.commit(tx); log.debug("resetAllPendingExtractionFlags: {}", rowCount); return rowCount; } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.ikon.dao.NodeDocumentDAO.java
License:Open Source License
/** * Clear pending extraction queue// w w w. j av a 2 s .com */ public int resetPendingExtractionFlag(String docUuid) throws DatabaseException { log.debug("resetPendingExtractionFlag({})", docUuid); String qs = "update NodeDocument nd set nd.textExtracted=:extracted where nd.uuid=:uuid"; Session session = null; Transaction tx = null; int rowCount = 0; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Query q = session.createQuery(qs); q.setBoolean("extracted", false); q.setString("uuid", docUuid); rowCount = q.executeUpdate(); HibernateUtil.commit(tx); log.debug("resetPendingExtractionFlag: {}", rowCount); return rowCount; } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.ikon.dao.NodeDocumentDAO.java
License:Open Source License
/** * Check for extraction queue/*from w ww .jav a 2 s . c o m*/ */ public boolean hasPendingExtractions() throws DatabaseException { log.debug("hasPendingExtractions()"); String qs = "from NodeDocument nd where nd.textExtracted=:extracted"; Session session = null; Transaction tx = null; boolean ret = false; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Query q = session.createQuery(qs); q.setBoolean("extracted", false); ret = q.iterate().hasNext(); HibernateUtil.commit(tx); log.debug("hasPendingExtractions: {}", ret); return ret; } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.ikon.dao.NodeDocumentDAO.java
License:Open Source License
/** * Get pending extraction queue/* w w w .j a v a2 s . co 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 { 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); 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); } }