Preparing constants

We will dedicate specific constants to keep the names and queries that are related to the entity (StockUpdate) that we will be persisting.

For this, let's create a separate package, packt.reactivestocks.storio, that will hold StorIO-related classes, and let's put a class, named StockUpdateTable, which will contain queries and constants for StockUpdate, there:

class StockUpdateTable {
static final String TABLE = "stock_updates";

static class
Columns {
static final String ID = "_id";
static final String STOCK_SYMBOL = "stock_symbol";
static final String PRICE = "price";
static final String DATE = "date";
}

private
StockUpdateTable() {
}

static
String createTableQuery() {
return "CREATE TABLE " + TABLE + "("
+ Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ Columns.STOCK_SYMBOL + " TEXT NOT NULL, "
+ Columns.DATE + " LONG NOT NULL, "
+ Columns.PRICE + " LONG NOT NULL"
+ ");";
}
}

The Columns subclass contains the column names that will later be used to query and update the data, while methods such as createTableQuery() will be used to set up the database on the first application run.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.0.85