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

License:Open Source License

/**
 * Delete/*from  w  w w . j  av  a2 s .c o  m*/
 */
public static void delete(String id) throws DatabaseException {
    log.debug("delete({})", id);
    Session session = null;
    Transaction tx = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        tx = session.beginTransaction();
        Language lang = (Language) session.load(Language.class, id);
        session.delete(lang);
        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.LanguageDAO.java

License:Open Source License

/**
 * Get all language translations/*  w w w.jav a  2s .  c  om*/
 */
public static Set<Translation> findTransAll(String langId) throws DatabaseException {
    log.debug("findTransAll({})", langId);
    Session session = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        Language lang = (Language) session.load(Language.class, langId);
        Set<Translation> trans = lang.getTranslations();
        log.debug("findTransAll: {}", trans);
        return trans;
    } catch (HibernateException e) {
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}

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

License:Open Source License

/**
 * Delete/*from   ww  w .ja v  a  2 s .  co  m*/
 */
public static void delete(long maId) throws DatabaseException {
    log.debug("delete({})", maId);
    Session session = null;
    Transaction tx = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        tx = session.beginTransaction();
        MailAccount ma = (MailAccount) session.load(MailAccount.class, maId);
        session.delete(ma);
        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.MailAccountDAO.java

License:Open Source License

/**
 * Delete//from  w  ww .  j a va  2  s. com
 */
public static void deleteFilter(long mfId) throws DatabaseException {
    log.debug("deleteFilter({})", mfId);
    Session session = null;
    Transaction tx = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        tx = session.beginTransaction();
        MailFilter mf = (MailFilter) session.load(MailFilter.class, mfId);
        session.delete(mf);
        HibernateUtil.commit(tx);
    } catch (HibernateException e) {
        HibernateUtil.rollback(tx);
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }

    log.debug("deleteFilter: void");
}

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

License:Open Source License

/**
 * Find by pk/*from ww  w.  jav  a 2  s.  c om*/
 */
public static MailFilter findFilterByPk(javax.jcr.Session jcrSession, long mfId)
        throws DatabaseException, RepositoryException {
    log.debug("findFilterByPk({})", mfId);
    Session session = null;
    Transaction tx = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        tx = session.beginTransaction();
        MailFilter ret = (MailFilter) session.load(MailFilter.class, mfId);
        Node node = jcrSession.getNodeByUUID(ret.getNode());

        // Always keep path in sync with uuid
        if (!node.getPath().equals(ret.getPath())) {
            ret.setPath(node.getPath());
            session.update(ret);
        }

        HibernateUtil.commit(tx);
        log.debug("findFilterByPk: {}", ret);
        return ret;
    } catch (javax.jcr.RepositoryException e) {
        HibernateUtil.rollback(tx);
        throw new RepositoryException(e.getMessage(), e);
    } catch (HibernateException e) {
        HibernateUtil.rollback(tx);
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}

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

License:Open Source License

/**
 * Find by pk/*from   w  w w  .  j  a v  a  2s  . c  o m*/
 */
public static MailFilter findFilterByPk(long mfId) throws PathNotFoundException, DatabaseException {
    log.debug("findFilterByPk({})", mfId);
    Session session = null;
    Transaction tx = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        tx = session.beginTransaction();
        MailFilter ret = (MailFilter) session.load(MailFilter.class, mfId);
        String nodePath = NodeBaseDAO.getInstance().getPathFromUuid(session, ret.getNode());

        // Always keep path in sync with uuid
        if (!nodePath.equals(ret.getPath())) {
            ret.setPath(nodePath);
            session.update(ret);
        }

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

License:Open Source License

/**
 * Delete//from w  w w. j  a  v a2s . co  m
 */
public static void deleteRule(long frId) throws DatabaseException {
    log.debug("deleteRule({})", frId);
    Session session = null;
    Transaction tx = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        tx = session.beginTransaction();
        MailFilterRule fr = (MailFilterRule) session.load(MailFilterRule.class, frId);
        session.delete(fr);
        HibernateUtil.commit(tx);
    } catch (HibernateException e) {
        HibernateUtil.rollback(tx);
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }

    log.debug("deleteRule: void");
}

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

License:Open Source License

/**
 * Find by pk//from   w ww .ja  v  a  2 s .  c  o  m
 */
public static MailFilterRule findRuleByPk(long frId) throws DatabaseException {
    log.debug("findRuleByPk({})", frId);
    Session session = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        MailFilterRule ret = (MailFilterRule) session.load(MailFilterRule.class, frId);
        log.debug("findRuleByPk: {}", ret);
        return ret;
    } catch (HibernateException e) {
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}

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

License:Open Source License

/**
 * Create/*  w ww .j a  v  a 2 s . co m*/
 */
public static long create(MimeType mt) throws DatabaseException {
    log.debug("create({})", mt);
    Session session = null;
    Transaction tx = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        tx = session.beginTransaction();
        Long id = (Long) session.save(mt);
        MimeType mtTmp = (MimeType) session.load(MimeType.class, id);

        for (String extensions : mt.getExtensions()) {
            mtTmp.getExtensions().add(extensions);
        }

        HibernateUtil.commit(tx);
        log.debug("create: {}", id);
        return id;
    } catch (HibernateException e) {
        HibernateUtil.rollback(tx);
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}

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

License:Open Source License

/**
 * Delete/* w  ww  .j av a  2 s  .  c om*/
 */
public static void delete(long mtId) throws DatabaseException {
    log.debug("delete({})", mtId);
    Session session = null;
    Transaction tx = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        tx = session.beginTransaction();
        MimeType mt = (MimeType) session.load(MimeType.class, mtId);
        session.delete(mt);
        HibernateUtil.commit(tx);
    } catch (HibernateException e) {
        HibernateUtil.rollback(tx);
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }

    log.debug("delete: void");
}