]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/db/Transaction.java
Transaction: when copying, use proper descriptionUpper member
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / db / Transaction.java
index f6808f9406c6f4c292ef939512a1205ba3175fee..8b98f923b65f1d698525f7f088f8a04a2b501499 100644 (file)
@@ -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;
@@ -51,26 +61,42 @@ public class Transaction {
     @ColumnInfo(collate = ColumnInfo.NOCASE)
     @NonNull
     private String description;
+    @ColumnInfo(name = "description_uc")
+    @NonNull
+    private String descriptionUpper;
     @ColumnInfo
     private String comment;
     @ColumnInfo
-    private int generation = 0;
-    public String getProfile() {
-        return profile;
+    private long generation = 0;
+    @NonNull
+    public String getDescriptionUpper() {
+        return descriptionUpper;
     }
-    public void setProfile(String profile) {
-        this.profile = profile;
+    public void setDescriptionUpper(@NonNull String descriptionUpper) {
+        this.descriptionUpper = descriptionUpper;
     }
-    public int getId() {
+    public long getLedgerId() {
+        return ledgerId;
+    }
+    public void setLedgerId(long ledgerId) {
+        this.ledgerId = ledgerId;
+    }
+    public long getProfileId() {
+        return profileId;
+    }
+    public void setProfileId(long profileId) {
+        this.profileId = profileId;
+    }
+    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() {
@@ -96,6 +122,7 @@ public class Transaction {
     }
     public void setDescription(String description) {
         this.description = description;
+        setDescriptionUpper(description.toUpperCase());
     }
     public String getComment() {
         return comment;
@@ -103,11 +130,24 @@ public class Transaction {
     public void setComment(String comment) {
         this.comment = comment;
     }
-    public int getGeneration() {
+    public long getGeneration() {
         return generation;
     }
-    public void setGeneration(int generation) {
+    public void setGeneration(long generation) {
         this.generation = generation;
     }
 
+    public void copyDataFrom(Transaction o) {
+        // id = o.id;
+        ledgerId = o.ledgerId;
+        profileId = o.profileId;
+        dataHash = o.dataHash;
+        year = o.year;
+        month = o.month;
+        day = o.day;
+        description = o.description;
+        descriptionUpper = o.description.toUpperCase();
+        comment = o.comment;
+        generation = o.generation;
+    }
 }