X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fdb%2FTransaction.java;h=d67cedf53d6df0002205cbd170a886f971ace772;hp=f6808f9406c6f4c292ef939512a1205ba3175fee;hb=93545c6fbf1244fbd96ecfc50e1115dbdc25f9ae;hpb=1c3647f273df2f15ef299896c24cda95c6119988 diff --git a/app/src/main/java/net/ktnx/mobileledger/db/Transaction.java b/app/src/main/java/net/ktnx/mobileledger/db/Transaction.java index f6808f94..d67cedf5 100644 --- a/app/src/main/java/net/ktnx/mobileledger/db/Transaction.java +++ b/app/src/main/java/net/ktnx/mobileledger/db/Transaction.java @@ -20,7 +20,11 @@ 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; + +import org.jetbrains.annotations.NotNull; /* create table transactions(profile varchar not null, id integer not null, data_hash varchar not @@ -29,16 +33,20 @@ collate NOCASE not null, comment varchar, generation integer default 0, primary create unique index un_transactions_data_hash on transactions(profile,data_hash); create index idx_transaction_description on transactions(description); */ -@Entity(tableName = "transactions", primaryKeys = {"profile", "id"}, indices = { - @Index(name = "un_transactions_data_hash", unique = true, value = {"profile", "data_hash"}), - @Index(name = "idx_transaction_description", value = "description") +@Entity(tableName = "transactions", foreignKeys = { + @ForeignKey(entity = Profile.class, parentColumns = "id", childColumns = "profile_id", + onDelete = ForeignKey.CASCADE, onUpdate = ForeignKey.RESTRICT) +}, indices = {@Index(name = "un_transactions_data_hash", unique = true, + value = {"profile_id", "data_hash"}), + @Index(name = "idx_transaction_description", value = "description"), + @Index(name = "fk_transaction_profile", value = "profile_id") }) public class Transaction { @ColumnInfo - @NonNull - private String profile; - @ColumnInfo - private int id; + @PrimaryKey(autoGenerate = true) + long id; + @ColumnInfo(name = "profile_id") + private long profileId; @ColumnInfo(name = "data_hash") @NonNull private String dataHash; @@ -55,22 +63,22 @@ public class Transaction { private String comment; @ColumnInfo private int generation = 0; - public String getProfile() { - return profile; + public long getProfileId() { + return profileId; } - public void setProfile(String profile) { - this.profile = profile; + public void setProfileId(long profileId) { + this.profileId = profileId; } - public int getId() { + public long getId() { return id; } - public void setId(int id) { + public void setId(long id) { this.id = id; } public String getDataHash() { return dataHash; } - public void setDataHash(String dataHash) { + public void setDataHash(@NotNull String dataHash) { this.dataHash = dataHash; } public int getYear() {