Example usage for org.hibernate LockOptions NONE

List of usage examples for org.hibernate LockOptions NONE

Introduction

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

Prototype

LockOptions NONE

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

Click Source Link

Document

Represents LockMode.NONE (timeout + scope do not apply).

Usage

From source file:org.bedework.calcore.hibernate.HibSessionImpl.java

License:Apache License

@Override
public void reAttach(final BwUnversionedDbentity<?> val) throws CalFacadeException {
    if (exc != null) {
        // Didn't hear me last time?
        throw new CalFacadeException(exc);
    }// w w w .java 2 s  . c  o  m

    try {
        if (!val.unsaved()) {
            //        sess.lock(val, LockMode.NONE);
            sess.buildLockRequest(LockOptions.NONE).lock(val);
        }
    } catch (Throwable t) {
        handleException(t);
    }
}

From source file:org.eclipse.emf.teneo.hibernate.HbSessionWrapper.java

License:Open Source License

/** Refresh the object */
public void refresh(Object obj) {
    getSessionInternal().refresh(obj, LockOptions.NONE);
}

From source file:org.eclipse.emf.teneo.hibernate.resource.HbResourceImpl.java

License:Open Source License

/**
 * Creates the session of this resource. As a default the FlushMode is set
 * to Never. The loaded objects of this resource are merged into the
 * session. It is the responsibility of the caller to close the session or
 * call the returnSession method here./* w w  w  .  j  a va2s . c  o m*/
 */
public Session getSession() {
    if (log.isDebugEnabled()) {
        log.debug("Creating session");
    }
    final SessionFactory sessionFactory = emfDataStore.getSessionFactory();
    final Session session = sessionFactory.openSession();
    session.setFlushMode(FlushMode.MANUAL);

    if (loadedEObjects.size() > 0) {
        session.beginTransaction();

        // merge the loaded objects into the session
        if (log.isDebugEnabled()) {
            log.debug("Merging " + loadedEObjects.size() + " eobjects into new session ");
        }
        for (Object obj : loadedEObjects) {
            session.buildLockRequest(LockOptions.NONE).lock(obj);
        }
        session.getTransaction().commit();
    }

    return session;
}

From source file:org.faster.orm.service.hibernate.HibernateInitializeService.java

License:Open Source License

@Override
public void initialize(PO po) {
    if (po == null) {
        return;/*from  w  w  w . j ava  2 s.  c  o  m*/
    }
    getSession().refresh(po, LockOptions.NONE);
    Hibernate.initialize(po);
}

From source file:org.jdal.dao.hibernate.HibernateDao.java

License:Apache License

public T initialize(T entity) {
    getSession().buildLockRequest(LockOptions.NONE).lock(entity);
    HibernateUtils.initialize(getSessionFactory(), entity);
    return entity;
}

From source file:org.jdal.dao.hibernate.HibernateDao.java

License:Apache License

public T initialize(T entity, int depth) {
    getSession().buildLockRequest(LockOptions.NONE).lock(entity);
    HibernateUtils.initialize(getSessionFactory(), entity, depth);

    return entity;
}

From source file:org.jdal.hibernate.HibernateUtils.java

License:Apache License

/** 
 * Initialize Object for use with closed Session. 
 * // w  w w  . j  a v a2s .com
 * @param sessionFactory max depth in recursion
 * @param obj Object to initialize
 * @param initializedObjects list with already initialized Objects
 * @param depth max depth in recursion
 */
private static void initialize(SessionFactory sessionFactory, Object obj, List<Object> initializedObjects,
        int depth) {

    // return on nulls, depth = 0 or already initialized objects
    if (obj == null || depth == 0) {
        return;
    }

    if (!Hibernate.isInitialized(obj)) {
        // if collection, initialize objects in collection too. Hibernate don't do it.
        if (obj instanceof Collection) {
            initializeCollection(sessionFactory, obj, initializedObjects, depth);
            return;
        }

        sessionFactory.getCurrentSession().buildLockRequest(LockOptions.NONE).lock(obj);
        Hibernate.initialize(obj);
    }

    // now we can call equals safely. If object are already initializated, return
    if (initializedObjects.contains(obj))
        return;

    initializedObjects.add(obj);

    // initialize all persistent associaciations.
    ClassMetadata classMetadata = getClassMetadata(sessionFactory, obj);

    if (classMetadata == null) {
        return; // Not persistent object
    }

    Object[] pvs = classMetadata.getPropertyValues(obj, EntityMode.POJO);

    for (Object pv : pvs) {
        initialize(sessionFactory, pv, initializedObjects, depth - 1);
    }
}

From source file:org.jspresso.framework.application.backend.persistence.hibernate.HibernateBackendController.java

License:Open Source License

/**
 * Locks an entity (LockMode.NONE) in current hibernate session.
 *
 * @param entity//from  w  w w .j  a v a  2s .  c om
 *     the entity to lock.
 * @param hibernateSession
 *     the hibernate session.
 */
private void lockInHibernate(IEntity entity, Session hibernateSession) {
    if (!hibernateSession.contains(entity)) {
        // Do not use get before trying to lock.
        // Get performs a DB query.
        try {
            hibernateSession.buildLockRequest(LockOptions.NONE).lock(entity);
        } catch (NonUniqueObjectException ex) {
            if (hibernateSession == noTxSession) {
                hibernateSession.clear();
                hibernateSession.buildLockRequest(LockOptions.NONE).lock(entity);
            } else {
                throw ex;
            }
        }
    }
}

From source file:org.molasdin.wbase.hibernate.BasicHibernateRepository.java

License:Apache License

private void attachRaw(T o, Session session) {
    if (session.contains(o)) {
        return;
    }
    session.buildLockRequest(LockOptions.NONE).lock(o);
}

From source file:org.molasdin.wbase.hibernate.cursor.BasicFilteredHibernateCursor.java

License:Apache License

@SuppressWarnings("unchecked")
@Override//from w w w  . ja v a2s. com
public List<T> dataCallback(Session session) {
    StringBuilder builder = new StringBuilder();
    session.buildLockRequest(LockOptions.NONE).lock(owner);
    builder.append(populateFilters());
    builder.append(' ');

    List<Pair<String, Order>> orders = orders();
    if (!orders.isEmpty()) {
        builder.append("order by ");
        boolean added = false;
        for (Pair<String, Order> order : orders) {
            if (added) {
                builder.append(",");
            }
            builder.append(String.format(FILTER_ORDER, order.getLeft(),
                    Order.ASC.equals(order.getRight()) ? ORDER_ASC : ORDER_DESC));
            added = true;
        }
        builder.append(' ');
    }

    return postProcessData((List<T>) session.createFilter(collectionProxy, builder.toString())
            .setFirstResult(calculatedRowOffset()).setMaxResults(pageSize()).list());
}