package i.b.a;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

/* JADX INFO: compiled from: AbstractDaoSession.java */
/* JADX INFO: loaded from: classes.dex */
public class c {
    private final i.b.a.i.a db;
    private final Map<Class<?>, a<?, ?>> entityToDao = new HashMap();

    public c(i.b.a.i.a aVar) {
        this.db = aVar;
    }

    public <V> V callInTx(Callable<V> callable) throws Exception {
        this.db.c();
        try {
            V vCall = callable.call();
            this.db.g();
            return vCall;
        } finally {
            this.db.b();
        }
    }

    public <V> V callInTxNoException(Callable<V> callable) {
        this.db.c();
        try {
            try {
                V vCall = callable.call();
                this.db.g();
                return vCall;
            } catch (Exception e2) {
                throw new d("Callable failed", e2);
            }
        } finally {
            this.db.b();
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    public <T> void delete(T t) {
        getDao(t.getClass()).delete(t);
    }

    public <T> void deleteAll(Class<T> cls) {
        getDao(cls).deleteAll();
    }

    public Collection<a<?, ?>> getAllDaos() {
        return Collections.unmodifiableCollection(this.entityToDao.values());
    }

    public a<?, ?> getDao(Class<? extends Object> cls) {
        a<?, ?> aVar = this.entityToDao.get(cls);
        if (aVar != null) {
            return aVar;
        }
        throw new d("No DAO registered for " + cls);
    }

    public i.b.a.i.a getDatabase() {
        return this.db;
    }

    /* JADX WARN: Multi-variable type inference failed */
    public <T> long insert(T t) {
        return getDao(t.getClass()).insert(t);
    }

    /* JADX WARN: Multi-variable type inference failed */
    public <T> long insertOrReplace(T t) {
        return getDao(t.getClass()).insertOrReplace(t);
    }

    /* JADX WARN: Multi-variable type inference failed */
    public <T, K> T load(Class<T> cls, K k2) {
        return (T) getDao(cls).load(k2);
    }

    public <T, K> List<T> loadAll(Class<T> cls) {
        return (List<T>) getDao(cls).loadAll();
    }

    public <T> i.b.a.l.f<T> queryBuilder(Class<T> cls) {
        return (i.b.a.l.f<T>) getDao(cls).queryBuilder();
    }

    public <T, K> List<T> queryRaw(Class<T> cls, String str, String... strArr) {
        return (List<T>) getDao(cls).queryRaw(str, strArr);
    }

    /* JADX WARN: Multi-variable type inference failed */
    public <T> void refresh(T t) {
        getDao(t.getClass()).refresh(t);
    }

    protected <T> void registerDao(Class<T> cls, a<T, ?> aVar) {
        this.entityToDao.put(cls, aVar);
    }

    public void runInTx(Runnable runnable) {
        this.db.c();
        try {
            runnable.run();
            this.db.g();
        } finally {
            this.db.b();
        }
    }

    public i.b.a.h.d startAsyncSession() {
        return new i.b.a.h.d(this);
    }

    /* JADX WARN: Multi-variable type inference failed */
    public <T> void update(T t) {
        getDao(t.getClass()).update(t);
    }
}
