I'm re-engineering an app that I've been writing and in doing so I'm currently separating table definitions into different interfaces, one per table and then an overall interface for the whole database.
In doing so I have some common constants, in the overall interface, that are used in the table interfaces. The overall, interface also utilises constants from the table interfaces.
I've compiled and successfully run an app (basically the ubiquitous Hello World app with just two additional lines of code) using this and all appears to be fine. I'm actually quite surprised that this compiles.
Basically, am I taking a path doomed to cause problems.
Here's some example code:-
Interface DBAislesTableConstants Note! reduced to just 1 row
import static mjt.shopwise.DBConstants.DEFAULTORDER;
import static mjt.shopwise.DBConstants.IDTYPE;
import static mjt.shopwise.DBConstants.INT;
import static mjt.shopwise.DBConstants.PERIOD;
import static mjt.shopwise.DBConstants.STD_ID;
import static mjt.shopwise.DBConstants.TXT;
public interface DBAislesTableConstants {
String AISLES_ID_COL = STD_ID;
String AISLES_ID_COL_FULL = AISLES_TABLE +
PERIOD +
AISLES_ID_COL;
String AISLES_ALTID_COL = AISLES_TABLE + STD_ID;
String AISLES_ALTID_COL_FULL = AISLES_TABLE +
PERIOD +
AISLES_ALTID_COL;
String AISLES_ID_TYPE = IDTYPE;
Boolean AISLES_ID_PRIMARY_INDEX = true;
DBColumn AISLESIDCOL = new DBColumn(AISLES_ID_COL,
AISLES_ID_TYPE,
AISLES_ID_PRIMARY_INDEX,
""
);
ArrayList<DBColumn> AISLESCOLS = new ArrayList<>(Arrays.asList(AISLESIDCOL));
DBTable AISLESTABLE = new DBTable(AISLES_TABLE,AISLESCOLS);
}
DBColum and DBTable are defined classes with methods used to build what I'll can an internal schema used for creating and updating the actual database.
Interface DBConstants is :-
import java.util.ArrayList;
import java.util.Arrays;
import static mjt.shopwise.DBAislesTableConstants.AISLESTABLE;
import static mjt.shopwise.DBProductsTableConstants.PRODUCTSTABLE;
import static mjt.shopwise.DBShopsTableConstants.SHOPSTABLE;
interface DBConstants {
String DATABASE_NAME = "ShopWise";
String STD_ID = "_id";
String PERIOD = ".";
String INT = "INTEGER";
String TXT = "TEXT";
String IDTYPE = INT;
String DEFAULTORDER = "1000";
ArrayList<DBTable> SHOPWISETABLES = new ArrayList<>(Arrays.asList(
AISLESTABLE));
DBDatabase SHOPWISE = new DBDatabase(DATABASE_NAME,SHOPWISETABLES);
}
DBDatabase is a defined class for the whole database e.g. below I use the generateExportSchemaSQL method.
To test this I've used the following, which creates the SQL to create all the tables (ran this and dropped the SQL into SQLite Manager and it created the tables). stophere was just used for a breakpoint so I could inspect and copy the SQL.
String sql = DBConstants.SHOPWISE.generateExportSchemaSQL();
int stophere = 0;