public class DBUtility
extends java.lang.Object
| 限定符和类型 | 方法和说明 |
|---|---|
static java.lang.String |
convertOrderByClauseToValidName(java.lang.String orderBy)
Convert the order by clause if it contains invalid column names which conflict with SQLite keywords.
|
static java.lang.String[] |
convertSelectClauseToValidNames(java.lang.String[] columns)
Convert the select clause if it contains invalid column names which conflict with SQLite keywords.
|
static java.lang.String |
convertToValidColumnName(java.lang.String columnName)
Convert the passed in name to valid column name if the name is conflicted with SQLite keywords.
|
static java.lang.String |
convertWhereClauseToColumnName(java.lang.String whereClause)
Convert the where clause if it contains invalid column names which conflict with SQLite keywords.
|
static java.util.List<java.lang.String> |
findAllTableNames(android.database.sqlite.SQLiteDatabase db)
Find all table names in the database.
|
static android.util.Pair<java.util.Set<java.lang.String>,java.util.Set<java.lang.String>> |
findIndexedColumns(java.lang.String tableName,
android.database.sqlite.SQLiteDatabase db)
Find all columns with index, including normal index and unique index of specified table.
|
static TableModel |
findPragmaTableInfo(java.lang.String tableName,
android.database.sqlite.SQLiteDatabase db)
Look from the database to find a table named same as the table name in
table model.
|
static java.lang.String |
getGenericTableName(java.lang.String className,
java.lang.String fieldName)
Create generic table name by the concatenation of the class model's table name and simple
generic type name with underline in the middle.
|
static java.lang.String |
getGenericValueIdColumnName(java.lang.String className)
The column name for referenced id in generic table.
|
static java.lang.String |
getIndexName(java.lang.String tableName,
java.lang.String columnName)
Get the index name by column name.
|
static java.lang.String |
getIntermediateTableName(java.lang.String tableName,
java.lang.String associatedTableName)
Create intermediate join table name by the concatenation of the two
target table names in alphabetical order with underline in the middle.
|
static java.lang.String |
getM2MSelfRefColumnName(java.lang.reflect.Field field) |
static java.lang.String |
getTableNameByClassName(java.lang.String className)
Get the corresponding table name by the full class name with package.
|
static java.lang.String |
getTableNameByForeignColumn(java.lang.String foreignColumnName)
Get table name by the given foreign column name.
|
static java.util.List<java.lang.String> |
getTableNameListByClassNameList(java.util.List<java.lang.String> classNames)
Get the corresponding table name list by the full class name list with
package.
|
static boolean |
isColumnExists(java.lang.String columnName,
java.lang.String tableName,
android.database.sqlite.SQLiteDatabase db)
Test if a column exists in a table.
|
static boolean |
isFieldNameConflictWithSQLiteKeywords(java.lang.String fieldName)
If the field name is conflicted with SQLite keywords.
|
static boolean |
isGenericTable(java.lang.String tableName,
android.database.sqlite.SQLiteDatabase db)
Judge the table name is an generic table or not.
|
static boolean |
isIntermediateTable(java.lang.String tableName,
android.database.sqlite.SQLiteDatabase db)
Judge the table name is an intermediate table or not.
|
static boolean |
isTableExists(java.lang.String tableName,
android.database.sqlite.SQLiteDatabase db)
Test if the table name passed in exists in the database.
|
public static java.lang.String getTableNameByClassName(java.lang.String className)
className - Full class name with package.public static java.lang.String getIndexName(java.lang.String tableName,
java.lang.String columnName)
tableName - Table name.columnName - Column name.public static java.util.List<java.lang.String> getTableNameListByClassNameList(java.util.List<java.lang.String> classNames)
classNames - The list of full class name with package.public static java.lang.String getTableNameByForeignColumn(java.lang.String foreignColumnName)
foreignColumnName - The foreign column name. Standard pattern is tablename_id.public static java.lang.String getIntermediateTableName(java.lang.String tableName,
java.lang.String associatedTableName)
tableName - First table name.associatedTableName - The associated table name.public static java.lang.String getGenericTableName(java.lang.String className,
java.lang.String fieldName)
className - Name of the class model.fieldName - Name of the generic type field.public static java.lang.String getGenericValueIdColumnName(java.lang.String className)
className - Name of the class model.public static java.lang.String getM2MSelfRefColumnName(java.lang.reflect.Field field)
public static boolean isIntermediateTable(java.lang.String tableName,
android.database.sqlite.SQLiteDatabase db)
tableName - Table name in database.public static boolean isGenericTable(java.lang.String tableName,
android.database.sqlite.SQLiteDatabase db)
tableName - Table name in database.public static boolean isTableExists(java.lang.String tableName,
android.database.sqlite.SQLiteDatabase db)
tableName - The table name.public static boolean isColumnExists(java.lang.String columnName,
java.lang.String tableName,
android.database.sqlite.SQLiteDatabase db)
columnName - The column name.tableName - The table name.db - Instance of SQLiteDatabase.public static java.util.List<java.lang.String> findAllTableNames(android.database.sqlite.SQLiteDatabase db)
db - Instance of SQLiteDatabase.DatabaseGenerateExceptionpublic static TableModel findPragmaTableInfo(java.lang.String tableName, android.database.sqlite.SQLiteDatabase db)
tableName - Table name.db - Instance of SQLiteDatabase.DatabaseGenerateExceptionpublic static android.util.Pair<java.util.Set<java.lang.String>,java.util.Set<java.lang.String>> findIndexedColumns(java.lang.String tableName,
android.database.sqlite.SQLiteDatabase db)
tableName - The table to find unique columns.db - Instance of SQLiteDatabase.public static boolean isFieldNameConflictWithSQLiteKeywords(java.lang.String fieldName)
fieldName - Name of the field.public static java.lang.String convertToValidColumnName(java.lang.String columnName)
KEYWORDS_COLUMN_SUFFIX to the name as new column name.columnName - Original column name.public static java.lang.String convertWhereClauseToColumnName(java.lang.String whereClause)
whereClause - where clause for query, update or delete.public static java.lang.String[] convertSelectClauseToValidNames(java.lang.String[] columns)
columns - A String array of which columns to return. Passing null will
return all columns.public static java.lang.String convertOrderByClauseToValidName(java.lang.String orderBy)
orderBy - How to order the rows, formatted as an SQL ORDER BY clause. Passing null will use
the default sort order, which may be unordered.