Added uuid to identities

pull/208/head
M66B 3 years ago
parent 1d8985cdce
commit f1efdb6018

File diff suppressed because it is too large Load Diff

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

@ -71,7 +71,7 @@ import io.requery.android.database.sqlite.SQLiteDatabase;
// https://developer.android.com/topic/libraries/architecture/room.html // https://developer.android.com/topic/libraries/architecture/room.html
@Database( @Database(
version = 238, version = 239,
entities = { entities = {
EntityIdentity.class, EntityIdentity.class,
EntityAccount.class, EntityAccount.class,
@ -2119,6 +2119,8 @@ public abstract class DB extends RoomDatabase {
String uuid = UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
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) {
Log.e(ex);
} }
} }
}).addMigrations(new Migration(204, 205) { }).addMigrations(new Migration(204, 205) {
@ -2359,6 +2361,8 @@ public abstract class DB extends RoomDatabase {
String uuid = UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
db.execSQL("UPDATE rule SET uuid = ? WHERE id = ?", new Object[]{uuid, id}); db.execSQL("UPDATE rule SET uuid = ? WHERE id = ?", new Object[]{uuid, id});
} }
} catch (Throwable ex) {
Log.e(ex);
} }
} }
}).addMigrations(new Migration(237, 238) { }).addMigrations(new Migration(237, 238) {
@ -2372,6 +2376,23 @@ public abstract class DB extends RoomDatabase {
String uuid = UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
db.execSQL("UPDATE answer SET uuid = ? WHERE id = ?", new Object[]{uuid, id}); db.execSQL("UPDATE answer SET uuid = ? WHERE id = ?", new Object[]{uuid, id});
} }
} catch (Throwable ex) {
Log.e(ex);
}
}
}).addMigrations(new Migration(238, 239) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
logMigration(startVersion, endVersion);
db.execSQL("ALTER TABLE `identity` ADD COLUMN `uuid` TEXT NOT NULL DEFAULT ''");
try (Cursor cursor = db.query("SELECT id FROM identity")) {
while (cursor != null && cursor.moveToNext()) {
long id = cursor.getLong(0);
String uuid = UUID.randomUUID().toString();
db.execSQL("UPDATE identity SET uuid = ? WHERE id = ?", new Object[]{uuid, id});
}
} catch (Throwable ex) {
Log.e(ex);
} }
} }
}).addMigrations(new Migration(998, 999) { }).addMigrations(new Migration(998, 999) {

@ -86,6 +86,9 @@ public interface DaoIdentity {
@Query("SELECT * FROM identity WHERE id = :id") @Query("SELECT * FROM identity WHERE id = :id")
EntityIdentity getIdentity(long id); EntityIdentity getIdentity(long id);
@Query("SELECT * FROM identity WHERE uuid = :uuid")
EntityIdentity getIdentityByUUID(String uuid);
@Insert @Insert
long insertIdentity(EntityIdentity identity); long insertIdentity(EntityIdentity identity);

@ -35,6 +35,7 @@ import org.json.JSONObject;
import java.util.Locale; import java.util.Locale;
import java.util.Objects; import java.util.Objects;
import java.util.UUID;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.mail.Address; import javax.mail.Address;
@ -56,6 +57,8 @@ public class EntityIdentity {
@PrimaryKey(autoGenerate = true) @PrimaryKey(autoGenerate = true)
public Long id; public Long id;
@NonNull @NonNull
public String uuid = UUID.randomUUID().toString();
@NonNull
public String name; public String name;
@NonNull @NonNull
public String email; public String email;
@ -187,6 +190,7 @@ public class EntityIdentity {
public JSONObject toJSON() throws JSONException { public JSONObject toJSON() throws JSONException {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("id", id); json.put("id", id);
json.put("uuid", uuid);
json.put("name", name); json.put("name", name);
json.put("email", email); json.put("email", email);
// not account // not account
@ -244,6 +248,10 @@ public class EntityIdentity {
public static EntityIdentity fromJSON(JSONObject json) throws JSONException { public static EntityIdentity fromJSON(JSONObject json) throws JSONException {
EntityIdentity identity = new EntityIdentity(); EntityIdentity identity = new EntityIdentity();
identity.id = json.getLong("id"); identity.id = json.getLong("id");
if (json.has("uuid"))
identity.uuid = json.getString("uuid");
identity.name = json.getString("name"); identity.name = json.getString("name");
identity.email = json.getString("email"); identity.email = json.getString("email");
if (json.has("display") && !json.isNull("display")) if (json.has("display") && !json.isNull("display"))
@ -315,7 +323,8 @@ public class EntityIdentity {
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj instanceof EntityIdentity) { if (obj instanceof EntityIdentity) {
EntityIdentity other = (EntityIdentity) obj; EntityIdentity other = (EntityIdentity) obj;
return (this.name.equals(other.name) && return (Objects.equals(this.uuid, other.uuid) &&
this.name.equals(other.name) &&
this.email.equals(other.email) && this.email.equals(other.email) &&
this.account.equals(other.account) && this.account.equals(other.account) &&
Objects.equals(this.display, other.display) && Objects.equals(this.display, other.display) &&

Loading…
Cancel
Save