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
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;
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() {