]> git.ktnx.net Git - mobile-ledger.git/blob - app/src/main/java/net/ktnx/mobileledger/db/Transaction.java
Room-based profile management
[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
65     private String comment;
66     @ColumnInfo
67     private long generation = 0;
68     public long getLedgerId() {
69         return ledgerId;
70     }
71     public void setLedgerId(long ledgerId) {
72         this.ledgerId = ledgerId;
73     }
74     public long getProfileId() {
75         return profileId;
76     }
77     public void setProfileId(long profileId) {
78         this.profileId = profileId;
79     }
80     public long getId() {
81         return id;
82     }
83     public void setId(long id) {
84         this.id = id;
85     }
86     public String getDataHash() {
87         return dataHash;
88     }
89     public void setDataHash(@NotNull String dataHash) {
90         this.dataHash = dataHash;
91     }
92     public int getYear() {
93         return year;
94     }
95     public void setYear(int year) {
96         this.year = year;
97     }
98     public int getMonth() {
99         return month;
100     }
101     public void setMonth(int month) {
102         this.month = month;
103     }
104     public int getDay() {
105         return day;
106     }
107     public void setDay(int day) {
108         this.day = day;
109     }
110     public String getDescription() {
111         return description;
112     }
113     public void setDescription(String description) {
114         this.description = description;
115     }
116     public String getComment() {
117         return comment;
118     }
119     public void setComment(String comment) {
120         this.comment = comment;
121     }
122     public long getGeneration() {
123         return generation;
124     }
125     public void setGeneration(long generation) {
126         this.generation = generation;
127     }
128
129 }