X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fdb%2FAccount.java;h=59c164b0b8e561423bed8bb7bda37743abaaec3c;hp=d0eb1ae08829c23838a2b58b3f88949b960f4dee;hb=93545c6fbf1244fbd96ecfc50e1115dbdc25f9ae;hpb=1c3647f273df2f15ef299896c24cda95c6119988 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..59c164b0 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; @@ -42,12 +53,17 @@ public class Account { private boolean amountsExpanded = false; @ColumnInfo(defaultValue = "0") private int generation; - @NonNull - public String getProfile() { - return profile; + 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() {