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 net.ktnx.mobileledger.utils.Misc;
29 @Entity(tableName = "transaction_accounts", foreignKeys = {
30 @ForeignKey(entity = Transaction.class, parentColumns = {"id"},
31 childColumns = {"transaction_id"}, onDelete = ForeignKey.CASCADE,
32 onUpdate = ForeignKey.RESTRICT)
33 }, indices = {@Index(name = "fk_trans_acc_trans", value = {"transaction_id"}),
34 @Index(name = "un_transaction_accounts", unique = true,
35 value = {"transaction_id", "order_no"})
37 public class TransactionAccount {
39 @PrimaryKey(autoGenerate = true)
41 @ColumnInfo(name = "transaction_id")
42 private long transactionId;
43 @ColumnInfo(name = "order_no")
45 @ColumnInfo(name = "account_name")
47 private String accountName;
48 @ColumnInfo(defaultValue = "")
50 private String currency = "";
54 private String comment;
55 @ColumnInfo(defaultValue = "0")
56 private long generation = 0;
60 public void setId(long id) {
64 public long getTransactionId() {
67 public void setTransactionId(long transactionId) {
68 this.transactionId = transactionId;
70 public int getOrderNo() {
73 public void setOrderNo(int orderNo) {
74 this.orderNo = orderNo;
77 public String getAccountName() {
80 public void setAccountName(@NonNull String accountName) {
81 this.accountName = accountName;
84 public String getCurrency() {
87 public void setCurrency(@NonNull String currency) {
88 this.currency = currency;
90 public float getAmount() {
93 public void setAmount(float amount) {
96 public String getComment() {
99 public void setComment(String comment) {
100 this.comment = comment;
102 public long getGeneration() {
105 public void setGeneration(long generation) {
106 this.generation = generation;
109 public void copyDataFrom(TransactionAccount o) {
111 transactionId = o.transactionId;
113 accountName = o.accountName;
114 currency = Misc.nullIsEmpty(o.currency);
117 generation = o.generation;