From 382746b9df2d6d98f429623e9779dce2207ee968 Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Thu, 12 Oct 2017 22:06:55 -0400 Subject: [PATCH] - Added new table crypto_coin_balance that holds cached balances of all coins --- .../dao/CryptoCoinBalanceDao.java | 31 +++++++++++++++++++ .../models/CryptoCoinBalance.java | 22 +++++++++++-- 2 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/dao/CryptoCoinBalanceDao.java diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoCoinBalanceDao.java b/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoCoinBalanceDao.java new file mode 100644 index 0000000..4a1da53 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoCoinBalanceDao.java @@ -0,0 +1,31 @@ +package cy.agorise.crystalwallet.dao; + +import android.arch.lifecycle.LiveData; +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.CryptoCoinBalance; +import cy.agorise.crystalwallet.models.CryptoNetAccount; +import cy.agorise.crystalwallet.models.CryptoNetBalance; + +/** + * Created by Henry Varona on 10/9/2017. + */ + +@Dao +public interface CryptoCoinBalanceDao { + + @Query("SELECT * FROM crypto_coin_balance") + List getAll(); + + @Query("SELECT * FROM crypto_net_account WHERE account_id = :acountId") + LiveData> getAllFromAccount(long accountId); + + @Insert(onConflict = OnConflictStrategy.REPLACE) + public long[] insertCryptoCoinBalance(CryptoCoinBalance... balances); + +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinBalance.java b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinBalance.java index 56695f5..c7e842a 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinBalance.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinBalance.java @@ -17,15 +17,30 @@ import cy.agorise.crystalwallet.enums.CryptoCoin; * Created by Henry Varona on 6/9/2017. */ -@Entity +@Entity(tableName="crypto_coin_balance", + indices = {@Index("id"),@Index("account_id")}, + foreignKeys = @ForeignKey(entity = CryptoNetAccount.class, + parentColumns = "id", + childColumns = "account_id")) public class CryptoCoinBalance { + @ColumnInfo(name="account_id") + private long mAccountId; + @ColumnInfo(name = "coin") private CryptoCoin mCoin; @ColumnInfo(name = "balance") private int mBalance; + public long getAccountId() { + return mAccountId; + } + + public void setAccountId(long accountId) { + this.mAccountId = accountId; + } + public CryptoCoin getCoin() { return mCoin; } @@ -62,8 +77,9 @@ public class CryptoCoinBalance { CryptoCoinBalance that = (CryptoCoinBalance) o; - if (this.mCoin != that.mCoin) return false; - return mBalance == that.mBalance; + if (mAccountId != that.mAccountId) return false; + if (mBalance != that.mBalance) return false; + return mCoin == that.mCoin; } }