public class Many2ManyAnalyzer extends LitePalBase
| 限定符和类型 | 字段和说明 |
|---|---|
static java.lang.String |
TAG |
| 构造器和说明 |
|---|
Many2ManyAnalyzer() |
| 限定符和类型 | 方法和说明 |
|---|---|
protected void |
analyzeAssociatedModels(DataSupport baseObj,
java.util.Collection<AssociationsInfo> associationInfos)
Find all the associated models of currently model.
|
protected void |
buildBidirectionalAssociations(DataSupport baseObj,
DataSupport associatedModel,
AssociationsInfo associationInfo)
Build the bidirectional association by setting the baseObj instance to
the associated model.
|
protected java.util.Collection<DataSupport> |
checkAssociatedModelCollection(java.util.Collection<DataSupport> associatedModelCollection,
java.lang.reflect.Field associatedField)
Check the associated model collection.
|
protected java.lang.Object |
createInstanceFromClass(java.lang.Class<?> modelClass)
Creates an instance from the passed in class.
|
protected void |
dealsAssociationsOnTheSideWithoutFK(DataSupport baseObj,
DataSupport associatedModel)
If the associated model is saved, add its' name and id to baseObj by
calling
DataSupport.addAssociatedModelWithFK(String, long). |
protected java.lang.reflect.Constructor<?> |
findBestSuitConstructor(java.lang.Class<?> modelClass)
Finds the best suit constructor for creating an instance of a class.
|
protected DataSupport |
getAssociatedModel(DataSupport baseObj,
AssociationsInfo associationInfo)
Get the associated model.
|
protected java.util.Collection<DataSupport> |
getAssociatedModels(DataSupport baseObj,
AssociationsInfo associationInfo)
Get the associated models collection.
|
protected java.lang.Object[] |
getConstructorParams(java.lang.Class<?> modelClass,
java.lang.reflect.Constructor<?> constructor)
Depends on the passed in constructor, creating a parameters array with
initialized values for the constructor.
|
protected DataSupport |
getEmptyModel(DataSupport baseObj)
Create an empty instance of baseObj if it hasn't created one yet.
|
protected java.util.List<AssociationsInfo> |
getForeignKeyAssociations(java.lang.String className,
boolean isEager)
Get the foreign key associations of the specified class.
|
protected java.lang.String |
getIntermediateTableName(DataSupport baseObj,
java.lang.String associatedTableName)
Get the name of intermediate join table.
|
protected java.lang.Class<?>[] |
getParameterTypes(java.lang.reflect.Field field,
java.lang.Object fieldValue,
java.lang.Object[] parameters)
Get the types of parameters for
ContentValues.put(java.lang.String, java.lang.String). |
protected java.util.Collection<DataSupport> |
getReverseAssociatedModels(DataSupport associatedModel,
AssociationsInfo associationInfo)
Get the associated models collection of associated model.
|
protected java.lang.String |
getTableName(java.lang.Class<?> modelClass)
Get the simple name of modelClass.
|
protected java.lang.String[] |
getWhereArgs(java.lang.String... conditions)
Get the WHERE arguments to fill into where clause when updating or
deleting multiple rows.
|
protected java.lang.String |
getWhereClause(java.lang.String... conditions)
Get the WHERE clause to apply when updating or deleting multiple rows.
|
protected java.lang.String |
getWhereOfIdsWithOr(java.util.Collection<java.lang.Long> ids)
Get the where clause by the passed in id collection to apply multiple
rows.
|
protected java.lang.String |
getWhereOfIdsWithOr(long... ids)
Get the where clause by the passed in id array to apply multiple rows.
|
protected void |
giveBaseObjIdValue(DataSupport baseObj,
long id)
Assign the generated id value to
DataSupport.baseObjId. |
protected boolean |
isAffectAllLines(java.lang.Object... conditions)
Check the passing conditions represent to affect all lines or not.
|
protected <T> T |
mathQuery(java.lang.String tableName,
java.lang.String[] columns,
java.lang.String[] conditions,
java.lang.Class<T> type)
Handles the math query of the given table.
|
protected void |
mightClearFKValue(DataSupport baseObj,
AssociationsInfo associationInfo)
If the associated model of self model is null, the FK value in database
should be cleared if it exists when updating.
|
protected void |
putContentValuesForSave(DataSupport baseObj,
java.lang.reflect.Field field,
android.content.ContentValues values)
This method deals with the putting values job into ContentValues.
|
protected void |
putContentValuesForUpdate(DataSupport baseObj,
java.lang.reflect.Field field,
android.content.ContentValues values)
This method deals with the putting values job into ContentValues.
|
protected void |
putFieldsValue(DataSupport baseObj,
java.util.List<java.lang.reflect.Field> supportedFields,
android.content.ContentValues values)
Iterate all the fields passed in.
|
protected void |
putSetMethodValueByField(DataSupport dataSupport,
java.lang.reflect.Field field,
java.lang.Object parameter)
It finds the setter method by the field.
|
protected <T> java.util.List<T> |
query(java.lang.Class<T> modelClass,
java.lang.String[] columns,
java.lang.String selection,
java.lang.String[] selectionArgs,
java.lang.String groupBy,
java.lang.String having,
java.lang.String orderBy,
java.lang.String limit,
java.util.List<AssociationsInfo> foreignKeyAssociations)
Query the table of the given model, returning a model list over the
result set.
|
protected void |
setGenericValueToModel(DataSupport baseObj,
java.util.List<java.lang.reflect.Field> supportedGenericFields,
java.util.Map<java.lang.reflect.Field,GenericModel> genericModelMap)
Get generic value from generic tables, then set the value into the baseObj.
|
protected void |
setReverseAssociatedModels(DataSupport associatedModel,
AssociationsInfo associationInfo,
java.util.Collection<DataSupport> associatedModelCollection)
Set the associated models collection of associated model.
|
protected void |
setValueToModel(java.lang.Object modelInstance,
java.util.List<java.lang.reflect.Field> supportedFields,
java.util.List<AssociationsInfo> foreignKeyAssociations,
android.database.Cursor cursor,
android.util.SparseArray<org.litepal.crud.DataHandler.QueryInfoCache> sparseArray)
Get value from database by cursor, then set the value into modelInstance.
|
protected boolean |
shouldGetOrSet(DataSupport dataSupport,
java.lang.reflect.Field field)
When executing
takeGetMethodValueByField(DataSupport, java.lang.reflect.Field) or
putSetMethodValueByField(DataSupport, java.lang.reflect.Field, Object), the
dataSupport and field passed in should be protected from null value. |
protected java.lang.Object |
takeGetMethodValueByField(DataSupport dataSupport,
java.lang.reflect.Field field)
It finds the getter method by the field.
|
public static final java.lang.String TAG
protected java.util.Collection<DataSupport> getReverseAssociatedModels(DataSupport associatedModel, AssociationsInfo associationInfo) throws java.lang.SecurityException, java.lang.IllegalArgumentException, java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
associatedModel - The associated model of baseObj.associationInfo - To get reverse associated models collection.java.lang.SecurityExceptionjava.lang.IllegalArgumentExceptionjava.lang.NoSuchMethodExceptionjava.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetExceptionprotected void setReverseAssociatedModels(DataSupport associatedModel, AssociationsInfo associationInfo, java.util.Collection<DataSupport> associatedModelCollection) throws java.lang.SecurityException, java.lang.IllegalArgumentException, java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
associatedModel - The associated model of baseObj.associationInfo - To get reverse associated models collection.associatedModelCollection - The new associated models collection with same data as source
collection but different quote.java.lang.SecurityExceptionjava.lang.IllegalArgumentExceptionjava.lang.NoSuchMethodExceptionjava.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetExceptionprotected java.util.Collection<DataSupport> checkAssociatedModelCollection(java.util.Collection<DataSupport> associatedModelCollection, java.lang.reflect.Field associatedField)
associatedModelCollection - The associated model collection to check null and initialize.associatedField - The field to decide which type to initialize for associated
model collection.DataSupportExceptionprotected void buildBidirectionalAssociations(DataSupport baseObj, DataSupport associatedModel, AssociationsInfo associationInfo) throws java.lang.SecurityException, java.lang.IllegalArgumentException, java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
baseObj - The instance of self model.associatedModel - The associated model.associationInfo - The association info to get the association.java.lang.SecurityExceptionjava.lang.IllegalArgumentExceptionjava.lang.NoSuchMethodExceptionjava.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetExceptionprotected void dealsAssociationsOnTheSideWithoutFK(DataSupport baseObj, DataSupport associatedModel)
DataSupport.addAssociatedModelWithFK(String, long). Or if
the baseObj is saved, add its' name and id to associated model by calling
DataSupport.addAssociatedModelWithoutFK(String, long).baseObj - The baseObj currently want to persist.associatedModel - The associated model.protected void mightClearFKValue(DataSupport baseObj, AssociationsInfo associationInfo)
baseObj - The baseObj currently want to persist or update.associationInfo - The associated info analyzed by
LitePalBase.getAssociationInfo(String).protected <T> java.util.List<T> query(java.lang.Class<T> modelClass,
java.lang.String[] columns,
java.lang.String selection,
java.lang.String[] selectionArgs,
java.lang.String groupBy,
java.lang.String having,
java.lang.String orderBy,
java.lang.String limit,
java.util.List<AssociationsInfo> foreignKeyAssociations)
modelClass - The model to compile the query against.columns - A list of which columns to return. Passing null will return
all columns, which is discouraged to prevent reading data from
storage that isn't going to be used.selection - A filter declaring which rows to return, formatted as an SQL
WHERE clause (excluding the WHERE itself). Passing null will
return all rows for the given table.selectionArgs - You may include ?s in selection, which will be replaced by the
values from selectionArgs, in order that they appear in the
selection. The values will be bound as Strings.groupBy - A filter declaring how to group rows, formatted as an SQL
GROUP BY clause (excluding the GROUP BY itself). Passing null
will cause the rows to not be grouped.having - A filter declare which row groups to include in the cursor, if
row grouping is being used, formatted as an SQL HAVING clause
(excluding the HAVING itself). Passing null will cause all row
groups to be included, and is required when row grouping is
not being used.orderBy - How to order the rows, formatted as an SQL ORDER BY clause
(excluding the ORDER BY itself). Passing null will use the
default sort order, which may be unordered.limit - Limits the number of rows returned by the query, formatted as
LIMIT clause. Passing null denotes no LIMIT clause.foreignKeyAssociations - Associated classes which have foreign keys in the current
model's table.protected <T> T mathQuery(java.lang.String tableName,
java.lang.String[] columns,
java.lang.String[] conditions,
java.lang.Class<T> type)
tableName - Which table to query from.columns - A list of which columns to return. Passing null will return
all columns, which is discouraged to prevent reading data from
storage that isn't going to be used.conditions - A filter declaring which rows to return, formatted as an SQL
WHERE clause. Passing null will return all rows.type - The type of the based on column.protected void giveBaseObjIdValue(DataSupport baseObj, long id) throws java.lang.SecurityException, java.lang.NoSuchFieldException, java.lang.IllegalArgumentException, java.lang.IllegalAccessException
DataSupport.baseObjId. This
value will be used as identify of this model for system use.baseObj - The class of base object.id - The value of id.java.lang.SecurityExceptionjava.lang.NoSuchFieldExceptionjava.lang.IllegalArgumentExceptionjava.lang.IllegalAccessExceptionprotected void putFieldsValue(DataSupport baseObj, java.util.List<java.lang.reflect.Field> supportedFields, android.content.ContentValues values) throws java.lang.SecurityException, java.lang.IllegalArgumentException, java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
putFieldsValueDependsOnSaveOrUpdate(DataSupport, java.lang.reflect.Field, android.content.ContentValues)
if it's not id field.baseObj - Current model to persist or update.supportedFields - List of all supported fields.values - To store data of current model for persisting or updating.java.lang.reflect.InvocationTargetExceptionjava.lang.IllegalAccessExceptionjava.lang.NoSuchMethodExceptionjava.lang.IllegalArgumentExceptionjava.lang.SecurityExceptionprotected void putContentValuesForSave(DataSupport baseObj, java.lang.reflect.Field field, android.content.ContentValues values) throws java.lang.SecurityException, java.lang.IllegalArgumentException, java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
baseObj - The class of base object.field - Field to put into ContentValues.values - To store data of current model for persisting or updating.java.lang.SecurityExceptionjava.lang.NoSuchMethodExceptionjava.lang.IllegalArgumentExceptionjava.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetExceptionprotected void putContentValuesForUpdate(DataSupport baseObj, java.lang.reflect.Field field, android.content.ContentValues values) throws java.lang.SecurityException, java.lang.IllegalArgumentException, java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
baseObj - The class of base object.field - Field to put into ContentValues.values - To store data of current model for persisting or updating.java.lang.SecurityExceptionjava.lang.NoSuchMethodExceptionjava.lang.IllegalArgumentExceptionjava.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetExceptionprotected java.lang.Object takeGetMethodValueByField(DataSupport dataSupport, java.lang.reflect.Field field) throws java.lang.SecurityException, java.lang.NoSuchMethodException, java.lang.IllegalArgumentException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
dataSupport - The model to get method from.field - Use to generate getter method name.java.lang.SecurityExceptionjava.lang.NoSuchMethodExceptionjava.lang.IllegalArgumentExceptionjava.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetExceptionprotected void putSetMethodValueByField(DataSupport dataSupport, java.lang.reflect.Field field, java.lang.Object parameter) throws java.lang.SecurityException, java.lang.NoSuchMethodException, java.lang.IllegalArgumentException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
dataSupport - The model to set method to.field - Use to generate setter method name.parameter - The parameter to invoke setter method.java.lang.SecurityExceptionjava.lang.NoSuchMethodExceptionjava.lang.IllegalArgumentExceptionjava.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetExceptionprotected void analyzeAssociatedModels(DataSupport baseObj, java.util.Collection<AssociationsInfo> associationInfos)
baseObj - The class of base object.protected DataSupport getAssociatedModel(DataSupport baseObj, AssociationsInfo associationInfo) throws java.lang.SecurityException, java.lang.IllegalArgumentException, java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
baseObj - The instance of self model.associationInfo - To get the associated model.java.lang.SecurityExceptionjava.lang.IllegalArgumentExceptionjava.lang.NoSuchMethodExceptionjava.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetExceptionprotected java.util.Collection<DataSupport> getAssociatedModels(DataSupport baseObj, AssociationsInfo associationInfo) throws java.lang.SecurityException, java.lang.IllegalArgumentException, java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
baseObj - The instance of self model.associationInfo - To get the associated models collection.java.lang.SecurityExceptionjava.lang.IllegalArgumentExceptionjava.lang.NoSuchMethodExceptionjava.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetExceptionprotected DataSupport getEmptyModel(DataSupport baseObj)
tempEmptyModel, no
need to create a new one.baseObj - Current model to update.protected java.lang.String getWhereClause(java.lang.String... conditions)
conditions - A string array representing the WHERE part of an SQL
statement.protected java.lang.String[] getWhereArgs(java.lang.String... conditions)
conditions - A string array representing the WHERE part of an SQL
statement.protected boolean isAffectAllLines(java.lang.Object... conditions)
conditions - An array representing the WHERE part of an SQL statement.protected java.lang.String getWhereOfIdsWithOr(java.util.Collection<java.lang.Long> ids)
ids - The id collection.protected java.lang.String getWhereOfIdsWithOr(long... ids)
ids - The id collection.protected boolean shouldGetOrSet(DataSupport dataSupport, java.lang.reflect.Field field)
takeGetMethodValueByField(DataSupport, java.lang.reflect.Field) or
putSetMethodValueByField(DataSupport, java.lang.reflect.Field, Object), the
dataSupport and field passed in should be protected from null value.dataSupport - The object to execute set or get method.field - The field of generating set and get methods.protected java.lang.String getIntermediateTableName(DataSupport baseObj, java.lang.String associatedTableName)
baseObj - Current model.associatedTableName - The name of associated table.protected java.lang.String getTableName(java.lang.Class<?> modelClass)
modelClass - Class of model to get table name from.protected java.lang.Object createInstanceFromClass(java.lang.Class<?> modelClass)
findBestSuitConstructor(Class) method.modelClass - The class to create instance.protected java.lang.reflect.Constructor<?> findBestSuitConstructor(java.lang.Class<?> modelClass)
modelClass - To get constructors from.protected java.lang.Object[] getConstructorParams(java.lang.Class<?> modelClass,
java.lang.reflect.Constructor<?> constructor)
modelClass - The original class the this constructor belongs to.constructor - The constructor to get parameters for it.protected void setValueToModel(java.lang.Object modelInstance,
java.util.List<java.lang.reflect.Field> supportedFields,
java.util.List<AssociationsInfo> foreignKeyAssociations,
android.database.Cursor cursor,
android.util.SparseArray<org.litepal.crud.DataHandler.QueryInfoCache> sparseArray)
throws java.lang.SecurityException,
java.lang.IllegalArgumentException,
java.lang.NoSuchMethodException,
java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException
modelInstance - The model to set into.supportedFields - Corresponding to each column in database.foreignKeyAssociations - Associated classes which have foreign keys in the current
model's table.cursor - Use to get value from database.sparseArray - Use SparseArray to cache the query information at first loop. Then the rest loop
can get query information directly to speed up.java.lang.SecurityExceptionjava.lang.IllegalArgumentExceptionjava.lang.NoSuchMethodExceptionjava.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetExceptionprotected void setGenericValueToModel(DataSupport baseObj, java.util.List<java.lang.reflect.Field> supportedGenericFields, java.util.Map<java.lang.reflect.Field,GenericModel> genericModelMap) throws java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
baseObj - The model to set into.supportedGenericFields - List of all supported generic fields.genericModelMap - Use HashMap to cache the query information at first loop. Then the rest loop can
get query information directly to speed up.java.lang.NoSuchMethodExceptionjava.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetExceptionprotected java.util.List<AssociationsInfo> getForeignKeyAssociations(java.lang.String className, boolean isEager)
className - The full class name.isEager - True to load the associated models, false not.protected java.lang.Class<?>[] getParameterTypes(java.lang.reflect.Field field,
java.lang.Object fieldValue,
java.lang.Object[] parameters)
ContentValues.put(java.lang.String, java.lang.String). Need two
parameters. First is String type for key. Second is depend on field for
value.field - The field to get parameter type.fieldValue - Value of the field. Only used to convert to String when the
field is char.parameters - If the field is char, convert the value to String at index 1.ContentValues.put(java.lang.String, java.lang.String).