Example usage for org.hibernate FlushMode COMMIT

List of usage examples for org.hibernate FlushMode COMMIT

Introduction

In this page you can find the example usage for org.hibernate FlushMode COMMIT.

Prototype

FlushMode COMMIT

To view the source code for org.hibernate FlushMode COMMIT.

Click Source Link

Document

The Session is flushed when Transaction#commit is called.

Usage

From source file:com.heliosapm.aa4h.parser.XMLQueryParser.java

License:Apache License

/**
 * Initializes a Criteria Query./*from   ww w .java 2s .co  m*/
 * Mandatory Attributes:<ul>
 * <li><b>name</b>: The unqualified class name driving the criteria query.</li>
 * </ul>
 * Optional Attributes:<ul>
 * <li><b>prefix</b>: The package name of the class driving the criteria query. If null, no package is assumed.</li>
 * <li><b>maxSize</b>: The maximum number of rows to return from the database.</li>
 * <li><b>fetchSize</b>: The number of rows to fetch when rows are requested. Usually not useful for AA4H.</li>
 * <li><b>cacheEnabled</b>: Enables or disables caching for the queried objects.</li>
 * <li><b>cacheMode</b>: The cache options for the queried objects.</li>
 * <li><b>flushMode</b>: The session flush options.</li>
 * <li><b>fetchMode</b>: The collection fetch options for the query.</li>
 * <li><b>lockMode</b>: The row lock options for the queried rows.</li>
 * <li><b>timeOut</b>: The query timeout option.</li>
 * <li><b>rowCountOnly</b>: Returns a count of the query rows only.</li>
 * </ul>
 * @param attrs The attributes of the processed node.
 * @return An appended or new CriteriaSpecification
 * @throws SAXException
 */
protected CriteriaSpecification processCriteria(Attributes attrs) throws SAXException {
    if (inDetached) {
        return criteriaStack.peek();
    }
    String name = attrs.getValue("name");
    String prefix = attrs.getValue("prefix");
    if (prefix != null) {
        className = prefix + "." + name;
    } else {
        className = name;
    }
    String maxSize = attrs.getValue("maxSize");
    String fetchSize = attrs.getValue("fetchSize");
    String firstResult = attrs.getValue("firstResult");
    String cacheEnabled = attrs.getValue("cacheEnabled");
    String cacheMode = attrs.getValue("cacheMode");
    String flushMode = attrs.getValue("flushMode");
    String fetchMode = attrs.getValue("fetchMode");
    String lockMode = attrs.getValue("lockMode");
    String timeOut = attrs.getValue("timeOut");
    String rowCountOnly = attrs.getValue("rowCountOnly");
    Criteria newCriteria = null;
    try {
        if (criteriaStack.size() == 0) {
            newCriteria = session.createCriteria(className);
        } else {
            newCriteria = ((Criteria) criteriaStack.peek()).createCriteria(className);
        }
        criteriaStack.push(newCriteria);
        if ("true".equalsIgnoreCase(rowCountOnly)) {
            newCriteria.setProjection(Projections.projectionList().add(Projections.rowCount())

            );
            setRowCountOnly(true);
        }
        if (maxSize != null && isRowCountOnly() == false) {
            newCriteria.setMaxResults(Integer.parseInt(maxSize));
        }
        if (fetchSize != null && isRowCountOnly() == false) {
            newCriteria.setFetchSize(Integer.parseInt(fetchSize));
        }
        if (firstResult != null && isRowCountOnly() == false) {
            newCriteria.setFirstResult(Integer.parseInt(firstResult));
        }
        if (timeOut != null) {
            newCriteria.setTimeout(Integer.parseInt(timeOut));
        }

        if ("true".equalsIgnoreCase(cacheEnabled)) {
            newCriteria.setCacheable(true);
        } else if ("false".equalsIgnoreCase(cacheEnabled)) {
            newCriteria.setCacheable(false);
        }
        if (fetchMode != null && fetchMode.length() > 0) {
            if ("JOIN".equalsIgnoreCase(fetchMode)) {
                newCriteria.setFetchMode(name, FetchMode.JOIN);
            } else if ("SELECT".equalsIgnoreCase(fetchMode)) {
                newCriteria.setFetchMode(name, FetchMode.SELECT);
            } else {
                newCriteria.setFetchMode(name, FetchMode.DEFAULT);
            }
        } else {
            newCriteria.setFetchMode(name, FetchMode.DEFAULT);
        }
        if (cacheMode != null && cacheMode.length() > 0) {
            if ("GET".equalsIgnoreCase(cacheMode)) {
                newCriteria.setCacheMode(CacheMode.GET);
            } else if ("IGNORE".equalsIgnoreCase(cacheMode)) {
                newCriteria.setCacheMode(CacheMode.IGNORE);
            } else if ("NORMAL".equalsIgnoreCase(cacheMode)) {
                newCriteria.setCacheMode(CacheMode.NORMAL);
            } else if ("PUT".equalsIgnoreCase(cacheMode)) {
                newCriteria.setCacheMode(CacheMode.PUT);
            } else if ("REFRESH".equalsIgnoreCase(cacheMode)) {
                newCriteria.setCacheMode(CacheMode.REFRESH);
            } else {
                newCriteria.setCacheMode(CacheMode.NORMAL);
            }
        }
        if (lockMode != null && lockMode.length() > 0) {
            if ("NONE".equalsIgnoreCase(lockMode)) {
                newCriteria.setLockMode(LockMode.NONE);
            } else if ("READ".equalsIgnoreCase(lockMode)) {
                newCriteria.setLockMode(LockMode.READ);
            } else if ("UPGRADE".equalsIgnoreCase(lockMode)) {
                newCriteria.setLockMode(LockMode.UPGRADE);
            } else if ("UPGRADE_NOWAIT".equalsIgnoreCase(lockMode)) {
                newCriteria.setLockMode(LockMode.UPGRADE_NOWAIT);
            } else if ("WRITE".equalsIgnoreCase(lockMode)) {
                newCriteria.setLockMode(LockMode.WRITE);
            } else {
                throw new SAXException("lockMode[" + lockMode + "] Not Recognized");
            }
        }
        if (flushMode != null && flushMode.length() > 0) {
            if ("ALWAYS".equalsIgnoreCase(flushMode)) {
                newCriteria.setFlushMode(FlushMode.ALWAYS);
            } else if ("AUTO".equalsIgnoreCase(flushMode)) {
                newCriteria.setFlushMode(FlushMode.AUTO);
            } else if ("COMMIT".equalsIgnoreCase(flushMode)) {
                newCriteria.setFlushMode(FlushMode.COMMIT);
            } else if ("NEVER".equalsIgnoreCase(flushMode)) {
                // NEVER is deprecated, so we won't throw an exception but we'll ignore it.
            } else {
                throw new SAXException("flushMode[" + flushMode + "] Not Recognized");
            }
        }
        return newCriteria;

    } catch (Exception e) {
        throw new SAXException("Unable to configure class " + className, e);
    }
}

