List of usage examples for org.hibernate Session load
void load(Object object, Serializable id);
From source file:com.ikon.dao.ReportDAO.java
License:Open Source License
/** * Delete//from ww w.ja v a 2 s . com */ public static void delete(long rpId) throws DatabaseException { log.debug("delete({})", rpId); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Report rp = (Report) session.load(Report.class, rpId); session.delete(rp); HibernateUtil.commit(tx); } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } log.debug("delete: void"); }
From source file:com.ikon.dao.SearchDAO.java
License:Open Source License
/** * Find by parent in depth/*from w ww . jav a2 s .co m*/ * * TODO This cache should be for every user (no pass through access manager) and cleaned * after a create, move or copy folder operation. */ public List<String> findFoldersInDepth(String parentUuid) throws PathNotFoundException, DatabaseException { log.debug("findFoldersInDepth({})", parentUuid); List<String> ret = null; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check NodeBase parentNode = (NodeBase) session.load(NodeBase.class, parentUuid); SecurityHelper.checkRead(parentNode); ret = findFoldersInDepthHelper(session, parentUuid); HibernateUtil.commit(tx); } 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); } log.debug("findFoldersInDepth: {}", ret); return ret; }
From source file:com.ikon.dao.StapleGroupDAO.java
License:Open Source License
/** * Delete/*from www. j a va2 s .c o m*/ */ public static void delete(int sgId) throws DatabaseException { log.debug("delete({})", sgId); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); StapleGroup sg = (StapleGroup) session.load(StapleGroup.class, sgId); session.delete(sg); HibernateUtil.commit(tx); } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } log.debug("delete: void"); }
From source file:com.ikon.dao.StapleGroupDAO.java
License:Open Source License
/** * Delete/*from www. j a v a 2 s . c om*/ */ public static void deleteStaple(int stId) throws DatabaseException { log.debug("delete({})", stId); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Staple st = (Staple) session.load(Staple.class, stId); session.delete(st); HibernateUtil.commit(tx); } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } log.debug("delete: void"); }
From source file:com.ikon.dao.TwitterAccountDAO.java
License:Open Source License
/** * Delete/*from w ww . j av a 2 s . c o m*/ */ public static void delete(long taId) throws DatabaseException { log.debug("delete({})", taId); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); TwitterAccount ta = (TwitterAccount) session.load(TwitterAccount.class, taId); session.delete(ta); HibernateUtil.commit(tx); } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } log.debug("deleteTwitterAccount: void"); }
From source file:com.ikon.dao.UserConfigDAO.java
License:Open Source License
/** * Delete//from w w w . j a va 2 s . c om */ public static void delete(String user) throws DatabaseException { log.debug("delete({})", user); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); UserConfig uc = (UserConfig) session.load(UserConfig.class, user); session.delete(uc); HibernateUtil.commit(tx); } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } log.debug("delete: void"); }
From source file:com.ikon.dao.UserConfigDAO.java
License:Open Source License
/** * Find by pk/* w w w . j av a 2 s . co m*/ */ public static UserConfig findByPk(String user) throws PathNotFoundException, DatabaseException { log.debug("findByPk({})", user); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); UserConfig ret = (UserConfig) session.get(UserConfig.class, user); if (ret == null) { String repoRootPath = "/" + Repository.ROOT; String repoRootUuid = NodeBaseDAO.getInstance().getUuidFromPath(repoRootPath); NodeFolder nfHome = (NodeFolder) session.load(NodeFolder.class, repoRootUuid); ret = new UserConfig(); String path = NodeBaseDAO.getInstance().getPathFromUuid(session, nfHome.getUuid()); ret.setHomePath(path); ret.setHomeNode(nfHome.getUuid()); ret.setHomeType(Folder.TYPE); ret.setUser(user); ret.setProfile(ProfileDAO.findByPk(1)); session.save(ret); } else { NodeBase nfHome = (NodeBase) session.get(NodeBase.class, ret.getHomeNode()); if (nfHome != null) { String path = NodeBaseDAO.getInstance().getPathFromUuid(session, nfHome.getUuid()); ret.setHomePath(path); ret.setHomeNode(nfHome.getUuid()); if (nfHome instanceof NodeFolder) { ret.setHomeType(Folder.TYPE); } else if (nfHome instanceof NodeDocument) { ret.setHomeType(Document.TYPE); } else if (nfHome instanceof NodeMail) { ret.setHomeType(Mail.TYPE); } session.update(ret); } else { String repoRootPath = "/" + Repository.ROOT; String repoRootUuid = NodeBaseDAO.getInstance().getUuidFromPath(repoRootPath); nfHome = (NodeFolder) session.load(NodeFolder.class, repoRootUuid); String path = NodeBaseDAO.getInstance().getPathFromUuid(session, nfHome.getUuid()); ret.setHomePath(path); ret.setHomeNode(nfHome.getUuid()); ret.setHomeType(Folder.TYPE); session.save(ret); } } HibernateUtil.commit(tx); log.debug("findByPk: {}", ret); return ret; } catch (PathNotFoundException 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.UserItemsDAO.java
License:Open Source License
/** * Remove//from www.ja va 2s.c om */ public static void remove(String user) throws DatabaseException { log.debug("remove({})", user); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); UserItems ui = (UserItems) session.load(UserItems.class, user); session.delete(ui); HibernateUtil.commit(tx); } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } log.debug("remove: void"); }
From source file:com.ikon.dao.UserNodeKeywordsDAO.java
License:Open Source License
/** * Remove//w w w.ja v a 2s.c o m */ public static void remove(int id) throws DatabaseException { log.debug("remove({})", id); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); UserNodeKeywords unk = (UserNodeKeywords) session.load(UserNodeKeywords.class, id); session.delete(unk); HibernateUtil.commit(tx); } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } log.debug("remove: void"); }
From source file:com.ikon.util.impexp.metadata.DbMetadataAdapter.java
License:Open Source License
@Override public void importWithMetadata(String parentPath, VersionMetadata vmd, InputStream is) throws ItemExistsException, RepositoryException, DatabaseException, IOException { log.debug("importWithMetadata({}, {})", vmd, is); VersionNumerationAdapter verNumAdapter = VersionNumerationFactory.getVersionNumerationAdapter(); NodeDocumentVersion nDocVer = new NodeDocumentVersion(); Session session = null; Transaction tx = null;/*ww w. j a v a2 s . c om*/ try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); String user = PrincipalUtils.getUser(); String parentUuid = NodeBaseDAO.getInstance().getUuidFromPath(session, parentPath); NodeDocument parentNode = (NodeDocument) session.load(NodeDocument.class, parentUuid); nDocVer.setParent(parentUuid); nDocVer.setUuid(UUID.randomUUID().toString()); nDocVer.setCurrent(true); NodeDocumentVersion prevDocVer = NodeDocumentVersionDAO.getInstance().findCurrentVersion(session, parentUuid); prevDocVer.setCurrent(false); // Basic if (vmd.getAuthor() != null && !vmd.getAuthor().equals("")) { nDocVer.setAuthor(vmd.getAuthor()); } else { nDocVer.setAuthor(user); } if (vmd.getComment() != null && !vmd.getComment().equals("")) { nDocVer.setComment(vmd.getComment()); } else { nDocVer.setComment("Imported by " + user); } if (vmd.getCreated() != null) { nDocVer.setCreated(vmd.getCreated()); } else { nDocVer.setCreated(Calendar.getInstance()); } if (vmd.getSize() > 0) { nDocVer.setSize(vmd.getSize()); } else { nDocVer.setSize(is.available()); } if (vmd.getMimeType() != null && !vmd.getMimeType().equals("")) { nDocVer.setMimeType(vmd.getMimeType()); } else { nDocVer.setMimeType(parentNode.getMimeType()); } if (vmd.getName() != null && !vmd.getName().equals("")) { nDocVer.setName(vmd.getName()); } else { nDocVer.setName(verNumAdapter.getNextVersionNumber(session, parentNode, nDocVer)); } // Persist file in datastore FsDataStore.persist(nDocVer, is); // Persist session.save(nDocVer); session.save(prevDocVer); HibernateUtil.commit(tx); } catch (HibernateException e) { HibernateUtil.rollback(tx); // What happen when create fails? This datastore file should be deleted! FsDataStore.delete(nDocVer.getUuid()); throw new DatabaseException(e.getMessage(), e); } catch (PathNotFoundException e) { HibernateUtil.rollback(tx); throw new RepositoryException("PathNotFound: " + e.getMessage(), e); } finally { HibernateUtil.close(session); } }