public class Operator
extends java.lang.Object
initialize(Context) method to make LitePal ready to
work. Also you can switch the using database by calling use(LitePalDB) and useDefault()
methods.| 构造器和说明 |
|---|
Operator() |
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
aesKey(java.lang.String key) |
static double |
average(java.lang.Class<?> modelClass,
java.lang.String column)
Calculates the average value on a given column.
|
static double |
average(java.lang.String tableName,
java.lang.String column)
Calculates the average value on a given column.
|
static AverageExecutor |
averageAsync(java.lang.Class<?> modelClass,
java.lang.String column)
已过时。
|
static AverageExecutor |
averageAsync(java.lang.String tableName,
java.lang.String column)
已过时。
|
static void |
beginTransaction()
Begins a transaction in EXCLUSIVE mode.
|
static int |
count(java.lang.Class<?> modelClass)
Count the records.
|
static int |
count(java.lang.String tableName)
Count the records.
|
static CountExecutor |
countAsync(java.lang.Class<?> modelClass)
已过时。
|
static CountExecutor |
countAsync(java.lang.String tableName)
已过时。
|
static int |
delete(java.lang.Class<?> modelClass,
long id)
Deletes the record in the database by id.
|
static int |
deleteAll(java.lang.Class<?> modelClass,
java.lang.String... conditions)
Deletes all records with details given if they match a set of conditions
supplied.
|
static int |
deleteAll(java.lang.String tableName,
java.lang.String... conditions)
Deletes all records with details given if they match a set of conditions
supplied.
|
static UpdateOrDeleteExecutor |
deleteAllAsync(java.lang.Class<?> modelClass,
java.lang.String... conditions)
已过时。
|
static UpdateOrDeleteExecutor |
deleteAllAsync(java.lang.String tableName,
java.lang.String... conditions)
已过时。
|
static UpdateOrDeleteExecutor |
deleteAsync(java.lang.Class<?> modelClass,
long id)
已过时。
|
static boolean |
deleteDatabase(java.lang.String dbName)
Delete the specified database.
|
static void |
endTransaction()
End a transaction.
|
static <T> T |
find(java.lang.Class<T> modelClass,
long id)
Finds the record by a specific id.
|
static <T> T |
find(java.lang.Class<T> modelClass,
long id,
boolean isEager)
It is mostly same as
find(Class, long) but an isEager
parameter. |
static <T> java.util.List<T> |
findAll(java.lang.Class<T> modelClass,
boolean isEager,
long... ids)
It is mostly same as
findAll(Class, long...) but an
isEager parameter. |
static <T> java.util.List<T> |
findAll(java.lang.Class<T> modelClass,
long... ids)
Finds multiple records by an id array.
|
static <T> FindMultiExecutor<T> |
findAllAsync(java.lang.Class<T> modelClass,
boolean isEager,
long... ids)
已过时。
|
static <T> FindMultiExecutor<T> |
findAllAsync(java.lang.Class<T> modelClass,
long... ids)
已过时。
|
static <T> FindExecutor<T> |
findAsync(java.lang.Class<T> modelClass,
long id)
已过时。
|
static <T> FindExecutor<T> |
findAsync(java.lang.Class<T> modelClass,
long id,
boolean isEager)
已过时。
|
static android.database.Cursor |
findBySQL(java.lang.String... sql)
Runs the provided SQL and returns a Cursor over the result set.
|
static <T> T |
findFirst(java.lang.Class<T> modelClass)
Finds the first record of a single table.
|
static <T> T |
findFirst(java.lang.Class<T> modelClass,
boolean isEager)
It is mostly same as
findFirst(Class) but an isEager
parameter. |
static <T> FindExecutor<T> |
findFirstAsync(java.lang.Class<T> modelClass)
已过时。
|
static <T> FindExecutor<T> |
findFirstAsync(java.lang.Class<T> modelClass,
boolean isEager)
已过时。
|
static <T> T |
findLast(java.lang.Class<T> modelClass)
Finds the last record of a single table.
|
static <T> T |
findLast(java.lang.Class<T> modelClass,
boolean isEager)
It is mostly same as
findLast(Class) but an isEager
parameter. |
static <T> FindExecutor<T> |
findLastAsync(java.lang.Class<T> modelClass)
已过时。
|
static <T> FindExecutor<T> |
findLastAsync(java.lang.Class<T> modelClass,
boolean isEager)
已过时。
|
static android.database.sqlite.SQLiteDatabase |
getDatabase()
Get a writable SQLiteDatabase.
|
static DatabaseListener |
getDBListener() |
static android.os.Handler |
getHandler()
Get the main thread handler.
|
static void |
initialize(android.content.Context context)
Initialize to make LitePal ready to work.
|
static <T> boolean |
isExist(java.lang.Class<T> modelClass,
java.lang.String... conditions)
Check if the specified conditions data already exists in the table.
|
static FluentQuery |
limit(int value)
Limits the number of rows returned by the query.
|
static <T extends LitePalSupport> |
markAsDeleted(java.util.Collection<T> collection)
Provide a way to mark all models in collection as deleted.
|
static <T> T |
max(java.lang.Class<?> modelClass,
java.lang.String columnName,
java.lang.Class<T> columnType)
Calculates the maximum value on a given column.
|
static <T> T |
max(java.lang.String tableName,
java.lang.String columnName,
java.lang.Class<T> columnType)
Calculates the maximum value on a given column.
|
static <T> FindExecutor<T> |
maxAsync(java.lang.Class<?> modelClass,
java.lang.String columnName,
java.lang.Class<T> columnType)
已过时。
|
static <T> FindExecutor<T> |
maxAsync(java.lang.String tableName,
java.lang.String columnName,
java.lang.Class<T> columnType)
已过时。
|
static <T> T |
min(java.lang.Class<?> modelClass,
java.lang.String columnName,
java.lang.Class<T> columnType)
Calculates the minimum value on a given column.
|
static <T> T |
min(java.lang.String tableName,
java.lang.String columnName,
java.lang.Class<T> columnType)
Calculates the minimum value on a given column.
|
static <T> FindExecutor<T> |
minAsync(java.lang.Class<?> modelClass,
java.lang.String columnName,
java.lang.Class<T> columnType)
已过时。
|
static <T> FindExecutor<T> |
minAsync(java.lang.String tableName,
java.lang.String columnName,
java.lang.Class<T> columnType)
已过时。
|
static FluentQuery |
offset(int value)
Declaring the offset of rows returned by the query.
|
static FluentQuery |
order(java.lang.String column)
Declaring how to order the rows queried from table.
|
static void |
registerDatabaseListener(DatabaseListener listener)
Register a listener to listen database create and upgrade events.
|
static <T extends LitePalSupport> |
saveAll(java.util.Collection<T> collection)
Saves the collection into database.
|
static <T extends LitePalSupport> |
saveAllAsync(java.util.Collection<T> collection)
已过时。
|
static FluentQuery |
select(java.lang.String... columns)
Declaring to query which columns in table.
|
static void |
setTransactionSuccessful()
Marks the current transaction as successful.
|
static <T> T |
sum(java.lang.Class<?> modelClass,
java.lang.String columnName,
java.lang.Class<T> columnType)
Calculates the sum of values on a given column.
|
static <T> T |
sum(java.lang.String tableName,
java.lang.String columnName,
java.lang.Class<T> columnType)
Calculates the sum of values on a given column.
|
static <T> FindExecutor<T> |
sumAsync(java.lang.Class<?> modelClass,
java.lang.String columnName,
java.lang.Class<T> columnType)
已过时。
|
static <T> FindExecutor<T> |
sumAsync(java.lang.String tableName,
java.lang.String columnName,
java.lang.Class<T> columnType)
已过时。
|
static int |
update(java.lang.Class<?> modelClass,
android.content.ContentValues values,
long id)
Updates the corresponding record by id with ContentValues.
|
static int |
updateAll(java.lang.Class<?> modelClass,
android.content.ContentValues values,
java.lang.String... conditions)
Updates all records with details given if they match a set of conditions
supplied.
|
static int |
updateAll(java.lang.String tableName,
android.content.ContentValues values,
java.lang.String... conditions)
Updates all records with details given if they match a set of conditions
supplied.
|
static UpdateOrDeleteExecutor |
updateAllAsync(java.lang.Class<?> modelClass,
android.content.ContentValues values,
java.lang.String... conditions)
已过时。
|
static UpdateOrDeleteExecutor |
updateAllAsync(java.lang.String tableName,
android.content.ContentValues values,
java.lang.String... conditions)
已过时。
|
static UpdateOrDeleteExecutor |
updateAsync(java.lang.Class<?> modelClass,
android.content.ContentValues values,
long id)
已过时。
|
static void |
use(LitePalDB litePalDB)
Switch the using database to the one specified by parameter.
|
static void |
useDefault()
Switch the using database to default with configuration by litepal.xml.
|
static FluentQuery |
where(java.lang.String... conditions)
Declaring to query which rows in table.
|
public static android.os.Handler getHandler()
public static void initialize(android.content.Context context)
context - Application context.public static android.database.sqlite.SQLiteDatabase getDatabase()
public static void beginTransaction()
public static void endTransaction()
public static void setTransactionSuccessful()
public static void use(LitePalDB litePalDB)
litePalDB - The database to switch to.public static void useDefault()
public static boolean deleteDatabase(java.lang.String dbName)
dbName - Name of database to delete.public static void aesKey(java.lang.String key)
public static FluentQuery select(java.lang.String... columns)
LitePal.select("name", "age").find(Person.class);
This will find all rows with name and age columns in Person table.columns - A String array of which columns to return. Passing null will
return all columns.public static FluentQuery where(java.lang.String... conditions)
LitePal.where("name = ? or age > ?", "Tom", "14").find(Person.class);
This will find rows which name is Tom or age greater than 14 in Person
table.conditions - A filter declaring which rows to return, formatted as an SQL
WHERE clause. Passing null will return all rows.public static FluentQuery order(java.lang.String column)
LitePal.order("name desc").find(Person.class);
This will find all rows in Person table sorted by name with inverted
order.column - How to order the rows, formatted as an SQL ORDER BY clause.
Passing null will use the default sort order, which may be
unordered.public static FluentQuery limit(int value)
LitePal.limit(2).find(Person.class);This will find the top 2 rows in Person table.
value - Limits the number of rows returned by the query, formatted as
LIMIT clause.public static FluentQuery offset(int value)
limit(int), or nothing will return.
LitePal.limit(1).offset(2).find(Person.class);This will find the third row in Person table.
value - The offset amount of rows returned by the query.public static int count(java.lang.Class<?> modelClass)
LitePal.count(Person.class);This will count all rows in person table.
LitePal.where("age > ?", "15").count(Person.class);
modelClass - Which table to query from by class.@Deprecated public static CountExecutor countAsync(java.lang.Class<?> modelClass)
public static int count(java.lang.String tableName)
LitePal.count("person");
This will count all rows in person table.
LitePal.where("age > ?", "15").count("person");
tableName - Which table to query from.@Deprecated public static CountExecutor countAsync(java.lang.String tableName)
public static double average(java.lang.Class<?> modelClass,
java.lang.String column)
LitePal.average(Person.class, "age");You can also specify a where clause when calculating.
LitePal.where("age > ?", "15").average(Person.class, "age");
modelClass - Which table to query from by class.column - The based on column to calculate.@Deprecated public static AverageExecutor averageAsync(java.lang.Class<?> modelClass, java.lang.String column)
public static double average(java.lang.String tableName,
java.lang.String column)
LitePal.average("person", "age");
You can also specify a where clause when calculating.
LitePal.where("age > ?", "15").average("person", "age");
tableName - Which table to query from.column - The based on column to calculate.@Deprecated public static AverageExecutor averageAsync(java.lang.String tableName, java.lang.String column)
public static <T> T max(java.lang.Class<?> modelClass,
java.lang.String columnName,
java.lang.Class<T> columnType)
LitePal.max(Person.class, "age", int.class);You can also specify a where clause when calculating.
LitePal.where("age > ?", "15").max(Person.class, "age", Integer.TYPE);
modelClass - Which table to query from by class.columnName - The based on column to calculate.columnType - The type of the based on column.@Deprecated public static <T> FindExecutor<T> maxAsync(java.lang.Class<?> modelClass, java.lang.String columnName, java.lang.Class<T> columnType)
public static <T> T max(java.lang.String tableName,
java.lang.String columnName,
java.lang.Class<T> columnType)
LitePal.max("person", "age", int.class);
You can also specify a where clause when calculating.
LitePal.where("age > ?", "15").max("person", "age", Integer.TYPE);
tableName - Which table to query from.columnName - The based on column to calculate.columnType - The type of the based on column.@Deprecated public static <T> FindExecutor<T> maxAsync(java.lang.String tableName, java.lang.String columnName, java.lang.Class<T> columnType)
public static <T> T min(java.lang.Class<?> modelClass,
java.lang.String columnName,
java.lang.Class<T> columnType)
LitePal.min(Person.class, "age", int.class);You can also specify a where clause when calculating.
LitePal.where("age > ?", "15").min(Person.class, "age", Integer.TYPE);
modelClass - Which table to query from by class.columnName - The based on column to calculate.columnType - The type of the based on column.@Deprecated public static <T> FindExecutor<T> minAsync(java.lang.Class<?> modelClass, java.lang.String columnName, java.lang.Class<T> columnType)
public static <T> T min(java.lang.String tableName,
java.lang.String columnName,
java.lang.Class<T> columnType)
LitePal.min("person", "age", int.class);
You can also specify a where clause when calculating.
LitePal.where("age > ?", "15").min("person", "age", Integer.TYPE);
tableName - Which table to query from.columnName - The based on column to calculate.columnType - The type of the based on column.@Deprecated public static <T> FindExecutor<T> minAsync(java.lang.String tableName, java.lang.String columnName, java.lang.Class<T> columnType)
public static <T> T sum(java.lang.Class<?> modelClass,
java.lang.String columnName,
java.lang.Class<T> columnType)
LitePal.sum(Person.class, "age", int.class);You can also specify a where clause when calculating.
LitePal.where("age > ?", "15").sum(Person.class, "age", Integer.TYPE);
modelClass - Which table to query from by class.columnName - The based on column to calculate.columnType - The type of the based on column.@Deprecated public static <T> FindExecutor<T> sumAsync(java.lang.Class<?> modelClass, java.lang.String columnName, java.lang.Class<T> columnType)
public static <T> T sum(java.lang.String tableName,
java.lang.String columnName,
java.lang.Class<T> columnType)
LitePal.sum("person", "age", int.class);
You can also specify a where clause when calculating.
LitePal.where("age > ?", "15").sum("person", "age", Integer.TYPE);
tableName - Which table to query from.columnName - The based on column to calculate.columnType - The type of the based on column.@Deprecated public static <T> FindExecutor<T> sumAsync(java.lang.String tableName, java.lang.String columnName, java.lang.Class<T> columnType)
public static <T> T find(java.lang.Class<T> modelClass,
long id)
Person p = LitePal.find(Person.class, 1);The modelClass determines which table to query and the object type to return. If no record can be found, then return null.
find(Class, long, boolean).modelClass - Which table to query and the object type to return.id - Which record to query.@Deprecated public static <T> FindExecutor<T> findAsync(java.lang.Class<T> modelClass, long id)
public static <T> T find(java.lang.Class<T> modelClass,
long id,
boolean isEager)
find(Class, long) but an isEager
parameter. If set true the associated models will be loaded as well.
modelClass - Which table to query and the object type to return.id - Which record to query.isEager - True to load the associated models, false not.@Deprecated public static <T> FindExecutor<T> findAsync(java.lang.Class<T> modelClass, long id, boolean isEager)
public static <T> T findFirst(java.lang.Class<T> modelClass)
Person p = LitePal.findFirst(Person.class);Note that the associated models won't be loaded by default considering the efficiency, but you can do that by using
findFirst(Class, boolean).modelClass - Which table to query and the object type to return.@Deprecated public static <T> FindExecutor<T> findFirstAsync(java.lang.Class<T> modelClass)
public static <T> T findFirst(java.lang.Class<T> modelClass,
boolean isEager)
findFirst(Class) but an isEager
parameter. If set true the associated models will be loaded as well.
modelClass - Which table to query and the object type to return.isEager - True to load the associated models, false not.@Deprecated public static <T> FindExecutor<T> findFirstAsync(java.lang.Class<T> modelClass, boolean isEager)
public static <T> T findLast(java.lang.Class<T> modelClass)
Person p = LitePal.findLast(Person.class);Note that the associated models won't be loaded by default considering the efficiency, but you can do that by using
findLast(Class, boolean).modelClass - Which table to query and the object type to return.@Deprecated public static <T> FindExecutor<T> findLastAsync(java.lang.Class<T> modelClass)
public static <T> T findLast(java.lang.Class<T> modelClass,
boolean isEager)
findLast(Class) but an isEager
parameter. If set true the associated models will be loaded as well.
modelClass - Which table to query and the object type to return.isEager - True to load the associated models, false not.@Deprecated public static <T> FindExecutor<T> findLastAsync(java.lang.Class<T> modelClass, boolean isEager)
public static <T> java.util.List<T> findAll(java.lang.Class<T> modelClass,
long... ids)
List<Person> people = LitePal.findAll(Person.class, 1, 2, 3);
long[] bookIds = { 10, 18 };
List<Book> books = LitePal.findAll(Book.class, bookIds);
Of course you can find all records by passing nothing to the ids
parameter.
List<Book> allBooks = LitePal.findAll(Book.class);Note that the associated models won't be loaded by default considering the efficiency, but you can do that by using
findAll(Class, boolean, long...).
The modelClass determines which table to query and the object type to
return.modelClass - Which table to query and the object type to return as a list.ids - Which records to query. Or do not pass it to find all records.@Deprecated public static <T> FindMultiExecutor<T> findAllAsync(java.lang.Class<T> modelClass, long... ids)
public static <T> java.util.List<T> findAll(java.lang.Class<T> modelClass,
boolean isEager,
long... ids)
findAll(Class, long...) but an
isEager parameter. If set true the associated models will be loaded as well.
modelClass - Which table to query and the object type to return as a list.isEager - True to load the associated models, false not.ids - Which records to query. Or do not pass it to find all records.@Deprecated public static <T> FindMultiExecutor<T> findAllAsync(java.lang.Class<T> modelClass, boolean isEager, long... ids)
public static android.database.Cursor findBySQL(java.lang.String... sql)
Cursor cursor = LitePal.findBySQL("select * from person where name=? and age=?", "Tom", "14");
sql - First parameter is the SQL clause to apply. Second to the last
parameters will replace the place holders.public static int delete(java.lang.Class<?> modelClass,
long id)
LitePal.delete(Person.class, 1);This means that the record 1 in person table will be removed.
modelClass - Which table to delete from by class.id - Which record to delete.@Deprecated public static UpdateOrDeleteExecutor deleteAsync(java.lang.Class<?> modelClass, long id)
public static int deleteAll(java.lang.Class<?> modelClass,
java.lang.String... conditions)
LitePal.deleteAll(Person.class, "name = ? and age = ?", "Tom", "14");This means that all the records which name is Tom and age is 14 will be removed.
modelClass - Which table to delete from by class.conditions - A string array representing the WHERE part of an SQL
statement. First parameter is the WHERE clause to apply when
deleting. The way of specifying place holders is to insert one
or more question marks in the SQL. The first question mark is
replaced by the second element of the array, the next question
mark by the third, and so on. Passing empty string will update
all rows.@Deprecated public static UpdateOrDeleteExecutor deleteAllAsync(java.lang.Class<?> modelClass, java.lang.String... conditions)
public static int deleteAll(java.lang.String tableName,
java.lang.String... conditions)
LitePal.deleteAll("person", "name = ? and age = ?", "Tom", "14");
This means that all the records which name is Tom and age is 14 will be
removed.tableName - Which table to delete from.conditions - A string array representing the WHERE part of an SQL
statement. First parameter is the WHERE clause to apply when
deleting. The way of specifying place holders is to insert one
or more question marks in the SQL. The first question mark is
replaced by the second element of the array, the next question
mark by the third, and so on. Passing empty string will update
all rows.@Deprecated public static UpdateOrDeleteExecutor deleteAllAsync(java.lang.String tableName, java.lang.String... conditions)
public static int update(java.lang.Class<?> modelClass,
android.content.ContentValues values,
long id)
ContentValues cv = new ContentValues();
cv.put("name", "Jim");
LitePal.update(Person.class, cv, 1);
This means that the name of record 1 will be updated into Jim.modelClass - Which table to update by class.values - A map from column names to new column values. null is a valid
value that will be translated to NULL.id - Which record to update.@Deprecated public static UpdateOrDeleteExecutor updateAsync(java.lang.Class<?> modelClass, android.content.ContentValues values, long id)
public static int updateAll(java.lang.Class<?> modelClass,
android.content.ContentValues values,
java.lang.String... conditions)
ContentValues cv = new ContentValues();
cv.put("name", "Jim");
LitePal.update(Person.class, cv, "name = ?", "Tom");
This means that all the records which name is Tom will be updated into
Jim.modelClass - Which table to update by class.values - A map from column names to new column values. null is a valid
value that will be translated to NULL.conditions - A string array representing the WHERE part of an SQL
statement. First parameter is the WHERE clause to apply when
updating. The way of specifying place holders is to insert one
or more question marks in the SQL. The first question mark is
replaced by the second element of the array, the next question
mark by the third, and so on. Passing empty string will update
all rows.@Deprecated public static UpdateOrDeleteExecutor updateAllAsync(java.lang.Class<?> modelClass, android.content.ContentValues values, java.lang.String... conditions)
public static int updateAll(java.lang.String tableName,
android.content.ContentValues values,
java.lang.String... conditions)
ContentValues cv = new ContentValues();
cv.put("name", "Jim");
LitePal.update("person", cv, "name = ?", "Tom");
This means that all the records which name is Tom will be updated into
Jim.tableName - Which table to update.values - A map from column names to new column values. null is a valid
value that will be translated to NULL.conditions - A string array representing the WHERE part of an SQL
statement. First parameter is the WHERE clause to apply when
updating. The way of specifying place holders is to insert one
or more question marks in the SQL. The first question mark is
replaced by the second element of the array, the next question
mark by the third, and so on. Passing empty string will update
all rows.@Deprecated public static UpdateOrDeleteExecutor updateAllAsync(java.lang.String tableName, android.content.ContentValues values, java.lang.String... conditions)
public static <T extends LitePalSupport> boolean saveAll(java.util.Collection<T> collection)
LitePal.saveAll(people);If the model in collection is a new record gets created in the database, otherwise the existing record gets updated.
for (Person person : people) {
person.save();
}
So when your collection holds huge of models, saveAll(Collection) is the better choice.collection - Holds all models to save.@Deprecated public static <T extends LitePalSupport> SaveExecutor saveAllAsync(java.util.Collection<T> collection)
public static <T extends LitePalSupport> void markAsDeleted(java.util.Collection<T> collection)
collection - Collection of models which want to mark as deleted and clear their save state.public static <T> boolean isExist(java.lang.Class<T> modelClass,
java.lang.String... conditions)
modelClass - Which table to check by class.conditions - A filter declaring which data to check. Exactly same use as
where(String...), except null conditions will result in false.public static void registerDatabaseListener(DatabaseListener listener)
public static DatabaseListener getDBListener()