From 00d45cadd729807355be2cc325204481100a0c07 Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Wed, 1 Nov 2017 22:31:31 -0400 Subject: [PATCH] - Equivalence DAOs created --- .../dao/CryptoCurrencyEquivalenceDao.java | 29 ++++++ .../crystalwallet/dao/CrystalDatabase.java | 13 ++- .../models/CryptoCoinTransaction.java | 30 ++++-- .../crystalwallet/models/CryptoCurrency.java | 6 +- .../models/CryptoCurrencyEquivalence.java | 97 +++++++++++++++++++ 5 files changed, 161 insertions(+), 14 deletions(-) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/dao/CryptoCurrencyEquivalenceDao.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/models/CryptoCurrencyEquivalence.java diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoCurrencyEquivalenceDao.java b/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoCurrencyEquivalenceDao.java new file mode 100644 index 0000000..7f5db5c --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoCurrencyEquivalenceDao.java @@ -0,0 +1,29 @@ +package cy.agorise.crystalwallet.dao; + +import android.arch.persistence.room.Dao; +import android.arch.persistence.room.Insert; +import android.arch.persistence.room.OnConflictStrategy; +import android.arch.persistence.room.Query; + +import java.util.List; + +import cy.agorise.crystalwallet.models.CryptoCurrency; +import cy.agorise.crystalwallet.models.CryptoCurrencyEquivalence; + +/** + * Created by henry on 15/10/2017. + */ + +@Dao +public interface CryptoCurrencyEquivalenceDao { + + @Query("SELECT * FROM crypto_currency_equivalence") + List getAll(); + + @Query("SELECT * FROM crypto_currency_equivalence WHERE id = :id") + CryptoCurrencyEquivalence getById(long id); + + @Insert(onConflict = OnConflictStrategy.REPLACE) + public long[] insertCryptoCurrencyEquivalence(CryptoCurrencyEquivalence... currenciesEquivalences); + +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java b/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java index 9918549..a6df432 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java @@ -12,6 +12,7 @@ import cy.agorise.crystalwallet.models.BitsharesAssetInfo; import cy.agorise.crystalwallet.models.CryptoCoinBalance; import cy.agorise.crystalwallet.models.CryptoCoinTransaction; import cy.agorise.crystalwallet.models.CryptoCurrency; +import cy.agorise.crystalwallet.models.CryptoCurrencyEquivalence; import cy.agorise.crystalwallet.models.CryptoNetAccount; import cy.agorise.crystalwallet.models.GrapheneAccountInfo; @@ -20,7 +21,16 @@ import cy.agorise.crystalwallet.models.GrapheneAccountInfo; * Created by Henry Varona on 4/9/2017. */ -@Database(entities = {AccountSeed.class, CryptoNetAccount.class, CryptoCoinTransaction.class, CryptoCurrency.class, CryptoCoinBalance.class, GrapheneAccountInfo.class, BitsharesAssetInfo.class}, version = 2) +@Database(entities = { + AccountSeed.class, + CryptoNetAccount.class, + CryptoCoinTransaction.class, + CryptoCurrency.class, + CryptoCoinBalance.class, + GrapheneAccountInfo.class, + BitsharesAssetInfo.class, + CryptoCurrencyEquivalence.class +}, version = 2) @TypeConverters({Converters.class}) public abstract class CrystalDatabase extends RoomDatabase { @@ -33,6 +43,7 @@ public abstract class CrystalDatabase extends RoomDatabase { public abstract CryptoCoinBalanceDao cryptoCoinBalanceDao(); public abstract CryptoCurrencyDao cryptoCurrencyDao(); public abstract BitsharesAssetDao bitsharesAssetDao(); + public abstract CryptoCurrencyEquivalenceDao cryptoCurrencyEquivalenceDao(); public static CrystalDatabase getAppDatabase(Context context) { if (instance == null) { diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinTransaction.java b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinTransaction.java index e62f455..d2e9756 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinTransaction.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinTransaction.java @@ -4,6 +4,7 @@ import android.arch.persistence.room.ColumnInfo; import android.arch.persistence.room.Entity; import android.arch.persistence.room.ForeignKey; import android.arch.persistence.room.Ignore; +import android.arch.persistence.room.Index; import android.arch.persistence.room.PrimaryKey; import android.support.annotation.NonNull; import android.support.v7.recyclerview.extensions.DiffCallback; @@ -17,17 +18,26 @@ import cy.agorise.crystalwallet.enums.CryptoCoin; * * Created by Henry Varona on 11/9/2017. */ -@Entity(tableName="crypto_coin_transaction", - foreignKeys = {@ForeignKey(entity = CryptoNetAccount.class, - parentColumns = "id", - childColumns = "account_id", - onDelete = ForeignKey.CASCADE), - @ForeignKey(entity = CryptoCurrency.class, - parentColumns = "id", - childColumns = "id_currency", - onDelete = ForeignKey.CASCADE) -} +@Entity( + tableName="crypto_coin_transaction", + indices={ + @Index(value={"account_id"}), + @Index(value={"id_currency"}) + }, + foreignKeys = { + @ForeignKey( + entity = CryptoNetAccount.class, + parentColumns = "id", + childColumns = "account_id", + onDelete = ForeignKey.CASCADE + ), + @ForeignKey(entity = CryptoCurrency.class, + parentColumns = "id", + childColumns = "id_currency", + onDelete = ForeignKey.CASCADE ) + } +) public class CryptoCoinTransaction { /** diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCurrency.java b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCurrency.java index 03ce6e1..3c732d9 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCurrency.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCurrency.java @@ -23,7 +23,7 @@ public class CryptoCurrency { */ @PrimaryKey(autoGenerate = true) @ColumnInfo(name = "id") - private int mId; + private long mId; /** * The name or tag of this currency @@ -45,11 +45,11 @@ public class CryptoCurrency { @ColumnInfo(name = "precision") private int mPrecision; - public int getId() { + public long getId() { return mId; } - public void setId(int mId) { + public void setId(long mId) { this.mId = mId; } diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCurrencyEquivalence.java b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCurrencyEquivalence.java new file mode 100644 index 0000000..2428ce9 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCurrencyEquivalence.java @@ -0,0 +1,97 @@ +package cy.agorise.crystalwallet.models; + +import android.arch.persistence.room.ColumnInfo; +import android.arch.persistence.room.Entity; +import android.arch.persistence.room.ForeignKey; +import android.arch.persistence.room.Index; +import android.arch.persistence.room.PrimaryKey; + +import java.util.Date; + +/** + * Created by Henry Varona on 1/11/2017. + */ + +@Entity( + tableName="crypto_currency_equivalence", + indices = { + @Index(value = {"from_crypto_currency_id","to_crypto_currency_id"}, unique=true), + @Index(value = {"from_crypto_currency_id"}), + @Index(value = {"to_crypto_currency_id"}), + }, + foreignKeys = { + @ForeignKey( + entity = CryptoCurrency.class, + parentColumns = "id", + childColumns = "from_crypto_currency_id", + onDelete = ForeignKey.CASCADE + ), + @ForeignKey( + entity = CryptoCurrency.class, + parentColumns = "id", + childColumns = "to_crypto_currency_id", + onDelete = ForeignKey.CASCADE + ) + } +) +public class CryptoCurrencyEquivalence { + + @PrimaryKey(autoGenerate = true) + @ColumnInfo(name = "id") + private long id; + @ColumnInfo(name="from_crypto_currency_id") + private long fromCurrencyId; + @ColumnInfo(name="to_crypto_currency_id") + private long toCurrencyId; + @ColumnInfo(name="value") + private int value; + @ColumnInfo(name="last_checked") + private Date lastChecked; + + public CryptoCurrencyEquivalence(long fromCurrencyId, long toCurrencyId, int value, Date lastChecked){ + this.fromCurrencyId = fromCurrencyId; + this.toCurrencyId = toCurrencyId; + this.value = value; + this.lastChecked = lastChecked; + } + + public long getId(){ + return this.id; + } + + public void setId(long id){ + this.id = id; + } + + public long getFromCurrencyId() { + return fromCurrencyId; + } + + public void setFromCurrencyId(long fromCurrencyId) { + this.fromCurrencyId = fromCurrencyId; + } + + public long getToCurrencyId() { + return toCurrencyId; + } + + public void setToCurrencyId(long toCurrencyId) { + this.toCurrencyId = toCurrencyId; + } + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } + + public Date getLastChecked() { + return lastChecked; + } + + public void setLastChecked(Date lastChecked) { + this.lastChecked = lastChecked; + } +}