129 lines
4.6 KiB
Java
129 lines
4.6 KiB
Java
package org.greenrobot.greendao.internal;
|
|
|
|
import java.lang.reflect.Field;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import org.greenrobot.greendao.AbstractDao;
|
|
import org.greenrobot.greendao.DaoException;
|
|
import org.greenrobot.greendao.Property;
|
|
import org.greenrobot.greendao.database.Database;
|
|
import org.greenrobot.greendao.identityscope.IdentityScope;
|
|
import org.greenrobot.greendao.identityscope.IdentityScopeLong;
|
|
import org.greenrobot.greendao.identityscope.IdentityScopeObject;
|
|
import org.greenrobot.greendao.identityscope.IdentityScopeType;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public final class DaoConfig implements Cloneable {
|
|
public final Database a;
|
|
public final String b;
|
|
public final Property[] c;
|
|
public final String[] d;
|
|
public final String[] e;
|
|
public final String[] f;
|
|
public final Property g;
|
|
public final boolean h;
|
|
public final TableStatements i;
|
|
private IdentityScope<?, ?> j;
|
|
|
|
public DaoConfig(Database database, Class<? extends AbstractDao<?, ?>> cls) {
|
|
this.a = database;
|
|
try {
|
|
this.b = (String) cls.getField("TABLENAME").get(null);
|
|
Property[] a = a(cls);
|
|
this.c = a;
|
|
this.d = new String[a.length];
|
|
ArrayList arrayList = new ArrayList();
|
|
ArrayList arrayList2 = new ArrayList();
|
|
Property property = null;
|
|
for (int i = 0; i < a.length; i++) {
|
|
Property property2 = a[i];
|
|
String str = property2.e;
|
|
this.d[i] = str;
|
|
if (property2.d) {
|
|
arrayList.add(str);
|
|
property = property2;
|
|
} else {
|
|
arrayList2.add(str);
|
|
}
|
|
}
|
|
this.f = (String[]) arrayList2.toArray(new String[arrayList2.size()]);
|
|
this.e = (String[]) arrayList.toArray(new String[arrayList.size()]);
|
|
boolean z = true;
|
|
this.g = this.e.length == 1 ? property : null;
|
|
this.i = new TableStatements(database, this.b, this.d, this.e);
|
|
if (this.g == null) {
|
|
this.h = false;
|
|
return;
|
|
}
|
|
Class<?> cls2 = this.g.b;
|
|
if (!cls2.equals(Long.TYPE) && !cls2.equals(Long.class) && !cls2.equals(Integer.TYPE) && !cls2.equals(Integer.class) && !cls2.equals(Short.TYPE) && !cls2.equals(Short.class) && !cls2.equals(Byte.TYPE) && !cls2.equals(Byte.class)) {
|
|
z = false;
|
|
}
|
|
this.h = z;
|
|
} catch (Exception e) {
|
|
throw new DaoException("Could not init DAOConfig", e);
|
|
}
|
|
}
|
|
|
|
private static Property[] a(Class<? extends AbstractDao<?, ?>> cls) throws ClassNotFoundException, IllegalArgumentException, IllegalAccessException {
|
|
Field[] declaredFields = Class.forName(cls.getName() + "$Properties").getDeclaredFields();
|
|
ArrayList arrayList = new ArrayList();
|
|
for (Field field : declaredFields) {
|
|
if ((field.getModifiers() & 9) == 9) {
|
|
Object obj = field.get(null);
|
|
if (obj instanceof Property) {
|
|
arrayList.add((Property) obj);
|
|
}
|
|
}
|
|
}
|
|
Property[] propertyArr = new Property[arrayList.size()];
|
|
Iterator it = arrayList.iterator();
|
|
while (it.hasNext()) {
|
|
Property property = (Property) it.next();
|
|
int i = property.a;
|
|
if (propertyArr[i] != null) {
|
|
throw new DaoException("Duplicate property ordinals");
|
|
}
|
|
propertyArr[i] = property;
|
|
}
|
|
return propertyArr;
|
|
}
|
|
|
|
public DaoConfig clone() {
|
|
return new DaoConfig(this);
|
|
}
|
|
|
|
public IdentityScope<?, ?> a() {
|
|
return this.j;
|
|
}
|
|
|
|
public void a(IdentityScopeType identityScopeType) {
|
|
if (identityScopeType == IdentityScopeType.None) {
|
|
this.j = null;
|
|
return;
|
|
}
|
|
if (identityScopeType == IdentityScopeType.Session) {
|
|
if (this.h) {
|
|
this.j = new IdentityScopeLong();
|
|
return;
|
|
} else {
|
|
this.j = new IdentityScopeObject();
|
|
return;
|
|
}
|
|
}
|
|
throw new IllegalArgumentException("Unsupported type: " + identityScopeType);
|
|
}
|
|
|
|
public DaoConfig(DaoConfig daoConfig) {
|
|
this.a = daoConfig.a;
|
|
this.b = daoConfig.b;
|
|
this.c = daoConfig.c;
|
|
this.d = daoConfig.d;
|
|
this.e = daoConfig.e;
|
|
this.f = daoConfig.f;
|
|
this.g = daoConfig.g;
|
|
this.i = daoConfig.i;
|
|
this.h = daoConfig.h;
|
|
}
|
|
}
|