List of usage examples for org.hibernate Query setMaxResults
@Override
Query<R> setMaxResults(int maxResult);
From source file:com.ikon.dao.NodeBaseDAO.java
License:Open Source License
/** * Get node path from UUID//from w ww .ja va 2s. co m */ @SuppressWarnings("unused") private String searchPathFromUuid(Session session, String uuid) throws PathNotFoundException, HibernateException { log.debug("searchPathFromUuid({})", uuid); String qs = "select nb.path from NodeBase nb where nb.uuid=:uuid"; Query q = session.createQuery(qs); q.setString("uuid", uuid); String path = (String) q.setMaxResults(1).uniqueResult(); log.debug("searchPathFromUuid: {}", path); return path; }
From source file:com.ikon.dao.NodeBaseDAO.java
License:Open Source License
/** * Get node UUID from path. This is the old one which calculates the uuid. *///from w ww . j ava 2s . c o m @SuppressWarnings("unused") private String searchUuidFromPath(String path) throws PathNotFoundException, DatabaseException { log.debug("searchUuidFromPath({})", path); String qs = "select nb.uuid from NodeBase nb where nb.path=:path"; Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs); q.setString("path", path); String uuid = (String) q.setMaxResults(1).uniqueResult(); if (uuid == null) { throw new PathNotFoundException(path); } log.debug("searchUuidFromPath: {}", uuid); return uuid; } catch (HibernateException e) { throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.ikon.dao.NodeBaseDAO.java
License:Open Source License
/** * Get parent node uuid// w w w . j ava 2 s. c o m */ public String getParentUuid(String uuid) throws DatabaseException { log.debug("getParentUuid({})", uuid); String qs = "select nb.parent from NodeBase nb where nb.uuid=:uuid"; Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs); q.setString("uuid", uuid); String parent = (String) q.setMaxResults(1).uniqueResult(); log.debug("getParentUuid: {}", parent); return parent; } catch (HibernateException e) { throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.ikon.dao.NodeBaseDAO.java
License:Open Source License
/** * Get parent node/*from w w w . j a va 2s . c o m*/ */ public NodeBase getParentNode(Session session, String uuid) throws HibernateException { log.debug("getParentNode({}, {})", session, uuid); String qs = "from NodeBase nb1 where nb1.uuid = (select nb2.parent from NodeBase nb2 where nb2.uuid=:uuid)"; Query q = session.createQuery(qs); q.setString("uuid", uuid); NodeBase parentNode = (NodeBase) q.setMaxResults(1).uniqueResult(); log.debug("getParentNode: {}", parentNode); return parentNode; }
From source file:com.ikon.dao.NodeBaseDAO.java
License:Open Source License
/** * Get result node count./*from w w w . ja v a 2s. co m*/ * * @see com.ikon.module.db.DbStatsModule */ public long getCount(String nodeType) throws PathNotFoundException, DatabaseException { log.debug("getCount({})", new Object[] { nodeType }); String qs = "select count(*) from " + nodeType + " nt"; Session session = null; Transaction tx = null; long total = 0; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Query q = session.createQuery(qs); total = (Long) q.setMaxResults(1).uniqueResult(); HibernateUtil.commit(tx); log.debug("getCount: {}", total); return total; } 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
/** * Find by pk and optionally initialize node property groups *//* www . j a v a 2 s .c o m*/ public NodeDocument findByPk(String uuid, boolean initPropGroups) throws PathNotFoundException, DatabaseException { log.debug("findByPk({}, {})", uuid, initPropGroups); String qs = "from NodeDocument nd where nd.uuid=:uuid"; Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs); q.setString("uuid", uuid); NodeDocument nDoc = (NodeDocument) q.setMaxResults(1).uniqueResult(); if (nDoc == null) { throw new PathNotFoundException(uuid); } // Security Check SecurityHelper.checkRead(nDoc); initialize(nDoc, initPropGroups); log.debug("findByPk: {}", nDoc); return nDoc; } 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./* ww w .j a v a 2s . c o 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
/** * Get pending extraction queue//from w w w.j a va 2 s. 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 { 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); } }
From source file:com.ikon.dao.NodeDocumentDAO.java
License:Open Source License
/** * Get pending extraction size//from w w w .java 2 s.c o m */ public long getPendingExtractionSize() throws DatabaseException { log.debug("getPendingExtractionSize()"); String qs = "select coalesce(count(*), 0) from NodeDocument nd where nd.textExtracted=:extracted"; Session session = null; Transaction tx = null; long total = 0; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Query q = session.createQuery(qs); q.setBoolean("extracted", false); total = (Long) q.setMaxResults(1).uniqueResult(); HibernateUtil.commit(tx); log.debug("getPendingExtractionSize: {}", total); return total; } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.ikon.dao.NodeDocumentVersionDAO.java
License:Open Source License
/** * Find current document version//from w w w . ja va 2 s . c o m */ public NodeDocumentVersion findCurrentVersion(Session session, String docUuid) throws HibernateException { log.debug("findCurrentVersion({})", docUuid); String qs = "from NodeDocumentVersion ndv where ndv.parent=:parent and ndv.current=:current"; Query q = session.createQuery(qs); q.setString("parent", docUuid); q.setBoolean("current", true); NodeDocumentVersion currentVersion = (NodeDocumentVersion) q.setMaxResults(1).uniqueResult(); return currentVersion; }