Example usage for org.hibernate LockMode NONE

List of usage examples for org.hibernate LockMode NONE

Introduction

In this page you can find the example usage for org.hibernate LockMode NONE.

Prototype

LockMode NONE

To view the source code for org.hibernate LockMode NONE.

Click Source Link

Document

No lock required.

Usage

From source file:org.jbpm.pvm.internal.hibernate.DbSessionImpl.java

License:Open Source License

public List<JobImpl<?>> findExclusiveJobs(Execution processInstance) {
    Query query = session.getNamedQuery("findExclusiveJobs");
    query.setTimestamp("now", Clock.getCurrentTime());
    query.setLockMode("job", LockMode.NONE);

    query.setEntity("processInstance", processInstance);
    return query.list();
}

From source file:org.jbpm.pvm.internal.hibernate.DbSessionImpl.java

License:Open Source License

public JobImpl<?> findFirstDueJob() {
    Query query = session.getNamedQuery("findFirstDueJob");
    query.setMaxResults(1);//from w w  w . ja v a2 s  .  co m
    //query.setLockMode("job", LockMode.READ);
    query.setLockMode("job", LockMode.NONE);
    return (JobImpl<?>) query.uniqueResult();
}

From source file:org.jbpm.pvm.internal.query.JobQueryImpl.java

License:Open Source License

protected void applyParameters(Query query) {
    query.setLockMode("j", LockMode.NONE);
}

From source file:org.libreplan.business.common.daos.GenericDAOHibernate.java

License:Open Source License

public void reattachUnmodifiedEntity(E entity) {
    if (Hibernate.isInitialized(entity) && entity.isNewObject()) {
        return;/*w  ww  .j a  va2s  . c o m*/
    }
    // TODO resolve deprecated
    getSession().lock(entity, LockMode.NONE);
}

From source file:org.malaguna.cmdit.dao.impl.BasicHibernateDAOImpl.java

License:Open Source License

@Override
public void reattach(T obj, int dirtyMode) {

    //Avoid bad parameters
    if ((obj != null)) {
        try {/*from  w  ww  . j  a  v a 2  s .c om*/
            switch (dirtyMode) {

            case DIRTY_EVALUATION:
                this.getCurrentSession().update(obj);
                break;

            case DIRTY_IGNORE:
                this.getCurrentSession().buildLockRequest(null).setLockMode(LockMode.NONE).lock(obj);
                break;
            }
        } catch (RuntimeException re) {
            logErrMsg("reattach", re);
            throw re;
        }
    }
}

From source file:org.medici.bia.dao.document.DocumentDAOJpaImpl.java

License:Open Source License

/**
 * /*  w  w  w  .  j av  a 2  s.c  o  m*/
 * @throws PersistenceException
 */
public void generateIndex() throws PersistenceException {
    Session session = null;
    FullTextSession fullTextSession = null;
    ScrollableResults results = null;
    try {
        EntityManager entityManager = getEntityManager();
        session = ((HibernateEntityManager) entityManager).getSession();
        session = session.getSessionFactory().openSession();
        fullTextSession = org.hibernate.search.Search.getFullTextSession(session);

        Long total = (Long) entityManager.createQuery("SELECT count(entryId) FROM Document").getSingleResult();
        logger.info("Total Entities to be indexed : " + total);

        if (total > 0) {
            Transaction tx = fullTextSession.beginTransaction();
            fullTextSession.purgeAll(Document.class);
            tx.commit();
            logger.info("Removed all documents.");
            Integer numberOfElements = 100;

            Integer numberOfElementsBeforeGC = 1000;
            String queryJPA = "FROM Document ORDER BY entryId asc";

            org.hibernate.Query query = session.createQuery(queryJPA);
            tx = fullTextSession.beginTransaction();
            query.setReadOnly(true);
            query.setLockMode("a", LockMode.NONE);
            results = query.scroll(ScrollMode.FORWARD_ONLY);
            Integer resultNumber = 0;
            while (results.next()) {
                Document document = (Document) results.get(0);
                fullTextSession.index(document);
                resultNumber++;

                if (resultNumber % numberOfElements == 0) {
                    logger.info("Initiating Lucene Index Flush... ");
                    fullTextSession.flushToIndexes();
                    fullTextSession.clear();
                    logger.info("Finished the Lucene Index Flush...  Total records on index " + resultNumber
                            + "/" + total);
                }

                if (resultNumber % numberOfElementsBeforeGC == 0) {
                    System.gc();
                    logger.info("Invoked Garbage collector to prevent OutOfMemory Errors");
                }
            }

            fullTextSession.flushToIndexes();
            fullTextSession.clear();
            tx.commit();

            logger.info("Initiating Lucene Index Optimze...");
            SearchFactory searchFactory = fullTextSession.getSearchFactory();
            searchFactory.optimize(Document.class);
            logger.info("Finished Lucene Index Optimze");
        } else {
            logger.info("No Entities found to be indexed.");
        }
        logger.info("Indexing documents terminated without errors.");
    } catch (Throwable throwable) {
        logger.error(throwable);
    } finally {
        if (results != null) {
            results.close();
        }
        if (fullTextSession != null) {
            fullTextSession.close();
        }
        if (session != null) {
            session.close();
        }
    }
}

From source file:org.medici.bia.dao.document.DocumentDAOJpaImpl.java

License:Open Source License

/**
 * //from   w  w  w  . j a  va 2s .c  o  m
 * @throws PersistenceException
 */
