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

License:Open Source License

/**
 * Rename document/*from  w w w . ja v  a2 s . c o  m*/
 */
public NodeDocument rename(String uuid, String newName) throws PathNotFoundException, AccessDeniedException,
        ItemExistsException, LockException, 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);
        NodeDocument nDoc = (NodeDocument) session.load(NodeDocument.class, uuid);
        SecurityHelper.checkRead(nDoc);
        SecurityHelper.checkWrite(nDoc);

        // Lock Check
        LockHelper.checkWriteLock(nDoc);

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

        nDoc.setName(newName);
        session.update(nDoc);
        initialize(nDoc, false);
        HibernateUtil.commit(tx);
        log.debug("rename: {}", nDoc);
        return nDoc;
    } catch (PathNotFoundException e) {
        HibernateUtil.rollback(tx);
        throw e;
    } catch (AccessDeniedException e) {
        HibernateUtil.rollback(tx);
        throw e;
    } catch (LockException 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.NodeDocumentDAO.java

License:Open Source License

/**
 * Move document/*from w  w w. j  av a 2  s .c o m*/
 */
public void move(String uuid, String dstUuid) throws PathNotFoundException, AccessDeniedException,
        ItemExistsException, LockException, 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);
        NodeDocument nDoc = (NodeDocument) session.load(NodeDocument.class, uuid);
        SecurityHelper.checkRead(nDoc);
        SecurityHelper.checkWrite(nDoc);

        // Lock Check
        LockHelper.checkWriteLock(nDoc);

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

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

        nDoc.setParent(dstUuid);
        session.update(nDoc);
        HibernateUtil.commit(tx);
        log.debug("move: void");
    } catch (PathNotFoundException e) {
        HibernateUtil.rollback(tx);
        throw e;
    } catch (AccessDeniedException e) {
        HibernateUtil.rollback(tx);
        throw e;
    } catch (LockException 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.NodeDocumentDAO.java

License:Open Source License

/**
 * Delete document/*  w w  w.  j a v  a  2 s  . c  om*/
 */
public void delete(String name, String uuid, String trashUuid, String docPath)
        throws PathNotFoundException, AccessDeniedException, LockException, 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);
        NodeDocument nDoc = (NodeDocument) session.load(NodeDocument.class, uuid);
        SecurityHelper.checkRead(nDoc);
        SecurityHelper.checkWrite(nDoc);

        // Lock Check
        LockHelper.checkWriteLock(nDoc);

        // Test if already exists a document with the same name in the trash
        String fileName = com.ikon.util.FileUtils.getFileName(name);
        String fileExtension = com.ikon.util.FileUtils.getFileExtension(name);
        String testName = name;

        for (int i = 1; NodeBaseDAO.getInstance().testItemExistence(session, trashUuid, testName); i++) {
            // log.info("Trying with: {}", testName);
            testName = fileName + " (" + i + ")." + fileExtension;
        }

        nDoc.setContext(nTrashFld.getContext());
        nDoc.setParent(trashUuid);
        nDoc.setName(testName);
        nDoc.setNbsOriginalPath(docPath);
        session.update(nDoc);
        HibernateUtil.commit(tx);
        log.debug("delete: void");
    } catch (PathNotFoundException e) {
        HibernateUtil.rollback(tx);
        throw e;
    } catch (AccessDeniedException e) {
        HibernateUtil.rollback(tx);
        throw e;
    } catch (LockException 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

/**
 * Checkout//  w w w . j  av a2 s  .  c om
 */
public void checkout(String user, String uuid)
        throws PathNotFoundException, AccessDeniedException, LockException, DatabaseException {
    log.debug("checkout({})", uuid);
    Session session = null;
    Transaction tx = null;

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

        // Security Check
        NodeDocument nDoc = (NodeDocument) session.load(NodeDocument.class, uuid);
        SecurityHelper.checkRead(nDoc);
        SecurityHelper.checkWrite(nDoc);

        nDoc.setCheckedOut(true);
        lock(session, user, nDoc);
        session.update(nDoc);
        HibernateUtil.commit(tx);
        log.debug("checkout: void");
    } catch (PathNotFoundException e) {
        HibernateUtil.rollback(tx);
        throw e;
    } catch (AccessDeniedException e) {
        HibernateUtil.rollback(tx);
        throw e;
    } catch (LockException 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

/**
 * Cancel checkout/*from w ww  .  j a va 2s .co m*/
 */
public void cancelCheckout(String user, String uuid, boolean force)
        throws PathNotFoundException, AccessDeniedException, LockException, DatabaseException {
    log.debug("cancelCheckout({}, {}, {})", new Object[] { user, uuid, force });
    Session session = null;
    Transaction tx = null;

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

        // Security Check
        NodeDocument nDoc = (NodeDocument) session.load(NodeDocument.class, uuid);
        SecurityHelper.checkRead(nDoc);
        SecurityHelper.checkWrite(nDoc);

        nDoc.setCheckedOut(false);
        unlock(session, user, nDoc, force);
        session.update(nDoc);
        HibernateUtil.commit(tx);
        log.debug("cancelCheckout: void");
    } catch (PathNotFoundException e) {
        HibernateUtil.rollback(tx);
        throw e;
    } catch (AccessDeniedException e) {
        HibernateUtil.rollback(tx);
        throw e;
    } catch (LockException 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

/**
 * Test for checked out status/*from   w  ww  .  j a  va2 s  . c o  m*/
 */
public boolean isCheckedOut(String uuid) throws PathNotFoundException, DatabaseException {
    log.debug("isCheckedOut({})", uuid);
    Session session = null;

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

        // Security Check
        NodeDocument nDoc = (NodeDocument) session.load(NodeDocument.class, uuid);
        SecurityHelper.checkRead(nDoc);

        boolean checkedOut = nDoc.isCheckedOut();
        log.debug("isCheckedOut: {}", checkedOut);
        return checkedOut;
    } catch (PathNotFoundException e) {
        throw e;
    } catch (HibernateException e) {
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}

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

License:Open Source License

/**
 * Purge in depth//from ww  w . jav a2 s . c om
 */
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();
        NodeDocument nDoc = (NodeDocument) session.load(NodeDocument.class, uuid);
        purgeHelper(session, nDoc);
        HibernateUtil.commit(tx);
        log.debug("purge: void");
    } catch (PathNotFoundException e) {
        HibernateUtil.rollback(tx);
        throw e;
    } catch (AccessDeniedException e) {
        HibernateUtil.rollback(tx);
        throw e;
    } catch (LockException 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.NodeDocumentDAO.java

License:Open Source License

/**
 * Lock node//from  w  ww. j  ava 2 s  .com
 */
public NodeLock lock(String user, String uuid)
        throws PathNotFoundException, AccessDeniedException, LockException, DatabaseException {
    log.debug("lock({}, {})", user, uuid);
    Session session = null;
    Transaction tx = null;

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

        // Security Check
        NodeDocument nDoc = (NodeDocument) session.load(NodeDocument.class, uuid);
        SecurityHelper.checkRead(nDoc);
        SecurityHelper.checkWrite(nDoc);

        lock(session, user, nDoc);
        session.update(nDoc);
        HibernateUtil.commit(tx);
        log.debug("lock: {}", nDoc.getLock());
        return nDoc.getLock();
    } catch (LockException 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

/**
 * Unlock node/*from w w  w . ja v a  2  s. c o  m*/
 */
public void unlock(String user, String uuid, boolean force)
        throws PathNotFoundException, AccessDeniedException, DatabaseException, LockException {
    log.debug("unlock({}, {}, {})", new Object[] { user, uuid, force });
    Session session = null;
    Transaction tx = null;

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

        // Security Check
        NodeDocument nDoc = (NodeDocument) session.load(NodeDocument.class, uuid);
        SecurityHelper.checkRead(nDoc);
        SecurityHelper.checkWrite(nDoc);

        unlock(session, user, nDoc, force);
        session.update(nDoc);
        HibernateUtil.commit(tx);
        log.debug("unlock: void");
    } catch (LockException 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

/**
 * Test for locked status/*from   w  ww. j a va  2s.  co  m*/
 */
public boolean isLocked(String uuid) throws PathNotFoundException, DatabaseException {
    log.debug("isLocked({})", uuid);
    Session session = null;

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

        // Security Check
        NodeDocument nDoc = (NodeDocument) session.load(NodeDocument.class, uuid);
        SecurityHelper.checkRead(nDoc);

        boolean locked = nDoc.isLocked();
        log.debug("isLocked: {}", locked);
        return locked;
    } catch (HibernateException e) {
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}