Example usage for org.springframework.transaction.interceptor DefaultTransactionAttribute setReadOnly

List of usage examples for org.springframework.transaction.interceptor DefaultTransactionAttribute setReadOnly

Introduction

In this page you can find the example usage for org.springframework.transaction.interceptor DefaultTransactionAttribute setReadOnly.

Prototype

public final void setReadOnly(boolean readOnly) 

Source Link

Document

Set whether to optimize as read-only transaction.

Usage

From source file:ome.services.sharing.ShareRestrictionTransactionAttributeSource.java

public TransactionAttribute getTransactionAttribute(Method method, Class targetClass) {
    try {//  w  ww. j  a  v a 2  s.com
        Principal principal = current.getLast();
        String uuid = principal.getName();
        EventContext ec = cache.getSessionContext(uuid);
        Long shareId = ec.getCurrentShareId();
        if (ec.getCurrentShareId() != null) {
            log.debug("Returning readOnly tx for shared " + shareId);
            DefaultTransactionAttribute ta = new DefaultTransactionAttribute();
            ta.setReadOnly(true);
            return ta;
        }
    } catch (SessionException se) {
        // No worries. It's not our job to enforce anything.
        return null;
    } catch (NoSuchElementException nse) {
        // No one is logged in so there can't be a share active!
        return null;
    }
    return null;
}