Added uuid to rules

pull/208/head
M66B 3 years ago
parent 258773cc9d
commit 825f800bf9

File diff suppressed because it is too large Load Diff

@ -1184,6 +1184,10 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
Log.e(ex);
}
EntityRule existing = db.rule().getRuleByUUID(rule.uuid);
if (existing != null)
db.rule().deleteRule(existing.id);
db.rule().insertRule(rule);
}
}

@ -71,7 +71,7 @@ import io.requery.android.database.sqlite.SQLiteDatabase;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 236,
version = 237,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -2113,19 +2113,12 @@ public abstract class DB extends RoomDatabase {
public void migrate(@NonNull SupportSQLiteDatabase db) {
logMigration(startVersion, endVersion);
db.execSQL("ALTER TABLE `account` ADD COLUMN `uuid` TEXT NOT NULL DEFAULT ''");
Cursor cursor = null;
try {
cursor = db.query("SELECT id FROM account");
try (Cursor cursor = db.query("SELECT id FROM account")) {
while (cursor != null && cursor.moveToNext()) {
long id = cursor.getLong(0);
String uuid = UUID.randomUUID().toString();
Log.i("MMM account=" + id + " uuid=" + uuid);
db.execSQL("UPDATE account SET uuid = ? WHERE id = ?",
new Object[]{uuid, id});
db.execSQL("UPDATE account SET uuid = ? WHERE id = ?", new Object[]{uuid, id});
}
} catch (Throwable ex) {
if (cursor != null)
cursor.close();
}
}
}).addMigrations(new Migration(204, 205) {
@ -2355,6 +2348,19 @@ public abstract class DB extends RoomDatabase {
logMigration(startVersion, endVersion);
db.execSQL("ALTER TABLE `identity` ADD COLUMN `octetmime` INTEGER NOT NULL DEFAULT 0");
}
}).addMigrations(new Migration(236, 237) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
logMigration(startVersion, endVersion);
db.execSQL("ALTER TABLE `rule` ADD COLUMN `uuid` TEXT NOT NULL DEFAULT ''");
try (Cursor cursor = db.query("SELECT id FROM rule")) {
while (cursor != null && cursor.moveToNext()) {
long id = cursor.getLong(0);
String uuid = UUID.randomUUID().toString();
db.execSQL("UPDATE rule SET uuid = ? WHERE id = ?", new Object[]{uuid, id});
}
}
}
}).addMigrations(new Migration(998, 999) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {

@ -46,6 +46,9 @@ public interface DaoRule {
" WHERE rule.id = :id")
TupleRuleEx getRule(long id);
@Query("SELECT * FROM rule WHERE uuid = :uuid")
EntityRule getRuleByUUID(String uuid);
@Query("SELECT rule.*, folder.account, folder.name AS folderName, account.name AS accountName FROM rule" +
" JOIN folder ON folder.id = rule.folder" +
" JOIN account ON account.id = folder.account" +

@ -56,6 +56,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.regex.Pattern;
@ -83,6 +84,8 @@ public class EntityRule {
@PrimaryKey(autoGenerate = true)
public Long id;
@NonNull
public String uuid = UUID.randomUUID().toString();
@NonNull
public Long folder;
@NonNull
public String name;
@ -1161,7 +1164,8 @@ public class EntityRule {
public boolean equals(Object obj) {
if (obj instanceof EntityRule) {
EntityRule other = (EntityRule) obj;
return this.folder.equals(other.folder) &&
return Objects.equals(this.uuid, other.uuid) &&
this.folder.equals(other.folder) &&
this.name.equals(other.name) &&
this.order == other.order &&
this.enabled == other.enabled &&
@ -1212,6 +1216,7 @@ public class EntityRule {
public JSONObject toJSON() throws JSONException {
JSONObject json = new JSONObject();
json.put("id", id);
json.put("uuid", uuid);
json.put("name", name);
json.put("order", order);
json.put("enabled", enabled);
@ -1226,6 +1231,8 @@ public class EntityRule {
public static EntityRule fromJSON(JSONObject json) throws JSONException {
EntityRule rule = new EntityRule();
// id
if (json.has("uuid"))
rule.uuid = json.getString("uuid");
rule.name = json.getString("name");
rule.order = json.getInt("order");
rule.enabled = json.getBoolean("enabled");

Loading…
Cancel
Save