package androidx.room; import androidx.annotation.RestrictTo; import androidx.annotation.VisibleForTesting; import androidx.sqlite.db.SupportSQLiteProgram; import androidx.sqlite.db.SupportSQLiteQuery; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.Arrays; import java.util.Iterator; import java.util.Map; import java.util.TreeMap; import kotlin.Unit; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.jvm.internal.Intrinsics; @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) /* loaded from: classes.dex */ public final class RoomSQLiteQuery implements SupportSQLiteQuery, SupportSQLiteProgram { private static final int BLOB = 5; 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; public static final int POOL_LIMIT = 15; private static final int STRING = 4; private int argCount; private final int[] bindingTypes; public final byte[][] blobBindings; @VisibleForTesting private final int capacity; public final double[] doubleBindings; public final long[] longBindings; private volatile String query; public final String[] stringBindings; public static final Companion Companion = new Companion(null); public static final TreeMap queryPool = new TreeMap<>(); @Retention(RetentionPolicy.SOURCE) public @interface Binding { } public /* synthetic */ RoomSQLiteQuery(int i, DefaultConstructorMarker defaultConstructorMarker) { this(i); } public static final RoomSQLiteQuery acquire(String str, int i) { return Companion.acquire(str, i); } public static final RoomSQLiteQuery copyFrom(SupportSQLiteQuery supportSQLiteQuery) { return Companion.copyFrom(supportSQLiteQuery); } private static /* synthetic */ void getBindingTypes$annotations() { } @VisibleForTesting public static /* synthetic */ void getBlobBindings$annotations() { } @VisibleForTesting public static /* synthetic */ void getDoubleBindings$annotations() { } @VisibleForTesting public static /* synthetic */ void getLongBindings$annotations() { } @VisibleForTesting public static /* synthetic */ void getStringBindings$annotations() { } @Override // java.io.Closeable, java.lang.AutoCloseable public void close() { } @Override // androidx.sqlite.db.SupportSQLiteQuery public int getArgCount() { return this.argCount; } public final int getCapacity() { return this.capacity; } public final void init(String query, int i) { Intrinsics.checkNotNullParameter(query, "query"); this.query = query; this.argCount = i; } private RoomSQLiteQuery(int i) { this.capacity = i; int i2 = i + 1; this.bindingTypes = new int[i2]; this.longBindings = new long[i2]; this.doubleBindings = new double[i2]; this.stringBindings = new String[i2]; this.blobBindings = new byte[i2][]; } public final void release() { TreeMap treeMap = queryPool; synchronized (treeMap) { treeMap.put(Integer.valueOf(this.capacity), this); Companion.prunePoolLocked$room_runtime_release(); Unit unit = Unit.INSTANCE; } } @Override // androidx.sqlite.db.SupportSQLiteQuery public String getSql() { String str = this.query; if (str != null) { return str; } throw new IllegalStateException("Required value was null.".toString()); } @Override // androidx.sqlite.db.SupportSQLiteQuery public void bindTo(SupportSQLiteProgram statement) { Intrinsics.checkNotNullParameter(statement, "statement"); int argCount = getArgCount(); if (1 > argCount) { return; } int i = 1; while (true) { int i2 = this.bindingTypes[i]; if (i2 == 1) { statement.bindNull(i); } else if (i2 == 2) { statement.bindLong(i, this.longBindings[i]); } else if (i2 == 3) { statement.bindDouble(i, this.doubleBindings[i]); } else if (i2 == 4) { String str = this.stringBindings[i]; if (str == null) { throw new IllegalArgumentException("Required value was null.".toString()); } statement.bindString(i, str); } else if (i2 == 5) { byte[] bArr = this.blobBindings[i]; if (bArr == null) { throw new IllegalArgumentException("Required value was null.".toString()); } statement.bindBlob(i, bArr); } if (i == argCount) { return; } else { i++; } } } @Override // androidx.sqlite.db.SupportSQLiteProgram public void bindNull(int i) { this.bindingTypes[i] = 1; } @Override // androidx.sqlite.db.SupportSQLiteProgram public void bindLong(int i, long j) { this.bindingTypes[i] = 2; this.longBindings[i] = j; } @Override // androidx.sqlite.db.SupportSQLiteProgram public void bindDouble(int i, double d) { this.bindingTypes[i] = 3; this.doubleBindings[i] = d; } @Override // androidx.sqlite.db.SupportSQLiteProgram public void bindString(int i, String value) { Intrinsics.checkNotNullParameter(value, "value"); this.bindingTypes[i] = 4; this.stringBindings[i] = value; } @Override // androidx.sqlite.db.SupportSQLiteProgram public void bindBlob(int i, byte[] value) { Intrinsics.checkNotNullParameter(value, "value"); this.bindingTypes[i] = 5; this.blobBindings[i] = value; } public final void copyArgumentsFrom(RoomSQLiteQuery other) { Intrinsics.checkNotNullParameter(other, "other"); int argCount = other.getArgCount() + 1; System.arraycopy(other.bindingTypes, 0, this.bindingTypes, 0, argCount); System.arraycopy(other.longBindings, 0, this.longBindings, 0, argCount); System.arraycopy(other.stringBindings, 0, this.stringBindings, 0, argCount); System.arraycopy(other.blobBindings, 0, this.blobBindings, 0, argCount); System.arraycopy(other.doubleBindings, 0, this.doubleBindings, 0, argCount); } @Override // androidx.sqlite.db.SupportSQLiteProgram public void clearBindings() { Arrays.fill(this.bindingTypes, 1); Arrays.fill(this.stringBindings, (Object) null); Arrays.fill(this.blobBindings, (Object) null); this.query = null; } public static final class Companion { public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } @VisibleForTesting public static /* synthetic */ void getDESIRED_POOL_SIZE$annotations() { } @VisibleForTesting public static /* synthetic */ void getPOOL_LIMIT$annotations() { } @VisibleForTesting public static /* synthetic */ void getQueryPool$annotations() { } private Companion() { } public final RoomSQLiteQuery copyFrom(SupportSQLiteQuery supportSQLiteQuery) { Intrinsics.checkNotNullParameter(supportSQLiteQuery, "supportSQLiteQuery"); final RoomSQLiteQuery acquire = acquire(supportSQLiteQuery.getSql(), supportSQLiteQuery.getArgCount()); supportSQLiteQuery.bindTo(new SupportSQLiteProgram() { // from class: androidx.room.RoomSQLiteQuery$Companion$copyFrom$1 @Override // androidx.sqlite.db.SupportSQLiteProgram public void bindBlob(int i, byte[] value) { Intrinsics.checkNotNullParameter(value, "value"); RoomSQLiteQuery.this.bindBlob(i, value); } @Override // androidx.sqlite.db.SupportSQLiteProgram public void bindDouble(int i, double d) { RoomSQLiteQuery.this.bindDouble(i, d); } @Override // androidx.sqlite.db.SupportSQLiteProgram public void bindLong(int i, long j) { RoomSQLiteQuery.this.bindLong(i, j); } @Override // androidx.sqlite.db.SupportSQLiteProgram public void bindNull(int i) { RoomSQLiteQuery.this.bindNull(i); } @Override // androidx.sqlite.db.SupportSQLiteProgram public void bindString(int i, String value) { Intrinsics.checkNotNullParameter(value, "value"); RoomSQLiteQuery.this.bindString(i, value); } @Override // androidx.sqlite.db.SupportSQLiteProgram public void clearBindings() { RoomSQLiteQuery.this.clearBindings(); } @Override // java.io.Closeable, java.lang.AutoCloseable public void close() { RoomSQLiteQuery.this.close(); } }); return acquire; } public final RoomSQLiteQuery acquire(String query, int i) { Intrinsics.checkNotNullParameter(query, "query"); TreeMap treeMap = RoomSQLiteQuery.queryPool; synchronized (treeMap) { Map.Entry ceilingEntry = treeMap.ceilingEntry(Integer.valueOf(i)); if (ceilingEntry != null) { treeMap.remove(ceilingEntry.getKey()); RoomSQLiteQuery sqliteQuery = ceilingEntry.getValue(); sqliteQuery.init(query, i); Intrinsics.checkNotNullExpressionValue(sqliteQuery, "sqliteQuery"); return sqliteQuery; } Unit unit = Unit.INSTANCE; RoomSQLiteQuery roomSQLiteQuery = new RoomSQLiteQuery(i, null); roomSQLiteQuery.init(query, i); return roomSQLiteQuery; } } public final void prunePoolLocked$room_runtime_release() { TreeMap treeMap = RoomSQLiteQuery.queryPool; if (treeMap.size() <= 15) { return; } int size = treeMap.size() - 10; Iterator it = treeMap.descendingKeySet().iterator(); Intrinsics.checkNotNullExpressionValue(it, "queryPool.descendingKeySet().iterator()"); while (true) { int i = size - 1; if (size <= 0) { return; } it.next(); it.remove(); size = i; } } } }