159 lines
5.6 KiB
Java
159 lines
5.6 KiB
Java
package androidx.room.util;
|
|
|
|
import android.database.Cursor;
|
|
import androidx.annotation.RestrictTo;
|
|
import androidx.annotation.VisibleForTesting;
|
|
import androidx.sqlite.db.SupportSQLiteDatabase;
|
|
import c.d.b.a.a;
|
|
import java.util.ArrayDeque;
|
|
import java.util.ArrayList;
|
|
import java.util.HashSet;
|
|
import java.util.Iterator;
|
|
import java.util.Set;
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
public class FtsTableInfo {
|
|
private static final String[] FTS_OPTIONS = {"tokenize=", "compress=", "content=", "languageid=", "matchinfo=", "notindexed=", "order=", "prefix=", "uncompress="};
|
|
public final Set<String> columns;
|
|
public final String name;
|
|
public final Set<String> options;
|
|
|
|
public FtsTableInfo(String str, Set<String> set, String str2) {
|
|
this.name = str;
|
|
this.columns = set;
|
|
this.options = parseOptions(str2);
|
|
}
|
|
|
|
public FtsTableInfo(String str, Set<String> set, Set<String> set2) {
|
|
this.name = str;
|
|
this.columns = set;
|
|
this.options = set2;
|
|
}
|
|
|
|
@VisibleForTesting
|
|
public static Set<String> parseOptions(String str) {
|
|
if (str.isEmpty()) {
|
|
return new HashSet();
|
|
}
|
|
String substring = str.substring(str.indexOf(40) + 1, str.lastIndexOf(41));
|
|
ArrayList arrayList = new ArrayList();
|
|
ArrayDeque arrayDeque = new ArrayDeque();
|
|
int i = -1;
|
|
for (int i2 = 0; i2 < substring.length(); i2++) {
|
|
char charAt = substring.charAt(i2);
|
|
if (!(charAt == '\"' || charAt == '\'')) {
|
|
if (charAt != ',') {
|
|
if (charAt != '[') {
|
|
if (charAt != ']') {
|
|
if (charAt != '`') {
|
|
}
|
|
} else if (!arrayDeque.isEmpty() && ((Character) arrayDeque.peek()).charValue() == '[') {
|
|
arrayDeque.pop();
|
|
}
|
|
} else if (arrayDeque.isEmpty()) {
|
|
arrayDeque.push(Character.valueOf(charAt));
|
|
}
|
|
} else if (arrayDeque.isEmpty()) {
|
|
arrayList.add(substring.substring(i + 1, i2).trim());
|
|
i = i2;
|
|
}
|
|
}
|
|
if (arrayDeque.isEmpty()) {
|
|
arrayDeque.push(Character.valueOf(charAt));
|
|
} else if (((Character) arrayDeque.peek()).charValue() == charAt) {
|
|
arrayDeque.pop();
|
|
}
|
|
}
|
|
arrayList.add(substring.substring(i + 1).trim());
|
|
HashSet hashSet = new HashSet();
|
|
Iterator it = arrayList.iterator();
|
|
while (it.hasNext()) {
|
|
String str2 = (String) it.next();
|
|
for (String str3 : FTS_OPTIONS) {
|
|
if (str2.startsWith(str3)) {
|
|
hashSet.add(str2);
|
|
}
|
|
}
|
|
}
|
|
return hashSet;
|
|
}
|
|
|
|
public static FtsTableInfo read(SupportSQLiteDatabase supportSQLiteDatabase, String str) {
|
|
return new FtsTableInfo(str, readColumns(supportSQLiteDatabase, str), readOptions(supportSQLiteDatabase, str));
|
|
}
|
|
|
|
private static Set<String> readColumns(SupportSQLiteDatabase supportSQLiteDatabase, String str) {
|
|
Cursor query = supportSQLiteDatabase.query("PRAGMA table_info(`" + str + "`)");
|
|
HashSet hashSet = new HashSet();
|
|
try {
|
|
if (query.getColumnCount() > 0) {
|
|
int columnIndex = query.getColumnIndex("name");
|
|
while (query.moveToNext()) {
|
|
hashSet.add(query.getString(columnIndex));
|
|
}
|
|
}
|
|
return hashSet;
|
|
} finally {
|
|
query.close();
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: finally extract failed */
|
|
private static Set<String> readOptions(SupportSQLiteDatabase supportSQLiteDatabase, String str) {
|
|
Cursor query = supportSQLiteDatabase.query("SELECT * FROM sqlite_master WHERE `name` = '" + str + "'");
|
|
try {
|
|
String string = query.moveToFirst() ? query.getString(query.getColumnIndexOrThrow("sql")) : "";
|
|
query.close();
|
|
return parseOptions(string);
|
|
} catch (Throwable th) {
|
|
query.close();
|
|
throw th;
|
|
}
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (obj == null || getClass() != obj.getClass()) {
|
|
return false;
|
|
}
|
|
FtsTableInfo ftsTableInfo = (FtsTableInfo) obj;
|
|
String str = this.name;
|
|
if (str == null ? ftsTableInfo.name != null : !str.equals(ftsTableInfo.name)) {
|
|
return false;
|
|
}
|
|
Set<String> set = this.columns;
|
|
if (set == null ? ftsTableInfo.columns != null : !set.equals(ftsTableInfo.columns)) {
|
|
return false;
|
|
}
|
|
Set<String> set2 = this.options;
|
|
Set<String> set3 = ftsTableInfo.options;
|
|
return set2 != null ? set2.equals(set3) : set3 == null;
|
|
}
|
|
|
|
public int hashCode() {
|
|
String str = this.name;
|
|
int i = 0;
|
|
int hashCode = (str != null ? str.hashCode() : 0) * 31;
|
|
Set<String> set = this.columns;
|
|
int hashCode2 = (hashCode + (set != null ? set.hashCode() : 0)) * 31;
|
|
Set<String> set2 = this.options;
|
|
if (set2 != null) {
|
|
i = set2.hashCode();
|
|
}
|
|
return hashCode2 + i;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder L = a.L("FtsTableInfo{name='");
|
|
L.append(this.name);
|
|
L.append('\'');
|
|
L.append(", columns=");
|
|
L.append(this.columns);
|
|
L.append(", options=");
|
|
L.append(this.options);
|
|
L.append('}');
|
|
return L.toString();
|
|
}
|
|
}
|