T
- the class being reflectedpublic static class SQLightable.Reflection<T extends SQLightable>
extends java.lang.Object
SQLightable
object, which represents, and
is used to marshal data for, an SQLite table. Usable by
SQLiteHouse
and any other class that needs to know how this
table class is defined.Modifier and Type | Class and Description |
---|---|
class |
SQLightable.Reflection.Column
A full reflection of a
SQLiteColumn field. |
static class |
SQLightable.Reflection.ColumnMap<ST extends SQLightable>
Provides a syntactic shorthand for working with maps of fields to
column reflections.
|
class |
SQLightable.Reflection.ColumnSequencer
Orders
SQLightable.Reflection.Column attributes in a list. |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
LOG_TAG |
protected java.util.ArrayList<SQLightable.Reflection.Column> |
m_aColumns
A simple list of columns, sorted roughly by the sequence defined by
the corresponding fields'
SQLiteColumn annotations. |
protected SQLiteTable |
m_antTable
The annotation on the reflected table class.
|
protected java.lang.Class<T> |
m_clsTable
The class being reflected.
|
protected java.lang.reflect.Field |
m_fldKey
The field that is the primary key for the table.
|
protected java.lang.reflect.Field |
m_fldMagicID
The field that is the class's placeholder for the magic SQLite
auto-incremented row key, if any.
|
protected java.util.HashMap<java.lang.String,java.lang.reflect.Field> |
m_mapColNames
Deprecated.
zer0bandwidth-net/android 0.2.1 (#56) — this is no
longer populated; use
getColumn(String) to directly fetch a
column reflection corresponding to the DB column name, then use
SQLightable.Reflection.Column.getField() to get the field |
protected java.util.HashMap<java.lang.String,SQLightable.Reflection.Column> |
m_mapColumns
A map of DB column names to column schemas.
|
protected SQLightable.Reflection.ColumnMap<T> |
m_mapFields
A map of fields to their column schemas.
|
protected java.lang.String |
m_sTableName
The name of the table.
|
Constructor and Description |
---|
Reflection(java.lang.Class<T> cls)
Constructor kicks off a reflection of the selected class.
|
Modifier and Type | Method and Description |
---|---|
DeletionBuilder |
buildDelete()
Get an instance of a
DeletionBuilder initialized with the
table name discovered by this reflection. |
static <ST extends SQLightable> |
buildDelete(java.lang.Class<ST> cls)
Shorthand to get an instance of
DeletionBuilder initialized
with the table name that would be reflected for the specified
schematic class. |
InsertionBuilder |
buildInsert()
Get an instance of an
InsertionBuilder initialized with the
table name discovered by this reflection. |
static <ST extends SQLightable> |
buildInsert(java.lang.Class<ST> cls)
Shorthand to get an instance of
InsertionBuilder initialized
with the table name that would be reflected for the specified
schematic class. |
SelectionBuilder |
buildSelect()
Get an instance of a
SelectionBuilder initialized with the
table name discovered by this reflection. |
static <ST extends SQLightable> |
buildSelect(java.lang.Class<ST> cls)
Shorthand to get an instance of
SelectionBuilder initialized
with the table name that would be reflected for the specified
schematic class. |
UpdateBuilder |
buildUpdate()
Get an instance of an
UpdateBuilder initialized with the
table name discovered by this reflection. |
static <ST extends SQLightable> |
buildUpdate(java.lang.Class<ST> cls)
Shorthand to get an instance of
UpdateBuilder initialized
with the table name that would be reflected for the specified
schematic class. |
T |
fromBundle(android.os.Bundle bndl)
Reads fields from a supplied
Bundle , and marshals it into a
schematic class instance. |
T |
fromCursor(android.database.Cursor crs)
Reads a row of data from the specified cursor, and marshals it into a
schematic class instance corresponding to the table from which the
row was fetched.
|
java.lang.String |
getAddColumnSQL(SQLightable.Reflection.Column col)
Generates the SQL statement which will add the specified column to
this table.
|
SQLightable.Reflection.Column |
getColumn(java.lang.String sColName)
Accesses the reflection of a database column (and its corresponding
class field) with the specified name.
|
SQLightable.Reflection.Column |
getColumnDef(java.lang.reflect.Field fld)
Deprecated.
zer0bandwidth-net/android 0.2.1 (#56) — it's
unlikely that anything outside of SQLiteHouse itself would have
also reflected the class and want to get to the column that way
|
SQLightable.Reflection.Column |
getColumnDef(java.lang.String sColName)
Deprecated.
zer0bandwidth-net/android 0.2.1 (#56) — use
getColumn(java.lang.String) instead |
SQLightable.Reflection.ColumnMap<T> |
getColumnMap()
Deprecated.
zer0bandwidth-net/android 0.2.1 (#56) — use
getColumns() to get the list of columns directly, or get
getColumn(String) to get a specific column |
java.util.List<SQLightable.Reflection.Column> |
getColumns()
Accesses the ordered list of column reflections.
|
java.lang.reflect.Field |
getField(java.lang.String sColName)
Accesses the field in the schematic class corresponding to the name
of a column in the table described by the class.
|
int |
getFirstSchemaVersion()
Determines the first version of the schema in which this schematic
class was included.
|
T |
getInstance()
Constructs an empty instance of the
SQLightable
implementation class reflected in this object. |
SQLightable.Reflection.Column |
getKeyColumn()
Accesses the column reflection for the field defined as the practical
key for the table.
|
java.lang.reflect.Field |
getKeyField()
Accesses the field that was defined as the practical key for the
table.
|
SQLightable.Reflection.Column |
getKeyOrMagicIDColumn()
Tries to find a usable key column, by first looking for a field
defined as the practical key, then looking for a field defined as the
magic auto-incremented row ID, then returning
null if neither
is defined. |
SQLightable.Reflection.Column |
getMagicIDColumn()
Accesses the column reflection for the field defined as the container
for the SQLite magic auto-incremented row ID, if any.
|
java.lang.reflect.Field |
getMagicIDField()
Accesses the field that was defined as the container for the SQLite
magic auto-incremented row ID, if any.
|
SQLiteTable |
getTableAttrs()
Accesses the
SQLiteTable annotation that defines the
attributes of the table described by this schematic class. |
java.lang.Class<T> |
getTableClass()
Accesses the schematic class reflected in this object.
|
java.lang.String |
getTableCreationSQL()
Generates the SQL statement which will create the table represented
by this schematic class, based on the class itself, and its
SQLiteTable annotation (if any). |
java.lang.String |
getTableName()
Accesses the name of the database table described by this schematic
class.
|
static <ST extends SQLightable> |
getTableName(java.lang.Class<ST> cls)
Standardized way to choose the name of a SQLite table based on the
schematic class definition and its annotations, if any.
|
protected static <ST extends SQLightable> |
getTableName(java.lang.Class<ST> cls,
SQLiteTable antTable)
Standardized way to choose the name of a SQLite table based on the
annotation attached to the schematic class.
|
protected void |
processInheritanceTo(java.lang.Class<?> cls,
int nSince)
If the class being reflected is annotated with
SQLiteInheritColumns , then this method will update the
Reflection 's list of "inherited" fields with anything that is
annotated with SQLiteColumn in the class's parent. |
static <ST extends SQLightable> |
reflect(java.lang.Class<ST> cls)
Obtain a reflection of the specified schematic class.
|
protected SQLightable.Reflection<T> |
reflectColumns()
Analyzes the fields defined in the selected class and its ancestors,
to produce a complete, ordered list of columns for the database table
in this version of the schema.
|
android.os.Bundle |
toBundle(T oSource)
Extracts the values of all known fields, corresponding to database
table columns, from a schematic class instance, and returns a
Bundle instance containing those values. |
android.content.ContentValues |
toContentValues(T oSource)
Extracts the values of all known fields, corresponding to database
table columns, from a schematic class instance, and returns a
ContentValues instance containing those values. |
public static final java.lang.String LOG_TAG
protected java.lang.Class<T extends SQLightable> m_clsTable
protected SQLiteTable m_antTable
protected java.lang.String m_sTableName
protected SQLightable.Reflection.ColumnMap<T extends SQLightable> m_mapFields
protected java.util.HashMap<java.lang.String,java.lang.reflect.Field> m_mapColNames
getColumn(String)
to directly fetch a
column reflection corresponding to the DB column name, then use
SQLightable.Reflection.Column.getField()
to get the fieldprotected java.util.ArrayList<SQLightable.Reflection.Column> m_aColumns
SQLiteColumn
annotations.
Replaces m_mapFields
, from which we used only the values (the
list of columns).protected java.util.HashMap<java.lang.String,SQLightable.Reflection.Column> m_mapColumns
m_mapColNames
, which mapped to fields.protected java.lang.reflect.Field m_fldKey
protected java.lang.reflect.Field m_fldMagicID
public Reflection(java.lang.Class<T> cls) throws IntrospectionException
cls
- the class being reflectedIntrospectionException
- if something goes wrongpublic static <ST extends SQLightable> SQLightable.Reflection<ST> reflect(java.lang.Class<ST> cls)
ST
- the schematic classcls
- the schematic classpublic static <ST extends SQLightable> java.lang.String getTableName(java.lang.Class<ST> cls)
ST
- the schematic classcls
- the schematic classprotected static <ST extends SQLightable> java.lang.String getTableName(java.lang.Class<ST> cls, SQLiteTable antTable)
ST
- the schematic classcls
- the schematic classantTable
- the annotation that describes the table defined by
the class (may be null)getTableName(Class)
,
getTableName()
public static <ST extends SQLightable> InsertionBuilder buildInsert(java.lang.Class<ST> cls)
InsertionBuilder
initialized
with the table name that would be reflected for the specified
schematic class. Use this method when you need a query builder but
don't need to retain a copy of the reflection.ST
- the schematic classcls
- the schematic classINSERT
statementpublic static <ST extends SQLightable> UpdateBuilder buildUpdate(java.lang.Class<ST> cls)
UpdateBuilder
initialized
with the table name that would be reflected for the specified
schematic class. Use this method when you need a query builder but
don't need to retain a copy of the reflection.ST
- the schematic classcls
- the schematic classUPDATE
statementpublic static <ST extends SQLightable> SelectionBuilder buildSelect(java.lang.Class<ST> cls)
SelectionBuilder
initialized
with the table name that would be reflected for the specified
schematic class. Use this method when you need a query builder but
don't need to retain a copy of the reflection.ST
- the schematic classcls
- the schematic classSELECT
statementpublic static <ST extends SQLightable> DeletionBuilder buildDelete(java.lang.Class<ST> cls)
DeletionBuilder
initialized
with the table name that would be reflected for the specified
schematic class. Use this method when you need a query builder but
don't need to retain a copy of the reflection.ST
- the schematic classcls
- the schematic classDELETE
statementprotected SQLightable.Reflection<T> reflectColumns()
initFieldMap()
.protected void processInheritanceTo(java.lang.Class<?> cls, int nSince)
SQLiteInheritColumns
, then this method will update the
Reflection
's list of "inherited" fields with anything that is
annotated with SQLiteColumn
in the class's parent.
Note that the parent class does not need to be annotated as an
SQLiteTable
, nor does it need to implement
SQLightable
.
THIS METHOD WILL RECURSE as long as it continues to find and
traverse classes whose parents are also annotated with
SQLiteInheritColumns
.cls
- the class to be examined; this is originally called with
the class that is being reflected, and may recurse with its parent
as far as we continue to see SQLiteInheritColumns
annotationsreflectColumns()
public java.lang.Class<T> getTableClass()
public SQLiteTable getTableAttrs()
SQLiteTable
annotation that defines the
attributes of the table described by this schematic class.public java.lang.String getTableName()
getTableName(Class, SQLiteTable)
public SQLightable.Reflection.Column getColumn(java.lang.String sColName)
sColName
- the name of a column in the database tablepublic java.lang.reflect.Field getField(java.lang.String sColName)
sColName
- the name of a column in the database tablepublic java.util.List<SQLightable.Reflection.Column> getColumns()
public SQLightable.Reflection.ColumnMap<T> getColumnMap()
getColumns()
to get the list of columns directly, or get
getColumn(String)
to get a specific columnpublic SQLightable.Reflection.Column getColumnDef(java.lang.reflect.Field fld)
fld
- the field that corresponds to a database table columnpublic SQLightable.Reflection.Column getColumnDef(java.lang.String sColName)
getColumn(java.lang.String)
insteadsColName
- the name of the table columnpublic java.lang.reflect.Field getKeyField()
public SQLightable.Reflection.Column getKeyColumn()
public java.lang.reflect.Field getMagicIDField()
public SQLightable.Reflection.Column getMagicIDColumn()
public SQLightable.Reflection.Column getKeyOrMagicIDColumn()
null
if neither
is defined.null
if neither a
practical key nor a magic row ID column is definedpublic java.lang.String getTableCreationSQL()
SQLiteTable
annotation (if any).public java.lang.String getAddColumnSQL(SQLightable.Reflection.Column col)
col
- the reflection of the column to be addedpublic int getFirstSchemaVersion()
SQLiteTable
annotation is missing,
then the method returns 1
.public T getInstance() throws IntrospectionException
SQLightable
implementation class reflected in this object.IntrospectionException
- if the schematic class could not be
constructed for some reasonpublic T fromCursor(android.database.Cursor crs) throws IntrospectionException, SchematicException
crs
- the cursor which is currently pointing to a data rowIntrospectionException
- if the data class could not be
constructed for some reasonSchematicException
- if the data could not be properly
marshalled into the class instancepublic T fromBundle(android.os.Bundle bndl) throws IntrospectionException, SchematicException
Bundle
, and marshals it into a
schematic class instance.bndl
- the bundle into which data was marshalledIntrospectionException
- if the data class could not be
constructed for some reasonSchematicException
- if the data could not be properly
marshalled into the class instancepublic android.content.ContentValues toContentValues(T oSource) throws SchematicException
ContentValues
instance containing those values.
Replaces SQLiteHouse#toContentValues(SQLightable)
.oSource
- the object to be processedSchematicException
- if no Refractor
implementation can
be found for one of the columns/fieldspublic android.os.Bundle toBundle(T oSource) throws SchematicException
Bundle
instance containing those values.oSource
- the object to be processedSchematicException
- if no Refractor
implementation can
be found for one of the column's fieldspublic InsertionBuilder buildInsert()
InsertionBuilder
initialized with the
table name discovered by this reflection.INSERT
statementpublic UpdateBuilder buildUpdate()
UpdateBuilder
initialized with the
table name discovered by this reflection.UPDATE
statementpublic SelectionBuilder buildSelect()
SelectionBuilder
initialized with the
table name discovered by this reflection.SELECT
statementpublic DeletionBuilder buildDelete()
DeletionBuilder
initialized with the
table name discovered by this reflection.DELETE
statement