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.MimeTypeDAO.java

License:Open Source License

/**
 * Find by pk//from  w  w w .  j  av a 2 s.  c  o m
 */
public static MimeType findByPk(long mtId) throws DatabaseException {
    log.debug("findByPk({})", mtId);
    Session session = null;
    Transaction tx = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        tx = session.beginTransaction();
        MimeType ret = (MimeType) session.load(MimeType.class, mtId);
        Hibernate.initialize(ret);
        HibernateUtil.commit(tx);
        log.debug("findByPk: {}", ret);
        return ret;
    } 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 user permissions//from w ww . j  av  a  2  s  .  c  o  m
 */
public Map<String, Integer> getUserPermissions(String uuid) throws PathNotFoundException, DatabaseException {
    log.debug("getUserPermissions({})", uuid);
    Map<String, Integer> ret = new HashMap<String, Integer>();
    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);

        if (node != null) {
            Hibernate.initialize(ret = node.getUserPermissions());
        }

        HibernateUtil.commit(tx);
        log.debug("getUserPermissions: {}", 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

/**
 * Grant user permissions/*from   w  ww  . j a  v  a 2s. co  m*/
 */
public void grantUserPermissions(String uuid, String user, int permissions, boolean recursive)
        throws PathNotFoundException, AccessDeniedException, DatabaseException {
    log.debug("grantUserPermissions({})", uuid);
    Session session = null;
    Transaction tx = null;

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

        // Root node
        NodeBase node = (NodeBase) session.load(NodeBase.class, uuid);

        if (recursive) {
            int total = grantUserPermissionsInDepth(session, node, user, permissions);
            log.info("grantUserPermissions.Total: {}", total);
        } else {
            grantUserPermissions(session, node, user, permissions, false);
        }

        HibernateUtil.commit(tx);
        log.debug("grantUserPermissions: 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

/**
 * Revoke user permissions// w ww  . j a  va2s .  co  m
 */
public void revokeUserPermissions(String uuid, String user, int permissions, boolean recursive)
        throws PathNotFoundException, AccessDeniedException, DatabaseException {
    log.debug("revokeUserPermissions({})", uuid);
    Session session = null;
    Transaction tx = null;

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

        // Root node
        NodeBase node = (NodeBase) session.load(NodeBase.class, uuid);

        if (recursive) {
            int total = revokeUserPermissionsInDepth(session, node, user, permissions);
            log.info("revokeUserPermissions.Total: {}", total);
        } else {
            revokeUserPermissions(session, node, user, permissions, false);
        }

        HibernateUtil.commit(tx);
        log.debug("revokeUserPermissions: 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 role permissions/*  ww  w  .j  a  v a2s  .  c o  m*/
 */
public Map<String, Integer> getRolePermissions(String uuid) throws PathNotFoundException, DatabaseException {
    log.debug("getRolePermissions({})", uuid);
    Map<String, Integer> ret = new HashMap<String, Integer>();
    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);

        if (node != null) {
            Hibernate.initialize(ret = node.getRolePermissions());
        }

        HibernateUtil.commit(tx);
        log.debug("getRolePermissions: {}", 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

/**
 * Grant role permissions//from  w  w w. j  a v a  2  s . c om
 */
public void grantRolePermissions(String uuid, String role, int permissions, boolean recursive)
        throws PathNotFoundException, AccessDeniedException, DatabaseException {
    log.debug("grantRolePermissions({}, {}, {}, {})", new Object[] { uuid, role, permissions, recursive });
    Session session = null;
    Transaction tx = null;

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

        // Root node
        NodeBase node = (NodeBase) session.load(NodeBase.class, uuid);

        if (recursive) {
            int total = grantRolePermissionsInDepth(session, node, role, permissions);
            log.info("grantRolePermissions.Total: {}", total);
        } else {
            grantRolePermissions(session, node, role, permissions, false);
        }

        HibernateUtil.commit(tx);
        log.debug("grantRolePermissions: 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

/**
 * Revoke role permissions/*from  www  .j  av a  2 s. c o m*/
 */
public void revokeRolePermissions(String uuid, String role, int permissions, boolean recursive)
        throws PathNotFoundException, AccessDeniedException, DatabaseException {
    log.debug("revokeRolePermissions({}, {}, {}, {})", new Object[] { uuid, role, permissions, recursive });
    Session session = null;
    Transaction tx = null;

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

        // Root node
        NodeBase node = (NodeBase) session.load(NodeBase.class, uuid);

        if (recursive) {
            int total = revokeRolePermissionsInDepth(session, node, role, permissions);
            log.info("revokeRolePermissions.Total: {}", total);
        } else {
            revokeRolePermissions(session, node, role, permissions, false);
        }

        HibernateUtil.commit(tx);
        log.debug("revokeRolePermissions: 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

/**
 * Change security of multiples nodes//from   w  w w . ja  va 2 s.  com
 */
public void changeSecurity(String uuid, Map<String, Integer> grantUsers, Map<String, Integer> revokeUsers,
        Map<String, Integer> grantRoles, Map<String, Integer> revokeRoles, boolean recursive)
        throws PathNotFoundException, AccessDeniedException, DatabaseException {
    log.debug("changeSecurity({}, {}, {}, {})",
            new Object[] { uuid, grantUsers, revokeUsers, grantRoles, revokeRoles, recursive });
    Session session = null;
    Transaction tx = null;

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

        // Root node
        NodeBase node = (NodeBase) session.load(NodeBase.class, uuid);

        if (recursive) {
            int total = changeSecurityInDepth(session, node, grantUsers, revokeUsers, grantRoles, revokeRoles);
            log.info("changeSecurity.Total: {}", total);
        } else {
            changeSecurity(session, node, grantUsers, revokeUsers, grantRoles, revokeRoles, false);
        }

        HibernateUtil.commit(tx);
        log.debug("grantRolePermissions: 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

/**
 * Add category to node/* ww w  . ja  va 2  s  .co m*/
 */
public void addCategory(String uuid, String catId)
        throws PathNotFoundException, AccessDeniedException, DatabaseException {
    log.debug("addCategory({}, {})", uuid, catId);
    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);

        if (!node.getCategories().contains(catId)) {
            node.getCategories().add(catId);
        }

        session.update(node);
        HibernateUtil.commit(tx);
        log.debug("addCategory: 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 category from node//from  w ww.ja v  a  2 s  . c o m
 */
public void removeCategory(String uuid, String catId)
        throws PathNotFoundException, AccessDeniedException, DatabaseException {
    log.debug("removeCategory({}, {})", uuid, catId);
    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);

        node.getCategories().remove(catId);
        session.update(node);
        HibernateUtil.commit(tx);
        log.debug("removeCategory: 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);
    }
}