Converting `sqlite` related files in `sqlite` from Java to Kotlin (Part 1/3).
Test: Existing tests
Bug: 240707042
Relnote: Converting `sqlite` related files in `sqlite` from Java to Kotlin.
Change-Id: I7bc3574feaacb12bd4aa1c006579ddc52607a3a5
diff --git a/room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/test/QueryInterceptorTest.kt b/room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/test/QueryInterceptorTest.kt
index c2d6323..145d0d1 100644
--- a/room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/test/QueryInterceptorTest.kt
+++ b/room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/test/QueryInterceptorTest.kt
@@ -158,7 +158,7 @@
SimpleSQLiteQuery(
"INSERT OR ABORT INTO `queryInterceptorTestDatabase` (`id`,`description`) " +
"VALUES (?,?)",
- arrayOf<Any>("3", "Description")
+ arrayOf("3", "Description")
)
)
assertQueryLogged(
diff --git a/room/room-compiler/build.gradle b/room/room-compiler/build.gradle
index 13d97c6..ad40553 100644
--- a/room/room-compiler/build.gradle
+++ b/room/room-compiler/build.gradle
@@ -125,7 +125,7 @@
dir: provider {
// Wrapping in a provider as we access buildDir before this project is configured
// Replace with AGP API once it is added b/228109260
- "${new File(project(":sqlite:sqlite").buildDir, "libJar")}"
+ "${new File(project(":sqlite:sqlite").buildDir, "intermediates/compile_library_classes_jar/release/")}"
},
include : "*.jar"
))
diff --git a/room/room-runtime/api/restricted_current.ignore b/room/room-runtime/api/restricted_current.ignore
index d53b9c9..ac20e68 100644
--- a/room/room-runtime/api/restricted_current.ignore
+++ b/room/room-runtime/api/restricted_current.ignore
@@ -1,6 +1,30 @@
// Baseline format: 1.0
AddedFinal: androidx.room.Room:
Class androidx.room.Room added 'final' qualifier
+AddedFinal: androidx.room.RoomSQLiteQuery#bindBlob(int, byte[]):
+ Method androidx.room.RoomSQLiteQuery.bindBlob has added 'final' qualifier
+AddedFinal: androidx.room.RoomSQLiteQuery#bindDouble(int, double):
+ Method androidx.room.RoomSQLiteQuery.bindDouble has added 'final' qualifier
+AddedFinal: androidx.room.RoomSQLiteQuery#bindLong(int, long):
+ Method androidx.room.RoomSQLiteQuery.bindLong has added 'final' qualifier
+AddedFinal: androidx.room.RoomSQLiteQuery#bindNull(int):
+ Method androidx.room.RoomSQLiteQuery.bindNull has added 'final' qualifier
+AddedFinal: androidx.room.RoomSQLiteQuery#bindString(int, String):
+ Method androidx.room.RoomSQLiteQuery.bindString has added 'final' qualifier
+AddedFinal: androidx.room.RoomSQLiteQuery#bindTo(androidx.sqlite.db.SupportSQLiteProgram):
+ Method androidx.room.RoomSQLiteQuery.bindTo has added 'final' qualifier
+AddedFinal: androidx.room.RoomSQLiteQuery#clearBindings():
+ Method androidx.room.RoomSQLiteQuery.clearBindings has added 'final' qualifier
+AddedFinal: androidx.room.RoomSQLiteQuery#close():
+ Method androidx.room.RoomSQLiteQuery.close has added 'final' qualifier
+AddedFinal: androidx.room.RoomSQLiteQuery#copyArgumentsFrom(androidx.room.RoomSQLiteQuery):
+ Method androidx.room.RoomSQLiteQuery.copyArgumentsFrom has added 'final' qualifier
+AddedFinal: androidx.room.RoomSQLiteQuery#getArgCount():
+ Method androidx.room.RoomSQLiteQuery.getArgCount has added 'final' qualifier
+AddedFinal: androidx.room.RoomSQLiteQuery#getSql():
+ Method androidx.room.RoomSQLiteQuery.getSql has added 'final' qualifier
+AddedFinal: androidx.room.RoomSQLiteQuery#release():
+ Method androidx.room.RoomSQLiteQuery.release has added 'final' qualifier
ChangedType: androidx.room.DatabaseConfiguration#autoMigrationSpecs:
diff --git a/room/room-runtime/api/restricted_current.txt b/room/room-runtime/api/restricted_current.txt
index aa860b1..ee903c6 100644
--- a/room/room-runtime/api/restricted_current.txt
+++ b/room/room-runtime/api/restricted_current.txt
@@ -225,28 +225,29 @@
field public final boolean isValid;
}
- @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX) public class RoomSQLiteQuery implements androidx.sqlite.db.SupportSQLiteProgram androidx.sqlite.db.SupportSQLiteQuery {
- method public static final androidx.room.RoomSQLiteQuery acquire(String query, int argumentCount);
+ @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX) public final class RoomSQLiteQuery implements androidx.sqlite.db.SupportSQLiteProgram androidx.sqlite.db.SupportSQLiteQuery {
+ method public static androidx.room.RoomSQLiteQuery acquire(String query, int argumentCount);
method public void bindBlob(int index, byte[] value);
method public void bindDouble(int index, double value);
method public void bindLong(int index, long value);
method public void bindNull(int index);
method public void bindString(int index, String value);
- method public void bindTo(androidx.sqlite.db.SupportSQLiteProgram program);
+ method public void bindTo(androidx.sqlite.db.SupportSQLiteProgram statement);
method public void clearBindings();
method public void close();
method public void copyArgumentsFrom(androidx.room.RoomSQLiteQuery other);
- method public static final androidx.room.RoomSQLiteQuery copyFrom(androidx.sqlite.db.SupportSQLiteQuery supportSQLiteQuery);
+ method public static androidx.room.RoomSQLiteQuery copyFrom(androidx.sqlite.db.SupportSQLiteQuery supportSQLiteQuery);
method public int getArgCount();
- method public final int getCapacity();
+ method public int getCapacity();
method public String getSql();
method public void init(String query, int initArgCount);
method public void release();
+ property public int argCount;
property public final int capacity;
+ property public String sql;
field public static final androidx.room.RoomSQLiteQuery.Companion Companion;
field @VisibleForTesting public static final int DESIRED_POOL_SIZE = 10; // 0xa
field @VisibleForTesting public static final int POOL_LIMIT = 15; // 0xf
- field @VisibleForTesting public int argCount;
field @VisibleForTesting public final byte[]![] blobBindings;
field @VisibleForTesting public final double[] doubleBindings;
field @VisibleForTesting public final long[] longBindings;
diff --git a/room/room-runtime/src/main/java/androidx/room/QueryInterceptorDatabase.kt b/room/room-runtime/src/main/java/androidx/room/QueryInterceptorDatabase.kt
index 1ae68ea3..ab9a009 100644
--- a/room/room-runtime/src/main/java/androidx/room/QueryInterceptorDatabase.kt
+++ b/room/room-runtime/src/main/java/androidx/room/QueryInterceptorDatabase.kt
@@ -103,7 +103,7 @@
val queryInterceptorProgram = QueryInterceptorProgram()
query.bindTo(queryInterceptorProgram)
queryCallbackExecutor.execute {
- queryCallback.onQuery(query.getSql(), queryInterceptorProgram.bindArgsCache)
+ queryCallback.onQuery(query.sql, queryInterceptorProgram.bindArgsCache)
}
return delegate.query(query)
}
diff --git a/room/room-runtime/src/main/java/androidx/room/RoomSQLiteQuery.kt b/room/room-runtime/src/main/java/androidx/room/RoomSQLiteQuery.kt
index 4c0ee9b..c13695e 100644
--- a/room/room-runtime/src/main/java/androidx/room/RoomSQLiteQuery.kt
+++ b/room/room-runtime/src/main/java/androidx/room/RoomSQLiteQuery.kt
@@ -32,7 +32,7 @@
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
-open class RoomSQLiteQuery private constructor(
+class RoomSQLiteQuery private constructor(
@field:VisibleForTesting val capacity: Int
) : SupportSQLiteQuery, SupportSQLiteProgram {
@Volatile
@@ -58,11 +58,10 @@
private val bindingTypes: IntArray
// number of arguments in the query
- @JvmField
- @VisibleForTesting
- var argCount = 0
+ override var argCount = 0
+ private set
- open fun init(query: String, initArgCount: Int) {
+ fun init(query: String, initArgCount: Int) {
this.query = query
argCount = initArgCount
}
@@ -83,29 +82,24 @@
* After released, the statement might be returned when [.acquire] is called
* so you should never re-use it after releasing.
*/
- open fun release() {
+ fun release() {
synchronized(queryPool) {
queryPool[capacity] = this
prunePoolLocked()
}
}
- override fun getSql(): String {
- return requireNotNull(query)
- }
+ override val sql: String
+ get() = checkNotNull(this.query)
- override fun getArgCount(): Int {
- return argCount
- }
-
- override fun bindTo(program: SupportSQLiteProgram) {
+ override fun bindTo(statement: SupportSQLiteProgram) {
for (index in 1..argCount) {
when (bindingTypes[index]) {
- NULL -> program.bindNull(index)
- LONG -> program.bindLong(index, longBindings[index])
- DOUBLE -> program.bindDouble(index, doubleBindings[index])
- STRING -> program.bindString(index, requireNotNull(stringBindings[index]))
- BLOB -> program.bindBlob(index, requireNotNull(blobBindings[index]))
+ NULL -> statement.bindNull(index)
+ LONG -> statement.bindLong(index, longBindings[index])
+ DOUBLE -> statement.bindDouble(index, doubleBindings[index])
+ STRING -> statement.bindString(index, requireNotNull(stringBindings[index]))
+ BLOB -> statement.bindBlob(index, requireNotNull(blobBindings[index]))
}
}
}
@@ -143,7 +137,7 @@
*
* @param other The other query, which holds the arguments to be copied.
*/
- open fun copyArgumentsFrom(other: RoomSQLiteQuery) {
+ fun copyArgumentsFrom(other: RoomSQLiteQuery) {
val argCount = other.argCount + 1 // +1 for the binding offsets
System.arraycopy(other.bindingTypes, 0, bindingTypes, 0, argCount)
System.arraycopy(other.longBindings, 0, longBindings, 0, argCount)
diff --git a/room/room-runtime/src/test/java/androidx/room/RoomSQLiteQueryTest.java b/room/room-runtime/src/test/java/androidx/room/RoomSQLiteQueryTest.java
index 3ff9773..0738a49 100644
--- a/room/room-runtime/src/test/java/androidx/room/RoomSQLiteQueryTest.java
+++ b/room/room-runtime/src/test/java/androidx/room/RoomSQLiteQueryTest.java
@@ -45,7 +45,7 @@
public void acquireBasic() {
RoomSQLiteQuery query = RoomSQLiteQuery.acquire("abc", 3);
assertThat(query.getSql(), is("abc"));
- assertThat(query.argCount, is(3));
+ assertThat(query.getArgCount(), is(3));
assertThat(query.blobBindings.length, is(4));
assertThat(query.longBindings.length, is(4));
assertThat(query.stringBindings.length, is(4));
diff --git a/sqlite/sqlite-framework/build.gradle b/sqlite/sqlite-framework/build.gradle
index 8f170c3..657c4f3 100644
--- a/sqlite/sqlite-framework/build.gradle
+++ b/sqlite/sqlite-framework/build.gradle
@@ -25,6 +25,7 @@
dependencies {
api("androidx.annotation:annotation:1.2.0")
api(project(":sqlite:sqlite"))
+ implementation(libs.kotlinStdlib)
androidTestImplementation(libs.kotlinStdlib)
androidTestImplementation(libs.testExtJunit)
androidTestImplementation(libs.testCore)
diff --git a/sqlite/sqlite/api/current.txt b/sqlite/sqlite/api/current.txt
index 1014417..53bbd20 100644
--- a/sqlite/sqlite/api/current.txt
+++ b/sqlite/sqlite/api/current.txt
@@ -2,12 +2,19 @@
package androidx.sqlite.db {
public final class SimpleSQLiteQuery implements androidx.sqlite.db.SupportSQLiteQuery {
- ctor public SimpleSQLiteQuery(String, Object![]?);
- ctor public SimpleSQLiteQuery(String);
- method public static void bind(androidx.sqlite.db.SupportSQLiteProgram, Object![]?);
- method public void bindTo(androidx.sqlite.db.SupportSQLiteProgram);
+ ctor public SimpleSQLiteQuery(String query, Object![]? bindArgs);
+ ctor public SimpleSQLiteQuery(String query);
+ method public static void bind(androidx.sqlite.db.SupportSQLiteProgram statement, Object![]? bindArgs);
+ method public void bindTo(androidx.sqlite.db.SupportSQLiteProgram statement);
method public int getArgCount();
method public String getSql();
+ property public int argCount;
+ property public String sql;
+ field public static final androidx.sqlite.db.SimpleSQLiteQuery.Companion Companion;
+ }
+
+ public static final class SimpleSQLiteQuery.Companion {
+ method public void bind(androidx.sqlite.db.SupportSQLiteProgram statement, Object![]? bindArgs);
}
public interface SupportSQLiteDatabase extends java.io.Closeable {
@@ -94,18 +101,20 @@
}
public interface SupportSQLiteProgram extends java.io.Closeable {
- method public void bindBlob(int, byte[]);
- method public void bindDouble(int, double);
- method public void bindLong(int, long);
- method public void bindNull(int);
- method public void bindString(int, String);
+ method public void bindBlob(int index, byte[] value);
+ method public void bindDouble(int index, double value);
+ method public void bindLong(int index, long value);
+ method public void bindNull(int index);
+ method public void bindString(int index, String value);
method public void clearBindings();
}
public interface SupportSQLiteQuery {
- method public void bindTo(androidx.sqlite.db.SupportSQLiteProgram);
+ method public void bindTo(androidx.sqlite.db.SupportSQLiteProgram statement);
method public int getArgCount();
method public String getSql();
+ property public abstract int argCount;
+ property public abstract String sql;
}
public final class SupportSQLiteQueryBuilder {
diff --git a/sqlite/sqlite/api/public_plus_experimental_current.txt b/sqlite/sqlite/api/public_plus_experimental_current.txt
index 1014417..53bbd20 100644
--- a/sqlite/sqlite/api/public_plus_experimental_current.txt
+++ b/sqlite/sqlite/api/public_plus_experimental_current.txt
@@ -2,12 +2,19 @@
package androidx.sqlite.db {
public final class SimpleSQLiteQuery implements androidx.sqlite.db.SupportSQLiteQuery {
- ctor public SimpleSQLiteQuery(String, Object![]?);
- ctor public SimpleSQLiteQuery(String);
- method public static void bind(androidx.sqlite.db.SupportSQLiteProgram, Object![]?);
- method public void bindTo(androidx.sqlite.db.SupportSQLiteProgram);
+ ctor public SimpleSQLiteQuery(String query, Object![]? bindArgs);
+ ctor public SimpleSQLiteQuery(String query);
+ method public static void bind(androidx.sqlite.db.SupportSQLiteProgram statement, Object![]? bindArgs);
+ method public void bindTo(androidx.sqlite.db.SupportSQLiteProgram statement);
method public int getArgCount();
method public String getSql();
+ property public int argCount;
+ property public String sql;
+ field public static final androidx.sqlite.db.SimpleSQLiteQuery.Companion Companion;
+ }
+
+ public static final class SimpleSQLiteQuery.Companion {
+ method public void bind(androidx.sqlite.db.SupportSQLiteProgram statement, Object![]? bindArgs);
}
public interface SupportSQLiteDatabase extends java.io.Closeable {
@@ -94,18 +101,20 @@
}
public interface SupportSQLiteProgram extends java.io.Closeable {
- method public void bindBlob(int, byte[]);
- method public void bindDouble(int, double);
- method public void bindLong(int, long);
- method public void bindNull(int);
- method public void bindString(int, String);
+ method public void bindBlob(int index, byte[] value);
+ method public void bindDouble(int index, double value);
+ method public void bindLong(int index, long value);
+ method public void bindNull(int index);
+ method public void bindString(int index, String value);
method public void clearBindings();
}
public interface SupportSQLiteQuery {
- method public void bindTo(androidx.sqlite.db.SupportSQLiteProgram);
+ method public void bindTo(androidx.sqlite.db.SupportSQLiteProgram statement);
method public int getArgCount();
method public String getSql();
+ property public abstract int argCount;
+ property public abstract String sql;
}
public final class SupportSQLiteQueryBuilder {
diff --git a/sqlite/sqlite/api/restricted_current.txt b/sqlite/sqlite/api/restricted_current.txt
index 1014417..53bbd20 100644
--- a/sqlite/sqlite/api/restricted_current.txt
+++ b/sqlite/sqlite/api/restricted_current.txt
@@ -2,12 +2,19 @@
package androidx.sqlite.db {
public final class SimpleSQLiteQuery implements androidx.sqlite.db.SupportSQLiteQuery {
- ctor public SimpleSQLiteQuery(String, Object![]?);
- ctor public SimpleSQLiteQuery(String);
- method public static void bind(androidx.sqlite.db.SupportSQLiteProgram, Object![]?);
- method public void bindTo(androidx.sqlite.db.SupportSQLiteProgram);
+ ctor public SimpleSQLiteQuery(String query, Object![]? bindArgs);
+ ctor public SimpleSQLiteQuery(String query);
+ method public static void bind(androidx.sqlite.db.SupportSQLiteProgram statement, Object![]? bindArgs);
+ method public void bindTo(androidx.sqlite.db.SupportSQLiteProgram statement);
method public int getArgCount();
method public String getSql();
+ property public int argCount;
+ property public String sql;
+ field public static final androidx.sqlite.db.SimpleSQLiteQuery.Companion Companion;
+ }
+
+ public static final class SimpleSQLiteQuery.Companion {
+ method public void bind(androidx.sqlite.db.SupportSQLiteProgram statement, Object![]? bindArgs);
}
public interface SupportSQLiteDatabase extends java.io.Closeable {
@@ -94,18 +101,20 @@
}
public interface SupportSQLiteProgram extends java.io.Closeable {
- method public void bindBlob(int, byte[]);
- method public void bindDouble(int, double);
- method public void bindLong(int, long);
- method public void bindNull(int);
- method public void bindString(int, String);
+ method public void bindBlob(int index, byte[] value);
+ method public void bindDouble(int index, double value);
+ method public void bindLong(int index, long value);
+ method public void bindNull(int index);
+ method public void bindString(int index, String value);
method public void clearBindings();
}
public interface SupportSQLiteQuery {
- method public void bindTo(androidx.sqlite.db.SupportSQLiteProgram);
+ method public void bindTo(androidx.sqlite.db.SupportSQLiteProgram statement);
method public int getArgCount();
method public String getSql();
+ property public abstract int argCount;
+ property public abstract String sql;
}
public final class SupportSQLiteQueryBuilder {
diff --git a/sqlite/sqlite/build.gradle b/sqlite/sqlite/build.gradle
index 63ddf32..d3f6c60 100644
--- a/sqlite/sqlite/build.gradle
+++ b/sqlite/sqlite/build.gradle
@@ -19,10 +19,12 @@
plugins {
id("AndroidXPlugin")
id("com.android.library")
+ id("org.jetbrains.kotlin.android")
}
dependencies {
api("androidx.annotation:annotation:1.0.0")
+ implementation(libs.kotlinStdlib)
testImplementation(libs.junit)
testImplementation(libs.mockitoCore)
}
diff --git a/sqlite/sqlite/src/main/java/androidx/sqlite/db/SimpleSQLiteQuery.kt b/sqlite/sqlite/src/main/java/androidx/sqlite/db/SimpleSQLiteQuery.kt
index c558ecf..2e6a9d9 100644
--- a/sqlite/sqlite/src/main/java/androidx/sqlite/db/SimpleSQLiteQuery.kt
+++ b/sqlite/sqlite/src/main/java/androidx/sqlite/db/SimpleSQLiteQuery.kt
@@ -13,100 +13,100 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package androidx.sqlite.db
-package androidx.sqlite.db;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
+import android.annotation.SuppressLint
/**
- * A basic implementation of {@link SupportSQLiteQuery} which receives a query and its args and
- * binds args based on the passed in the Object type.
+ * A basic implementation of [SupportSQLiteQuery] which receives a query and its args and
+ * binds args based on the passed in Object type.
+ *
+ * @constructor Creates an SQL query with the sql string and the bind arguments.
+ *
+ * @param query The query string, can include bind arguments (.e.g ?).
+ * @param bindArgs The bind argument value that will replace the placeholders in the query.
*/
-public final class SimpleSQLiteQuery implements SupportSQLiteQuery {
- private final String mQuery;
- @Nullable
- private final Object[] mBindArgs;
-
- /**
- * Creates an SQL query with the sql string and the bind arguments.
- *
- * @param query The query string, can include bind arguments (.e.g ?).
- * @param bindArgs The bind argument value that will replace the placeholders in the query.
- */
- public SimpleSQLiteQuery(@NonNull String query, @Nullable Object[] bindArgs) {
- mQuery = query;
- mBindArgs = bindArgs;
- }
+class SimpleSQLiteQuery(
+ private val query: String,
+ @Suppress("ArrayReturn") // Due to legacy API
+ private val bindArgs: Array<Any?>?
+ ) : SupportSQLiteQuery {
/**
* Creates an SQL query without any bind arguments.
*
* @param query The SQL query to execute. Cannot include bind parameters.
*/
- public SimpleSQLiteQuery(@NonNull String query) {
- this(query, null);
- }
+ constructor(query: String) : this(query, null)
- @NonNull
- @Override
- public String getSql() {
- return mQuery;
- }
-
- @Override
- public void bindTo(@NonNull SupportSQLiteProgram statement) {
- bind(statement, mBindArgs);
- }
-
- @Override
- public int getArgCount() {
- return mBindArgs == null ? 0 : mBindArgs.length;
- }
+ override val sql: String
+ get() = this.query
/**
- * Binds the given arguments into the given sqlite statement.
+ * Creates an SQL query without any bind arguments.
*
- * @param statement The sqlite statement
- * @param bindArgs The list of bind arguments
+ * @param [statement] The SQL query to execute. Cannot include bind parameters.
*/
- public static void bind(@NonNull SupportSQLiteProgram statement, @Nullable Object[] bindArgs) {
- if (bindArgs == null) {
- return;
- }
- final int limit = bindArgs.length;
- for (int i = 0; i < limit; i++) {
- final Object arg = bindArgs[i];
- bind(statement, i + 1, arg);
- }
+ override fun bindTo(statement: SupportSQLiteProgram) {
+ bind(statement, bindArgs)
}
- private static void bind(SupportSQLiteProgram statement, int index, Object arg) {
- // extracted from android.database.sqlite.SQLiteConnection
- if (arg == null) {
- statement.bindNull(index);
- } else if (arg instanceof byte[]) {
- statement.bindBlob(index, (byte[]) arg);
- } else if (arg instanceof Float) {
- statement.bindDouble(index, (Float) arg);
- } else if (arg instanceof Double) {
- statement.bindDouble(index, (Double) arg);
- } else if (arg instanceof Long) {
- statement.bindLong(index, (Long) arg);
- } else if (arg instanceof Integer) {
- statement.bindLong(index, (Integer) arg);
- } else if (arg instanceof Short) {
- statement.bindLong(index, (Short) arg);
- } else if (arg instanceof Byte) {
- statement.bindLong(index, (Byte) arg);
- } else if (arg instanceof String) {
- statement.bindString(index, (String) arg);
- } else if (arg instanceof Boolean) {
- statement.bindLong(index, ((Boolean) arg) ? 1 : 0);
- } else {
- throw new IllegalArgumentException("Cannot bind " + arg + " at index " + index
- + " Supported types: null, byte[], float, double, long, int, short, byte,"
- + " string");
+ override val argCount: Int
+ get() = bindArgs?.size ?: 0
+
+ companion object {
+ /**
+ * Binds the given arguments into the given sqlite statement.
+ *
+ * @param [statement] The sqlite statement
+ * @param [bindArgs] The list of bind arguments
+ */
+ @SuppressLint("SyntheticAccessor")
+ @JvmStatic
+ fun bind(
+ statement: SupportSQLiteProgram,
+ @Suppress("ArrayReturn") // Due to legacy API
+ bindArgs: Array<Any?>?
+ ) {
+ if (bindArgs == null) {
+ return
+ }
+
+ val limit = bindArgs.size
+ for (i in 0 until limit) {
+ val arg = bindArgs[i]
+ bind(statement, i + 1, arg)
+ }
+ }
+
+ private fun bind(statement: SupportSQLiteProgram, index: Int, arg: Any?) {
+ // extracted from android.database.sqlite.SQLiteConnection
+ if (arg == null) {
+ statement.bindNull(index)
+ } else if (arg is ByteArray) {
+ statement.bindBlob(index, arg)
+ } else if (arg is Float) {
+ statement.bindDouble(index, arg.toDouble())
+ } else if (arg is Double) {
+ statement.bindDouble(index, arg)
+ } else if (arg is Long) {
+ statement.bindLong(index, arg)
+ } else if (arg is Int) {
+ statement.bindLong(index, arg.toLong())
+ } else if (arg is Short) {
+ statement.bindLong(index, arg.toLong())
+ } else if (arg is Byte) {
+ statement.bindLong(index, arg.toLong())
+ } else if (arg is String) {
+ statement.bindString(index, arg)
+ } else if (arg is Boolean) {
+ statement.bindLong(index, if (arg) 1 else 0)
+ } else {
+ throw IllegalArgumentException(
+ "Cannot bind $arg at index $index Supported types: Null, ByteArray, " +
+ "Float, Double, Long, Int, Short, Byte, String"
+ )
+ }
}
}
-}
+}
\ No newline at end of file
diff --git a/sqlite/sqlite/src/main/java/androidx/sqlite/db/SupportSQLiteCompat.kt b/sqlite/sqlite/src/main/java/androidx/sqlite/db/SupportSQLiteCompat.kt
index 286d449..c0d7fd8 100644
--- a/sqlite/sqlite/src/main/java/androidx/sqlite/db/SupportSQLiteCompat.kt
+++ b/sqlite/sqlite/src/main/java/androidx/sqlite/db/SupportSQLiteCompat.kt
@@ -13,36 +13,29 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package androidx.sqlite.db
-package androidx.sqlite.db;
-
-import android.app.ActivityManager;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.database.ContentObserver;
-import android.database.Cursor;
-import android.database.sqlite.SQLiteDatabase;
-import android.database.sqlite.SQLiteOpenHelper;
-import android.net.Uri;
-import android.os.Bundle;
-import android.os.CancellationSignal;
-import android.os.OperationCanceledException;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.RequiresApi;
-import androidx.annotation.RestrictTo;
-
-import java.io.File;
-import java.util.List;
+import android.app.ActivityManager
+import android.content.ContentResolver
+import android.content.Context
+import android.database.Cursor
+import android.database.sqlite.SQLiteDatabase
+import android.database.sqlite.SQLiteDatabase.CursorFactory
+import android.database.sqlite.SQLiteOpenHelper
+import android.net.Uri
+import android.os.Bundle
+import android.os.CancellationSignal
+import androidx.annotation.RequiresApi
+import androidx.annotation.RestrictTo
+import java.io.File
/**
- * Helper for accessing features in {@link SupportSQLiteOpenHelper}.
+ * Helper for accessing features in [SupportSQLiteOpenHelper].
*
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
-public final class SupportSQLiteCompat {
- private SupportSQLiteCompat() { }
+class SupportSQLiteCompat private constructor() {
/**
* Class for accessing functions that require SDK version 16 and higher.
*
@@ -50,8 +43,7 @@
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@RequiresApi(16)
- public static final class Api16Impl {
-
+ object Api16Impl {
/**
* Cancels the operation and signals the cancellation listener. If the operation has not yet
* started, then it will be canceled as soon as it does.
@@ -59,8 +51,9 @@
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
- public static void cancel(@NonNull CancellationSignal cancellationSignal) {
- cancellationSignal.cancel();
+ @JvmStatic
+ fun cancel(cancellationSignal: CancellationSignal) {
+ cancellationSignal.cancel()
}
/**
@@ -71,9 +64,9 @@
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
- @NonNull
- public static CancellationSignal createCancellationSignal() {
- return new CancellationSignal();
+ @JvmStatic
+ fun createCancellationSignal(): CancellationSignal {
+ return CancellationSignal()
}
/**
@@ -86,9 +79,9 @@
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
- @SuppressWarnings("StreamFiles")
- public static boolean deleteDatabase(@NonNull File file) {
- return SQLiteDatabase.deleteDatabase(file);
+ @JvmStatic
+ fun deleteDatabase(file: File): Boolean {
+ return SQLiteDatabase.deleteDatabase(file)
}
/**
@@ -96,26 +89,32 @@
*
* @param sql the SQL query. The SQL string must not be ; terminated
* @param selectionArgs You may include ?s in where clause in the query,
- * which will be replaced by the values from selectionArgs. The
- * values will be bound as Strings.
+ * which will be replaced by the values from selectionArgs. The
+ * values will be bound as Strings.
* @param editTable the name of the first table, which is editable
* @param cancellationSignal A signal to cancel the operation in progress, or null if none.
- * If the operation is canceled, then {@link OperationCanceledException} will be thrown
+ * If the operation is canceled, then [OperationCanceledException] will be thrown
* when the query is executed.
* @param cursorFactory the cursor factory to use, or null for the default factory
- * @return A {@link Cursor} object, which is positioned before the first entry. Note that
- * {@link Cursor}s are not synchronized, see the documentation for more details.
+ * @return A [Cursor] object, which is positioned before the first entry. Note that
+ * [Cursor]s are not synchronized, see the documentation for more details.
*
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
- @NonNull
- public static Cursor rawQueryWithFactory(@NonNull SQLiteDatabase sQLiteDatabase,
- @NonNull String sql, @NonNull String[] selectionArgs,
- @NonNull String editTable, @NonNull CancellationSignal cancellationSignal,
- @NonNull SQLiteDatabase.CursorFactory cursorFactory) {
- return sQLiteDatabase.rawQueryWithFactory(cursorFactory, sql, selectionArgs, editTable,
- cancellationSignal);
+ @JvmStatic
+ fun rawQueryWithFactory(
+ sQLiteDatabase: SQLiteDatabase,
+ sql: String,
+ selectionArgs: Array<String?>,
+ editTable: String?,
+ cancellationSignal: CancellationSignal,
+ cursorFactory: CursorFactory
+ ): Cursor {
+ return sQLiteDatabase.rawQueryWithFactory(
+ cursorFactory, sql, selectionArgs, editTable,
+ cancellationSignal
+ )
}
/**
@@ -123,62 +122,66 @@
*
* @param enable True to enable foreign key constraints, false to disable them.
*
- * @throws IllegalStateException if the are transactions is in progress
+ * @throws [IllegalStateException] if the are transactions is in progress
* when this method is called.
*
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
- public static void setForeignKeyConstraintsEnabled(@NonNull SQLiteDatabase sQLiteDatabase,
- boolean enable) {
- sQLiteDatabase.setForeignKeyConstraintsEnabled(enable);
+ @JvmStatic
+ fun setForeignKeyConstraintsEnabled(
+ sQLiteDatabase: SQLiteDatabase,
+ enable: Boolean
+ ) {
+ sQLiteDatabase.setForeignKeyConstraintsEnabled(enable)
}
/**
* This method disables the features enabled by
- * {@link SQLiteDatabase#enableWriteAheadLogging()}.
+ * [SQLiteDatabase.enableWriteAheadLogging].
*
- * @throws IllegalStateException if there are transactions in progress at the
+ * @throws - if there are transactions in progress at the
* time this method is called. WAL mode can only be changed when there are no
* transactions in progress.
*
- * @see SQLiteDatabase#enableWriteAheadLogging
- *
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
- public static void disableWriteAheadLogging(@NonNull SQLiteDatabase sQLiteDatabase) {
- sQLiteDatabase.disableWriteAheadLogging();
+ @JvmStatic
+ fun disableWriteAheadLogging(sQLiteDatabase: SQLiteDatabase) {
+ sQLiteDatabase.disableWriteAheadLogging()
}
/**
- * Returns true if write-ahead logging has been enabled for this database.
+ * Returns true if [SQLiteDatabase.enableWriteAheadLogging] logging has been enabled for
+ * this database.
+ *
+ * For details, see [SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING].
*
* @return True if write-ahead logging has been enabled for this database.
*
- * @see SQLiteDatabase#enableWriteAheadLogging
- * @see SQLiteDatabase#ENABLE_WRITE_AHEAD_LOGGING
- *
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
- public static boolean isWriteAheadLoggingEnabled(@NonNull SQLiteDatabase sQLiteDatabase) {
- return sQLiteDatabase.isWriteAheadLoggingEnabled();
+ @JvmStatic
+ fun isWriteAheadLoggingEnabled(sQLiteDatabase: SQLiteDatabase): Boolean {
+ return sQLiteDatabase.isWriteAheadLoggingEnabled
}
/**
- * Sets {@link SQLiteDatabase#ENABLE_WRITE_AHEAD_LOGGING} flag if {@code enabled} is {@code
- * true}, unsets otherwise.
+ * Sets [SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING] flag if `enabled` is `true`, unsets
+ * otherwise.
*
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
- public static void setWriteAheadLoggingEnabled(@NonNull SQLiteOpenHelper sQLiteOpenHelper,
- boolean enabled) {
- sQLiteOpenHelper.setWriteAheadLoggingEnabled(enabled);
+ @JvmStatic
+ fun setWriteAheadLoggingEnabled(
+ sQLiteOpenHelper: SQLiteOpenHelper,
+ enabled: Boolean
+ ) {
+ sQLiteOpenHelper.setWriteAheadLoggingEnabled(enabled)
}
-
- private Api16Impl() {}
}
/**
@@ -188,25 +191,23 @@
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@RequiresApi(19)
- public static final class Api19Impl {
+ object Api19Impl {
/**
* Return the URI at which notifications of changes in this Cursor's data
* will be delivered.
*
- * @return Returns a URI that can be used with
- * {@link ContentResolver#registerContentObserver(android.net.Uri, boolean, ContentObserver)
- * ContentResolver.registerContentObserver} to find out about changes to this Cursor's
- * data. May be null if no notification URI has been set.
+ * @return Returns a URI that can be used with [ContentResolver.registerContentObserver] to
+ * find out about changes to this Cursor's data. May be null if no notification URI has been
+ * set.
*
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
- @NonNull
- public static Uri getNotificationUri(@NonNull Cursor cursor) {
- return cursor.getNotificationUri();
+ @JvmStatic
+ fun getNotificationUri(cursor: Cursor): Uri {
+ return cursor.notificationUri
}
-
/**
* Returns true if this is a low-RAM device. Exactly whether a device is low-RAM
* is ultimately up to the device configuration, but currently it generally means
@@ -216,11 +217,10 @@
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
- public static boolean isLowRamDevice(@NonNull ActivityManager activityManager) {
- return activityManager.isLowRamDevice();
+ @JvmStatic
+ fun isLowRamDevice(activityManager: ActivityManager): Boolean {
+ return activityManager.isLowRamDevice
}
-
- private Api19Impl() {}
}
/**
@@ -230,23 +230,20 @@
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@RequiresApi(21)
- public static final class Api21Impl {
-
+ object Api21Impl {
/**
* Returns the absolute path to the directory on the filesystem.
*
- * @return The path of the directory holding application files that will not
- * be automatically backed up to remote storage.
+ * @return The path of the directory holding application files that will not be
+ * automatically backed up to remote storage.
*
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
- @NonNull
- public static File getNoBackupFilesDir(@NonNull Context context) {
- return context.getNoBackupFilesDir();
+ @JvmStatic
+ fun getNoBackupFilesDir(context: Context): File {
+ return context.noBackupFilesDir
}
-
- private Api21Impl() {}
}
/**
@@ -256,21 +253,19 @@
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@RequiresApi(23)
- public static final class Api23Impl {
-
+ object Api23Impl {
/**
- * Sets a {@link Bundle} that will be returned by {@link Cursor#getExtras()}.
+ * Sets a [Bundle] that will be returned by [Cursor.getExtras].
*
- * @param extras {@link Bundle} to set, or null to set an empty bundle.
+ * @param extras [Bundle] to set, or null to set an empty bundle.
*
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
- public static void setExtras(@NonNull Cursor cursor, @NonNull Bundle extras) {
- cursor.setExtras(extras);
+ @JvmStatic
+ fun setExtras(cursor: Cursor, extras: Bundle) {
+ cursor.extras = extras
}
-
- private Api23Impl() {}
}
/**
@@ -280,10 +275,9 @@
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@RequiresApi(29)
- public static final class Api29Impl {
-
+ object Api29Impl {
/**
- * Similar to {@link Cursor#setNotificationUri(ContentResolver, Uri)}, except this version
+ * Similar to [Cursor.setNotificationUri], except this version
* allows to watch multiple content URIs for changes.
*
* @param cr The content resolver from the caller's context. The listener attached to
@@ -293,29 +287,29 @@
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
- public static void setNotificationUris(@NonNull Cursor cursor, @NonNull ContentResolver cr,
- @NonNull List<Uri> uris) {
- cursor.setNotificationUris(cr, uris);
+ @JvmStatic
+ fun setNotificationUris(
+ cursor: Cursor,
+ cr: ContentResolver,
+ uris: List<Uri?>
+ ) {
+ cursor.setNotificationUris(cr, uris)
}
/**
* Return the URIs at which notifications of changes in this Cursor's data
- * will be delivered, as previously set by {@link #setNotificationUris}.
+ * will be delivered, as previously set by [setNotificationUris].
*
- * @return Returns URIs that can be used with
- * {@link ContentResolver#registerContentObserver(android.net.Uri, boolean, ContentObserver)
- * ContentResolver.registerContentObserver} to find out about changes to this Cursor's
- * data. May be null if no notification URI has been set.
+ * @return Returns URIs that can be used with [ContentResolver.registerContentObserver]
+ * to find out about changes to this Cursor's data. May be null if no notification URI has
+ * been set.
*
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
- @NonNull
- public static List<Uri> getNotificationUris(@NonNull Cursor cursor) {
- return cursor.getNotificationUris();
+ @JvmStatic
+ fun getNotificationUris(cursor: Cursor): List<Uri> {
+ return cursor.notificationUris!!
}
-
- private Api29Impl() {}
}
-
-}
+}
\ No newline at end of file
diff --git a/sqlite/sqlite/src/main/java/androidx/sqlite/db/SupportSQLiteProgram.kt b/sqlite/sqlite/src/main/java/androidx/sqlite/db/SupportSQLiteProgram.kt
index cd0a5ef..2397f94 100644
--- a/sqlite/sqlite/src/main/java/androidx/sqlite/db/SupportSQLiteProgram.kt
+++ b/sqlite/sqlite/src/main/java/androidx/sqlite/db/SupportSQLiteProgram.kt
@@ -13,65 +13,60 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package androidx.sqlite.db
-package androidx.sqlite.db;
-
-import androidx.annotation.NonNull;
-
-import java.io.Closeable;
+import java.io.Closeable
/**
- * An interface to map the behavior of {@link android.database.sqlite.SQLiteProgram}.
+ * An interface to map the behavior of [android.database.sqlite.SQLiteProgram].
*/
-
-@SuppressWarnings("unused")
-public interface SupportSQLiteProgram extends Closeable {
+interface SupportSQLiteProgram : Closeable {
/**
* Bind a NULL value to this statement. The value remains bound until
- * {@link #clearBindings} is called.
+ * [.clearBindings] is called.
*
* @param index The 1-based index to the parameter to bind null to
*/
- void bindNull(int index);
+ fun bindNull(index: Int)
/**
* Bind a long value to this statement. The value remains bound until
- * {@link #clearBindings} is called.
- *addToBindArgs
+ * [clearBindings] is called.
+ * addToBindArgs
* @param index The 1-based index to the parameter to bind
* @param value The value to bind
*/
- void bindLong(int index, long value);
+ fun bindLong(index: Int, value: Long)
/**
* Bind a double value to this statement. The value remains bound until
- * {@link #clearBindings} is called.
+ * [.clearBindings] is called.
*
* @param index The 1-based index to the parameter to bind
* @param value The value to bind
*/
- void bindDouble(int index, double value);
+ fun bindDouble(index: Int, value: Double)
/**
* Bind a String value to this statement. The value remains bound until
- * {@link #clearBindings} is called.
+ * [.clearBindings] is called.
*
* @param index The 1-based index to the parameter to bind
* @param value The value to bind, must not be null
*/
- void bindString(int index, @NonNull String value);
+ fun bindString(index: Int, value: String)
/**
* Bind a byte array value to this statement. The value remains bound until
- * {@link #clearBindings} is called.
+ * [.clearBindings] is called.
*
* @param index The 1-based index to the parameter to bind
* @param value The value to bind, must not be null
*/
- void bindBlob(int index, @NonNull byte[] value);
+ fun bindBlob(index: Int, value: ByteArray)
/**
* Clears all existing bindings. Unset bindings are treated as NULL.
*/
- void clearBindings();
-}
+ fun clearBindings()
+}
\ No newline at end of file
diff --git a/sqlite/sqlite/src/main/java/androidx/sqlite/db/SupportSQLiteQuery.kt b/sqlite/sqlite/src/main/java/androidx/sqlite/db/SupportSQLiteQuery.kt
index 82909fc..8108f2d 100644
--- a/sqlite/sqlite/src/main/java/androidx/sqlite/db/SupportSQLiteQuery.kt
+++ b/sqlite/sqlite/src/main/java/androidx/sqlite/db/SupportSQLiteQuery.kt
@@ -13,37 +13,29 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-package androidx.sqlite.db;
-
-import androidx.annotation.NonNull;
+package androidx.sqlite.db
/**
* A query with typed bindings. It is better to use this API instead of
- * {@link android.database.sqlite.SQLiteDatabase#rawQuery(String, String[])} because it allows
+ * [android.database.sqlite.SQLiteDatabase.rawQuery] because it allows
* binding type safe parameters.
*/
-public interface SupportSQLiteQuery {
+interface SupportSQLiteQuery {
/**
* The SQL query. This query can have placeholders(?) for bind arguments.
- *
- * @return The SQL query to compile
*/
- @NonNull
- String getSql();
+ val sql: String
/**
* Callback to bind the query parameters to the compiled statement.
*
* @param statement The compiled statement
*/
- void bindTo(@NonNull SupportSQLiteProgram statement);
+ fun bindTo(statement: SupportSQLiteProgram)
/**
- * Returns the number of arguments in this query. This is equal to the number of placeholders
+ * Is the number of arguments in this query. This is equal to the number of placeholders
* in the query string. See: https://www.sqlite.org/c3ref/bind_blob.html for details.
- *
- * @return The number of arguments in the query.
*/
- int getArgCount();
-}
+ val argCount: Int
+}
\ No newline at end of file
diff --git a/sqlite/sqlite/src/main/java/androidx/sqlite/db/SupportSQLiteStatement.kt b/sqlite/sqlite/src/main/java/androidx/sqlite/db/SupportSQLiteStatement.kt
index ed00b46..097ffb5 100644
--- a/sqlite/sqlite/src/main/java/androidx/sqlite/db/SupportSQLiteStatement.kt
+++ b/sqlite/sqlite/src/main/java/androidx/sqlite/db/SupportSQLiteStatement.kt
@@ -13,34 +13,30 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-package androidx.sqlite.db;
-
-import androidx.annotation.Nullable;
+package androidx.sqlite.db
/**
- * An interface to map the behavior of {@link android.database.sqlite.SQLiteStatement}.
+ * An interface to map the behavior of [android.database.sqlite.SQLiteStatement].
*/
-@SuppressWarnings("unused")
-public interface SupportSQLiteStatement extends SupportSQLiteProgram {
+interface SupportSQLiteStatement : SupportSQLiteProgram {
/**
* Execute this SQL statement, if it is not a SELECT / INSERT / DELETE / UPDATE, for example
* CREATE / DROP table, view, trigger, index etc.
*
- * @throws android.database.SQLException If the SQL string is invalid for
- * some reason
+ * @throws [android.database.SQLException] If the SQL string is invalid for
+ * some reason
*/
- void execute();
+ fun execute()
/**
* Execute this SQL statement, if the the number of rows affected by execution of this SQL
* statement is of any importance to the caller - for example, UPDATE / DELETE SQL statements.
*
* @return the number of rows affected by this SQL statement execution.
- * @throws android.database.SQLException If the SQL string is invalid for
- * some reason
+ * @throws [android.database.SQLException] If the SQL string is invalid for
+ * some reason
*/
- int executeUpdateDelete();
+ fun executeUpdateDelete(): Int
/**
* Execute this SQL statement and return the ID of the row inserted due to this call.
@@ -48,10 +44,10 @@
*
* @return the row ID of the last row inserted, if this insert is successful. -1 otherwise.
*
- * @throws android.database.SQLException If the SQL string is invalid for
- * some reason
+ * @throws [android.database.SQLException] If the SQL string is invalid for
+ * some reason
*/
- long executeInsert();
+ fun executeInsert(): Long
/**
* Execute a statement that returns a 1 by 1 table with a numeric value.
@@ -59,17 +55,17 @@
*
* @return The result of the query.
*
- * @throws android.database.sqlite.SQLiteDoneException if the query returns zero rows
+ * @throws [android.database.sqlite.SQLiteDoneException] if the query returns zero rows
*/
- long simpleQueryForLong();
+ fun simpleQueryForLong(): Long
+
/**
* Execute a statement that returns a 1 by 1 table with a text value.
* For example, SELECT COUNT(*) FROM table;
*
* @return The result of the query.
*
- * @throws android.database.sqlite.SQLiteDoneException if the query returns zero rows
+ * @throws [android.database.sqlite.SQLiteDoneException] if the query returns zero rows
*/
- @Nullable
- String simpleQueryForString();
-}
+ fun simpleQueryForString(): String?
+}
\ No newline at end of file
diff --git a/sqlite/sqlite/src/test/java/androidx/sqlite/db/SimpleSQLiteQueryTest.kt b/sqlite/sqlite/src/test/java/androidx/sqlite/db/SimpleSQLiteQueryTest.kt
index 7b04a2b..bf6edb4 100644
--- a/sqlite/sqlite/src/test/java/androidx/sqlite/db/SimpleSQLiteQueryTest.kt
+++ b/sqlite/sqlite/src/test/java/androidx/sqlite/db/SimpleSQLiteQueryTest.kt
@@ -13,62 +13,54 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-package androidx.sqlite.db;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-import org.mockito.Mockito;
-
-@RunWith(JUnit4.class)
-public class SimpleSQLiteQueryTestTest {
-
+package androidx.sqlite.db
+import org.hamcrest.CoreMatchers.`is`
+import org.hamcrest.MatcherAssert.assertThat
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+import org.mockito.Mockito
+import org.mockito.Mockito.verify
+import org.mockito.Mockito.verifyNoMoreInteractions
+@RunWith(JUnit4::class)
+class SimpleSQLiteQueryTest {
@Test
- public void getSql() {
- SimpleSQLiteQuery query = new SimpleSQLiteQuery("foo");
- assertThat(query.getSql(), is("foo"));
+ fun sql() {
+ val query = SimpleSQLiteQuery("foo", emptyArray())
+ assertThat(query.sql, `is`("foo"))
}
-
@Test
- public void bindTo_noArgs() {
- SimpleSQLiteQuery query = new SimpleSQLiteQuery("foo");
- SupportSQLiteProgram program = Mockito.mock(SupportSQLiteProgram.class);
- query.bindTo(program);
- verifyNoMoreInteractions(program);
+ fun bindTo_noArgs() {
+ val query = SimpleSQLiteQuery("foo", emptyArray())
+ val program: SupportSQLiteProgram = Mockito.mock(SupportSQLiteProgram::class.java)
+ query.bindTo(program)
+ verifyNoMoreInteractions(program)
}
-
@Test
- public void bindTo_withArgs() {
- byte[] bytes = new byte[3];
- SimpleSQLiteQuery query = new SimpleSQLiteQuery("foo",
- new Object[]{"bar", 2, true, .5f, null, bytes});
- SupportSQLiteProgram program = Mockito.mock(SupportSQLiteProgram.class);
- query.bindTo(program);
- verify(program).bindString(1, "bar");
- verify(program).bindLong(2, 2);
- verify(program).bindLong(3, 1);
- verify(program).bindDouble(4, .5f);
- verify(program).bindNull(5);
- verify(program).bindBlob(6, bytes);
- verifyNoMoreInteractions(program);
+ fun bindTo_withArgs() {
+ val bytes = ByteArray(3)
+ val query = SimpleSQLiteQuery("foo", arrayOf("bar", 2, true, 0.5f, null, bytes))
+ val program: SupportSQLiteProgram = Mockito.mock(SupportSQLiteProgram::class.java)
+ query.bindTo(program)
+ verify(program).bindString(1, "bar")
+ verify(program).bindLong(2, 2)
+ verify(program).bindLong(3, 1)
+ verify(program).bindDouble(
+ 4,
+ (0.5f).toDouble()
+ )
+ verify(program).bindNull(5)
+ verify(program).bindBlob(6, bytes)
+ verifyNoMoreInteractions(program)
}
-
@Test
- public void getArgCount_withArgs() {
- SimpleSQLiteQuery query = new SimpleSQLiteQuery("foo",
- new Object[]{"bar", 2, true});
- assertThat(query.getArgCount(), is(3));
+ fun argCount_withArgs() {
+ val query = SimpleSQLiteQuery("foo", arrayOf("bar", 2, true))
+ assertThat(query.argCount, `is`(3))
}
-
@Test
- public void getArgCount_noArgs() {
- SimpleSQLiteQuery query = new SimpleSQLiteQuery("foo");
- assertThat(query.getArgCount(), is(0));
+ fun argCount_noArgs() {
+ val query = SimpleSQLiteQuery("foo", emptyArray())
+ assertThat(query.argCount, `is`(0))
}
-}
+}
\ No newline at end of file