6.7.0 - Alpha13 - Fine tuning
This commit is contained in:
@@ -25,8 +25,8 @@ public class Database extends SQLiteOpenHelper implements Closeable {
|
||||
private final ScriptRuntime mScriptRuntime;
|
||||
private final TypeAdapter mTypeAdapter;
|
||||
|
||||
public Database(@NonNull Context context, @NonNull ScriptRuntime scriptRuntime, @NonNull String name, int version, boolean readable, @Nullable DatabaseCallback databaseCallback, @NonNull TypeAdapter typeAdapter) {
|
||||
super(context, scriptRuntime.files.nonNullPath(name), null, version, databaseCallback == null ? null : new DatabaseErrorHandlerWrapper(databaseCallback));
|
||||
public Database(@NonNull Context context, @NonNull ScriptRuntime scriptRuntime, @NonNull String databaseFilePath, int version, boolean readable, @Nullable DatabaseCallback databaseCallback, @NonNull TypeAdapter typeAdapter) {
|
||||
super(context, scriptRuntime.files.nonNullPath(databaseFilePath), null, version, databaseCallback == null ? null : new DatabaseErrorHandlerWrapper(databaseCallback));
|
||||
mTypeAdapter = typeAdapter;
|
||||
mCallback = databaseCallback;
|
||||
mScriptRuntime = scriptRuntime;
|
||||
|
||||
@@ -18,8 +18,8 @@ import org.mozilla.javascript.NativeObject
|
||||
|
||||
class SQLite(private val context: Context, private val scriptRuntime: ScriptRuntime) {
|
||||
|
||||
fun open(name: String, version: Int, readOnly: Boolean, callback: Database.DatabaseCallback?): Database {
|
||||
return Database(context, scriptRuntime, name, version, readOnly, callback, TypeAdapterImpl())
|
||||
fun open(databaseFilePath: String, version: Int, readOnly: Boolean, callback: Database.DatabaseCallback?): Database {
|
||||
return Database(context, scriptRuntime, databaseFilePath, version, readOnly, callback, TypeAdapterImpl())
|
||||
}
|
||||
|
||||
private class TypeAdapterImpl : Database.TypeAdapter {
|
||||
|
||||
@@ -36,10 +36,10 @@ class SQLite(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunti
|
||||
@JvmStatic
|
||||
@RhinoRuntimeFunctionInterface
|
||||
fun open(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Database = ensureArgumentsLengthInRange(args, 1..3) { argList ->
|
||||
val (name, options, callback) = argList
|
||||
val (databaseFilePath, options, callback) = argList
|
||||
|
||||
val niceName = coerceString(name, "")
|
||||
require(niceName.isNotEmpty()) { "Argument name of sqlite.open() must not be empty" }
|
||||
val filePath = coerceString(databaseFilePath, "")
|
||||
require(filePath.isNotEmpty()) { "Argument databaseFilePath of sqlite.open() must not be empty" }
|
||||
|
||||
val niceOptions = if (options.isJsNullish()) newNativeObject() else options
|
||||
require(niceOptions is NativeObject) { "Argument \"options\" ${options.jsBrief()} for sqlite.open() must be a JavaScript Object" }
|
||||
@@ -48,7 +48,7 @@ class SQLite(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunti
|
||||
require(niceCallback is DatabaseCallback?) { "Argument \"callback\" ${callback.jsBrief()} for sqlite.open() must be a DatabaseCallback" }
|
||||
|
||||
scriptRuntime.sqlite.open(
|
||||
name = niceName,
|
||||
databaseFilePath = filePath,
|
||||
version = niceOptions.inquire("version", ::coerceIntNumber, DEFAULT_VERSION),
|
||||
readOnly = niceOptions.inquire("readOnly", ::coerceBoolean, DEFAULT_READ_ONLY),
|
||||
callback = niceCallback,
|
||||
|
||||
Reference in New Issue
Block a user