1 /* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package androidx.room.util 17 18 import androidx.annotation.RestrictTo 19 import androidx.room.driver.SupportSQLiteConnection 20 import androidx.sqlite.SQLiteConnection 21 import androidx.sqlite.db.SupportSQLiteDatabase 22 23 /** A data class that holds the information about an FTS table. */ 24 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) // used in generated code 25 actual class FtsTableInfo( 26 /** The table name */ 27 @JvmField actual val name: String, 28 29 /** The column names */ 30 @JvmField actual val columns: Set<String>, 31 32 /** 33 * The set of options. Each value in the set contains the option in the following format: <key, 34 * value>. 35 */ 36 @JvmField actual val options: Set<String> 37 ) { 38 actual constructor( 39 name: String, 40 columns: Set<String>, 41 createSql: String 42 ) : this(name, columns, parseFtsOptions(createSql)) 43 equalsnull44 override fun equals(other: Any?) = equalsCommon(other) 45 46 override fun hashCode() = hashCodeCommon() 47 48 override fun toString() = toStringCommon() 49 50 actual companion object { 51 52 /** 53 * Reads the table information from the given database. 54 * 55 * @param database The database to read the information from. 56 * @param tableName The table name. 57 * @return A FtsTableInfo containing the columns and options for the provided table name. 58 */ 59 @JvmStatic 60 fun read(database: SupportSQLiteDatabase, tableName: String): FtsTableInfo { 61 return read(SupportSQLiteConnection(database), tableName) 62 } 63 64 /** 65 * Reads the table information from the given database. 66 * 67 * @param connection The database connection to read the information from. 68 * @param tableName The table name. 69 * @return A FtsTableInfo containing the columns and options for the provided table name. 70 */ 71 @JvmStatic 72 actual fun read(connection: SQLiteConnection, tableName: String): FtsTableInfo { 73 val columns = readFtsColumns(connection, tableName) 74 val options = readFtsOptions(connection, tableName) 75 return FtsTableInfo(tableName, columns, options) 76 } 77 } 78 } 79