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;
65 private String comment;
67 private long generation = 0;
68 public long getLedgerId() {
71 public void setLedgerId(long ledgerId) {
72 this.ledgerId = ledgerId;
74 public long getProfileId() {
77 public void setProfileId(long profileId) {
78 this.profileId = profileId;
83 public void setId(long id) {
86 public String getDataHash() {
89 public void setDataHash(@NotNull String dataHash) {
90 this.dataHash = dataHash;
92 public int getYear() {
95 public void setYear(int year) {
98 public int getMonth() {
101 public void setMonth(int month) {
104 public int getDay() {
107 public void setDay(int day) {
110 public String getDescription() {
113 public void setDescription(String description) {
114 this.description = description;
116 public String getComment() {
119 public void setComment(String comment) {
120 this.comment = comment;
122 public long getGeneration() {
125 public void setGeneration(long generation) {
126 this.generation = generation;
129 public void copyDataFrom(Transaction o) {
131 ledgerId = o.ledgerId;
132 profileId = o.profileId;
133 dataHash = o.dataHash;
137 description = o.description;
139 generation = o.generation;