223 lines
7.6 KiB
Java
223 lines
7.6 KiB
Java
package androidx.room;
|
|
|
|
import androidx.annotation.RestrictTo;
|
|
import androidx.annotation.VisibleForTesting;
|
|
import androidx.sqlite.db.SupportSQLiteProgram;
|
|
import androidx.sqlite.db.SupportSQLiteQuery;
|
|
import java.util.Arrays;
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
import java.util.TreeMap;
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
public class RoomSQLiteQuery implements SupportSQLiteQuery, SupportSQLiteProgram {
|
|
private static final int BLOB = 5;
|
|
@VisibleForTesting
|
|
public static final int DESIRED_POOL_SIZE = 10;
|
|
private static final int DOUBLE = 3;
|
|
private static final int LONG = 2;
|
|
private static final int NULL = 1;
|
|
@VisibleForTesting
|
|
public static final int POOL_LIMIT = 15;
|
|
private static final int STRING = 4;
|
|
@VisibleForTesting
|
|
public static final TreeMap<Integer, RoomSQLiteQuery> sQueryPool = new TreeMap<>();
|
|
@VisibleForTesting
|
|
public int mArgCount;
|
|
private final int[] mBindingTypes;
|
|
@VisibleForTesting
|
|
public final byte[][] mBlobBindings;
|
|
@VisibleForTesting
|
|
public final int mCapacity;
|
|
@VisibleForTesting
|
|
public final double[] mDoubleBindings;
|
|
@VisibleForTesting
|
|
public final long[] mLongBindings;
|
|
private volatile String mQuery;
|
|
@VisibleForTesting
|
|
public final String[] mStringBindings;
|
|
|
|
/* renamed from: androidx.room.RoomSQLiteQuery$1 reason: invalid class name */
|
|
public static class AnonymousClass1 implements SupportSQLiteProgram {
|
|
public final /* synthetic */ RoomSQLiteQuery val$query;
|
|
|
|
public AnonymousClass1(RoomSQLiteQuery roomSQLiteQuery) {
|
|
this.val$query = roomSQLiteQuery;
|
|
}
|
|
|
|
@Override // androidx.sqlite.db.SupportSQLiteProgram
|
|
public void bindBlob(int i, byte[] bArr) {
|
|
this.val$query.bindBlob(i, bArr);
|
|
}
|
|
|
|
@Override // androidx.sqlite.db.SupportSQLiteProgram
|
|
public void bindDouble(int i, double d) {
|
|
this.val$query.bindDouble(i, d);
|
|
}
|
|
|
|
@Override // androidx.sqlite.db.SupportSQLiteProgram
|
|
public void bindLong(int i, long j) {
|
|
this.val$query.bindLong(i, j);
|
|
}
|
|
|
|
@Override // androidx.sqlite.db.SupportSQLiteProgram
|
|
public void bindNull(int i) {
|
|
this.val$query.bindNull(i);
|
|
}
|
|
|
|
@Override // androidx.sqlite.db.SupportSQLiteProgram
|
|
public void bindString(int i, String str) {
|
|
this.val$query.bindString(i, str);
|
|
}
|
|
|
|
@Override // androidx.sqlite.db.SupportSQLiteProgram
|
|
public void clearBindings() {
|
|
this.val$query.clearBindings();
|
|
}
|
|
|
|
@Override // java.io.Closeable, java.lang.AutoCloseable
|
|
public void close() {
|
|
}
|
|
}
|
|
|
|
private RoomSQLiteQuery(int i) {
|
|
this.mCapacity = i;
|
|
int i2 = i + 1;
|
|
this.mBindingTypes = new int[i2];
|
|
this.mLongBindings = new long[i2];
|
|
this.mDoubleBindings = new double[i2];
|
|
this.mStringBindings = new String[i2];
|
|
this.mBlobBindings = new byte[i2][];
|
|
}
|
|
|
|
public static RoomSQLiteQuery acquire(String str, int i) {
|
|
TreeMap<Integer, RoomSQLiteQuery> treeMap = sQueryPool;
|
|
synchronized (treeMap) {
|
|
Map.Entry<Integer, RoomSQLiteQuery> ceilingEntry = treeMap.ceilingEntry(Integer.valueOf(i));
|
|
if (ceilingEntry != null) {
|
|
treeMap.remove(ceilingEntry.getKey());
|
|
RoomSQLiteQuery value = ceilingEntry.getValue();
|
|
value.init(str, i);
|
|
return value;
|
|
}
|
|
RoomSQLiteQuery roomSQLiteQuery = new RoomSQLiteQuery(i);
|
|
roomSQLiteQuery.init(str, i);
|
|
return roomSQLiteQuery;
|
|
}
|
|
}
|
|
|
|
public static RoomSQLiteQuery copyFrom(SupportSQLiteQuery supportSQLiteQuery) {
|
|
RoomSQLiteQuery acquire = acquire(supportSQLiteQuery.getSql(), supportSQLiteQuery.getArgCount());
|
|
supportSQLiteQuery.bindTo(new AnonymousClass1(acquire));
|
|
return acquire;
|
|
}
|
|
|
|
private static void prunePoolLocked() {
|
|
TreeMap<Integer, RoomSQLiteQuery> treeMap = sQueryPool;
|
|
if (treeMap.size() > 15) {
|
|
int size = treeMap.size() - 10;
|
|
Iterator<Integer> it = treeMap.descendingKeySet().iterator();
|
|
while (true) {
|
|
int i = size - 1;
|
|
if (size > 0) {
|
|
it.next();
|
|
it.remove();
|
|
size = i;
|
|
} else {
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // androidx.sqlite.db.SupportSQLiteProgram
|
|
public void bindBlob(int i, byte[] bArr) {
|
|
this.mBindingTypes[i] = 5;
|
|
this.mBlobBindings[i] = bArr;
|
|
}
|
|
|
|
@Override // androidx.sqlite.db.SupportSQLiteProgram
|
|
public void bindDouble(int i, double d) {
|
|
this.mBindingTypes[i] = 3;
|
|
this.mDoubleBindings[i] = d;
|
|
}
|
|
|
|
@Override // androidx.sqlite.db.SupportSQLiteProgram
|
|
public void bindLong(int i, long j) {
|
|
this.mBindingTypes[i] = 2;
|
|
this.mLongBindings[i] = j;
|
|
}
|
|
|
|
@Override // androidx.sqlite.db.SupportSQLiteProgram
|
|
public void bindNull(int i) {
|
|
this.mBindingTypes[i] = 1;
|
|
}
|
|
|
|
@Override // androidx.sqlite.db.SupportSQLiteProgram
|
|
public void bindString(int i, String str) {
|
|
this.mBindingTypes[i] = 4;
|
|
this.mStringBindings[i] = str;
|
|
}
|
|
|
|
@Override // androidx.sqlite.db.SupportSQLiteQuery
|
|
public void bindTo(SupportSQLiteProgram supportSQLiteProgram) {
|
|
for (int i = 1; i <= this.mArgCount; i++) {
|
|
int i2 = this.mBindingTypes[i];
|
|
if (i2 == 1) {
|
|
supportSQLiteProgram.bindNull(i);
|
|
} else if (i2 == 2) {
|
|
supportSQLiteProgram.bindLong(i, this.mLongBindings[i]);
|
|
} else if (i2 == 3) {
|
|
supportSQLiteProgram.bindDouble(i, this.mDoubleBindings[i]);
|
|
} else if (i2 == 4) {
|
|
supportSQLiteProgram.bindString(i, this.mStringBindings[i]);
|
|
} else if (i2 == 5) {
|
|
supportSQLiteProgram.bindBlob(i, this.mBlobBindings[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // androidx.sqlite.db.SupportSQLiteProgram
|
|
public void clearBindings() {
|
|
Arrays.fill(this.mBindingTypes, 1);
|
|
Arrays.fill(this.mStringBindings, (Object) null);
|
|
Arrays.fill(this.mBlobBindings, (Object) null);
|
|
this.mQuery = null;
|
|
}
|
|
|
|
@Override // java.io.Closeable, java.lang.AutoCloseable
|
|
public void close() {
|
|
}
|
|
|
|
public void copyArgumentsFrom(RoomSQLiteQuery roomSQLiteQuery) {
|
|
int argCount = roomSQLiteQuery.getArgCount() + 1;
|
|
System.arraycopy(roomSQLiteQuery.mBindingTypes, 0, this.mBindingTypes, 0, argCount);
|
|
System.arraycopy(roomSQLiteQuery.mLongBindings, 0, this.mLongBindings, 0, argCount);
|
|
System.arraycopy(roomSQLiteQuery.mStringBindings, 0, this.mStringBindings, 0, argCount);
|
|
System.arraycopy(roomSQLiteQuery.mBlobBindings, 0, this.mBlobBindings, 0, argCount);
|
|
System.arraycopy(roomSQLiteQuery.mDoubleBindings, 0, this.mDoubleBindings, 0, argCount);
|
|
}
|
|
|
|
@Override // androidx.sqlite.db.SupportSQLiteQuery
|
|
public int getArgCount() {
|
|
return this.mArgCount;
|
|
}
|
|
|
|
@Override // androidx.sqlite.db.SupportSQLiteQuery
|
|
public String getSql() {
|
|
return this.mQuery;
|
|
}
|
|
|
|
public void init(String str, int i) {
|
|
this.mQuery = str;
|
|
this.mArgCount = i;
|
|
}
|
|
|
|
public void release() {
|
|
TreeMap<Integer, RoomSQLiteQuery> treeMap = sQueryPool;
|
|
synchronized (treeMap) {
|
|
treeMap.put(Integer.valueOf(this.mCapacity), this);
|
|
prunePoolLocked();
|
|
}
|
|
}
|
|
}
|