package net.ktnx.mobileledger.db;
+import android.os.AsyncTask;
+
import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
+import androidx.room.PrimaryKey;
+import androidx.room.Transaction;
-/*
- create table profiles(uuid varchar not null primary key, name not null, url not null,
- use_authentication boolean not null, auth_user varchar, auth_password varchar, order_no
- integer, permit_posting boolean default 0, theme integer default -1, preferred_accounts_filter
- varchar, future_dates integer, api_version integer, show_commodity_by_default boolean default
- 0, default_commodity varchar, show_comments_by_default boolean default 1,
- detected_version_pre_1_19 boolean, detected_version_major integer, detected_version_minor
- integer);
-*/
-@Entity(tableName = "profiles", primaryKeys = {"uuid"})
+import net.ktnx.mobileledger.dao.AccountDAO;
+import net.ktnx.mobileledger.dao.DescriptionHistoryDAO;
+import net.ktnx.mobileledger.dao.OptionDAO;
+import net.ktnx.mobileledger.dao.TransactionDAO;
+import net.ktnx.mobileledger.utils.Misc;
+
+@Entity(tableName = "profiles")
public class Profile {
- @NonNull
+ public static final long NO_PROFILE_ID = 0;
@ColumnInfo
- private String uuid = "invalid";
+ @PrimaryKey(autoGenerate = true)
+ private long id;
@NonNull
@ColumnInfo
private String name = "";
+ @ColumnInfo(name = "deprecated_uuid")
+ private String deprecatedUUID;
@NonNull
@ColumnInfo
private String url = "";
private int detectedVersionMajor;
@ColumnInfo(name = "detected_version_minor")
private int detectedVersionMinor;
- @NonNull
- public String getUuid() {
- return uuid;
+ public String getDeprecatedUUID() {
+ return deprecatedUUID;
+ }
+ public void setDeprecatedUUID(String deprecatedUUID) {
+ this.deprecatedUUID = deprecatedUUID;
+ }
+ public long getId() {
+ return id;
}
- public void setUuid(@NonNull String uuid) {
- this.uuid = uuid;
+ public void setId(long id) {
+ this.id = id;
}
@NonNull
public String getName() {
public String toString() {
return getName();
}
+ @Override
+ public boolean equals(@Nullable Object o) {
+ if (!(o instanceof Profile))
+ return false;
+ Profile p = (Profile) o;
+ return id == p.id && Misc.equalStrings(name, p.name) &&
+ Misc.equalStrings(deprecatedUUID, p.deprecatedUUID) &&
+ Misc.equalStrings(url, p.url) && useAuthentication == p.useAuthentication &&
+ Misc.equalStrings(authUser, p.authUser) &&
+ Misc.equalStrings(authPassword, p.authPassword) && orderNo == p.orderNo &&
+ permitPosting == p.permitPosting && theme == p.theme &&
+ Misc.equalStrings(preferredAccountsFilter, p.preferredAccountsFilter) &&
+ futureDates == p.futureDates && apiVersion == p.apiVersion &&
+ showCommentsByDefault == p.showCommentsByDefault &&
+ Misc.equalStrings(defaultCommodity, p.defaultCommodity) &&
+ showCommentsByDefault == p.showCommentsByDefault &&
+ detectedVersionPre_1_19 == p.detectedVersionPre_1_19 &&
+ detectedVersionMajor == p.detectedVersionMajor &&
+ detectedVersionMinor == p.detectedVersionMinor;
+ }
+ @Transaction
+ public void wipeAllDataSync() {
+ OptionDAO optDao = DB.get()
+ .getOptionDAO();
+ optDao.deleteSync(optDao.allForProfileSync(id));
+
+ AccountDAO accDao = DB.get()
+ .getAccountDAO();
+ accDao.deleteSync(accDao.allForProfileSync(id));
+
+ TransactionDAO trnDao = DB.get()
+ .getTransactionDAO();
+ trnDao.deleteSync(trnDao.allForProfileSync(id));
+
+ DescriptionHistoryDAO descDao = DB.get()
+ .getDescriptionHistoryDAO();
+ descDao.sweepSync();
+ }
+ public void wipeAllData() {
+ AsyncTask.execute(this::wipeAllDataSync);
+ }
+
}