jimu-decompiled/sources/org/greenrobot/greendao/query/QueryBuilder.java
2025-05-13 19:24:51 +02:00

197 lines
5.3 KiB
Java

package org.greenrobot.greendao.query;
import java.util.ArrayList;
import java.util.List;
import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.DaoLog;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.SqlUtils;
/* loaded from: classes2.dex */
public class QueryBuilder<T> {
public static boolean k;
public static boolean l;
private final WhereCollector<T> a;
private StringBuilder b;
private final List<Object> c;
private final List<Join<T, ?>> d;
private final AbstractDao<T, ?> e;
private final String f;
private Integer g;
private Integer h;
private boolean i;
private String j;
protected QueryBuilder(AbstractDao<T, ?> abstractDao) {
this(abstractDao, "T");
}
public static <T2> QueryBuilder<T2> a(AbstractDao<T2, ?> abstractDao) {
return new QueryBuilder<>(abstractDao);
}
private void d() {
StringBuilder sb = this.b;
if (sb == null) {
this.b = new StringBuilder();
} else if (sb.length() > 0) {
this.b.append(",");
}
}
private StringBuilder e() {
StringBuilder sb = new StringBuilder(SqlUtils.a(this.e.h(), this.f, this.e.c(), this.i));
a(sb, this.f);
StringBuilder sb2 = this.b;
if (sb2 != null && sb2.length() > 0) {
sb.append(" ORDER BY ");
sb.append((CharSequence) this.b);
}
return sb;
}
public QueryBuilder<T> b(Property... propertyArr) {
a(" DESC", propertyArr);
return this;
}
public T c() {
return a().d();
}
protected QueryBuilder(AbstractDao<T, ?> abstractDao, String str) {
this.e = abstractDao;
this.f = str;
this.c = new ArrayList();
this.d = new ArrayList();
this.a = new WhereCollector<>(abstractDao, str);
this.j = " COLLATE NOCASE";
}
private int b(StringBuilder sb) {
if (this.h == null) {
return -1;
}
if (this.g == null) {
throw new IllegalStateException("Offset cannot be set without limit");
}
sb.append(" OFFSET ?");
this.c.add(this.h);
return this.c.size() - 1;
}
public QueryBuilder<T> a(WhereCondition whereCondition, WhereCondition... whereConditionArr) {
this.a.a(whereCondition, whereConditionArr);
return this;
}
public <J> Join<T, J> a(Class<J> cls, Property property) {
return a(this.e.e(), cls, property);
}
public <J> Join<T, J> a(Property property, Class<J> cls, Property property2) {
return a(this.f, property, this.e.g().a((Class<? extends Object>) cls), property2);
}
private <J> Join<T, J> a(String str, Property property, AbstractDao<J, ?> abstractDao, Property property2) {
Join<T, J> join = new Join<>(str, property, abstractDao, property2, "J" + (this.d.size() + 1));
this.d.add(join);
return join;
}
public List<T> b() {
return a().c();
}
public QueryBuilder<T> a(Property... propertyArr) {
a(" ASC", propertyArr);
return this;
}
private void a(String str, Property... propertyArr) {
String str2;
for (Property property : propertyArr) {
d();
a(this.b, property);
if (String.class.equals(property.b) && (str2 = this.j) != null) {
this.b.append(str2);
}
this.b.append(str);
}
}
protected StringBuilder a(StringBuilder sb, Property property) {
this.a.a(property);
sb.append(this.f);
sb.append('.');
sb.append('\'');
sb.append(property.e);
sb.append('\'');
return sb;
}
public QueryBuilder<T> a(int i) {
this.g = Integer.valueOf(i);
return this;
}
public Query<T> a() {
StringBuilder e = e();
int a = a(e);
int b = b(e);
String sb = e.toString();
a(sb);
return Query.a(this.e, sb, this.c.toArray(), a, b);
}
private int a(StringBuilder sb) {
if (this.g == null) {
return -1;
}
sb.append(" LIMIT ?");
this.c.add(this.g);
return this.c.size() - 1;
}
private void a(String str) {
if (k) {
DaoLog.a("Built SQL for query: " + str);
}
if (l) {
DaoLog.a("Values for query: " + this.c);
}
}
private void a(StringBuilder sb, String str) {
this.c.clear();
for (Join<T, ?> join : this.d) {
sb.append(" JOIN ");
sb.append('\"');
sb.append(join.b.h());
sb.append('\"');
sb.append(' ');
sb.append(join.e);
sb.append(" ON ");
SqlUtils.a(sb, join.a, join.c);
sb.append('=');
SqlUtils.a(sb, join.e, join.d);
}
boolean z = !this.a.a();
if (z) {
sb.append(" WHERE ");
this.a.a(sb, str, this.c);
}
for (Join<T, ?> join2 : this.d) {
if (!join2.f.a()) {
if (!z) {
sb.append(" WHERE ");
z = true;
} else {
sb.append(" AND ");
}
join2.f.a(sb, join2.e, this.c);
}
}
}
}