@Override
public void updateIndex(Date fromDate) throws PersistenceException {
    Session session = null;
    FullTextSession fullTextSession = null;
    ScrollableResults results = null;
    try {
        EntityManager entityManager = getEntityManager();
        session = ((HibernateEntityManager) entityManager).getSession();
        session = session.getSessionFactory().openSession();
        fullTextSession = org.hibernate.search.Search.getFullTextSession(session);

        Query queryTotal = entityManager
                .createQuery("SELECT count(entryId) FROM Document where lastUpdate>=:lastUpdate");
        queryTotal.setParameter("lastUpdate", fromDate);
        Long total = (Long) queryTotal.getSingleResult();
        logger.info("Total Entities to be updated : " + total);

        if (total > 0) {
            Integer numberOfElements = 50;
            Integer numberOfElementsBeforeGC = 1000;
            org.hibernate.Query query = session.createQuery("FROM Document where lastUpdate>=:lastUpdate");
            query.setParameter("lastUpdate", fromDate);

            Transaction tx = fullTextSession.beginTransaction();
            query.setReadOnly(true);
            query.setLockMode("a", LockMode.NONE);
            results = query.scroll(ScrollMode.FORWARD_ONLY);
            Integer resultNumber = 0;
            while (results.next()) {
                Document document = (Document) results.get(0);
                fullTextSession.delete(document);
                fullTextSession.index(document);
                resultNumber++;

                if (resultNumber % numberOfElements == 0) {
                    flushingFullTextSession(total, resultNumber, fullTextSession);
                }

                if (resultNumber % numberOfElementsBeforeGC == 0) {
                    System.gc();
                    logger.info("Invoked Garbage collector to prevent OutOfMemory Errors");
                }
            }

            flushingFullTextSession(total, resultNumber, fullTextSession);

            /*            logger.info("Initiating Lucene Index Optimze...");
                          SearchFactory searchFactory = fullTextSession.getSearchFactory();
                          searchFactory.optimize(Document.class);
            */
            logger.info("Finished Lucene Index Optimze");

            tx.commit();
        } else {
            logger.info("No Entities found to be indexed.");
        }
        logger.info("Indexing documents terminated without errors.");
    } catch (Throwable throwable) {
        logger.error(throwable);
    } finally {
        if (results != null) {
            results.close();
        }
        /*if (fullTextSession.isOpen()) {
           fullTextSession.close();
        }*/
        if (session.isOpen()) {
            session.close();
        }
    }
}

From source file:org.medici.bia.dao.JpaDao.java

License:Open Source License

/**
 * /*from  ww  w.ja v a  2s. co  m*/
 * @param fromDate
 * @throws PersistenceException
 */
public void updateIndex(Date fromDate) throws PersistenceException {
    Session session = null;
    FullTextSession fullTextSession = null;
    ScrollableResults results = null;
    try {
        EntityManager entityManager = getEntityManager();
        session = ((HibernateEntityManager) entityManager).getSession();
        session = session.getSessionFactory().openSession();
        fullTextSession = org.hibernate.search.Search.getFullTextSession(session);

        Query queryTotal = entityManager
                .createQuery("SELECT count(*) FROM " + entityClass + " where lastUpdate>=:lastUpdate");
        queryTotal.setParameter("lastUpdate", fromDate);
        Long total = (Long) queryTotal.getSingleResult();
        logger.info("Total Entities to be updated : " + total);

        if (total > 0) {
            Integer numberOfElements = 50;
            Integer numberOfElementsBeforeGC = 1000;
            org.hibernate.Query query = session
                    .createQuery("FROM " + entityClass + "  where lastUpdate>=:lastUpdate");
            query.setParameter("lastUpdate", fromDate);

            Transaction tx = fullTextSession.beginTransaction();
            query.setReadOnly(true);
            query.setLockMode("a", LockMode.NONE);
            results = query.scroll(ScrollMode.FORWARD_ONLY);
            Integer resultNumber = 0;
            while (results.next()) {
                Object entityClass = (Object) results.get(0);
                fullTextSession.delete(entityClass);
                fullTextSession.index(entityClass);
                resultNumber++;

                if (resultNumber % numberOfElements == 0) {
                    flushingFullTextSession(total, resultNumber, fullTextSession);
                }

                if (resultNumber % numberOfElementsBeforeGC == 0) {
                    System.gc();
                    logger.info("Invoked Garbage collector to prevent OutOfMemory Errors");
                }
            }

            flushingFullTextSession(total, resultNumber, fullTextSession);
            tx.commit();

            logger.info("Initiating Lucene Index Optimze...");
            SearchFactory searchFactory = fullTextSession.getSearchFactory();
            searchFactory.optimize(entityClass);
            logger.info("Finished Lucene Index Optimze");
        } else {
            logger.info("No Entities found to be indexed.");
        }
        logger.info("Indexing documents terminated without errors.");
    } catch (Throwable throwable) {
        logger.error(throwable);
    } finally {
        if (results != null) {
            results.close();
        }
        if (fullTextSession.isOpen()) {
            fullTextSession.close();
        }
        if (session.isOpen()) {
            session.close();
        }
    }
}

From source file:org.ncbo.stanford.domain.generated.NcboUserOntologyLicenseDAO.java

public void attachClean(NcboUserOntologyLicense instance) {
    log.debug("attaching clean NcboUserOntologyLicense instance");
    try {//from w  ww. j av a 2 s. c  o m
        getHibernateTemplate().lock(instance, LockMode.NONE);
        log.debug("attach successful");
    } catch (RuntimeException re) {
        log.error("attach failed", re);
        throw re;
    }
}

From source file:org.osaf.cosmo.dao.hibernate.ItemDaoImpl.java

License:Apache License

protected void attachToSession(Item item) {
    if (getSession().contains(item))
        return;
    getSession().lock(item, LockMode.NONE);
}