Example usage for org.hibernate Session setFlushMode

List of usage examples for org.hibernate Session setFlushMode

Introduction

In this page you can find the example usage for org.hibernate Session setFlushMode.

Prototype

@Deprecated
void setFlushMode(FlushMode flushMode);

Source Link

Document

Set the flush mode for this session.

Usage

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

License:Open Source License

private void initializeProperty(IComponent componentOrEntity, String propertyName) {
    Session hibernateSession = getHibernateSession();
    FlushMode oldFlushMode = hibernateSession.getFlushMode();
    try {//w  w  w  . j  a v  a2 s  .  c  o m
        // Temporary switch to a read-only session.
        hibernateSession.setFlushMode(FlushMode.MANUAL);
        try {
            currentInitializationSession = hibernateSession;
            performPropertyInitializationUsingSession(componentOrEntity, propertyName, hibernateSession);
        } finally {
            currentInitializationSession = null;
        }
    } finally {
        hibernateSession.setFlushMode(oldFlushMode);
    }
}

From source file:org.jtalks.poulpe.web.osod.OpenSessions.java

License:Open Source License

/**
 * Creates a new session for the specified desktop id if doesn't exist. If it's already inside {@link OpenSessions},
 * then it will be returned. It also sets the flush mode to {@link FlushMode#MANUAL} when session is opened. This
 * method doesn't bind sessions to the thread.
 *
 * @param desktopId an id of the desktop to search the session for
 * @return a session that is bound to the desktop or new session that is not bound to anything if no desktop with
 *         such id was registered/*w w  w.ja v a2  s.  c  o  m*/
 */
@VisibleForTesting
Session getOrCreateSession(String desktopId) {
    Session session = sessions.get(desktopId);
    if (session == null) {
        session = createSession();
        session.setFlushMode(FlushMode.MANUAL);
    }
    return session;
}

From source file:org.kaaproject.kaa.server.common.dao.impl.sql.HibernateAbstractDao.java

License:Apache License

@Override
public Session getSession(FlushMode flushMode) {
    Session session = sessionFactory.getCurrentSession();
    session.setFlushMode(flushMode);
    return session;
}

From source file:org.kuali.rice.krad.dao.impl.BusinessObjectDaoJpa.java

License:Educational Community License

/**
 * @see org.kuali.rice.krad.dao.BusinessObjectDao#manageReadOnly(org.kuali.rice.krad.bo.PersistableBusinessObject)
 *//*from w ww  . j ava  2s  .c o  m*/
public PersistableBusinessObject manageReadOnly(PersistableBusinessObject bo) {
    Session session = ((HibernateEntityManager) entityManager).getSession();
    FlushMode currentFlushMode = session.getFlushMode();
    session.setFlushMode(FlushMode.MANUAL); // make sure the merge doesn't flush what we're trying to make read only
    PersistableBusinessObject managedBO = entityManager.merge(bo);
    session.setReadOnly(managedBO, true);
    session.setFlushMode(currentFlushMode);
    return managedBO;
}

From source file:org.mifos.framework.persistence.LegacyGenericDao.java

License:Open Source License

public Object execUniqueResultNamedQueryWithoutFlush(final String queryName,
        final Map<String, ?> queryParameters) throws PersistenceException {
    try {/*from www  . j av a  2 s  . co m*/
        Session sess = getSession();
        sess.setFlushMode(FlushMode.MANUAL);
        Query query = getSession().getNamedQuery(queryName);
        logger.debug("The query object for the query with the name  " + queryName + " has been obtained");
        query.setProperties(queryParameters);
        Object returnObject = query.uniqueResult();
        sess.setFlushMode(FlushMode.AUTO);
        return returnObject;
    } catch (GenericJDBCException gje) {
        throw new ConnectionNotFoundException(gje);
    } catch (Exception e) {
        throw new PersistenceException(e);
    }
}

From source file:org.openeos.services.ui.vaadin.internal.OpenSessionInViewListener.java

License:Apache License

@Override
public void onTransactionStart(IUnoVaadinApplication application) {
    if (sessionFactory != null) {
        if (TransactionSynchronizationManager.hasResource(sessionFactory)) {
            LOG.debug("Participating in existing open session.");
        } else {/*from   w w  w.  j  a v a 2  s .  c o  m*/
            LOG.debug("Opening session in View...");
            Session session = SessionFactoryUtils.openSession(sessionFactory);
            session.setFlushMode(FlushMode.MANUAL);
            TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
            tlSession.set(session);
        }
    }
}

From source file:org.openmrs.api.db.hibernate.HibernateContextDAO.java

License:Mozilla Public License

public void openSession() {
    log.debug("HibernateContext: Opening Hibernate Session");
    if (TransactionSynchronizationManager.hasResource(sessionFactory)) {
        if (log.isDebugEnabled()) {
            log.debug("Participating in existing session (" + sessionFactory.hashCode() + ")");
        }//from w ww.  jav  a  2  s.c om
        participate = true;
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Registering session with synchronization manager (" + sessionFactory.hashCode() + ")");
        }
        Session session = sessionFactory.openSession();
        session.setFlushMode(FlushMode.MANUAL);
        TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
    }
}

From source file:org.openmrs.api.db.hibernate.HibernateTransactionManagerFlushOnCommit.java

License:Open Source License

/**
 * @see org.springframework.orm.hibernate3.HibernateTransactionManager#doBegin(java.lang.Object,
 *      org.springframework.transaction.TransactionDefinition)
 *///from  w  ww .j  av  a 2 s  .c o m
@Override
protected void doBegin(Object transaction, TransactionDefinition definition) {
    super.doBegin(transaction, definition);
    Session session = getSessionFactory().getCurrentSession();
    if (!session.getFlushMode().lessThan(FlushMode.COMMIT)) {
        session.setFlushMode(FlushMode.COMMIT);
    }
}

From source file:org.openmrs.module.patientportal.api.db.hibernate.HibernatePatientPortalReminderDAO.java

License:Open Source License

@Override
public PatientPortalReminder savePatientPortalReminder(PatientPortalReminder reminder) {
    log.debug("Save reminder - reminder.getFollowProcedure()=" + reminder.getFollowProcedure()
            + ", reminder.getFollowProcedureName() = " + reminder.getFollowProcedureName());

    if (reminder.getFollowProcedureName() != null) {
        reminder.setFollowProcedure(/*from ww w .  j  av  a2s .  c  o m*/
                Context.getConceptService().getConceptByName(reminder.getFollowProcedureName()));
        log.debug("New reminder.getFollowProcedure()=" + reminder.getFollowProcedure());
    }

    Session sess = sessionFactory.openSession();
    Transaction tx = sess.beginTransaction();
    sess.setFlushMode(FlushMode.COMMIT); // allow queries to return stale state
    sess.saveOrUpdate(reminder);
    tx.commit();
    //sess.flush();
    sess.close();
    //sessionFactory.getCurrentSession().saveOrUpdate(token);
    return reminder;
}

From source file:org.openmrs.module.patientportal.api.db.hibernate.HibernatePatientPortalReminderDAO.java

License:Open Source License

@Override
public void deletePatientPortalReminder(PatientPortalReminder reminder) {
    //sessionFactory.getCurrentSession().delete(token);
    //sessionFactory.getCurrentSession().close();
    Session sess = sessionFactory.openSession();
    Transaction tx = sess.beginTransaction();
    sess.setFlushMode(FlushMode.COMMIT); // allow queries to return stale state
    sess.delete(reminder);/*  www.java  2  s .com*/
    tx.commit();
    sess.close();

}