Example usage for org.hibernate Session load

List of usage examples for org.hibernate Session load

Introduction

In this page you can find the example usage for org.hibernate Session load.

Prototype

void load(Object object, Serializable id);

Source Link

Document

Read the persistent state associated with the given identifier into the given transient instance.

Usage

From source file:com.ikon.dao.NodeMailDAO.java

License:Open Source License

/**
 * Create node/*from  www.  j  av a2  s  . co m*/
 */
public void create(NodeMail nMail)
        throws PathNotFoundException, AccessDeniedException, ItemExistsException, DatabaseException {
    log.debug("create({})", nMail);
    Session session = null;
    Transaction tx = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        tx = session.beginTransaction();

        // Security Check
        NodeBase parentNode = (NodeBase) session.load(NodeBase.class, nMail.getParent());
        SecurityHelper.checkRead(parentNode);
        SecurityHelper.checkWrite(parentNode);

        // Check for same mail name in same parent
        NodeBaseDAO.getInstance().checkItemExistence(session, nMail.getParent(), nMail.getName());

        session.save(nMail);
        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.NodeMailDAO.java

License:Open Source License

/**
 * Find by parent/* www . j  a  v  a 2  s.com*/
 */
@SuppressWarnings("unchecked")
public List<NodeMail> findByParent(String parentUuid) throws PathNotFoundException, DatabaseException {
    log.debug("findByParent({})", parentUuid);
    String qs = "from NodeMail nm where nm.parent=:parent order by nm.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<NodeMail> 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.NodeMailDAO.java

License:Open Source License

/**
 * Search nodes by category/*from  www  . ja v a 2s  .co  m*/
 */
@SuppressWarnings("unchecked")
public List<NodeMail> findByCategory(String catUuid) throws PathNotFoundException, DatabaseException {
    log.debug("findByCategory({})", catUuid);
    final String qs = "from NodeMail nm where :category in elements(nm.categories) order by nm.name";
    List<NodeMail> ret = new ArrayList<NodeMail>();
    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.NodeMailDAO.java

License:Open Source License

/**
 * Check if folder has childs//from w w  w.j av a  2s. c o  m
 */
@SuppressWarnings("unchecked")
public boolean hasChildren(String parentUuid) throws PathNotFoundException, DatabaseException {
    log.debug("hasChildren({})", parentUuid);
    String qs = "from NodeMail nm where nm.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.NodeMailDAO.java

License:Open Source License

/**
 * Rename mail/*  w w w  . jav  a2 s  . com*/
 */
public NodeMail 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);
        NodeMail nMail = (NodeMail) session.load(NodeMail.class, uuid);
        SecurityHelper.checkRead(nMail);
        SecurityHelper.checkWrite(nMail);

        // Check for same folder name in same parent
        NodeBaseDAO.getInstance().checkItemExistence(session, nMail.getParent(), newName);

        nMail.setName(newName);
        session.update(nMail);
        initialize(nMail);
        HibernateUtil.commit(tx);
        log.debug("rename: {}", nMail);
        return nMail;
    } 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.NodeMailDAO.java

License:Open Source License

/**
 * Move mail//from ww w. jav a  2 s.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);
        NodeMail nMail = (NodeMail) session.load(NodeMail.class, uuid);
        SecurityHelper.checkRead(nMail);
        SecurityHelper.checkWrite(nMail);

        // Check for same folder name in same parent
        NodeBaseDAO.getInstance().checkItemExistence(session, dstUuid, nMail.getName());

        // Check if context changes
        if (!nDstFld.getContext().equals(nMail.getContext())) {
            nMail.setContext(nDstFld.getContext());

            // Need recursive context changes
            moveHelper(session, uuid, nDstFld.getContext());
        }

        nMail.setParent(dstUuid);
        session.update(nMail);
        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.NodeMailDAO.java

License:Open Source License

/**
 * Delete mail/*from ww w .j a  v  a 2  s .c o  m*/
 */
public void delete(String name, String uuid, String trashUuid)
        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);
        NodeMail nMail = (NodeMail) session.load(NodeMail.class, uuid);
        SecurityHelper.checkRead(nMail);
        SecurityHelper.checkWrite(nMail);

        // Test if already exists a mail 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());

        nMail.setContext(nTrashFld.getContext());
        nMail.setParent(trashUuid);
        nMail.setName(testName);
        session.update(nMail);
        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.NodeMailDAO.java

License:Open Source License

/**
 * Purge in depth//from   w  w w. j a  v  a2  s . c o  m
 */
public void purge(String uuid)
        throws PathNotFoundException, AccessDeniedException, LockException, DatabaseException, IOException {
    log.debug("purge({})", uuid);
    Session session = null;
    Transaction tx = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        tx = session.beginTransaction();

        // Security Check
        NodeMail nMail = (NodeMail) session.load(NodeMail.class, uuid);
        SecurityHelper.checkRead(nMail);
        SecurityHelper.checkDelete(nMail);

        purgeHelper(session, nMail);
        HibernateUtil.commit(tx);
        log.debug("purge: 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);
    }
}

From source file:com.ikon.dao.NodeNoteDAO.java

License:Open Source License

/**
 * Find by parent//from   w ww. j a v  a2  s.  c  o  m
 */
@SuppressWarnings("unchecked")
public List<NodeNote> findByParent(String parentUuid) throws PathNotFoundException, DatabaseException {
    log.debug("findByParent({})", parentUuid);
    String qs = "from NodeNote nn where nn.parent=:parent order by nn.created";
    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);

        Query q = session.createQuery(qs);
        q.setString("parent", parentUuid);
        List<NodeNote> ret = q.list();
        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.NodeNoteDAO.java

License:Open Source License

/**
 * Find by path/*from  w  w w .  j  a v  a 2s .  c  o m*/
 */
public NodeNote findByPk(String uuid) throws PathNotFoundException, DatabaseException {
    log.debug("findByPk({})", uuid);
    Session session = null;
    Transaction tx = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        tx = session.beginTransaction();

        // Security Check
        NodeBase parentNode = getParentNode(session, uuid);
        SecurityHelper.checkRead(parentNode);

        NodeNote ret = (NodeNote) session.load(NodeNote.class, uuid);
        initialize(ret);
        HibernateUtil.commit(tx);
        log.debug("findByPk: {}", 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);
    }
}