Code example for WebRequest

Methods: getAttribute, setAttribute

0
 * @see org.springframework.transaction.support.TransactionSynchronizationManager 
 */ 
public class OpenEntityManagerInViewInterceptor extends EntityManagerFactoryAccessor implements AsyncWebRequestInterceptor { 
 
	/** 
	 * Suffix that gets appended to the EntityManagerFactory toString 
	 * representation for the "participate in existing entity manager 
	 * handling" request attribute. 
	 * @see #getParticipateAttributeName 
	 */ 
	public static final String PARTICIPATE_SUFFIX = ".PARTICIPATE"; 
 
 
	@Override 
	public void preHandle(WebRequest request) throws DataAccessException { 
 
		String participateAttributeName = getParticipateAttributeName(); 
 
		WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request); 
		if (asyncManager.hasConcurrentResult()) { 
			if (applyCallableInterceptor(asyncManager, participateAttributeName)) { 
				return; 
			} 
		} 
 
		if (TransactionSynchronizationManager.hasResource(getEntityManagerFactory())) { 
			// do not modify the EntityManager: just mark the request accordingly 
			Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST); 
			int newCount = (count != null ? count + 1 : 1); 
			request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST); 
		} 
		else { 
			logger.debug("Opening JPA EntityManager in OpenEntityManagerInViewInterceptor"); 
			try { 
				EntityManager em = createEntityManager(); 
Contextual code suggestions in your IDE  Get Codota for Java