Package org.hibernate.envers.synchronization

Source Code of org.hibernate.envers.synchronization.SessionCacheCleaner

package org.hibernate.envers.synchronization;

import org.hibernate.Session;
import org.hibernate.action.AfterTransactionCompletionProcess;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.event.EventSource;

/**
* Class responsible for evicting audit data entries that have been stored in the session level cache.
* This operation increases Envers performance in case of massive entity updates without clearing persistence context.
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/
public class SessionCacheCleaner {
    /**
     * Schedules audit data removal from session level cache after transaction completion. The operation is performed
     * regardless of commit success.
     * @param session Active Hibernate session.
     * @param data Audit data that shall be evicted (e.g. revision data or entity snapshot)
     */
    public void scheduleAuditDataRemoval(final Session session, final Object data) {
        ((EventSource) session).getActionQueue().registerProcess(new AfterTransactionCompletionProcess() {
            public void doAfterTransactionCompletion(boolean success, SessionImplementor session) {
                ((Session) session).evict(data);
            }
        });
    }
}
TOP

Related Classes of org.hibernate.envers.synchronization.SessionCacheCleaner

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.