Example usage for javax.persistence FlushModeType AUTO

List of usage examples for javax.persistence FlushModeType AUTO

Introduction

In this page you can find the example usage for javax.persistence FlushModeType AUTO.

Prototype

FlushModeType AUTO

To view the source code for javax.persistence FlushModeType AUTO.

Click Source Link

Document

(Default) Flushing to occur at query execution.

Usage

From source file:org.grails.datastore.gorm.support.DatastorePersistenceContextInterceptor.java

public void init() {
    if (TransactionSynchronizationManager.getResource(datastore) != null) {
        // Do not modify the Session: just set the participate flag.
        participate = true;/*w  w w . ja  v a  2  s  . co  m*/
    } else {
        LOG.debug("Opening single Datastore session in DatastorePersistenceContextInterceptor");
        Session session = getSession();
        session.setFlushMode(FlushModeType.AUTO);
        try {
            DatastoreUtils.bindSession(session);
        } catch (IllegalStateException e) {
            // ignore, already bound
        }
    }
}

From source file:org.grails.datastore.gorm.jpa.support.JpaPersistenceContextInterceptor.java

@Override
public void setReadWrite() {
    entityManager.setFlushMode(FlushModeType.AUTO);
}

From source file:org.grails.datastore.mapping.web.support.OpenSessionInViewInterceptor.java

public void postHandle(WebRequest webRequest, ModelMap modelMap) throws Exception {
    // Only potentially flush in single session mode.
    if (!hasSessionBound()) {
        return;//  ww  w .  j  a v a 2 s .  c o  m
    }

    SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.getResource(getDatastore());
    LOG.debug("Flushing single Datastore Session in OpenSessionInViewInterceptor");
    final Session session = sessionHolder.getSession();

    if (session.getFlushMode() == FlushModeType.AUTO) {
        session.flush();
    }
}

From source file:org.grails.datastore.gorm.support.DatastorePersistenceContextInterceptor.java

public void setReadWrite() {
    getSession().setFlushMode(FlushModeType.AUTO);
}

From source file:com.haulmont.cuba.core.sys.QueryImpl.java

private JpaQuery<T> getQuery() {
    if (query == null) {
        View view = views.isEmpty() ? null : views.get(0);

        if (isNative) {
            log.trace("Creating SQL query: {}", queryString);
            if (resultClass == null)
                query = (JpaQuery) emDelegate.createNativeQuery(queryString);
            else {
                if (!Entity.class.isAssignableFrom(resultClass)) {
                    throw new IllegalArgumentException(
                            "Non-entity result class for native query is not supported" + " by EclipseLink: "
                                    + resultClass);
                }/* w  w  w .ja v a2s. co m*/
                Class effectiveClass = metadata.getExtendedEntities().getEffectiveClass(resultClass);
                query = (JpaQuery) emDelegate.createNativeQuery(queryString, effectiveClass);
            }
        } else {
            log.trace("Creating JPQL query: {}", queryString);
            String s = transformQueryString();
            log.trace("Transformed JPQL query: {}", s);

            Class effectiveClass = getEffectiveResultClass();
            if (effectiveClass != null) {
                query = (JpaQuery) emDelegate.createQuery(s, effectiveClass);
            } else {
                query = (JpaQuery) emDelegate.createQuery(s);
            }
            if (view != null) {
                MetaClass metaClass = metadata.getClassNN(view.getEntityClass());
                if (!metadata.getTools().isCacheable(metaClass) || !singleResultExpected) {
                    query.setHint(QueryHints.REFRESH, HintValues.TRUE);
                    query.setHint(QueryHints.REFRESH_CASCADE, CascadePolicy.CascadeByMapping);
                }
            }
        }
        if (view != null && !view.loadPartialEntities()) {
            query.setFlushMode(FlushModeType.AUTO);
        } else {
            query.setFlushMode(FlushModeType.COMMIT);
        }

        boolean nullParam = false;
        for (Param param : params) {
            param.apply(query);
            if (param.value == null)
                nullParam = true;
        }

        addMacroParams(query);

        // disable SQL caching to support "is null" generation
        if (nullParam)
            query.setHint(QueryHints.PREPARE, HintValues.FALSE);

        // Set maxResults and firstResult only if the query is not by ID, otherwise EclipseLink does not select
        // nested collections in some cases
        if (maxResults != null && !singleResultExpected)
            query.setMaxResults(maxResults);
        if (firstResult != null && !singleResultExpected)
            query.setFirstResult(firstResult);

        if (lockMode != null)
            query.setLockMode(lockMode);

        for (int i = 0; i < views.size(); i++) {
            if (i == 0)
                fetchGroupMgr.setView(query, queryString, views.get(i), singleResultExpected);
            else
                fetchGroupMgr.addView(query, queryString, views.get(i), singleResultExpected);
        }
    }
    //noinspection unchecked
    return query;
}

From source file:org.grails.datastore.mapping.jpa.JpaSession.java

public void setFlushMode(FlushModeType flushMode) {
    this.flushMode = flushMode;
    jpaTemplate.setFlushEager(flushMode == FlushModeType.AUTO);
}

From source file:org.grails.orm.hibernate.HibernateSession.java

public void setFlushMode(FlushModeType flushMode) {
    if (flushMode == FlushModeType.AUTO) {
        hibernateTemplate.setFlushMode(GrailsHibernateTemplate.FLUSH_AUTO);
    } else if (flushMode == FlushModeType.COMMIT) {
        hibernateTemplate.setFlushMode(GrailsHibernateTemplate.FLUSH_COMMIT);
    }//from   w  w w .  ja v a2 s  .  c  om
}

From source file:org.grails.orm.hibernate.HibernateSession.java

public FlushModeType getFlushMode() {
    switch (hibernateTemplate.getFlushMode()) {
    case GrailsHibernateTemplate.FLUSH_AUTO:
        return FlushModeType.AUTO;
    case GrailsHibernateTemplate.FLUSH_COMMIT:
        return FlushModeType.COMMIT;
    case GrailsHibernateTemplate.FLUSH_ALWAYS:
        return FlushModeType.AUTO;
    default:/* www  .  j a  va2s .  com*/
        return FlushModeType.AUTO;
    }
}

From source file:org.grails.datastore.mapping.redis.RedisSession.java

private void flushIfNecessary() {
    if (getFlushMode() == FlushModeType.AUTO) {
        flush();
    }
}

From source file:com.impetus.kundera.persistence.PersistenceDelegator.java

/**
 * @return
 */
private boolean applyFlush() {

    return flushMode.equals(FlushModeType.AUTO) ? true : enableFlush;
}