Example usage for org.springframework.orm.hibernate5 HibernateOperations contains

List of usage examples for org.springframework.orm.hibernate5 HibernateOperations contains

Introduction

In this page you can find the example usage for org.springframework.orm.hibernate5 HibernateOperations contains.

Prototype

boolean contains(Object entity) throws DataAccessException;

Source Link

Document

Check whether the given object is in the Session cache.

Usage

From source file:org.springframework.batch.item.database.HibernateItemWriter.java

/**
 * Do perform the actual write operation using {@link HibernateOperations}.
 * This can be overridden in a subclass if necessary.
 *
 * @param hibernateTemplate//from  w  w w  .j  a va2 s.c  o m
 *            the HibernateTemplate to use for the operation
 * @param items
 *            the list of items to use for the write
 * @deprecated As of 2.2 in favor of using Hibernate's session management APIs directly
 */
@Deprecated
protected void doWrite(HibernateOperations hibernateTemplate, List<? extends T> items) {

    if (logger.isDebugEnabled()) {
        logger.debug("Writing to Hibernate with " + items.size() + " items.");
    }

    if (!items.isEmpty()) {
        long saveOrUpdateCount = 0;
        for (T item : items) {
            if (!hibernateTemplate.contains(item)) {
                hibernateTemplate.saveOrUpdate(item);
                saveOrUpdateCount++;
            }
        }
        if (logger.isDebugEnabled()) {
            logger.debug(saveOrUpdateCount + " entities saved/updated.");
            logger.debug((items.size() - saveOrUpdateCount) + " entities found in session.");
        }
    }

}