Example usage for android.database.sqlite SQLiteTransactionListener onBegin

List of usage examples for android.database.sqlite SQLiteTransactionListener onBegin

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteTransactionListener onBegin.

Prototype

void onBegin();

Source Link

Document

Called immediately after the transaction begins.

Usage

From source file:io.requery.android.database.sqlite.SQLiteSession.java

private void beginTransactionUnchecked(int transactionMode, SQLiteTransactionListener transactionListener,
        int connectionFlags, CancellationSignal cancellationSignal) {
    if (cancellationSignal != null) {
        cancellationSignal.throwIfCanceled();
    }/*from www  .  ja v  a2 s .  c  o m*/

    if (mTransactionStack == null) {
        acquireConnection(null, connectionFlags, cancellationSignal); // might throw
    }
    try {
        // Set up the transaction such that we can back out safely
        // in case we fail part way.
        if (mTransactionStack == null) {
            // Execute SQL might throw a runtime exception.
            switch (transactionMode) {
            case TRANSACTION_MODE_IMMEDIATE:
                mConnection.execute("BEGIN IMMEDIATE;", null, cancellationSignal); // might throw
                break;
            case TRANSACTION_MODE_EXCLUSIVE:
                mConnection.execute("BEGIN EXCLUSIVE;", null, cancellationSignal); // might throw
                break;
            default:
                mConnection.execute("BEGIN;", null, cancellationSignal); // might throw
                break;
            }
        }

        // Listener might throw a runtime exception.
        if (transactionListener != null) {
            try {
                transactionListener.onBegin(); // might throw
            } catch (RuntimeException ex) {
                if (mTransactionStack == null) {
                    mConnection.execute("ROLLBACK;", null, cancellationSignal); // might throw
                }
                throw ex;
            }
        }

        // Bookkeeping can't throw, except an OOM, which is just too bad...
        Transaction transaction = obtainTransaction(transactionMode, transactionListener);
        transaction.mParent = mTransactionStack;
        mTransactionStack = transaction;
    } finally {
        if (mTransactionStack == null) {
            releaseConnection(); // might throw
        }
    }
}