- Added new table crypto_coin_balance that holds cached balances of all coins
This commit is contained in:
parent
697c2406fd
commit
382746b9df
2 changed files with 50 additions and 3 deletions
|
@ -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);
|
||||||
|
|
||||||
|
}
|
|
@ -17,15 +17,30 @@ import cy.agorise.crystalwallet.enums.CryptoCoin;
|
||||||
* Created by Henry Varona on 6/9/2017.
|
* 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 {
|
public class CryptoCoinBalance {
|
||||||
|
|
||||||
|
@ColumnInfo(name="account_id")
|
||||||
|
private long mAccountId;
|
||||||
|
|
||||||
@ColumnInfo(name = "coin")
|
@ColumnInfo(name = "coin")
|
||||||
private CryptoCoin mCoin;
|
private CryptoCoin mCoin;
|
||||||
|
|
||||||
@ColumnInfo(name = "balance")
|
@ColumnInfo(name = "balance")
|
||||||
private int mBalance;
|
private int mBalance;
|
||||||
|
|
||||||
|
public long getAccountId() {
|
||||||
|
return mAccountId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAccountId(long accountId) {
|
||||||
|
this.mAccountId = accountId;
|
||||||
|
}
|
||||||
|
|
||||||
public CryptoCoin getCoin() {
|
public CryptoCoin getCoin() {
|
||||||
return mCoin;
|
return mCoin;
|
||||||
}
|
}
|
||||||
|
@ -62,8 +77,9 @@ public class CryptoCoinBalance {
|
||||||
|
|
||||||
CryptoCoinBalance that = (CryptoCoinBalance) o;
|
CryptoCoinBalance that = (CryptoCoinBalance) o;
|
||||||
|
|
||||||
if (this.mCoin != that.mCoin) return false;
|
if (mAccountId != that.mAccountId) return false;
|
||||||
return mBalance == that.mBalance;
|
if (mBalance != that.mBalance) return false;
|
||||||
|
return mCoin == that.mCoin;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue