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.
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.
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/>.
18 package net.ktnx.mobileledger.db;
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;
27 import org.jetbrains.annotations.NotNull;
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);
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")
44 public class Transaction {
46 @PrimaryKey(autoGenerate = true)
48 @ColumnInfo(name = "ledger_id")
50 @ColumnInfo(name = "profile_id")
51 private long profileId;
52 @ColumnInfo(name = "data_hash")
54 private String dataHash;
61 @ColumnInfo(collate = ColumnInfo.NOCASE)
63 private String description;
64 @ColumnInfo(name = "description_uc")
66 private String descriptionUpper;
68 private String comment;
70 private long generation = 0;
72 public String getDescriptionUpper() {
73 return descriptionUpper;
75 public void setDescriptionUpper(@NonNull String descriptionUpper) {
76 this.descriptionUpper = descriptionUpper;
78 public long getLedgerId() {
81 public void setLedgerId(long ledgerId) {
82 this.ledgerId = ledgerId;
84 public long getProfileId() {
87 public void setProfileId(long profileId) {
88 this.profileId = profileId;
93 public void setId(long id) {
96 public String getDataHash() {
99 public void setDataHash(@NotNull String dataHash) {
100 this.dataHash = dataHash;
102 public int getYear() {
105 public void setYear(int year) {
108 public int getMonth() {
111 public void setMonth(int month) {
114 public int getDay() {
117 public void setDay(int day) {
120 public String getDescription() {
123 public void setDescription(String description) {
124 this.description = description;
125 setDescriptionUpper(description.toUpperCase());
127 public String getComment() {
130 public void setComment(String comment) {
131 this.comment = comment;
133 public long getGeneration() {
136 public void setGeneration(long generation) {
137 this.generation = generation;
140 public void copyDataFrom(Transaction o) {
142 ledgerId = o.ledgerId;
143 profileId = o.profileId;
144 dataHash = o.dataHash;
148 description = o.description;
149 descriptionUpper = o.description.toUpperCase();
151 generation = o.generation;