- Added new table crypto_coin_balance that holds cached balances of all coins

This commit is contained in:
Javier Varona 2017-10-12 22:06:55 -04:00
parent 697c2406fd
commit 382746b9df
2 changed files with 50 additions and 3 deletions

View file

@ -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<CryptoCoinBalance> getAll();
@Query("SELECT * FROM crypto_net_account WHERE account_id = :acountId")
LiveData<List<CryptoNetBalance>> getAllFromAccount(long accountId);
@Insert(onConflict = OnConflictStrategy.REPLACE)
public long[] insertCryptoCoinBalance(CryptoCoinBalance... balances);
}

View file

@ -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;
}
}