package org.greenrobot.greendao; import android.database.CrossProcessCursor; import android.database.Cursor; import android.database.CursorWindow; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteStatement; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; import org.greenrobot.greendao.database.Database; import org.greenrobot.greendao.database.DatabaseStatement; import org.greenrobot.greendao.identityscope.IdentityScope; import org.greenrobot.greendao.identityscope.IdentityScopeLong; import org.greenrobot.greendao.internal.DaoConfig; import org.greenrobot.greendao.internal.TableStatements; import org.greenrobot.greendao.query.QueryBuilder; /* loaded from: classes2.dex */ public abstract class AbstractDao { protected final DaoConfig a; protected final Database b; protected final boolean c; protected final IdentityScope d; protected final IdentityScopeLong e; protected final TableStatements f; protected final AbstractDaoSession g; protected final int h; public AbstractDao(DaoConfig daoConfig, AbstractDaoSession abstractDaoSession) { this.a = daoConfig; this.g = abstractDaoSession; this.b = daoConfig.a; this.c = this.b.b() instanceof SQLiteDatabase; this.d = (IdentityScope) daoConfig.a(); IdentityScope identityScope = this.d; if (identityScope instanceof IdentityScopeLong) { this.e = (IdentityScopeLong) identityScope; } else { this.e = null; } this.f = daoConfig.i; Property property = daoConfig.g; this.h = property != null ? property.a : -1; } public T a(long j) { return d(this.b.a(this.f.f(), new String[]{Long.toString(j)})); } protected abstract T a(Cursor cursor, int i); protected abstract K a(T t, long j); protected abstract void a(Cursor cursor, T t, int i); protected abstract void a(SQLiteStatement sQLiteStatement, T t); protected void a(T t) { } protected abstract void a(DatabaseStatement databaseStatement, T t); protected abstract K b(Cursor cursor, int i); public void b(Iterable iterable) { a(iterable, i()); } public String[] c() { return this.a.d; } protected T d(Cursor cursor) { try { return c(cursor); } finally { cursor.close(); } } protected abstract K d(T t); public Property e() { return this.a.g; } public Property[] f() { return this.a.c; } public AbstractDaoSession g() { return this.g; } public String h() { return this.a.b; } public void i(T t) { a(); K e = e((AbstractDao) t); Cursor a = this.b.a(this.f.e(), new String[]{e.toString()}); try { if (!a.moveToFirst()) { throw new DaoException("Entity does not exist in the database anymore: " + t.getClass() + " with key " + e); } if (a.isLast()) { a(a, (Cursor) t, 0); a((AbstractDao) e, (K) t, true); } else { throw new DaoException("Expected unique result, but count was " + a.getCount()); } } finally { a.close(); } } protected abstract boolean i(); public List j() { return a(this.b.a(this.f.d(), null)); } public QueryBuilder k() { return QueryBuilder.a(this); } private CursorWindow e(Cursor cursor) { this.d.unlock(); try { return cursor.moveToNext() ? ((CrossProcessCursor) cursor).getWindow() : null; } finally { this.d.lock(); } } public void b(Iterable iterable, boolean z) { a(this.f.b(), (Iterable) iterable, z); } protected T c(Cursor cursor) { if (!cursor.moveToFirst()) { return null; } if (cursor.isLast()) { return a(cursor, 0, true); } throw new DaoException("Expected unique result, but count was " + cursor.getCount()); } public long f(T t) { return b(t, this.f.c(), true); } public long g(T t) { return b(t, this.f.b(), true); } public T h(K k) { T t; a(); if (k == null) { return null; } IdentityScope identityScope = this.d; return (identityScope == null || (t = identityScope.get(k)) == null) ? d(this.b.a(this.f.e(), new String[]{k.toString()})) : t; } public void j(T t) { a(); DatabaseStatement g = this.f.g(); if (this.b.d()) { synchronized (g) { if (this.c) { a((AbstractDao) t, (SQLiteStatement) g.b(), true); } else { a((AbstractDao) t, g, true); } } return; } this.b.a(); try { synchronized (g) { a((AbstractDao) t, g, true); } this.b.c(); } finally { this.b.e(); } } private long b(T t, DatabaseStatement databaseStatement, boolean z) { long b; if (this.b.d()) { b = b((AbstractDao) t, databaseStatement); } else { this.b.a(); try { b = b((AbstractDao) t, databaseStatement); this.b.c(); } finally { this.b.e(); } } if (z) { a((AbstractDao) t, b, true); } return b; } protected List a(Cursor cursor) { try { return b(cursor); } finally { cursor.close(); } } public void d(Iterable iterable) { DatabaseStatement g = this.f.g(); this.b.a(); try { synchronized (g) { if (this.d != null) { this.d.lock(); } try { if (this.c) { SQLiteStatement sQLiteStatement = (SQLiteStatement) g.b(); Iterator it = iterable.iterator(); while (it.hasNext()) { a((AbstractDao) it.next(), sQLiteStatement, false); } } else { Iterator it2 = iterable.iterator(); while (it2.hasNext()) { a((AbstractDao) it2.next(), g, false); } } } finally { if (this.d != null) { this.d.unlock(); } } } this.b.c(); } catch (RuntimeException e) { e = e; try { this.b.e(); } catch (RuntimeException e2) { DaoLog.b("Could not end transaction (rethrowing initial exception)", e2); throw e; } } catch (Throwable th) { try { this.b.e(); throw th; } catch (RuntimeException e3) { throw e3; } } try { this.b.e(); e = null; if (e != null) { throw e; } } catch (RuntimeException e4) { throw e4; } } public void c(Iterable iterable) { b(iterable, i()); } public void a(Iterable iterable, boolean z) { a(this.f.c(), (Iterable) iterable, z); } public void c(K k) { a(); DatabaseStatement a = this.f.a(); if (this.b.d()) { synchronized (a) { a((AbstractDao) k, a); } } else { this.b.a(); try { synchronized (a) { a((AbstractDao) k, a); } this.b.c(); } finally { this.b.e(); } } IdentityScope identityScope = this.d; if (identityScope != null) { identityScope.remove(k); } } protected K e(T t) { K d = d((AbstractDao) t); if (d != null) { return d; } if (t == null) { throw new NullPointerException("Entity may not be null"); } throw new DaoException("Entity has no key"); } public void a(T... tArr) { b(Arrays.asList(tArr), i()); } private void a(DatabaseStatement databaseStatement, Iterable iterable, boolean z) { this.b.a(); try { synchronized (databaseStatement) { if (this.d != null) { this.d.lock(); } try { if (this.c) { SQLiteStatement sQLiteStatement = (SQLiteStatement) databaseStatement.b(); for (T t : iterable) { a(sQLiteStatement, (SQLiteStatement) t); if (z) { a((AbstractDao) t, sQLiteStatement.executeInsert(), false); } else { sQLiteStatement.execute(); } } } else { for (T t2 : iterable) { a(databaseStatement, (DatabaseStatement) t2); if (z) { a((AbstractDao) t2, databaseStatement.c(), false); } else { databaseStatement.execute(); } } } } finally { if (this.d != null) { this.d.unlock(); } } } this.b.c(); } finally { this.b.e(); } } private long b(T t, DatabaseStatement databaseStatement) { synchronized (databaseStatement) { if (this.c) { SQLiteStatement sQLiteStatement = (SQLiteStatement) databaseStatement.b(); a(sQLiteStatement, (SQLiteStatement) t); return sQLiteStatement.executeInsert(); } a(databaseStatement, (DatabaseStatement) t); return databaseStatement.c(); } } /* JADX WARN: Removed duplicated region for block: B:15:0x0054 */ /* JADX WARN: Removed duplicated region for block: B:26:0x007d */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ protected java.util.List b(android.database.Cursor r7) { /* r6 = this; int r0 = r7.getCount() if (r0 != 0) goto Lc java.util.ArrayList r7 = new java.util.ArrayList r7.() return r7 Lc: java.util.ArrayList r1 = new java.util.ArrayList r1.(r0) r2 = 0 boolean r3 = r7 instanceof android.database.CrossProcessCursor r4 = 0 if (r3 == 0) goto L4d r2 = r7 android.database.CrossProcessCursor r2 = (android.database.CrossProcessCursor) r2 android.database.CursorWindow r2 = r2.getWindow() if (r2 == 0) goto L4d int r3 = r2.getNumRows() if (r3 != r0) goto L2d org.greenrobot.greendao.internal.FastCursor r7 = new org.greenrobot.greendao.internal.FastCursor r7.(r2) r3 = 1 goto L4e L2d: java.lang.StringBuilder r3 = new java.lang.StringBuilder r3.() java.lang.String r5 = "Window vs. result size: " r3.append(r5) int r5 = r2.getNumRows() r3.append(r5) java.lang.String r5 = "/" r3.append(r5) r3.append(r0) java.lang.String r3 = r3.toString() org.greenrobot.greendao.DaoLog.a(r3) L4d: r3 = 0 L4e: boolean r5 = r7.moveToFirst() if (r5 == 0) goto L8a org.greenrobot.greendao.identityscope.IdentityScope r5 = r6.d if (r5 == 0) goto L60 r5.lock() org.greenrobot.greendao.identityscope.IdentityScope r5 = r6.d r5.a(r0) L60: if (r3 != 0) goto L6c if (r2 == 0) goto L6c org.greenrobot.greendao.identityscope.IdentityScope r0 = r6.d // Catch: java.lang.Throwable -> L81 if (r0 == 0) goto L6c r6.a(r7, r2, r1) // Catch: java.lang.Throwable -> L81 goto L79 L6c: java.lang.Object r0 = r6.a(r7, r4, r4) // Catch: java.lang.Throwable -> L81 r1.add(r0) // Catch: java.lang.Throwable -> L81 boolean r0 = r7.moveToNext() // Catch: java.lang.Throwable -> L81 if (r0 != 0) goto L6c L79: org.greenrobot.greendao.identityscope.IdentityScope r7 = r6.d if (r7 == 0) goto L8a r7.unlock() goto L8a L81: r7 = move-exception org.greenrobot.greendao.identityscope.IdentityScope r0 = r6.d if (r0 == 0) goto L89 r0.unlock() L89: throw r7 L8a: return r1 */ throw new UnsupportedOperationException("Method not decompiled: org.greenrobot.greendao.AbstractDao.b(android.database.Cursor):java.util.List"); } public Database d() { return this.b; } protected void a(T t, long j, boolean z) { if (j != -1) { a((AbstractDao) a((AbstractDao) t, j), (K) t, z); } else { DaoLog.b("Could not insert row (executeInsert returned -1)"); } } private void a(Cursor cursor, CursorWindow cursorWindow, List list) { int startPosition = cursorWindow.getStartPosition() + cursorWindow.getNumRows(); int i = 0; while (true) { list.add(a(cursor, 0, false)); int i2 = i + 1; if (i2 >= startPosition) { CursorWindow e = e(cursor); if (e == null) { return; } else { startPosition = e.getStartPosition() + e.getNumRows(); } } else if (!cursor.moveToNext()) { return; } i = i2 + 1; } } public void b() { this.b.a("DELETE FROM '" + this.a.b + "'"); IdentityScope identityScope = this.d; if (identityScope != null) { identityScope.clear(); } } protected final T a(Cursor cursor, int i, boolean z) { if (this.e != null) { if (i != 0 && cursor.isNull(this.h + i)) { return null; } long j = cursor.getLong(this.h + i); IdentityScopeLong identityScopeLong = this.e; T a = z ? identityScopeLong.a(j) : identityScopeLong.b(j); if (a != null) { return a; } T a2 = a(cursor, i); a((AbstractDao) a2); if (z) { this.e.a(j, (long) a2); } else { this.e.b(j, (long) a2); } return a2; } if (this.d != null) { K b = b(cursor, i); if (i != 0 && b == null) { return null; } IdentityScope identityScope = this.d; T a3 = z ? identityScope.get(b) : identityScope.a((IdentityScope) b); if (a3 != null) { return a3; } T a4 = a(cursor, i); a((AbstractDao) b, (K) a4, z); return a4; } if (i != 0 && b(cursor, i) == null) { return null; } T a5 = a(cursor, i); a((AbstractDao) a5); return a5; } public void b(T t) { a(); c((AbstractDao) e((AbstractDao) t)); } public void b(T... tArr) { d((Iterable) Arrays.asList(tArr)); } /* JADX WARN: Multi-variable type inference failed */ private void a(K k, DatabaseStatement databaseStatement) { if (k instanceof Long) { databaseStatement.a(1, ((Long) k).longValue()); } else if (k != 0) { databaseStatement.a(1, k.toString()); } else { throw new DaoException("Cannot delete entity, key is null"); } databaseStatement.execute(); } private void a(Iterable iterable, Iterable iterable2) { ArrayList arrayList; a(); DatabaseStatement a = this.f.a(); this.b.a(); try { synchronized (a) { if (this.d != null) { this.d.lock(); arrayList = new ArrayList(); } else { arrayList = null; } if (iterable != null) { try { Iterator it = iterable.iterator(); while (it.hasNext()) { K e = e((AbstractDao) it.next()); a((AbstractDao) e, a); if (arrayList != null) { arrayList.add(e); } } } catch (Throwable th) { if (this.d != null) { this.d.unlock(); } throw th; } } if (iterable2 != null) { for (K k : iterable2) { a((AbstractDao) k, a); if (arrayList != null) { arrayList.add(k); } } } if (this.d != null) { this.d.unlock(); } } this.b.c(); if (arrayList != null && this.d != null) { this.d.a((Iterable) arrayList); } } finally { this.b.e(); } } public void a(Iterable iterable) { a(iterable, (Iterable) null); } /* JADX WARN: Multi-variable type inference failed */ protected void a(T t, DatabaseStatement databaseStatement, boolean z) { a(databaseStatement, (DatabaseStatement) t); int length = this.a.d.length + 1; Object d = d((AbstractDao) t); if (d instanceof Long) { databaseStatement.a(length, ((Long) d).longValue()); } else if (d != null) { databaseStatement.a(length, d.toString()); } else { throw new DaoException("Cannot update entity without key - was it inserted before?"); } databaseStatement.execute(); a((AbstractDao) d, t, z); } /* JADX WARN: Multi-variable type inference failed */ protected void a(T t, SQLiteStatement sQLiteStatement, boolean z) { a(sQLiteStatement, (SQLiteStatement) t); int length = this.a.d.length + 1; Object d = d((AbstractDao) t); if (d instanceof Long) { sQLiteStatement.bindLong(length, ((Long) d).longValue()); } else if (d != null) { sQLiteStatement.bindString(length, d.toString()); } else { throw new DaoException("Cannot update entity without key - was it inserted before?"); } sQLiteStatement.execute(); a((AbstractDao) d, t, z); } protected final void a(K k, T t, boolean z) { a((AbstractDao) t); IdentityScope identityScope = this.d; if (identityScope == null || k == null) { return; } if (z) { identityScope.put(k, t); } else { identityScope.a(k, t); } } protected void a() { if (this.a.e.length == 1) { return; } throw new DaoException(this + " (" + this.a.b + ") does not have a single-column primary key"); } }