X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fdb%2FAccount.java;h=82524fcb36ae199a417163cfddd5640899f3465d;hb=55e1029ad80ef8eb223413d9cc633efefb1b68ac;hp=d0eb1ae08829c23838a2b58b3f88949b960f4dee;hpb=bdf127ab4c79dbfcf50697cb919c46d73063227e;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/db/Account.java b/app/src/main/java/net/ktnx/mobileledger/db/Account.java index d0eb1ae0..82524fcb 100644 --- a/app/src/main/java/net/ktnx/mobileledger/db/Account.java +++ b/app/src/main/java/net/ktnx/mobileledger/db/Account.java @@ -20,14 +20,25 @@ package net.ktnx.mobileledger.db; import androidx.annotation.NonNull; import androidx.room.ColumnInfo; import androidx.room.Entity; +import androidx.room.ForeignKey; +import androidx.room.Index; +import androidx.room.PrimaryKey; -@Entity(tableName = "accounts", primaryKeys = {"profile", "name"}) +@Entity(tableName = "accounts", + indices = {@Index(name = "un_account_name", unique = true, value = {"profile_id", "name"}), + @Index(name = "fk_account_profile", value = "profile_id") + }, foreignKeys = { + @ForeignKey(entity = Profile.class, parentColumns = "id", childColumns = "profile_id", + onDelete = ForeignKey.CASCADE, onUpdate = ForeignKey.RESTRICT) +}) public class Account { @ColumnInfo - int level; + @PrimaryKey(autoGenerate = true) + long id; + @ColumnInfo(name = "profile_id") + long profileId; @ColumnInfo - @NonNull - private String profile; + int level; @ColumnInfo @NonNull private String name; @@ -41,13 +52,18 @@ public class Account { @ColumnInfo(name = "amounts_expanded", defaultValue = "0") private boolean amountsExpanded = false; @ColumnInfo(defaultValue = "0") - private int generation; - @NonNull - public String getProfile() { - return profile; + private long generation; + public long getId() { + return id; + } + public void setId(long id) { + this.id = id; + } + public long getProfileId() { + return profileId; } - public void setProfile(@NonNull String profile) { - this.profile = profile; + public void setProfileId(long profileId) { + this.profileId = profileId; } @NonNull public String getName() { @@ -87,10 +103,10 @@ public class Account { public void setAmountsExpanded(boolean amountsExpanded) { this.amountsExpanded = amountsExpanded; } - public int getGeneration() { + public long getGeneration() { return generation; } - public void setGeneration(int generation) { + public void setGeneration(long generation) { this.generation = generation; } @NonNull