]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/db/AccountValue.java
methods for deleting all DB tables
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / db / AccountValue.java
index f41b0e73ddce51c641cbd258dafa7bd4b81a7910..2ebc3ec483b9ca214609f99fd7c472a42d98ac6e 100644 (file)
@@ -20,40 +20,42 @@ 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;
 
-/*
-create table account_values(profile varchar not null, account varchar not null, currency varchar
-not null default '', value decimal not null, generation integer default 0 );
-create unique index un_account_values on account_values(profile,account,currency);
- */
-@Entity(tableName = "account_values", primaryKeys = {"profile", "account", "currency"})
+
+@Entity(tableName = "account_values", indices = {
+        @Index(name = "un_account_values", unique = true, value = {"account_id", "currency"}),
+        @Index(name = "fk_account_value_acc", value = "account_id")
+}, foreignKeys = {
+        @ForeignKey(entity = Account.class, parentColumns = "id", childColumns = "account_id",
+                    onDelete = ForeignKey.CASCADE, onUpdate = ForeignKey.RESTRICT)
+})
 public class AccountValue {
     @ColumnInfo
-    @NonNull
-    private String profile;
-    @ColumnInfo
-    @NonNull
-    private String account;
+    @PrimaryKey(autoGenerate = true)
+    long id;
+    @ColumnInfo(name = "account_id")
+    private long accountId;
     @NonNull
     @ColumnInfo(defaultValue = "")
     private String currency = "";
     @ColumnInfo
     private float value;
     @ColumnInfo(defaultValue = "0")
-    private int generation = 0;
-    @NonNull
-    public String getProfile() {
-        return profile;
+    private long generation = 0;
+    public long getId() {
+        return id;
     }
-    public void setProfile(@NonNull String profile) {
-        this.profile = profile;
+    public void setId(long id) {
+        this.id = id;
     }
-    @NonNull
-    public String getAccount() {
-        return account;
+    public long getAccountId() {
+        return accountId;
     }
-    public void setAccount(@NonNull String account) {
-        this.account = account;
+    public void setAccountId(long accountId) {
+        this.accountId = accountId;
     }
     @NonNull
     public String getCurrency() {
@@ -68,10 +70,10 @@ public class AccountValue {
     public void setValue(float value) {
         this.value = value;
     }
-    public int getGeneration() {
+    public long getGeneration() {
         return generation;
     }
-    public void setGeneration(int generation) {
+    public void setGeneration(long generation) {
         this.generation = generation;
     }
 }