62 lines
1.7 KiB
Java
62 lines
1.7 KiB
Java
package org.greenrobot.greendao.query;
|
|
|
|
import java.lang.ref.WeakReference;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
import org.greenrobot.greendao.AbstractDao;
|
|
import org.greenrobot.greendao.query.AbstractQuery;
|
|
|
|
/* loaded from: classes2.dex */
|
|
abstract class AbstractQueryData<T, Q extends AbstractQuery<T>> {
|
|
final String a;
|
|
final AbstractDao<T, ?> b;
|
|
final String[] c;
|
|
final Map<Long, WeakReference<Q>> d = new HashMap();
|
|
|
|
AbstractQueryData(AbstractDao<T, ?> abstractDao, String str, String[] strArr) {
|
|
this.b = abstractDao;
|
|
this.a = str;
|
|
this.c = strArr;
|
|
}
|
|
|
|
protected abstract Q a();
|
|
|
|
Q a(Q q) {
|
|
if (Thread.currentThread() != q.e) {
|
|
return b();
|
|
}
|
|
String[] strArr = this.c;
|
|
System.arraycopy(strArr, 0, q.d, 0, strArr.length);
|
|
return q;
|
|
}
|
|
|
|
Q b() {
|
|
Q q;
|
|
long id = Thread.currentThread().getId();
|
|
synchronized (this.d) {
|
|
WeakReference<Q> weakReference = this.d.get(Long.valueOf(id));
|
|
q = weakReference != null ? weakReference.get() : null;
|
|
if (q == null) {
|
|
c();
|
|
q = a();
|
|
this.d.put(Long.valueOf(id), new WeakReference<>(q));
|
|
} else {
|
|
System.arraycopy(this.c, 0, q.d, 0, this.c.length);
|
|
}
|
|
}
|
|
return q;
|
|
}
|
|
|
|
void c() {
|
|
synchronized (this.d) {
|
|
Iterator<Map.Entry<Long, WeakReference<Q>>> it = this.d.entrySet().iterator();
|
|
while (it.hasNext()) {
|
|
if (it.next().getValue().get() == null) {
|
|
it.remove();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|