List of usage examples for org.hibernate Session load
void load(Object object, Serializable id);
From source file:com.ikon.dao.NodeBaseDAO.java
License:Open Source License
/** * Add property group//from ww w .j a v a 2s .co m */ public void addPropertyGroup(String uuid, String grpName) throws PathNotFoundException, AccessDeniedException, RepositoryException, DatabaseException { log.info("addPropertyGroup({}, {})", uuid, grpName); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check NodeBase node = (NodeBase) session.load(NodeBase.class, uuid); SecurityHelper.checkRead(node); SecurityHelper.checkWrite(node); RegisteredPropertyGroup rpg = (RegisteredPropertyGroup) session.get(RegisteredPropertyGroup.class, grpName); if (rpg != null) { for (String propName : rpg.getProperties().keySet()) { NodeProperty nodProp = new NodeProperty(); nodProp.setNode(node); nodProp.setGroup(rpg.getName()); nodProp.setName(propName); boolean alreadyAssigned = false; for (NodeProperty np : node.getProperties()) { if (np.getGroup().equals(nodProp.getGroup()) && np.getName().equals(nodProp.getName())) { alreadyAssigned = true; break; } } if (!alreadyAssigned) { node.getProperties().add(nodProp); } } } else { HibernateUtil.rollback(tx); throw new RepositoryException("Property Group not registered: " + grpName); } session.update(node); HibernateUtil.commit(tx); log.debug("addPropertyGroup: 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.NodeBaseDAO.java
License:Open Source License
/** * Remove property group/*from w w w . ja v a 2 s . c om*/ */ public void removePropertyGroup(String uuid, String grpName) throws PathNotFoundException, AccessDeniedException, DatabaseException { log.debug("removePropertyGroup({}, {})", uuid, grpName); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check NodeBase node = (NodeBase) session.load(NodeBase.class, uuid); SecurityHelper.checkRead(node); SecurityHelper.checkWrite(node); for (Iterator<NodeProperty> it = node.getProperties().iterator(); it.hasNext();) { NodeProperty nodProp = it.next(); if (grpName.equals(nodProp.getGroup())) { it.remove(); session.delete(nodProp); } } session.update(node); HibernateUtil.commit(tx); log.debug("removePropertyGroup: 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.NodeBaseDAO.java
License:Open Source License
/** * Get assigned property groups/*from ww w.j a v a 2 s. c om*/ */ @SuppressWarnings("unchecked") public List<String> getPropertyGroups(String uuid) throws PathNotFoundException, DatabaseException { log.debug("getPropertyGroups({}, {})", uuid); String qs = "select distinct(nbp.group) from NodeBase nb join nb.properties nbp where nb.uuid=:uuid"; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check NodeBase node = (NodeBase) session.load(NodeBase.class, uuid); SecurityHelper.checkRead(node); Query q = session.createQuery(qs); q.setString("uuid", uuid); List<String> ret = q.list(); HibernateUtil.commit(tx); log.debug("getPropertyGroups: {}", 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.NodeBaseDAO.java
License:Open Source License
/** * Get properties from property group//from w ww . j ava2 s .c o m */ public Map<String, String> getProperties(String uuid, String grpName) throws PathNotFoundException, DatabaseException { log.debug("getProperties({}, {})", uuid, grpName); Map<String, String> ret = new HashMap<String, String>(); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check NodeBase node = (NodeBase) session.load(NodeBase.class, uuid); SecurityHelper.checkRead(node); for (NodeProperty nodProp : node.getProperties()) { if (grpName.equals(nodProp.getGroup())) { ret.put(nodProp.getName(), nodProp.getValue()); } } HibernateUtil.commit(tx); log.debug("getProperties: {}", 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.NodeBaseDAO.java
License:Open Source License
/** * Get single property value from property group *//*from w ww . jav a 2s .com*/ public String getProperty(String uuid, String grpName, String propName) throws PathNotFoundException, DatabaseException { log.debug("getProperty({}, {}, {})", new Object[] { uuid, grpName, propName }); String propValue = null; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check NodeBase node = (NodeBase) session.load(NodeBase.class, uuid); SecurityHelper.checkRead(node); for (NodeProperty nodProp : node.getProperties()) { if (grpName.equals(nodProp.getGroup()) && propName.equals(nodProp.getName())) { propValue = nodProp.getValue(); break; } } HibernateUtil.commit(tx); log.debug("getProperty: {}", propValue); return propValue; } 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.NodeBaseDAO.java
License:Open Source License
/** * Set properties from property group/*from ww w .ja va2s.c o m*/ */ public Map<String, String> setProperties(String uuid, String grpName, Map<String, String> properties) throws PathNotFoundException, AccessDeniedException, RepositoryException, DatabaseException { log.debug("setProperties({}, {}, {})", new Object[] { uuid, grpName, properties }); Map<String, String> ret = new HashMap<String, String>(); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check NodeBase node = (NodeBase) session.load(NodeBase.class, uuid); SecurityHelper.checkRead(node); SecurityHelper.checkWrite(node); Set<NodeProperty> tmp = new HashSet<NodeProperty>(); for (Entry<String, String> prop : properties.entrySet()) { boolean alreadyAssigned = false; // Set new property group values for (NodeProperty nodProp : node.getProperties()) { if (grpName.equals(nodProp.getGroup())) { if (prop.getKey().equals(nodProp.getName())) { log.debug("UPDATE - Group: {}, Property: {}, Value: {}", new Object[] { grpName, prop.getKey(), prop.getValue() }); nodProp.setValue(prop.getValue()); alreadyAssigned = true; // TODO: Workaround for Hibernate Search tmp.add(nodProp); } } } if (!alreadyAssigned) { log.debug("ADD - Group: {}, Property: {}, Value: {}", new Object[] { grpName, prop.getKey(), prop.getValue() }); NodeProperty nodProp = new NodeProperty(); nodProp.setNode(node); nodProp.setGroup(grpName); nodProp.setName(prop.getKey()); nodProp.setValue(prop.getValue()); // TODO: Workaround for Hibernate Search tmp.add(nodProp); } } node.setProperties(tmp); session.update(node); HibernateUtil.commit(tx); log.debug("setProperties: {}", 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.ikon.dao.NodeDocumentDAO.java
License:Open Source License
/** * Create document and first version/*from www. java 2 s.c om*/ */ public NodeDocumentVersion create(NodeDocument nDoc, InputStream is, long size) throws PathNotFoundException, AccessDeniedException, ItemExistsException, DatabaseException, IOException { log.debug("create({}, {}, {})", new Object[] { nDoc, is, size }); Session session = null; Transaction tx = null; NodeDocumentVersion newDocVer = new NodeDocumentVersion(); try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check NodeBase parentNode = (NodeBase) session.load(NodeBase.class, nDoc.getParent()); SecurityHelper.checkRead(parentNode); SecurityHelper.checkWrite(parentNode); // Check for same document name in same folder NodeBaseDAO.getInstance().checkItemExistence(session, nDoc.getParent(), nDoc.getName()); // Create first document version VersionNumerationAdapter verNumAdapter = VersionNumerationFactory.getVersionNumerationAdapter(); newDocVer.setUuid(UUID.randomUUID().toString()); newDocVer.setParent(nDoc.getUuid()); newDocVer.setName(verNumAdapter.getInitialVersionNumber()); newDocVer.setAuthor(nDoc.getAuthor()); newDocVer.setCurrent(true); newDocVer.setCreated(nDoc.getCreated()); newDocVer.setSize(size); newDocVer.setMimeType(nDoc.getMimeType()); // Persist file in datastore FsDataStore.persist(newDocVer, is); session.save(nDoc); session.save(newDocVer); HibernateUtil.commit(tx); log.debug("create: {}", newDocVer); return newDocVer; } 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 (HibernateException e) { HibernateUtil.rollback(tx); // What happen when create fails? This datastore file should be deleted! FsDataStore.delete(newDocVer.getUuid()); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.ikon.dao.NodeDocumentDAO.java
License:Open Source License
/** * Find by parent//ww w. ja v a2 s. com */ @SuppressWarnings("unchecked") public List<NodeDocument> findByParent(String parentUuid) throws PathNotFoundException, DatabaseException { log.debug("findByParent({})", parentUuid); String qs = "from NodeDocument nd where nd.parent=:parent order by nd.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<NodeDocument> 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.NodeDocumentDAO.java
License:Open Source License
/** * Search nodes by category//from w w w. j a v a 2 s. c o m */ @SuppressWarnings("unchecked") public List<NodeDocument> findByCategory(String catUuid) throws PathNotFoundException, DatabaseException { log.debug("findByCategory({})", catUuid); final String qs = "from NodeDocument nd where :category in elements(nd.categories) order by nd.name"; List<NodeDocument> ret = new ArrayList<NodeDocument>(); 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.NodeDocumentDAO.java
License:Open Source License
/** * Check if folder has children//from w ww . j a va 2s . c o m */ @SuppressWarnings("unchecked") public boolean hasChildren(String parentUuid) throws PathNotFoundException, DatabaseException { log.debug("hasChildren({})", parentUuid); String qs = "from NodeDocument nd where nd.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); } }