- Equivalence DAOs created

This commit is contained in:
Javier Varona 2017-11-01 22:31:31 -04:00
parent 60ef2eb4ba
commit 00d45cadd7
5 changed files with 161 additions and 14 deletions

View file

@ -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<CryptoCurrencyEquivalence> getAll();
@Query("SELECT * FROM crypto_currency_equivalence WHERE id = :id")
CryptoCurrencyEquivalence getById(long id);
@Insert(onConflict = OnConflictStrategy.REPLACE)
public long[] insertCryptoCurrencyEquivalence(CryptoCurrencyEquivalence... currenciesEquivalences);
}

View file

@ -12,6 +12,7 @@ import cy.agorise.crystalwallet.models.BitsharesAssetInfo;
import cy.agorise.crystalwallet.models.CryptoCoinBalance; import cy.agorise.crystalwallet.models.CryptoCoinBalance;
import cy.agorise.crystalwallet.models.CryptoCoinTransaction; import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
import cy.agorise.crystalwallet.models.CryptoCurrency; import cy.agorise.crystalwallet.models.CryptoCurrency;
import cy.agorise.crystalwallet.models.CryptoCurrencyEquivalence;
import cy.agorise.crystalwallet.models.CryptoNetAccount; import cy.agorise.crystalwallet.models.CryptoNetAccount;
import cy.agorise.crystalwallet.models.GrapheneAccountInfo; import cy.agorise.crystalwallet.models.GrapheneAccountInfo;
@ -20,7 +21,16 @@ import cy.agorise.crystalwallet.models.GrapheneAccountInfo;
* Created by Henry Varona on 4/9/2017. * 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}) @TypeConverters({Converters.class})
public abstract class CrystalDatabase extends RoomDatabase { public abstract class CrystalDatabase extends RoomDatabase {
@ -33,6 +43,7 @@ public abstract class CrystalDatabase extends RoomDatabase {
public abstract CryptoCoinBalanceDao cryptoCoinBalanceDao(); public abstract CryptoCoinBalanceDao cryptoCoinBalanceDao();
public abstract CryptoCurrencyDao cryptoCurrencyDao(); public abstract CryptoCurrencyDao cryptoCurrencyDao();
public abstract BitsharesAssetDao bitsharesAssetDao(); public abstract BitsharesAssetDao bitsharesAssetDao();
public abstract CryptoCurrencyEquivalenceDao cryptoCurrencyEquivalenceDao();
public static CrystalDatabase getAppDatabase(Context context) { public static CrystalDatabase getAppDatabase(Context context) {
if (instance == null) { if (instance == null) {

View file

@ -4,6 +4,7 @@ import android.arch.persistence.room.ColumnInfo;
import android.arch.persistence.room.Entity; import android.arch.persistence.room.Entity;
import android.arch.persistence.room.ForeignKey; import android.arch.persistence.room.ForeignKey;
import android.arch.persistence.room.Ignore; import android.arch.persistence.room.Ignore;
import android.arch.persistence.room.Index;
import android.arch.persistence.room.PrimaryKey; import android.arch.persistence.room.PrimaryKey;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v7.recyclerview.extensions.DiffCallback; import android.support.v7.recyclerview.extensions.DiffCallback;
@ -17,15 +18,24 @@ import cy.agorise.crystalwallet.enums.CryptoCoin;
* *
* Created by Henry Varona on 11/9/2017. * Created by Henry Varona on 11/9/2017.
*/ */
@Entity(tableName="crypto_coin_transaction", @Entity(
foreignKeys = {@ForeignKey(entity = CryptoNetAccount.class, tableName="crypto_coin_transaction",
indices={
@Index(value={"account_id"}),
@Index(value={"id_currency"})
},
foreignKeys = {
@ForeignKey(
entity = CryptoNetAccount.class,
parentColumns = "id", parentColumns = "id",
childColumns = "account_id", childColumns = "account_id",
onDelete = ForeignKey.CASCADE), onDelete = ForeignKey.CASCADE
),
@ForeignKey(entity = CryptoCurrency.class, @ForeignKey(entity = CryptoCurrency.class,
parentColumns = "id", parentColumns = "id",
childColumns = "id_currency", childColumns = "id_currency",
onDelete = ForeignKey.CASCADE) onDelete = ForeignKey.CASCADE
)
} }
) )
public class CryptoCoinTransaction { public class CryptoCoinTransaction {

View file

@ -23,7 +23,7 @@ public class CryptoCurrency {
*/ */
@PrimaryKey(autoGenerate = true) @PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id") @ColumnInfo(name = "id")
private int mId; private long mId;
/** /**
* The name or tag of this currency * The name or tag of this currency
@ -45,11 +45,11 @@ public class CryptoCurrency {
@ColumnInfo(name = "precision") @ColumnInfo(name = "precision")
private int mPrecision; private int mPrecision;
public int getId() { public long getId() {
return mId; return mId;
} }
public void setId(int mId) { public void setId(long mId) {
this.mId = mId; this.mId = mId;
} }

View file

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