List of usage examples for org.hibernate Query setBoolean
@Deprecated @SuppressWarnings("unchecked") default Query<R> setBoolean(String name, boolean val)
From source file:com.openkm.dao.NodeDocumentDAO.java
License:Open Source License
/** * Get pending extraction size//from w w w . ja va2 s .co 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 { long begin = System.currentTimeMillis(); 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); SystemProfiling.log(null, System.currentTimeMillis() - begin); log.trace("getPendingExtractionSize.Time: {}", System.currentTimeMillis() - begin); 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.openkm.dao.NodeDocumentDAO.java
License:Open Source License
/** * Check if text has been already extracted. *///from w ww.j a va2 s. c o m public boolean isTextExtracted(String uuid) throws DatabaseException { log.debug("isTextExtracted()"); String qs = "from NodeDocument nd where nd.uuid=:uuid and 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.setString("uuid", uuid); q.setBoolean("extracted", true); ret = q.iterate().hasNext(); HibernateUtil.commit(tx); log.debug("isTextExtracted: {}", 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
/** * Cancel checkout and delete temporal file. *///w w w .j a v a2 s . c o m public void liveEditCancelCheckout(String user, String uuid, boolean force) throws PathNotFoundException, AccessDeniedException, LockException, DatabaseException { log.debug("liveEditCancelCheckout({}, {}, {})", new Object[] { user, uuid, force }); String qs = "from NodeDocumentVersion ndv where ndv.parent=:parent and ndv.current=:current"; Session session = null; Transaction tx = null; File tmpFile = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check NodeDocument nDoc = (NodeDocument) session.load(NodeDocument.class, uuid); SecurityHelper.checkRead(nDoc); SecurityHelper.checkWrite(nDoc); Query q = session.createQuery(qs); q.setString("parent", uuid); q.setBoolean("current", true); NodeDocumentVersion curDocVersion = (NodeDocumentVersion) q.setMaxResults(1).uniqueResult(); // Delete temporal file tmpFile = FsDataStore.resolveFile(curDocVersion.getUuid() + ".tmp"); if (tmpFile.exists()) { FileUtils.deleteQuietly(tmpFile); } nDoc.setCheckedOut(false); unlock(user, nDoc, force); session.update(nDoc); HibernateUtil.commit(tx); log.debug("cancelCheckout: void"); } catch (PathNotFoundException e) { HibernateUtil.rollback(tx); throw e; } catch (AccessDeniedException e) { HibernateUtil.rollback(tx); throw e; } catch (LockException 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.openkm.dao.NodeDocumentVersionDAO.java
License:Open Source License
/** * Find current document version/*from ww w . j a v a 2 s. com*/ */ 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).setCacheable(true); q.setString("parent", docUuid); q.setBoolean("current", true); NodeDocumentVersion currentVersion = (NodeDocumentVersion) q.setMaxResults(1).uniqueResult(); return currentVersion; }
From source file:com.openkm.dao.NodeDocumentVersionDAO.java
License:Open Source License
/** * Get document version content//from www .j av a2 s. co m * * @param docUuid Id of the document to get the content. * @param extendedSecurity If the extended security DOWNLOAD permission should be evaluated. * This is used to enable the document preview. */ public InputStream getCurrentContentByParent(String docUuid, boolean extendedSecurity) throws PathNotFoundException, AccessDeniedException, DatabaseException, FileNotFoundException, IOException { log.debug("getContent({}, {})", docUuid, extendedSecurity); 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); if (extendedSecurity) { if ((Config.SECURITY_EXTENDED_MASK & Permission.DOWNLOAD) == Permission.DOWNLOAD) { SecurityHelper.checkExtended(nDoc, Permission.DOWNLOAD); } } Query q = session.createQuery(qs); q.setString("parent", docUuid); q.setBoolean("current", true); NodeDocumentVersion nDocVer = (NodeDocumentVersion) q.setMaxResults(1).uniqueResult(); if (nDocVer != null) { if (FsDataStore.DATASTORE_BACKEND_FS.equals(Config.REPOSITORY_DATASTORE_BACKEND)) { ret = FsDataStore.read(nDocVer.getUuid()); } else { ret = new ByteArrayInputStream(nDocVer.getContent()); } } else { throw new DatabaseException("Document version content not found for: " + docUuid); } HibernateUtil.commit(tx); log.debug("getContent: {}", ret); return ret; } 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 (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.openkm.dao.NodeDocumentVersionDAO.java
License:Open Source License
/** * Create or update dummy version/*from ww w . j ava2 s .co m*/ */ public NodeDocumentVersion checkin(String user, String comment, String docUuid, InputStream is, long size, int increment) throws IOException, PathNotFoundException, AccessDeniedException, LockException, DatabaseException { log.debug("checkin({}, {}, {}, {}, {}, {})", new Object[] { user, comment, docUuid, is, size, increment }); 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, increment); // 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(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.openkm.dao.NodeDocumentVersionDAO.java
License:Open Source License
/** * Set a document version as current./*from ww w .j a va 2 s .c o 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); if ((Config.SECURITY_EXTENDED_MASK & Permission.COMPACT_HISTORY) == Permission.COMPACT_HISTORY) { SecurityHelper.checkExtended(nDoc, Permission.COMPACT_HISTORY); } // 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.openkm.dao.NodeDocumentVersionDAO.java
License:Open Source License
/** * Purge all non-current document version history nodes *///from ww w.j a v a 2 s . c o 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 order by ndv.created"; 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); if ((Config.SECURITY_EXTENDED_MASK & Permission.COMPACT_HISTORY) == Permission.COMPACT_HISTORY) { SecurityHelper.checkExtended(nDoc, Permission.COMPACT_HISTORY); } // 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()); } // And delete version session.delete(nDocVer); // Update user items size if (Config.USER_ITEM_CACHE) { UserItemsManager.decSize(author, size); } HibernateUtil.commit(tx); tx = session.beginTransaction(); } 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.openkm.dao.NodeDocumentVersionDAO.java
License:Open Source License
/** * Set temporal version content./*from ww w . ja v a 2 s . co m*/ */ public void liveEditSetContent(String docUuid, InputStream is, long size) throws IOException, PathNotFoundException, AccessDeniedException, LockException, DatabaseException { log.debug("liveEditSetContent({}, {}, {})", 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); // Persist temporal version content NodeDocumentVersion curDocVersion = (NodeDocumentVersion) q.setMaxResults(1).uniqueResult(); FsDataStore.save(curDocVersion.getUuid() + ".tmp", is); HibernateUtil.commit(tx); log.debug("liveEditSetContent: 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.openkm.dao.NodeDocumentVersionDAO.java
License:Open Source License
/** * Create new version from temporal file. *///w w w .j ava2 s . c o m public NodeDocumentVersion liveEditCheckin(String user, String comment, int increment, String docUuid) throws IOException, PathNotFoundException, AccessDeniedException, LockException, DatabaseException { log.debug("liveEditCheckin({}, {}, {})", new Object[] { user, comment, docUuid }); String qs = "from NodeDocumentVersion ndv where ndv.parent=:parent and ndv.current=:current"; NodeDocumentVersion newDocVersion = new NodeDocumentVersion(); Session session = null; Transaction tx = null; FileInputStream is = null; File tmpFile = 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); NodeDocumentVersion curDocVersion = (NodeDocumentVersion) q.setMaxResults(1).uniqueResult(); VersionNumerationAdapter verNumAdapter = VersionNumerationFactory.getVersionNumerationAdapter(); String nextVersionNumber = verNumAdapter.getNextVersionNumber(session, nDoc, curDocVersion, increment); // 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.setMimeType(curDocVersion.getMimeType()); newDocVersion.setPrevious(curDocVersion.getUuid()); // Persist file in datastore tmpFile = FsDataStore.resolveFile(curDocVersion.getUuid() + ".tmp"); if (tmpFile.exists()) { newDocVersion.setSize(tmpFile.length()); is = new FileInputStream(tmpFile); FsDataStore.persist(newDocVersion, is); FileUtils.deleteQuietly(tmpFile); } else { // When there is no file uploaded from applet and user perform checkin newDocVersion.setSize(curDocVersion.getSize()); newDocVersion.setChecksum(curDocVersion.getChecksum()); FsDataStore.copy(curDocVersion, newDocVersion); } 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(user, nDoc, false); session.update(nDoc); HibernateUtil.commit(tx); log.debug("liveEditCheckin: {}", 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 { IOUtils.closeQuietly(is); HibernateUtil.close(session); } }