I have an abstract class, Foo
, which Bars
, Barz
, and a bunch of others that hold some bits of data.
I am storing the data into several different tables in SQLite. I also wrote a small class that basically contains the java class that it "creates", the name of the table in the sqlite master and a pair for each column's name and column's data type to help with quickly turning records into objects when the application is running.
I would like to keep things as abstract as possible for re-usability. How could I create the correct subclass of the object with the correct data types by just having the table
information from above for a single record from "that table" without an O(n) loop over each class (it's fast, but it's also hard coded for each class and it's a lot of typing).
SQLiteTable class:
class SQLiteTable<T>
{
...
SQLiteTable(String name, SQLiteColumn...columns)
...
}
JDBC SQLite abstract requested help:
...
public ArrayList<Foo> query(SQLiteTable table, String statement)
{
safeString = purgeOfFilt(statement);
statement = connection.prepareStatement(safeString);
results = statement.executeQuery();
ArrayList<Foo> records = new ArrayList<>();
while(results.next())
{
... // for loop to extract field information about the object I'd like to create
records.add(/*I'm not sure how to create the correct instance of the class here
(with the extracted fields--some of which are final at creation)*/));
}
}
...