From source file:com.jeroensteenbeeke.hyperion.data.HibernateDAO.java

License:Open Source License

/**
 * @return The Session for this factory// w ww.  jav a2 s  . c  om
 */
public Session getSession() {
    Session session = sessionFactory.getCurrentSession();
    session.setFlushMode(FlushMode.COMMIT);

    log.info("DAO using session " + session.hashCode());

    return session;
}

From source file:com.lecaddyfute.model.dao.AbstractHibernateDAO.java

protected final Session getCurrentSession() {
    Session s = this.sessionFactory.getCurrentSession();
    s.setFlushMode(FlushMode.COMMIT);
    return s;
}

From source file:com.maydesk.base.util.CledaConnector.java

License:Mozilla Public License

public Session createSession() {
    Session session = sessionFactory.openSession();
    session.setFlushMode(FlushMode.COMMIT);
    session.beginTransaction();
    return session;
}

From source file:com.pacs.utils.HibernateUtilsAnnot.java

public static Session currentSession() {
    Session s = (Session) session.get();
    // Open a new Session, if this Thread has none yet
    if ((s == null) || (!s.isOpen())) {
        if (localInterceptor.get() == null) {
            //            localInterceptor.set(new AuditLogInterceptor());
            s = sessionFactory.openSession((Interceptor) localInterceptor.get());
            s.setFlushMode(FlushMode.COMMIT);
        } else {/*from   w  w w .j  a  va 2  s  .com*/
            Interceptor interceptor = (Interceptor) localInterceptor.get();
            s = sessionFactory.openSession(interceptor);
            s.setFlushMode(FlushMode.COMMIT);
        }
        session.set(s);
    }
    return s;
}

From source file:com.rdsic.pcm.common.HibernateUtil.java

public static Session currentSession() {
    initSessionFactory("hibernate.cfg.xml");
    Session s = (Session) session.get();
    if ((s == null) || (!s.isConnected())) {
        s = sessionFactory.openSession();
        s.setFlushMode(FlushMode.COMMIT);
        s.setCacheMode(CacheMode.IGNORE);
        session.set(s);/*www .  j ava  2  s  .  c o  m*/
    }
    return s;
}

From source file:com.rdsic.pcm.common.HibernateUtil.java

public static Session currentSession(String cfgFile) {
    initSessionFactory(cfgFile);/* w w  w.j av a2 s  .  c  o m*/
    Session s = (Session) session.get();
    if ((s == null) || (!s.isConnected())) {
        s = sessionFactory.openSession();
        s.setFlushMode(FlushMode.COMMIT);
        s.setCacheMode(CacheMode.IGNORE);
        session.set(s);
    }
    return s;
}

From source file:com.syncnapsis.utils.SessionFactoryUtil.java

License:Open Source License

/**
 * Open a Session that is bound to the {@link TransactionSynchronizationManager}.<br>
 * The Session will be configured with {@link FlushMode#COMMIT}
 * //from w w w .j  av  a  2s.  c o  m
 * @param useSessionHolder - select wether to use a SessionHolder for binding or not
 * @return the session opened
 */
public Session openBoundSession() {
    Session session = sessionFactory.openSession();
    session.setFlushMode(FlushMode.COMMIT);
    TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
    return session;
}

From source file:com.tysanclan.site.projectewok.dataaccess.EwokHibernateDAO.java

License:Open Source License

/**
 * @return The Session for this factory/*from w  w w .j  a va2s.co m*/
 */
@Override
public Session getSession() {
    Session session = sessionFactory.getCurrentSession();
    session.setFlushMode(FlushMode.COMMIT);
    return session;
}

From source file:com.xpn.xwiki.internal.store.hibernate.HibernateStore.java

License:Open Source License

/**
 * @return the current {@link Session} or null
 *///from ww w .j  a  v a2  s .com
public Session getCurrentSession() {
    ExecutionContext context = this.execution.getContext();

    if (context != null) {
        Session session = (Session) context.getProperty(CONTEXT_SESSION);

        // Make sure we are in this mode
        try {
            if (session != null) {
                session.setFlushMode(FlushMode.COMMIT);
            }
        } catch (org.hibernate.SessionException ex) {
            session = null;
        }

        return session;
    }

    return null;
}