Java tutorial
/* Copyright 2017 Zutubi Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.zutubi.pulse.master.xwork.interceptor; import com.opensymphony.xwork.ActionInvocation; import com.opensymphony.xwork.interceptor.Interceptor; import org.hibernate.FlushMode; import org.hibernate.Session; import org.hibernate.SessionFactory; /** * An interceptor to wrap a read-only transaction around a request. Used to * ensure that nothing will be flushed at the end of the hibernate session. */ public class ReadOnlyInterceptor implements Interceptor { private SessionFactory sessionFactory; public void init() { } public void destroy() { } public String intercept(ActionInvocation invocation) throws Exception { Session session = sessionFactory.getCurrentSession(); session.setFlushMode(FlushMode.MANUAL); return invocation.invoke(); } public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } }