]> git.ktnx.net Git - mobile-ledger.git/blob - app/src/main/java/net/ktnx/mobileledger/db/TemplateAccount.java
describe options to Room
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / db / TemplateAccount.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 @Entity(tableName = "template_accounts",
30         indices = {@Index(name = "fk_template_accounts_template", value = "template_id"),
31                    @Index(name = "fk_template_accounts_currency", value = "currency")
32         }, foreignKeys = {@ForeignKey(childColumns = "template_id", parentColumns = "id",
33                                       entity = TemplateHeader.class, onDelete = ForeignKey.CASCADE,
34                                       onUpdate = ForeignKey.RESTRICT),
35                           @ForeignKey(childColumns = "currency", parentColumns = "id",
36                                       entity = Currency.class, onDelete = ForeignKey.RESTRICT,
37                                       onUpdate = ForeignKey.RESTRICT)
38 })
39 public class TemplateAccount extends TemplateBase {
40     @PrimaryKey(autoGenerate = true)
41     @NotNull
42     private Long id;
43     @NonNull
44     @ColumnInfo(name = "template_id")
45     private Long templateId;
46     @ColumnInfo(name = "acc")
47     private String accountName;
48     @ColumnInfo(name = "position")
49     @NonNull
50     private Long position;
51     @ColumnInfo(name = "acc_match_group")
52     private Integer accountNameMatchGroup;
53     @ColumnInfo(name = "currency")
54     private Integer currency;
55     @ColumnInfo(name = "currency_match_group")
56     private Integer currencyMatchGroup;
57     @ColumnInfo(name = "amount")
58     private Float amount;
59     @ColumnInfo(name = "amount_match_group")
60     private Integer amountMatchGroup;
61     @ColumnInfo(name = "comment")
62     private String accountComment;
63     @ColumnInfo(name = "comment_match_group")
64     private Integer accountCommentMatchGroup;
65     @ColumnInfo(name = "negate_amount")
66     private Boolean negateAmount;
67     public TemplateAccount(@NotNull Long id, @NonNull Long templateId, @NonNull Long position) {
68         this.id = id;
69         this.templateId = templateId;
70         this.position = position;
71     }
72     public TemplateAccount(TemplateAccount o) {
73         id = o.id;
74         templateId = o.templateId;
75         accountName = o.accountName;
76         position = o.position;
77         accountNameMatchGroup = o.accountNameMatchGroup;
78         currency = o.currency;
79         currencyMatchGroup = o.currencyMatchGroup;
80         amount = o.amount;
81         amountMatchGroup = o.amountMatchGroup;
82         accountComment = o.accountComment;
83         accountCommentMatchGroup = o.accountCommentMatchGroup;
84         negateAmount = o.negateAmount;
85     }
86     public Long getId() {
87         return id;
88     }
89     public void setId(Long id) {
90         this.id = id;
91     }
92     public Boolean getNegateAmount() {
93         return negateAmount;
94     }
95     public void setNegateAmount(Boolean negateAmount) {
96         this.negateAmount = negateAmount;
97     }
98     public @NotNull Long getTemplateId() {
99         return templateId;
100     }
101     public void setTemplateId(@NonNull Long templateId) {
102         this.templateId = templateId;
103     }
104     @NonNull
105     public String getAccountName() {
106         return accountName;
107     }
108     public void setAccountName(@NonNull String accountName) {
109         this.accountName = accountName;
110     }
111     @NonNull
112     public Long getPosition() {
113         return position;
114     }
115     public void setPosition(@NonNull Long position) {
116         this.position = position;
117     }
118     public void setPosition(int position) {
119         this.position = (long) position;
120     }
121     public Integer getAccountNameMatchGroup() {
122         return accountNameMatchGroup;
123     }
124     public void setAccountNameMatchGroup(Integer accountNameMatchGroup) {
125         this.accountNameMatchGroup = accountNameMatchGroup;
126     }
127     public Integer getCurrency() {
128         return currency;
129     }
130     public void setCurrency(Integer currency) {
131         this.currency = currency;
132     }
133     public Integer getCurrencyMatchGroup() {
134         return currencyMatchGroup;
135     }
136     public void setCurrencyMatchGroup(Integer currencyMatchGroup) {
137         this.currencyMatchGroup = currencyMatchGroup;
138     }
139     public Float getAmount() {
140         return amount;
141     }
142     public void setAmount(Float amount) {
143         this.amount = amount;
144     }
145     public Integer getAmountMatchGroup() {
146         return amountMatchGroup;
147     }
148     public void setAmountMatchGroup(Integer amountMatchGroup) {
149         this.amountMatchGroup = amountMatchGroup;
150     }
151     public String getAccountComment() {
152         return accountComment;
153     }
154     public void setAccountComment(String accountComment) {
155         this.accountComment = accountComment;
156     }
157     public Integer getAccountCommentMatchGroup() {
158         return accountCommentMatchGroup;
159     }
160     public void setAccountCommentMatchGroup(Integer accountCommentMatchGroup) {
161         this.accountCommentMatchGroup = accountCommentMatchGroup;
162     }
163     public TemplateAccount createDuplicate() {
164         TemplateAccount dup = new TemplateAccount(this);
165         dup.id = null;
166         dup.templateId = null;
167
168         return dup;
169     }
170 }