--- /dev/null
+/*
+ * Copyright © 2021 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.dao;
+
+import androidx.lifecycle.LiveData;
+import androidx.room.Dao;
+import androidx.room.Delete;
+import androidx.room.Insert;
+import androidx.room.Query;
+import androidx.room.Update;
+
+import net.ktnx.mobileledger.db.Currency;
+
+import java.util.List;
+
+@Dao
+public interface CurrencyDAO {
+ @Insert
+ void insert(Currency... items);
+
+ @Update
+ void update(Currency... items);
+
+ @Delete
+ void delete(Currency item);
+
+ @Query("SELECT * FROM currencies")
+ LiveData<List<Currency>> getCurrencies();
+
+ @Query("SELECT * FROM currencies WHERE id = :id")
+ LiveData<Currency> getCurrencyById(Long id);
+
+// not useful for now
+// @Transaction
+// @Query("SELECT * FROM patterns")
+// List<PatternWithAccounts> getPatternsWithAccounts();
+}
--- /dev/null
+/*
+ * Copyright © 2021 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.dao;
+
+import androidx.lifecycle.LiveData;
+import androidx.room.Dao;
+import androidx.room.Delete;
+import androidx.room.Insert;
+import androidx.room.Query;
+import androidx.room.Update;
+
+import net.ktnx.mobileledger.db.PatternAccount;
+
+import java.util.List;
+
+@Dao
+public interface PatternAccountDAO {
+ @Insert
+ Long insert(PatternAccount item);
+
+ @Update
+ void update(PatternAccount... items);
+
+ @Delete
+ void delete(PatternAccount item);
+
+ @Query("SELECT * FROM pattern_accounts WHERE pattern_id=:pattern_id")
+ LiveData<List<PatternAccount>> getPatternAccounts(Long pattern_id);
+
+ @Query("SELECT * FROM pattern_accounts WHERE id = :id")
+ LiveData<PatternAccount> getPatternAccountById(Long id);
+
+// not useful for now
+// @Transaction
+// @Query("SELECT * FROM patterns")
+// List<PatternWithAccounts> getPatternsWithAccounts();
+}
--- /dev/null
+/*
+ * Copyright © 2021 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.dao;
+
+import androidx.lifecycle.LiveData;
+import androidx.room.Dao;
+import androidx.room.Delete;
+import androidx.room.Insert;
+import androidx.room.OnConflictStrategy;
+import androidx.room.Query;
+import androidx.room.Update;
+
+import net.ktnx.mobileledger.db.PatternHeader;
+
+import java.util.List;
+
+@Dao
+public interface PatternHeaderDAO {
+ @Insert(onConflict = OnConflictStrategy.REPLACE)
+ long insert(PatternHeader item);
+
+ @Update
+ void update(PatternHeader... items);
+
+ @Delete
+ void delete(PatternHeader item);
+
+ @Query("SELECT * FROM patterns")
+ LiveData<List<PatternHeader>> getPatterns();
+
+ @Query("SELECT * FROM patterns WHERE id = :id")
+ LiveData<PatternHeader> getPattern(Long id);
+
+// not useful for now
+// @Transaction
+// @Query("SELECT * FROM patterns")
+// List<PatternWithAccounts> getPatternsWithAccounts();
+}
--- /dev/null
+package net.ktnx.mobileledger.db;
+
+import androidx.annotation.NonNull;
+import androidx.room.ColumnInfo;
+import androidx.room.Entity;
+import androidx.room.PrimaryKey;
+
+@Entity(tableName = "currencies")
+public class Currency {
+ @PrimaryKey(autoGenerate = true)
+ @NonNull
+ private final Long id;
+ @NonNull
+ private String name;
+ @NonNull
+ private String position;
+ @NonNull
+ @ColumnInfo(name = "has_gap")
+ private Boolean hasGap;
+ public Currency(@NonNull Long id, @NonNull String name, @NonNull String position,
+ @NonNull Boolean hasGap) {
+ this.id = id;
+ this.name = name;
+ this.position = position;
+ this.hasGap = hasGap;
+ }
+ @NonNull
+ public Long getId() {
+ return id;
+ }
+ @NonNull
+ public String getName() {
+ return name;
+ }
+ public void setName(@NonNull String name) {
+ this.name = name;
+ }
+ @NonNull
+ public String getPosition() {
+ return position;
+ }
+ public void setPosition(@NonNull String position) {
+ this.position = position;
+ }
+ @NonNull
+ public Boolean getHasGap() {
+ return hasGap;
+ }
+ public void setHasGap(@NonNull Boolean hasGap) {
+ this.hasGap = hasGap;
+ }
+}
--- /dev/null
+/*
+ * Copyright © 2021 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.db;
+
+import androidx.room.Database;
+import androidx.room.RoomDatabase;
+
+import net.ktnx.mobileledger.dao.CurrencyDAO;
+import net.ktnx.mobileledger.dao.PatternAccountDAO;
+import net.ktnx.mobileledger.dao.PatternHeaderDAO;
+
+@Database(version = 49, entities = {PatternHeader.class, PatternAccount.class, Currency.class})
+abstract public class DB extends RoomDatabase {
+ public abstract PatternHeaderDAO getPatternDAO();
+ public abstract PatternAccountDAO getPatternAccountDAO();
+ public abstract CurrencyDAO getCurrencyDAO();
+}
--- /dev/null
+package net.ktnx.mobileledger.db;
+
+import androidx.annotation.NonNull;
+import androidx.room.ColumnInfo;
+import androidx.room.Entity;
+import androidx.room.ForeignKey;
+import androidx.room.Index;
+import androidx.room.PrimaryKey;
+
+import org.jetbrains.annotations.NotNull;
+
+@Entity(tableName = "pattern_accounts",
+ indices = {@Index(name = "un_pattern_accounts", unique = true, value = "id")},
+ foreignKeys = {@ForeignKey(childColumns = "pattern_id", parentColumns = "id",
+ entity = PatternHeader.class),
+ @ForeignKey(childColumns = "currency", parentColumns = "id",
+ entity = Currency.class)
+ })
+public class PatternAccount extends PatternBase {
+ @NonNull
+ @ColumnInfo(name = "pattern_id")
+ private Long patternId;
+ @PrimaryKey(autoGenerate = true)
+ @NotNull
+ private Long id;
+ @ColumnInfo(name = "acc")
+ private String accountName;
+ @ColumnInfo(name = "position")
+ @NonNull
+ private Long position;
+ @ColumnInfo(name = "acc_match_group")
+ private Integer accountNameMatchGroup;
+ @ColumnInfo(name = "currency")
+ private Integer currency;
+ @ColumnInfo(name = "currency_match_group")
+ private Integer currencyMatchGroup;
+ @ColumnInfo(name = "amount")
+ private Float amount;
+ @ColumnInfo(name = "amount_match_group")
+ private Integer amountMatchGroup;
+ @ColumnInfo(name = "comment")
+ private String accountComment;
+ @ColumnInfo(name = "comment_match_group")
+ private Integer accountCommentMatchGroup;
+ public PatternAccount(@NotNull Long id, @NonNull Long patternId, @NonNull Long position) {
+ this.id = id;
+ this.patternId = patternId;
+ this.position = position;
+ }
+ public Long getId() {
+ return id;
+ }
+ public void setId(Long id) {
+ this.id = id;
+ }
+ public @NotNull Long getPatternId() {
+ return patternId;
+ }
+ public void setPatternId(@NonNull Long patternId) {
+ this.patternId = patternId;
+ }
+ @NonNull
+ public String getAccountName() {
+ return accountName;
+ }
+ public void setAccountName(@NonNull String accountName) {
+ this.accountName = accountName;
+ }
+ @NonNull
+ public Long getPosition() {
+ return position;
+ }
+ public void setPosition(@NonNull Long position) {
+ this.position = position;
+ }
+ public Integer getAccountNameMatchGroup() {
+ return accountNameMatchGroup;
+ }
+ public void setAccountNameMatchGroup(Integer accountNameMatchGroup) {
+ this.accountNameMatchGroup = accountNameMatchGroup;
+ }
+ public Integer getCurrency() {
+ return currency;
+ }
+ public void setCurrency(Integer currency) {
+ this.currency = currency;
+ }
+ public Integer getCurrencyMatchGroup() {
+ return currencyMatchGroup;
+ }
+ public void setCurrencyMatchGroup(Integer currencyMatchGroup) {
+ this.currencyMatchGroup = currencyMatchGroup;
+ }
+ public Float getAmount() {
+ return amount;
+ }
+ public void setAmount(Float amount) {
+ this.amount = amount;
+ }
+ public Integer getAmountMatchGroup() {
+ return amountMatchGroup;
+ }
+ public void setAmountMatchGroup(Integer amountMatchGroup) {
+ this.amountMatchGroup = amountMatchGroup;
+ }
+ public String getAccountComment() {
+ return accountComment;
+ }
+ public void setAccountComment(String accountComment) {
+ this.accountComment = accountComment;
+ }
+ public Integer getAccountCommentMatchGroup() {
+ return accountCommentMatchGroup;
+ }
+ public void setAccountCommentMatchGroup(Integer accountCommentMatchGroup) {
+ this.accountCommentMatchGroup = accountCommentMatchGroup;
+ }
+}
--- /dev/null
+/*
+ * Copyright © 2021 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.db;
+
+public class PatternBase {}
--- /dev/null
+package net.ktnx.mobileledger.db;
+
+import androidx.annotation.NonNull;
+import androidx.room.ColumnInfo;
+import androidx.room.Entity;
+import androidx.room.Index;
+import androidx.room.PrimaryKey;
+
+import org.jetbrains.annotations.NotNull;
+
+@Entity(tableName = "patterns",
+ indices = {@Index(name = "un_patterns_id", value = "id", unique = true)})
+public class PatternHeader extends PatternBase {
+ @PrimaryKey(autoGenerate = true)
+ @NonNull
+ private Long id;
+ @ColumnInfo(name = "name")
+ @NonNull
+ private String name;
+ @ColumnInfo(name = "position")
+ @NonNull
+ private Long position;
+ @NonNull
+ @ColumnInfo(name = "regular_expression")
+ private String regularExpression;
+ @ColumnInfo(name = "transaction_description")
+ private String transactionDescription;
+ @ColumnInfo(name = "transaction_description_match_group")
+ private Integer transactionDescriptionMatchGroup;
+ @ColumnInfo(name = "transaction_comment")
+ private String transactionComment;
+ @ColumnInfo(name = "transaction_comment_match_group")
+ private Integer transactionCommentMatchGroup;
+ @ColumnInfo(name = "date_year")
+ private Integer dateYear;
+ @ColumnInfo(name = "date_year_match_group")
+ private Integer dateYearMatchGroup;
+ @ColumnInfo(name = "date_month")
+ private Integer dateMonth;
+ @ColumnInfo(name = "date_month_match_group")
+ private Integer dateMonthMatchGroup;
+ @ColumnInfo(name = "date_day")
+ private Integer dateDay;
+ @ColumnInfo(name = "date_day_match_group")
+ private Integer dateDayMatchGroup;
+ public PatternHeader(@NotNull Long id, @NonNull String name, @NotNull Long position,
+ @NonNull String regularExpression) {
+ this.id = id;
+ this.name = name;
+ this.position = position;
+ this.regularExpression = regularExpression;
+ }
+ public Integer getTransactionDescriptionMatchGroup() {
+ return transactionDescriptionMatchGroup;
+ }
+ public void setTransactionDescriptionMatchGroup(Integer transactionDescriptionMatchGroup) {
+ this.transactionDescriptionMatchGroup = transactionDescriptionMatchGroup;
+ }
+ public Integer getTransactionCommentMatchGroup() {
+ return transactionCommentMatchGroup;
+ }
+ public void setTransactionCommentMatchGroup(Integer transactionCommentMatchGroup) {
+ this.transactionCommentMatchGroup = transactionCommentMatchGroup;
+ }
+ public Integer getDateYear() {
+ return dateYear;
+ }
+ public void setDateYear(Integer dateYear) {
+ this.dateYear = dateYear;
+ }
+ public Integer getDateMonth() {
+ return dateMonth;
+ }
+ public void setDateMonth(Integer dateMonth) {
+ this.dateMonth = dateMonth;
+ }
+ public Integer getDateDay() {
+ return dateDay;
+ }
+ public void setDateDay(Integer dateDay) {
+ this.dateDay = dateDay;
+ }
+ @NonNull
+ public Long getId() {
+ return id;
+ }
+ public void setId(@NonNull Long id) {
+ this.id = id;
+ }
+ @NonNull
+ public String getName() {
+ return name;
+ }
+ public void setName(@NonNull String name) {
+ this.name = name;
+ }
+ @NonNull
+ public Long getPosition() {
+ return position;
+ }
+ public void setPosition(@NonNull Long position) {
+ this.position = position;
+ }
+ @NonNull
+ public String getRegularExpression() {
+ return regularExpression;
+ }
+ public void setRegularExpression(@NonNull String regularExpression) {
+ this.regularExpression = regularExpression;
+ }
+ public String getTransactionDescription() {
+ return transactionDescription;
+ }
+ public void setTransactionDescription(String transactionDescription) {
+ this.transactionDescription = transactionDescription;
+ }
+ public String getTransactionComment() {
+ return transactionComment;
+ }
+ public void setTransactionComment(String transactionComment) {
+ this.transactionComment = transactionComment;
+ }
+ public Integer getDateYearMatchGroup() {
+ return dateYearMatchGroup;
+ }
+ public void setDateYearMatchGroup(Integer dateYearMatchGroup) {
+ this.dateYearMatchGroup = dateYearMatchGroup;
+ }
+ public Integer getDateMonthMatchGroup() {
+ return dateMonthMatchGroup;
+ }
+ public void setDateMonthMatchGroup(Integer dateMonthMatchGroup) {
+ this.dateMonthMatchGroup = dateMonthMatchGroup;
+ }
+ public Integer getDateDayMatchGroup() {
+ return dateDayMatchGroup;
+ }
+ public void setDateDayMatchGroup(Integer dateDayMatchGroup) {
+ this.dateDayMatchGroup = dateDayMatchGroup;
+ }
+}