2017-09-08 00:31:38 +00:00
|
|
|
package cy.agorise.crystalwallet.dao;
|
|
|
|
|
|
|
|
import android.arch.persistence.db.SupportSQLiteDatabase;
|
2017-09-13 21:52:36 +00:00
|
|
|
import android.arch.persistence.room.Database;
|
|
|
|
import android.arch.persistence.room.Room;
|
|
|
|
import android.arch.persistence.room.RoomDatabase;
|
2017-09-14 02:09:58 +00:00
|
|
|
import android.arch.persistence.room.TypeConverters;
|
2017-09-08 00:31:38 +00:00
|
|
|
import android.arch.persistence.room.migration.Migration;
|
2017-09-10 23:13:32 +00:00
|
|
|
import android.content.Context;
|
2017-09-08 00:31:38 +00:00
|
|
|
|
2017-09-14 02:09:58 +00:00
|
|
|
import cy.agorise.crystalwallet.dao.converters.Converters;
|
2017-09-08 00:31:38 +00:00
|
|
|
import cy.agorise.crystalwallet.models.AccountSeed;
|
2017-10-15 02:02:55 +00:00
|
|
|
import cy.agorise.crystalwallet.models.CryptoCoinBalance;
|
2017-09-13 16:12:22 +00:00
|
|
|
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
|
2017-09-25 02:59:46 +00:00
|
|
|
import cy.agorise.crystalwallet.models.CryptoCurrency;
|
2017-09-08 00:31:38 +00:00
|
|
|
import cy.agorise.crystalwallet.models.CryptoNetAccount;
|
|
|
|
|
|
|
|
/**
|
2017-09-13 21:52:36 +00:00
|
|
|
* Manage the Database
|
2017-09-08 00:31:38 +00:00
|
|
|
* Created by Henry Varona on 4/9/2017.
|
|
|
|
*/
|
|
|
|
|
2017-10-15 02:02:55 +00:00
|
|
|
@Database(entities = {AccountSeed.class, CryptoNetAccount.class, CryptoCoinTransaction.class, CryptoCurrency.class, CryptoCoinBalance.class}, version = 2)
|
2017-09-14 02:09:58 +00:00
|
|
|
@TypeConverters({Converters.class})
|
2017-09-08 00:31:38 +00:00
|
|
|
public abstract class CrystalDatabase extends RoomDatabase {
|
|
|
|
|
2017-09-10 23:13:32 +00:00
|
|
|
private static CrystalDatabase instance;
|
|
|
|
|
|
|
|
public abstract AccountSeedDao accountSeedDao();
|
|
|
|
public abstract CryptoNetAccountDao cryptoNetAccountDao();
|
2017-09-13 16:12:22 +00:00
|
|
|
public abstract TransactionDao transactionDao();
|
2017-10-15 02:02:55 +00:00
|
|
|
public abstract CryptoCoinBalanceDao cryptoCoinBalanceDao();
|
2017-10-16 00:23:44 +00:00
|
|
|
public abstract CryptoCurrencyDao cryptoCurrencyDao();
|
2017-09-10 23:13:32 +00:00
|
|
|
|
|
|
|
public static CrystalDatabase getAppDatabase(Context context) {
|
|
|
|
if (instance == null) {
|
|
|
|
instance =
|
|
|
|
Room.databaseBuilder(context,
|
|
|
|
CrystalDatabase.class, "CrystalWallet.db")
|
|
|
|
.allowMainThreadQueries()
|
2017-09-27 02:24:23 +00:00
|
|
|
//.addMigrations(MIGRATION_1_2)
|
2017-09-10 23:13:32 +00:00
|
|
|
.build();
|
|
|
|
}
|
|
|
|
return instance;
|
|
|
|
}
|
2017-09-08 00:31:38 +00:00
|
|
|
|
2017-10-10 02:44:44 +00:00
|
|
|
|
|
|
|
|
2017-09-27 02:24:23 +00:00
|
|
|
/*static final Migration MIGRATION_1_2 = new Migration(1, 2) {
|
2017-09-08 00:31:38 +00:00
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase database) {
|
|
|
|
database.execSQL("CREATE TABLE 'account_seed' ('id' INTEGER PRIMARY KEY AUTOINCREMENT, "
|
|
|
|
+ "'name' TEXT, 'master_seed' NUMERIC)");
|
|
|
|
database.execSQL("CREATE TABLE 'crypto_net_account' ('id' INTEGER PRIMARY KEY AUTOINCREMENT, "
|
2017-09-12 02:07:43 +00:00
|
|
|
+ "'seed_id' INTEGER, "
|
2017-09-08 00:31:38 +00:00
|
|
|
+ "'account_number' INT, 'account_index' INT,"
|
|
|
|
+ "FOREIGN_KEY(seed_id) REFERENCES seed(id))");
|
2017-09-12 02:07:43 +00:00
|
|
|
database.execSQL("CREATE TABLE 'crypto_coin_transaction' ('id' INTEGER PRIMARY KEY AUTOINCREMENT, "
|
|
|
|
+ "'account_id' INTEGER, "
|
2017-09-13 16:12:22 +00:00
|
|
|
+ "'date' INT, 'is_input' INT, amount INT, crypto_coin TEXT, is_confirmed INT, "
|
2017-09-12 02:07:43 +00:00
|
|
|
+ "FOREIGN_KEY(account_id) REFERENCES crypto_net_account(id))");
|
2017-09-08 00:31:38 +00:00
|
|
|
}
|
2017-09-27 02:24:23 +00:00
|
|
|
};*/
|
2017-09-08 00:31:38 +00:00
|
|
|
}
|