]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/db/TransactionAccount.java
migrate to surrogate IDs for all database objects
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / db / TransactionAccount.java
index 6d51fec9d44e5cb1c20b8f89fb6f5832b96b01e2..730a866a1daf2d2da48cefc491ab6ed3137b487e 100644 (file)
@@ -22,19 +22,20 @@ import androidx.room.ColumnInfo;
 import androidx.room.Entity;
 import androidx.room.ForeignKey;
 import androidx.room.Index;
+import androidx.room.PrimaryKey;
 
-@Entity(tableName = "transaction_accounts", primaryKeys = {"profile", "transaction_id", "order_no"},
-        foreignKeys = {@ForeignKey(entity = Transaction.class, parentColumns = {"profile", "id"},
-                                   childColumns = {"profile", "transaction_id"},
-                                   onDelete = ForeignKey.CASCADE, onUpdate = ForeignKey.RESTRICT),
-                       @ForeignKey(entity = Account.class, parentColumns = {"profile", "name"},
-                                   childColumns = {"profile", "account_name"},
-                                   onDelete = ForeignKey.CASCADE, onUpdate = ForeignKey.RESTRICT)
-        }, indices = {@Index(name = "fk_tran_acc_prof_acc", value = {"profile", "account_name"})})
+@Entity(tableName = "transaction_accounts", foreignKeys = {
+        @ForeignKey(entity = Transaction.class, parentColumns = {"id"},
+                    childColumns = {"transaction_id"}, onDelete = ForeignKey.CASCADE,
+                    onUpdate = ForeignKey.RESTRICT),
+}, indices = {@Index(name = "fk_tran_acc_trans", value = {"transaction_id"}),
+              @Index(name = "un_transaction_accounts", unique = true,
+                     value = {"transaction_id", "order_no"})
+})
 public class TransactionAccount {
     @ColumnInfo
-    @NonNull
-    private String profile;
+    @PrimaryKey(autoGenerate = true)
+    private long id;
     @ColumnInfo(name = "transaction_id")
     private int transactionId;
     @ColumnInfo(name = "order_no")
@@ -51,13 +52,13 @@ public class TransactionAccount {
     private String comment;
     @ColumnInfo(defaultValue = "0")
     private int generation = 0;
-    @NonNull
-    public String getProfile() {
-        return profile;
+    public long getId() {
+        return id;
     }
-    public void setProfile(@NonNull String profile) {
-        this.profile = profile;
+    public void setId(long id) {
+        this.id = id;
     }
+    @NonNull
     public int getTransactionId() {
         return transactionId;
     }