X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fdb%2FTransaction.java;h=05e63d8c0e92dd05c3db2aa48603a65159d5cd6e;hb=87a1e58f79757bb0257c911e9bd77eb5d77a3e40;hp=f6808f9406c6f4c292ef939512a1205ba3175fee;hpb=32ef1438acbd5328433be04668362402e26095cb;p=mobile-ledger.git 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..05e63d8c 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,22 @@ 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_ledger_id", unique = true, + value = {"profile_id", "ledger_id"}), + @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 = "ledger_id") + long ledgerId; + @ColumnInfo(name = "profile_id") + private long profileId; @ColumnInfo(name = "data_hash") @NonNull private String dataHash; @@ -55,22 +65,28 @@ public class Transaction { private String comment; @ColumnInfo private int generation = 0; - public String getProfile() { - return profile; + public long getLedgerId() { + return ledgerId; + } + public void setLedgerId(long ledgerId) { + this.ledgerId = ledgerId; + } + 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() {