<commit_before>package org.ccci.gto.android.common.db

import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteTransactionListener
import androidx.annotation.RestrictTo
import androidx.core.util.Pools.SynchronizedPool
import java.io.Closeable

private const val STATE_INIT = 0
private const val STATE_OPEN = 1
private const val STATE_SUCCESSFUL = 2
private const val STATE_CLOSED = 3
private const val STATE_RECYCLED = 4

private val POOL = SynchronizedPool<Transaction>(10)

/**
 * Not Thread-safe, this object is designed to be used on a single-thread only
 */
@Deprecated("""
    Since v3.3.0, this is now an internal class and not meant to be part of the public API.
    You should transition to utilize Dao.inTransaction() or Dao.transaction {} instead.
    This will be restricted to Library usage only in v3.4.0, and removed from the public API completely in v3.5.0.
    """)
class Transaction private constructor(
    private var db: SQLiteDatabase?,
    internal var transactionListener: SQLiteTransactionListener? = null
) : Closeable {
    private var state = STATE_INIT

    fun begin() = beginTransaction(true)
    fun beginTransactionNonExclusive() = beginTransaction(false)
    @JvmOverloads
    fun beginTransaction(exclusive: Boolean = true): Transaction {
        if (state < STATE_OPEN) {
            db?.run {
                if (exclusive) beginTransactionWithListener(transactionListener)
                else beginTransactionWithListenerNonExclusive(transactionListener)
            }
            state = STATE_OPEN
        }
        return this
    }

    fun setSuccessful() = setTransactionSuccessful()
    fun setTransactionSuccessful(): Transaction {
        if (state in STATE_OPEN until STATE_SUCCESSFUL) {
            db?.setTransactionSuccessful()
            state = STATE_SUCCESSFUL<commit_msg>db is only null in the recycled state.<commit_after>package org.ccci.gto.android.common.db

import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteTransactionListener
import androidx.annotation.RestrictTo
import androidx.core.util.Pools.SynchronizedPool
import java.io.Closeable

private const val STATE_INIT = 0
private const val STATE_OPEN = 1
private const val STATE_SUCCESSFUL = 2
private const val STATE_CLOSED = 3
private const val STATE_RECYCLED = 4

private val POOL = SynchronizedPool<Transaction>(10)

/**
 * Not Thread-safe, this object is designed to be used on a single-thread only
 */
@Deprecated("""
    Since v3.3.0, this is now an internal class and not meant to be part of the public API.
    You should transition to utilize Dao.inTransaction() or Dao.transaction {} instead.
    This will be restricted to Library usage only in v3.4.0, and removed from the public API completely in v3.5.0.
    """)
class Transaction private constructor(
    private var db: SQLiteDatabase?,
    internal var transactionListener: SQLiteTransactionListener? = null
) : Closeable {
    private var state = STATE_INIT

    fun begin() = beginTransaction(true)
    fun beginTransactionNonExclusive() = beginTransaction(false)
    @JvmOverloads
    fun beginTransaction(exclusive: Boolean = true): Transaction {
        if (state < STATE_OPEN) {
            if (exclusive) db!!.beginTransactionWithListener(transactionListener)
            else db!!.beginTransactionWithListenerNonExclusive(transactionListener)
            state = STATE_OPEN
        }
        return this
    }

    fun setSuccessful() = setTransactionSuccessful()
    fun setTransactionSuccessful(): Transaction {
        if (state in STATE_OPEN until STATE_SUCCESSFUL) {
            db!!.setTransactionSuccessful()
            state = STATE_SUCCESSFUL
{'fraction_non_alphanumeric': 0.07077255537547272, 'fraction_numerical': 0.00864397622906537, 'mean_word_length': 3.622971285892634, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '984445', 'n_tokens_mistral': 1013, 'n_tokens_neox': 973, 'n_words': 323}