From 6ed34d20ebb05124487f5da4020be7ef196f0162 Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Tue, 22 Jan 2019 13:28:17 -0600 Subject: [PATCH] Created MerchantDao and TellerDao to be able to access the merchants and tellers db tables. Modified Room to export the db schema to enable proper testing. --- app/build.gradle | 7 + .../1.json | 307 ++++++++++++++++++ .../database/BitsyDatabase.kt | 6 +- .../database/daos/MerchantDao.kt | 15 + .../database/daos/TellerDao.kt | 15 + 5 files changed, 349 insertions(+), 1 deletion(-) create mode 100644 app/schemas/cy.agorise.bitsybitshareswallet.database.BitsyDatabase/1.json create mode 100644 app/src/main/java/cy/agorise/bitsybitshareswallet/database/daos/MerchantDao.kt create mode 100644 app/src/main/java/cy/agorise/bitsybitshareswallet/database/daos/TellerDao.kt diff --git a/app/build.gradle b/app/build.gradle index 65bfcac..46b3b43 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -15,6 +15,13 @@ android { versionCode 1 versionName "0.8.0-beta" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + + javaCompileOptions { + annotationProcessorOptions { + arguments = ["room.schemaLocation": + "$projectDir/schemas".toString()] + } + } } buildTypes { release { diff --git a/app/schemas/cy.agorise.bitsybitshareswallet.database.BitsyDatabase/1.json b/app/schemas/cy.agorise.bitsybitshareswallet.database.BitsyDatabase/1.json new file mode 100644 index 0000000..81454e8 --- /dev/null +++ b/app/schemas/cy.agorise.bitsybitshareswallet.database.BitsyDatabase/1.json @@ -0,0 +1,307 @@ +{ + "formatVersion": 1, + "database": { + "version": 1, + "identityHash": "3e1791887e71a028d3b6fe58e060e7a4", + "entities": [ + { + "tableName": "assets", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `symbol` TEXT NOT NULL, `precision` INTEGER NOT NULL, `description` TEXT NOT NULL, `bit_asset_id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "symbol", + "columnName": "symbol", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "precision", + "columnName": "precision", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "description", + "columnName": "description", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "bitAssetId", + "columnName": "bit_asset_id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "authorities", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `user_id` TEXT NOT NULL, `authority_type` INTEGER NOT NULL, `encrypted_wif` TEXT NOT NULL, `encrypted_brain_key` TEXT NOT NULL, `encrypted_sequence_number` TEXT NOT NULL)", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "userId", + "columnName": "user_id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "authorityType", + "columnName": "authority_type", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "encryptedWIF", + "columnName": "encrypted_wif", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "encryptedBrainKey", + "columnName": "encrypted_brain_key", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "encryptedSequenceNumber", + "columnName": "encrypted_sequence_number", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "balances", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`asset_id` TEXT NOT NULL, `asset_amount` INTEGER NOT NULL, `last_update` INTEGER NOT NULL, PRIMARY KEY(`asset_id`))", + "fields": [ + { + "fieldPath": "assetId", + "columnName": "asset_id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "assetAmount", + "columnName": "asset_amount", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "lastUpdate", + "columnName": "last_update", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "asset_id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "equivalent_values", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `transfer_id` TEXT NOT NULL, `value` INTEGER NOT NULL, `asset_id` TEXT NOT NULL, FOREIGN KEY(`transfer_id`) REFERENCES `transfers`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION , FOREIGN KEY(`asset_id`) REFERENCES `assets`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION )", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "transferId", + "columnName": "transfer_id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "value", + "columnName": "value", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "assetId", + "columnName": "asset_id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [ + { + "table": "transfers", + "onDelete": "NO ACTION", + "onUpdate": "NO ACTION", + "columns": [ + "transfer_id" + ], + "referencedColumns": [ + "id" + ] + }, + { + "table": "assets", + "onDelete": "NO ACTION", + "onUpdate": "NO ACTION", + "columns": [ + "asset_id" + ], + "referencedColumns": [ + "id" + ] + } + ] + }, + { + "tableName": "transfers", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `block_number` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL, `fee_amount` INTEGER NOT NULL, `fee_asset_id` TEXT NOT NULL, `source` TEXT NOT NULL, `destination` TEXT NOT NULL, `transfer_amount` INTEGER NOT NULL, `transfer_asset_id` TEXT NOT NULL, `memo` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "blockNumber", + "columnName": "block_number", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "timestamp", + "columnName": "timestamp", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "feeAmount", + "columnName": "fee_amount", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "feeAssetId", + "columnName": "fee_asset_id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "source", + "columnName": "source", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "destination", + "columnName": "destination", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "transferAmount", + "columnName": "transfer_amount", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "transferAssetId", + "columnName": "transfer_asset_id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "memo", + "columnName": "memo", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "user_accounts", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `is_ltm` INTEGER NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "isLtm", + "columnName": "is_ltm", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + } + ], + "views": [], + "setupQueries": [ + "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"3e1791887e71a028d3b6fe58e060e7a4\")" + ] + } +} \ No newline at end of file diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/database/BitsyDatabase.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/database/BitsyDatabase.kt index 8cfd754..cc2b792 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/database/BitsyDatabase.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/database/BitsyDatabase.kt @@ -17,7 +17,8 @@ import cy.agorise.bitsybitshareswallet.database.joins.TransferDetailDao Transfer::class, UserAccount::class ], - version = 1, exportSchema = false) + version = 1, + exportSchema = true) abstract class BitsyDatabase : RoomDatabase() { abstract fun assetDao(): AssetDao @@ -28,6 +29,9 @@ abstract class BitsyDatabase : RoomDatabase() { abstract fun userAccountDao(): UserAccountDao abstract fun balanceDetailDao(): BalanceDetailDao abstract fun transferDetailDao(): TransferDetailDao + // version 2 +// abstract fun merchantDao(): MerchantDao +// abstract fun tellerDao(): TellerDao companion object { diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/database/daos/MerchantDao.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/database/daos/MerchantDao.kt new file mode 100644 index 0000000..55e60fe --- /dev/null +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/database/daos/MerchantDao.kt @@ -0,0 +1,15 @@ +package cy.agorise.bitsybitshareswallet.database.daos + +import androidx.room.Dao +import androidx.room.Insert +import androidx.room.OnConflictStrategy +import cy.agorise.bitsybitshareswallet.database.entities.Merchant + +@Dao +interface MerchantDao { + @Insert + fun insert(merchant: Merchant) + + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun insertAll(merchants: List) +} \ No newline at end of file diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/database/daos/TellerDao.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/database/daos/TellerDao.kt new file mode 100644 index 0000000..7009f07 --- /dev/null +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/database/daos/TellerDao.kt @@ -0,0 +1,15 @@ +package cy.agorise.bitsybitshareswallet.database.daos + +import androidx.room.Dao +import androidx.room.Insert +import androidx.room.OnConflictStrategy +import cy.agorise.bitsybitshareswallet.database.entities.Teller + +@Dao +interface TellerDao { + @Insert + fun insert(teller: Teller) + + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun insertAll(tellers: List) +} \ No newline at end of file