<commit_before>package com.tightdb;

import com.tightdb.internal.CloseMutex;
import com.tightdb.typed.TightDB;

public class SharedGroup {
	
    private long nativePtr;
    private boolean activeTransaction;

    static {
        TightDB.loadLibrary();
    }

    public enum Durability {
    	FULL(0),
    	MEM_ONLY(1),
    	ASYNC(2);
        private final int value;
        private Durability(int value)
        {
            this.value = value;
        }
        public int getValue() {
        	return value;
        }
    }
    
    public SharedGroup(String databaseFile) {
        this.nativePtr = createNative(databaseFile, Durability.FULL.getValue(), false, false);
        checkNativePtr();
    }
    public SharedGroup(String databaseFile, Durability durability) {
        this.nativePtr = createNative(databaseFile, durability.getValue(), false, false);
        checkNativePtr();
    }
    public SharedGroup(String databaseFile, Durability durability, boolean fileMustExist) {
        this.nativePtr = createNative(databaseFile, durability.getValue(), fileMustExist, false);
        checkNativePtr();
    }
/*
    SharedGroup(String databaseFile, Durability durability, boolean no_create, boolean enableReplication) {
        this.nativePtr = createNative(databaseFile, durability.getValue(), no_create, enableReplication);
        checkNativePtr();
    }
*/
    public WriteTransaction beginWrite() {
        if (activeTransaction)
            throw new IllegalStateException(
                    "Can't beginWrite() during another active transaction");
        // FIXME: throw from nativeMethod in case of error
        WriteTransaction t = new WriteTransaction(this,
                nativeBeginWrite(nativePtr));
        activeTransaction = true;
        return t;
    }

    long beginReadGroup() {
        if (activeTransaction)
            throw new IllegalStateException(
                    "Can't beginReadGroup() during another active transaction");
        activeTransaction = true;
        return nativeBeginRead(nativePtr);
    }

    public ReadTransaction beginRead() {
        if (activeTransaction)
            throw new IllegalStateException(
                    "Can't beginRead() during another active transaction");
        // FIXME: throw from nativeMethod in case of error
        ReadTransaction t = new ReadTransaction(this, nativeBeginRead(nativePtr));
        activeTransaction = true;
        return t;
    }

    void endRead() {
        if(isClosed())
            throw new IllegalStateException(
                    "Can't endRead() on closed group. ReadTransaction is invalid.");
        nativeEndRead(nativePtr);
        activeTransaction = false;
    }

    public void close() {
        if (activeTransaction)
            throw new IllegalStateException(
                    "Can't close() SharedGroup during an active transaction");

        doClose();
    }

    void commit() {
        if(isClosed())
            throw new IllegalStateException(
                    "Can't commit() on closed group. WriteTransaction is invalid.");
        nativeCommit(nativePtr);
        activeTransaction = false;
    }

    void rollback() {
        if(isClosed())
            throw new IllegalStateException(
                    "Can't rollback() on closed group. WriteTransaction is invalid.");
        nativeRollback(nativePtr);
        activeTransaction = false;
    }

    private void doClose() {
        synchronized (CloseMutex.getInstance()) {
            if (nativePtr == 0)
                return;
            nativeClose(nativePtr);
            nativePtr = 0;
        }
    }
    
    private boolean isClosed(){
        if(nativePtr == 0){
            return true;
        }
        return false;
    }

    static native String nativeGetDefaultReplicationDatabaseFileName();

    protected void finalize() {
        doClose();
    }<commit_msg>cleanup<commit_after>package com.tightdb;

import com.tightdb.internal.CloseMutex;
import com.tightdb.typed.TightDB;

public class SharedGroup {
	
    private long nativePtr;
    private boolean activeTransaction;

    static {
        TightDB.loadLibrary();
    }

    public enum Durability {
    	FULL(0),
    	MEM_ONLY(1),
    	ASYNC(2);
        private final int value;
        private Durability(int value)
        {
            this.value = value;
        }
        public int getValue() {
        	return value;
        }
    }
    
    public SharedGroup(String databaseFile) {
        this.nativePtr = createNative(databaseFile, Durability.FULL.getValue(), false, false);
        checkNativePtr();
    }
    public SharedGroup(String databaseFile, Durability durability) {
        this.nativePtr = createNative(databaseFile, durability.getValue(), false, false);
        checkNativePtr();
    }
    public SharedGroup(String databaseFile, Durability durability, boolean fileMustExist) {
        this.nativePtr = createNative(databaseFile, durability.getValue(), fileMustExist, false);
        checkNativePtr();
    }
/*
    SharedGroup(String databaseFile, Durability durability, boolean no_create, boolean enableReplication) {
        this.nativePtr = createNative(databaseFile, durability.getValue(), no_create, enableReplication);
        checkNativePtr();
    }
*/
    public WriteTransaction beginWrite() {
        if (activeTransaction)
            throw new IllegalStateException(
                    "Can't beginWrite() during another active transaction");
        // FIXME: throw from nativeMethod in case of error
        WriteTransaction t = new WriteTransaction(this,
                nativeBeginWrite(nativePtr));
        activeTransaction = true;
        return t;
    }

    long beginReadGroup() {
        if (activeTransaction)
            throw new IllegalStateException(
                    "Can't beginReadGroup() during another active transaction");
        activeTransaction = true;
        return nativeBeginRead(nativePtr);
    }

    public ReadTransaction beginRead() {
        if (activeTransaction)
            throw new IllegalStateException(
                    "Can't beginRead() during another active transaction");
        // FIXME: throw from nativeMethod in case of error
        ReadTransaction t = new ReadTransaction(this, nativeBeginRead(nativePtr));
        activeTransaction = true;
        return t;
    }

    void endRead() {
        if (isClosed())
            throw new IllegalStateException(
                    "Can't endRead() on closed group. ReadTransaction is invalid.");
        nativeEndRead(nativePtr);
        activeTransaction = false;
    }

    public void close() {
        if (activeTransaction)
            throw new IllegalStateException(
                    "Can't close() SharedGroup during an active transaction");

        doClose();
    }

    void commit() {
        if (isClosed())
            throw new IllegalStateException(
                    "Can't commit() on closed group. WriteTransaction is invalid.");
        nativeCommit(nativePtr);
        activeTransaction = false;
    }

    void rollback() {
        if (isClosed())
            throw new IllegalStateException(
                    "Can't rollback() on closed group. WriteTransaction is invalid.");
        nativeRollback(nativePtr);
        activeTransaction = false;
    }

    private void doClose() {
        synchronized (CloseMutex.getInstance()) {
            if (nativePtr == 0)
                return;
            nativeClose(nativePtr);
            nativePtr = 0;
        }
    }
    
    private boolean isClosed(){
        return nativePtr == 0;
    }

    static native String nativeGetDefaultReplicationDatabaseFileName();

    protected void finalize() {
        doClose();
    }
{'fraction_non_alphanumeric': 0.08493859082094377, 'fraction_numerical': 0.0015513897866839042, 'mean_word_length': 2.223333333333333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5934659', 'n_tokens_mistral': 1939, 'n_tokens_neox': 1847, 'n_words': 518}