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.NodeDocumentDAO.java
License:Open Source License
/** * Get pending extraction size// w w w .j a v a 2s .c om */ 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 ww. j a v a 2 s .c om*/ */ 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; }
From source file:com.ikon.dao.NodeDocumentVersionDAO.java
License:Open Source License
/** * Get document version content/*from w ww .j ava 2 s. co m*/ * * @param docUuid Id of the document to get the content. * This is used to enable the document preview. */ public InputStream getCurrentContentByParent(String docUuid) throws PathNotFoundException, AccessDeniedException, DatabaseException, FileNotFoundException, IOException { log.debug("getContent({})", docUuid); String qs = "from NodeDocumentVersion ndv where ndv.parent=:parent and ndv.current=:current"; Session session = null; Transaction tx = null; InputStream ret = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check NodeDocument nDoc = (NodeDocument) session.load(NodeDocument.class, docUuid); SecurityHelper.checkRead(nDoc); Query q = session.createQuery(qs); q.setString("parent", docUuid); q.setBoolean("current", true); NodeDocumentVersion nDocVer = (NodeDocumentVersion) q.setMaxResults(1).uniqueResult(); if (FsDataStore.DATASTORE_BACKEND_FS.equals(Config.REPOSITORY_DATASTORE_BACKEND)) { ret = FsDataStore.read(nDocVer.getUuid()); } else { ret = new ByteArrayInputStream(nDocVer.getContent()); } HibernateUtil.commit(tx); log.debug("getContent: {}", ret); return ret; } catch (PathNotFoundException e) { HibernateUtil.rollback(tx); throw e; } catch (DatabaseException e) { HibernateUtil.rollback(tx); throw e; } 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
/** * Create or update dummy version/*w w w. j a v a2s .c o m*/ */ public NodeDocumentVersion checkin(String user, String comment, String docUuid, InputStream is, long size) throws IOException, PathNotFoundException, AccessDeniedException, LockException, DatabaseException { log.debug("checkin({}, {}, {}, {}, {})", new Object[] { user, comment, docUuid, is, size }); String qs = "from NodeDocumentVersion ndv where ndv.parent=:parent and ndv.current=:current"; NodeDocumentVersion newDocVersion = new NodeDocumentVersion(); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check NodeDocument nDoc = (NodeDocument) session.load(NodeDocument.class, docUuid); SecurityHelper.checkRead(nDoc); SecurityHelper.checkWrite(nDoc); // Lock Check LockHelper.checkWriteLock(user, nDoc); Query q = session.createQuery(qs); q.setString("parent", docUuid); q.setBoolean("current", true); NodeDocumentVersion curDocVersion = (NodeDocumentVersion) q.setMaxResults(1).uniqueResult(); VersionNumerationAdapter verNumAdapter = VersionNumerationFactory.getVersionNumerationAdapter(); String nextVersionNumber = verNumAdapter.getNextVersionNumber(session, nDoc, curDocVersion); // Make current version obsolete curDocVersion.setCurrent(false); session.update(curDocVersion); // New document version newDocVersion.setUuid(UUID.randomUUID().toString()); newDocVersion.setParent(docUuid); newDocVersion.setName(nextVersionNumber); newDocVersion.setAuthor(user); newDocVersion.setComment(comment); newDocVersion.setCurrent(true); newDocVersion.setCreated(Calendar.getInstance()); newDocVersion.setSize(size); newDocVersion.setMimeType(curDocVersion.getMimeType()); newDocVersion.setPrevious(curDocVersion.getUuid()); // Persist file in datastore FsDataStore.persist(newDocVersion, is); session.save(newDocVersion); // Set document checkout status to false nDoc.setLastModified(newDocVersion.getCreated()); nDoc.setCheckedOut(false); // Text extraction nDoc.setText(""); nDoc.setTextExtracted(false); // Remove lock NodeDocumentDAO.getInstance().unlock(session, user, nDoc, false); session.update(nDoc); HibernateUtil.commit(tx); log.debug("checkin: {}", newDocVersion); return newDocVersion; } catch (PathNotFoundException e) { HibernateUtil.rollback(tx); throw e; } catch (AccessDeniedException e) { HibernateUtil.rollback(tx); throw e; } catch (DatabaseException e) { HibernateUtil.rollback(tx); throw e; } catch (LockException e) { HibernateUtil.rollback(tx); throw e; } catch (HibernateException e) { HibernateUtil.rollback(tx); // What happen when create fails? This datastore file should be deleted! FsDataStore.delete(newDocVersion.getUuid()); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.ikon.dao.NodeDocumentVersionDAO.java
License:Open Source License
/** * Set version content.//from www .ja v a2s . c o m */ public void setContent(String docUuid, InputStream is, long size) throws IOException, PathNotFoundException, AccessDeniedException, LockException, DatabaseException { log.debug("setContent({}, {}, {})", new Object[] { docUuid, is, size }); String qs = "from NodeDocumentVersion ndv where ndv.parent=:parent and ndv.current=:current"; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check NodeDocument nDoc = (NodeDocument) session.load(NodeDocument.class, docUuid); SecurityHelper.checkRead(nDoc); SecurityHelper.checkWrite(nDoc); // Lock Check LockHelper.checkWriteLock(nDoc); Query q = session.createQuery(qs); q.setString("parent", docUuid); q.setBoolean("current", true); // Text extraction nDoc.setText(""); nDoc.setTextExtracted(false); session.update(nDoc); // Update version content NodeDocumentVersion curDocVersion = (NodeDocumentVersion) q.setMaxResults(1).uniqueResult(); curDocVersion.setText(""); curDocVersion.setSize(size); session.update(curDocVersion); // Persist file in datastore FsDataStore.persist(curDocVersion, is); HibernateUtil.commit(tx); log.debug("setContent: void"); } catch (PathNotFoundException e) { HibernateUtil.rollback(tx); throw e; } catch (AccessDeniedException e) { HibernateUtil.rollback(tx); throw e; } catch (DatabaseException e) { HibernateUtil.rollback(tx); throw e; } catch (LockException e) { HibernateUtil.rollback(tx); throw e; } 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
/** * Set a document version as current.// www.j a v a 2s .co m */ public void restoreVersion(String docUuid, String versionId) throws PathNotFoundException, AccessDeniedException, LockException, DatabaseException { log.debug("restoreVersion({}, {})", new Object[] { docUuid, versionId }); String qsCurrent = "from NodeDocumentVersion ndv where ndv.parent=:parent and ndv.current=:current"; String qsName = "from NodeDocumentVersion ndv where ndv.parent=:parent and ndv.name=:name"; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check NodeDocument nDoc = (NodeDocument) session.load(NodeDocument.class, docUuid); SecurityHelper.checkRead(nDoc); SecurityHelper.checkWrite(nDoc); // Lock Check LockHelper.checkWriteLock(nDoc); Query qCurrent = session.createQuery(qsCurrent); qCurrent.setString("parent", docUuid); qCurrent.setBoolean("current", true); Query qName = session.createQuery(qsName); qName.setString("parent", docUuid); qName.setString("name", versionId); // Update current version NodeDocumentVersion curDocVersion = (NodeDocumentVersion) qCurrent.setMaxResults(1).uniqueResult(); NodeDocumentVersion namDocVersion = (NodeDocumentVersion) qName.setMaxResults(1).uniqueResult(); curDocVersion.setCurrent(false); namDocVersion.setCurrent(true); session.update(namDocVersion); session.update(curDocVersion); // Text extraction nDoc.setText(namDocVersion.getText()); session.update(nDoc); HibernateUtil.commit(tx); log.debug("restoreVersion: void"); } catch (PathNotFoundException e) { HibernateUtil.rollback(tx); throw e; } catch (AccessDeniedException e) { HibernateUtil.rollback(tx); throw e; } catch (DatabaseException e) { HibernateUtil.rollback(tx); throw e; } catch (LockException e) { HibernateUtil.rollback(tx); throw e; } 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
/** * Purge all non-current document version history nodes *///w ww. jav a2 s . co m @SuppressWarnings("unchecked") public void purgeVersionHistory(String docUuid) throws PathNotFoundException, AccessDeniedException, LockException, IOException, DatabaseException { log.debug("purgeVersionHistory({})", docUuid); String qs = "from NodeDocumentVersion ndv where ndv.parent=:parent and ndv.current=:current"; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check NodeDocument nDoc = (NodeDocument) session.load(NodeDocument.class, docUuid); SecurityHelper.checkRead(nDoc); SecurityHelper.checkWrite(nDoc); // Lock Check LockHelper.checkWriteLock(nDoc); Query q = session.createQuery(qs); q.setString("parent", docUuid); q.setBoolean("current", false); // Remove non-current version nodes for (NodeDocumentVersion nDocVer : (List<NodeDocumentVersion>) q.list()) { String author = nDocVer.getAuthor(); long size = nDocVer.getSize(); if (FsDataStore.DATASTORE_BACKEND_FS.equals(Config.REPOSITORY_DATASTORE_BACKEND)) { FsDataStore.delete(nDocVer.getUuid()); } session.delete(nDocVer); // Update user items size if (Config.USER_ITEM_CACHE) { UserItemsManager.decSize(author, size); } } HibernateUtil.commit(tx); log.debug("purgeVersionHistory: void"); } catch (PathNotFoundException e) { HibernateUtil.rollback(tx); throw e; } catch (AccessDeniedException e) { HibernateUtil.rollback(tx); throw e; } catch (DatabaseException e) { HibernateUtil.rollback(tx); throw e; } catch (LockException e) { HibernateUtil.rollback(tx); throw e; } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.ikon.dao.OmrDAO.java
License:Open Source License
/** * Find all active/*from w ww.ja v a 2 s.co m*/ */ @SuppressWarnings("unchecked") public List<Omr> findAllActive() throws DatabaseException { log.debug("findAll()"); String qs = "from Omr om where om.active=:active order by om.name"; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Query q = session.createQuery(qs).setCacheable(true); q.setBoolean("active", true); List<Omr> 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.ikon.dao.ProfileDAO.java
License:Open Source License
/** * Find by pk/* w w w .j a va2 s. c o m*/ */ @SuppressWarnings("unchecked") public static List<Profile> findAll(boolean filterByActive) throws DatabaseException { log.debug("findAll()"); String qs = "from Profile prf " + (filterByActive ? "where prf.active=:active" : ""); Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs); if (filterByActive) { q.setBoolean("active", true); } List<Profile> 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.TwitterAccountDAO.java
License:Open Source License
/** * Find by user// w w w. ja v a 2 s. c o m */ @SuppressWarnings("unchecked") public static List<TwitterAccount> findByUser(String user, boolean filterByActive) throws DatabaseException { log.debug("findByUser({})", user); String qs = "from TwitterAccount ta where ta.user=:user " + (filterByActive ? "and ta.active=:active" : "") + " order by ta.id"; Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs); q.setString("user", user); if (filterByActive) { q.setBoolean("active", true); } List<TwitterAccount> ret = q.list(); log.debug("findByUser: {}", ret); return ret; } catch (HibernateException e) { throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }