List of usage examples for org.hibernate Session load
void load(Object object, Serializable id);
From source file:com.ikon.dao.NodeDocumentVersionDAO.java
License:Open Source License
/** * Purge all non-current document version history nodes *//* www . j av a2 s . c om*/ @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.NodeFolderDAO.java
License:Open Source License
/** * Create node//from ww w . ja v a 2s.c o m */ public void create(NodeFolder nFolder) throws PathNotFoundException, AccessDeniedException, ItemExistsException, DatabaseException { log.debug("create({})", nFolder); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check NodeBase parentNode = (NodeBase) session.load(NodeBase.class, nFolder.getParent()); SecurityHelper.checkRead(parentNode); SecurityHelper.checkWrite(parentNode); // Check for same folder name in same parent NodeBaseDAO.getInstance().checkItemExistence(session, nFolder.getParent(), nFolder.getName()); session.save(nFolder); HibernateUtil.commit(tx); log.debug("create: void"); } catch (PathNotFoundException e) { HibernateUtil.rollback(tx); throw e; } catch (AccessDeniedException e) { HibernateUtil.rollback(tx); throw e; } catch (ItemExistsException 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.NodeFolderDAO.java
License:Open Source License
/** * Find by parent//from w w w . j a v a2 s . c o m */ @SuppressWarnings("unchecked") public List<NodeFolder> findByParent(String parentUuid) throws PathNotFoundException, DatabaseException { log.debug("findByParent({})", parentUuid); String qs = "from NodeFolder nf where nf.parent=:parent order by nf.name"; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check if (!Config.ROOT_NODE_UUID.equals(parentUuid)) { NodeBase parentNode = (NodeBase) session.load(NodeBase.class, parentUuid); SecurityHelper.checkRead(parentNode); } Query q = session.createQuery(qs); q.setString("parent", parentUuid); List<NodeFolder> ret = q.list(); // Security Check SecurityHelper.pruneNodeList(ret); initialize(ret); HibernateUtil.commit(tx); log.debug("findByParent: {}", 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.NodeFolderDAO.java
License:Open Source License
/** * Search nodes by category/*from ww w .j a va 2 s.c om*/ */ @SuppressWarnings("unchecked") public List<NodeFolder> findByCategory(String catUuid) throws PathNotFoundException, DatabaseException { log.debug("findByCategory({})", catUuid); final String qs = "from NodeFolder nf where :category in elements(nf.categories) order by nf.name"; List<NodeFolder> ret = new ArrayList<NodeFolder>(); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check NodeBase catNode = (NodeBase) session.load(NodeBase.class, catUuid); SecurityHelper.checkRead(catNode); Query q = session.createQuery(qs); q.setString("category", catUuid); ret = q.list(); // Security Check SecurityHelper.pruneNodeList(ret); initialize(ret); HibernateUtil.commit(tx); log.debug("findByCategory: {}", 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.NodeFolderDAO.java
License:Open Source License
/** * Check if folder has childs//from www .j av a 2s . c o m */ @SuppressWarnings("unchecked") public boolean hasChildren(String parentUuid) throws PathNotFoundException, DatabaseException { log.debug("hasChildren({})", parentUuid); String qs = "from NodeFolder nf where nf.parent=:parent"; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check if (!Config.ROOT_NODE_UUID.equals(parentUuid)) { NodeBase parentNode = (NodeBase) session.load(NodeBase.class, parentUuid); SecurityHelper.checkRead(parentNode); } Query q = session.createQuery(qs); q.setString("parent", parentUuid); List<NodeFolder> nodeList = q.list(); // Security Check SecurityHelper.pruneNodeList(nodeList); boolean ret = !nodeList.isEmpty(); HibernateUtil.commit(tx); log.debug("hasChildren: {}", 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.NodeFolderDAO.java
License:Open Source License
/** * Rename folder/*from www . ja v a2s . c om*/ */ public NodeFolder rename(String uuid, String newName) throws PathNotFoundException, AccessDeniedException, ItemExistsException, DatabaseException { log.debug("rename({}, {})", uuid, newName); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check NodeBase parentNode = NodeBaseDAO.getInstance().getParentNode(session, uuid); SecurityHelper.checkRead(parentNode); SecurityHelper.checkWrite(parentNode); NodeFolder nFld = (NodeFolder) session.load(NodeFolder.class, uuid); SecurityHelper.checkRead(nFld); SecurityHelper.checkWrite(nFld); // Check for same folder name in same parent NodeBaseDAO.getInstance().checkItemExistence(session, nFld.getParent(), newName); nFld.setName(newName); session.update(nFld); initialize(nFld); HibernateUtil.commit(tx); log.debug("rename: {}", nFld); return nFld; } catch (PathNotFoundException e) { HibernateUtil.rollback(tx); throw e; } catch (AccessDeniedException e) { HibernateUtil.rollback(tx); throw e; } catch (ItemExistsException 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.NodeFolderDAO.java
License:Open Source License
/** * Move folder//from w w w.j a v a 2s. co m */ public void move(String uuid, String dstUuid) throws PathNotFoundException, AccessDeniedException, ItemExistsException, DatabaseException { log.debug("move({}, {})", uuid, dstUuid); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check NodeFolder nDstFld = (NodeFolder) session.load(NodeFolder.class, dstUuid); SecurityHelper.checkRead(nDstFld); SecurityHelper.checkWrite(nDstFld); NodeFolder nFld = (NodeFolder) session.load(NodeFolder.class, uuid); SecurityHelper.checkRead(nFld); SecurityHelper.checkWrite(nFld); // Check if move to itself if (uuid.equals(dstUuid)) { String dstPath = NodeBaseDAO.getInstance().getPathFromUuid(dstUuid); throw new ItemExistsException(dstPath); } // Check for same folder name in same parent NodeBaseDAO.getInstance().checkItemExistence(session, dstUuid, nFld.getName()); // Check if context changes if (!nDstFld.getContext().equals(nFld.getContext())) { nFld.setContext(nDstFld.getContext()); // Need recursive context changes moveHelper(session, uuid, nDstFld.getContext()); } nFld.setParent(dstUuid); session.update(nFld); HibernateUtil.commit(tx); log.debug("move: void"); } catch (PathNotFoundException e) { HibernateUtil.rollback(tx); throw e; } catch (AccessDeniedException e) { HibernateUtil.rollback(tx); throw e; } catch (ItemExistsException 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.NodeFolderDAO.java
License:Open Source License
/** * Delete folder/* w w w . j a v a 2 s. c o m*/ */ public void delete(String name, String uuid, String trashUuid, String fldPath) throws PathNotFoundException, AccessDeniedException, DatabaseException { log.debug("delete({}, {}, {})", new Object[] { name, uuid, trashUuid }); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check NodeFolder nTrashFld = (NodeFolder) session.load(NodeFolder.class, trashUuid); SecurityHelper.checkRead(nTrashFld); SecurityHelper.checkWrite(nTrashFld); NodeFolder nFld = (NodeFolder) session.load(NodeFolder.class, uuid); SecurityHelper.checkRead(nFld); SecurityHelper.checkWrite(nFld); // Test if already exists a folder with the same name in the trash String testName = name; for (int i = 1; NodeBaseDAO.getInstance().testItemExistence(session, trashUuid, testName); i++) { // log.info("Trying with: {}", testName); testName = name + " (" + i + ")"; } // Need recursive context changes moveHelper(session, uuid, nTrashFld.getContext()); nFld.setContext(nTrashFld.getContext()); nFld.setParent(trashUuid); nFld.setName(testName); nFld.setNbsOriginalPath(fldPath); session.update(nFld); HibernateUtil.commit(tx); log.debug("delete: 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 (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.ikon.dao.NodeFolderDAO.java
License:Open Source License
/** * Get categories from node/*from ww w . j a va2 s . c om*/ */ public Set<NodeFolder> resolveCategories(Set<String> categories) throws DatabaseException { log.debug("resolveCategories({})", categories); Set<NodeFolder> ret = new HashSet<NodeFolder>(); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); DbAccessManager am = SecurityHelper.getAccessManager(); for (String catUuid : categories) { NodeFolder nFld = (NodeFolder) session.load(NodeFolder.class, catUuid); // Security Check if (am.isGranted(nFld, Permission.READ)) { initialize(nFld); ret.add(nFld); } } log.debug("resolveCategories: {}", ret); return ret; } 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.NodeFolderDAO.java
License:Open Source License
/** * Purge in depth. Respect the parameter deleteBase, it means if the node nFolder should be deleted itself. This * parameter is present because this "purge" method is called from NrRepositoryModule.purgeTrash(String token) and * NrFolderModule.purge(String token, String fldPath). *///from ww w .ja va 2s . co m public void purge(String uuid, boolean deleteBase) throws PathNotFoundException, AccessDeniedException, LockException, DatabaseException, IOException { log.debug("purgue({}, {})", uuid, deleteBase); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check NodeFolder nFld = (NodeFolder) session.load(NodeFolder.class, uuid); SecurityHelper.checkRead(nFld); SecurityHelper.checkDelete(nFld); purgeHelper(session, nFld, deleteBase); HibernateUtil.commit(tx); log.debug("purgue: void"); } catch (PathNotFoundException e) { HibernateUtil.rollback(tx); throw e; } catch (AccessDeniedException e) { HibernateUtil.rollback(tx); throw e; } catch (IOException 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); } }