]> git.ktnx.net Git - mobile-ledger.git/blob - app/src/main/java/net/ktnx/mobileledger/db/Transaction.java
migrate to surrogate IDs for all database objects
[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_data_hash", unique = true,
40                      value = {"profile_id", "data_hash"}),
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 = "profile_id")
49     private long profileId;
50     @ColumnInfo(name = "data_hash")
51     @NonNull
52     private String dataHash;
53     @ColumnInfo
54     private int year;
55     @ColumnInfo
56     private int month;
57     @ColumnInfo
58     private int day;
59     @ColumnInfo(collate = ColumnInfo.NOCASE)
60     @NonNull
61     private String description;
62     @ColumnInfo
63     private String comment;
64     @ColumnInfo
65     private int generation = 0;
66     public long getProfileId() {
67         return profileId;
68     }
69     public void setProfileId(long profileId) {
70         this.profileId = profileId;
71     }
72     public long getId() {
73         return id;
74     }
75     public void setId(long id) {
76         this.id = id;
77     }
78     public String getDataHash() {
79         return dataHash;
80     }
81     public void setDataHash(@NotNull String dataHash) {
82         this.dataHash = dataHash;
83     }
84     public int getYear() {
85         return year;
86     }
87     public void setYear(int year) {
88         this.year = year;
89     }
90     public int getMonth() {
91         return month;
92     }
93     public void setMonth(int month) {
94         this.month = month;
95     }
96     public int getDay() {
97         return day;
98     }
99     public void setDay(int day) {
100         this.day = day;
101     }
102     public String getDescription() {
103         return description;
104     }
105     public void setDescription(String description) {
106         this.description = description;
107     }
108     public String getComment() {
109         return comment;
110     }
111     public void setComment(String comment) {
112         this.comment = comment;
113     }
114     public int getGeneration() {
115         return generation;
116     }
117     public void setGeneration(int generation) {
118         this.generation = generation;
119     }
120
121 }