Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add to StorIO.LowLevel getter for underlying sqLiteOpenHelper #706

Merged
merged 2 commits into from
Feb 9, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.WorkerThread;
Expand Down Expand Up @@ -329,6 +330,21 @@ public static abstract class LowLevel {
* how to use this and when transactions are committed and rolled back.
*/
public abstract void endTransaction();

/**
* Returns {@link SQLiteOpenHelper} for the direct access to underlining database.
* It can be used in cases when {@link StorIOSQLite} APIs are not enough.
* <p>
* Notice: Database changes through the direct access
* to the {@link SQLiteOpenHelper} will not trigger notifications.
* If it possible you should use {@link StorIOSQLite} methods instead
* or call {@link #notifyAboutChanges(Changes)} manually.
*
* @return {@link SQLiteOpenHelper}.
*/
@NonNull
public abstract SQLiteOpenHelper sqliteOpenHelper();

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,15 @@ public void endTransaction() {
numberOfRunningTransactions.decrementAndGet();
notifyAboutPendingChangesIfNotInTransaction();
}

/**
* {@inheritDoc}
*/
@NonNull
@Override
public SQLiteOpenHelper sqliteOpenHelper() {
return sqLiteOpenHelper;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

Expand Down Expand Up @@ -94,6 +95,14 @@ public void setTransactionSuccessful() {
public void endTransaction() {
// no impl
}

@NonNull
@Override
public SQLiteOpenHelper sqliteOpenHelper() {
// not required in design test
// noinspection ConstantConditions
return null;
}
};

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ public void nullSQLiteOpenHelper() {
builder.sqliteOpenHelper(null);
}

@Test
public void lowLevelReturnsSameInstanceOfSQLiteOpenHelper() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

SQLiteOpenHelper sqLiteOpenHelper = mock(SQLiteOpenHelper.class);
DefaultStorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder()
.sqliteOpenHelper(sqLiteOpenHelper)
.build();
assertThat(storIOSQLite.lowLevel().sqliteOpenHelper()).isSameAs(sqLiteOpenHelper);
}

@Test
public void addTypeMappingNullType() {
DefaultStorIOSQLite.CompleteBuilder builder = DefaultStorIOSQLite.builder()
Expand Down