90 lines
2.9 KiB
Java
90 lines
2.9 KiB
Java
package com.ubt.jimu.base.db.diy;
|
|
|
|
import android.content.Context;
|
|
import com.ubt.jimu.base.cache.Cache;
|
|
import com.ubt.jimu.base.db.DatabaseUtils;
|
|
import com.ubt.jimu.gen.DaoMaster;
|
|
import com.ubt.jimu.gen.DaoSession;
|
|
import com.ubt.jimu.gen.DiyDBModelDao;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import org.greenrobot.greendao.query.QueryBuilder;
|
|
import org.greenrobot.greendao.query.WhereCondition;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class DiyHelper {
|
|
public static final boolean ENCRYPTED = true;
|
|
private static final DiyHelper ourInstance = new DiyHelper();
|
|
private DaoSession daoSession;
|
|
|
|
private DiyHelper() {
|
|
}
|
|
|
|
public static DiyHelper getInstance() {
|
|
return ourInstance;
|
|
}
|
|
|
|
public void deleteItem(DiyDBModel diyDBModel) {
|
|
DatabaseUtils.getDaoSession(true).a((DaoSession) diyDBModel);
|
|
}
|
|
|
|
public DaoSession getDaoSession() {
|
|
return this.daoSession;
|
|
}
|
|
|
|
public List<DiyDBModel> getDiyList() {
|
|
ArrayList arrayList = new ArrayList();
|
|
try {
|
|
QueryBuilder<DiyDBModel> k = DatabaseUtils.getDaoSession(true).d().k();
|
|
k.a(DiyDBModelDao.Properties.ModelCreatedId.a((Object) Cache.getInstance().getUserId()), new WhereCondition[0]);
|
|
List<DiyDBModel> b = k.b();
|
|
for (int size = b.size(); size > 0; size--) {
|
|
arrayList.add(b.get(size - 1));
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
return arrayList;
|
|
}
|
|
|
|
public void insertData(DiyDBModel diyDBModel) {
|
|
try {
|
|
DatabaseUtils.getDaoSession(true).b((DaoSession) diyDBModel);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public boolean nameRepeat(String str) {
|
|
QueryBuilder b = DatabaseUtils.getDaoSession(false).b(DiyDBModel.class);
|
|
b.a(DiyDBModelDao.Properties.ModelName.a((Object) str), new WhereCondition[0]);
|
|
return ((DiyDBModel) b.c()) != null;
|
|
}
|
|
|
|
public boolean queryForName(String str) {
|
|
try {
|
|
QueryBuilder<DiyDBModel> k = DatabaseUtils.getDaoSession(true).d().k();
|
|
k.a(DiyDBModelDao.Properties.ModelName.a((Object) str), new WhereCondition[0]);
|
|
return k.c() != null;
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public DiyDBModel queryForUUid(String str) {
|
|
try {
|
|
QueryBuilder<DiyDBModel> k = DatabaseUtils.getDaoSession(true).d().k();
|
|
k.a(DiyDBModelDao.Properties.CustomModelId.a((Object) str), new WhereCondition[0]);
|
|
return k.c();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return new DiyDBModel();
|
|
}
|
|
}
|
|
|
|
public void rigisterDb(Context context) {
|
|
this.daoSession = new DaoMaster(new DaoMaster.DevOpenHelper(context, "diy-db-encrypted").getEncryptedWritableDb("super-secret")).newSession();
|
|
}
|
|
}
|