au.com.nicta.ct.db.CtManualFlush.java Source code

Java tutorial

Introduction

Here is the source code for au.com.nicta.ct.db.CtManualFlush.java

Source

// ====================================================================================================================
// Copyright (c) 2013, National ICT Australia Ltd and The Walter and Eliza Hall Institute of Medical Research.
// All rights reserved.
//
// This software and source code is made available under a GPL v2 licence.
// The terms of the licence can be read here: http://www.gnu.org/licenses/gpl-2.0.txt
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// ====================================================================================================================

package au.com.nicta.ct.db;

import org.hibernate.FlushMode;
import org.hibernate.Session;

/**
 *
 * @author alan
 */
public class CtManualFlush {

    Session s;
    FlushMode fm = null;

    public CtManualFlush(Session s) {
        this.s = s;
        fm = s.getFlushMode();
        s.setFlushMode(FlushMode.MANUAL);
    }

    public void restore() {
        if (fm != null) {
            s.setFlushMode(fm);
            fm = null;
        }
    }

    @Override
    protected void finalize() throws Throwable {
        if (fm != null) {
            throw new Exception("Must call restore().");
        }
        super.finalize();
    }

}