]> git.ktnx.net Git - mobile-ledger.git/blob - 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
1 /*
2  * Copyright © 2021 Damyan Ivanov.
3  * This file is part of MoLe.
4  * MoLe is free software: you can distribute it and/or modify it
5  * under the term of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your opinion), any later version.
8  *
9  * MoLe is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License terms for details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
16  */
17
18 package net.ktnx.mobileledger.db;
19
20 import androidx.annotation.NonNull;
21 import androidx.room.ColumnInfo;
22 import androidx.room.Entity;
23 import androidx.room.ForeignKey;
24 import androidx.room.Index;
25 import androidx.room.PrimaryKey;
26
27 import org.jetbrains.annotations.NotNull;
28
29 /*
30 create table transactions(profile varchar not null, id integer not null, data_hash varchar not
31 null, year integer not null, month integer not null, day integer not null, description varchar
32 collate NOCASE not null, comment varchar, generation integer default 0, primary key(profile,id));
33 create unique index un_transactions_data_hash on transactions(profile,data_hash);
34 create index idx_transaction_description on transactions(description);
35  */
36 @Entity(tableName = "transactions", foreignKeys = {
37         @ForeignKey(entity = Profile.class, parentColumns = "id", childColumns = "profile_id",
38                     onDelete = ForeignKey.CASCADE, onUpdate = ForeignKey.RESTRICT)
39 }, indices = {@Index(name = "un_transactions_ledger_id", unique = true,
40                      value = {"profile_id", "ledger_id"}),
41               @Index(name = "idx_transaction_description", value = "description"),
42               @Index(name = "fk_transaction_profile", value = "profile_id")
43 })
44 public class Transaction {
45     @ColumnInfo
46     @PrimaryKey(autoGenerate = true)
47     long id;
48     @ColumnInfo(name = "ledger_id")
49     long ledgerId;
50     @ColumnInfo(name = "profile_id")
51     private long profileId;
52     @ColumnInfo(name = "data_hash")
53     @NonNull
54     private String dataHash;
55     @ColumnInfo
56     private int year;
57     @ColumnInfo
58     private int month;
59     @ColumnInfo
60     private int day;
61     @ColumnInfo(collate = ColumnInfo.NOCASE)
62     @NonNull
63     private String description;
64     @ColumnInfo(name = "description_uc")
65     @NonNull
66     private String descriptionUpper;
67     @ColumnInfo
68     private String comment;
69     @ColumnInfo
70     private long generation = 0;
71     @NonNull
72     public String getDescriptionUpper() {
73         return descriptionUpper;
74     }
75     public void setDescriptionUpper(@NonNull String descriptionUpper) {
76         this.descriptionUpper = descriptionUpper;
77     }
78     public long getLedgerId() {
79         return ledgerId;
80     }
81     public void setLedgerId(long ledgerId) {
82         this.ledgerId = ledgerId;
83     }
84     public long getProfileId() {
85         return profileId;
86     }
87     public void setProfileId(long profileId) {
88         this.profileId = profileId;
89     }
90     public long getId() {
91         return id;
92     }
93     public void setId(long id) {
94         this.id = id;
95     }
96     public String getDataHash() {
97         return dataHash;
98     }
99     public void setDataHash(@NotNull String dataHash) {
100         this.dataHash = dataHash;
101     }
102     public int getYear() {
103         return year;
104     }
105     public void setYear(int year) {
106         this.year = year;
107     }
108     public int getMonth() {
109         return month;
110     }
111     public void setMonth(int month) {
112         this.month = month;
113     }
114     public int getDay() {
115         return day;
116     }
117     public void setDay(int day) {
118         this.day = day;
119     }
120     public String getDescription() {
121         return description;
122     }
123     public void setDescription(String description) {
124         this.description = description;
125         setDescriptionUpper(description.toUpperCase());
126     }
127     public String getComment() {
128         return comment;
129     }
130     public void setComment(String comment) {
131         this.comment = comment;
132     }
133     public long getGeneration() {
134         return generation;
135     }
136     public void setGeneration(long generation) {
137         this.generation = generation;
138     }
139
140     public void copyDataFrom(Transaction o) {
141         // id = o.id;
142         ledgerId = o.ledgerId;
143         profileId = o.profileId;
144         dataHash = o.dataHash;
145         year = o.year;
146         month = o.month;
147         day = o.day;
148         description = o.description;
149         descriptionUpper = o.description.toUpperCase();
150         comment = o.comment;
151         generation = o.generation;
152     }
153 }