public class ClusterQuery
extends java.lang.Object
| 限定符和类型 | 方法和说明 |
|---|---|
double |
average(java.lang.Class<?> modelClass,
java.lang.String column)
Calculates the average value on a given column.
|
double |
average(java.lang.String tableName,
java.lang.String column)
Calculates the average value on a given column.
|
int |
count(java.lang.Class<?> modelClass)
Count the records.
|
int |
count(java.lang.String tableName)
Count the records.
|
<T> java.util.List<T> |
find(java.lang.Class<T> modelClass)
Finds multiple records by the cluster parameters.
|
<T> java.util.List<T> |
find(java.lang.Class<T> modelClass,
boolean isEager)
It is mostly same as
find(Class) but an isEager
parameter. |
<T> T |
findFirst(java.lang.Class<T> modelClass)
Finds the first record by the cluster parameters.
|
<T> T |
findFirst(java.lang.Class<T> modelClass,
boolean isEager)
It is mostly same as
findFirst(Class) but an isEager
parameter. |
<T> T |
findLast(java.lang.Class<T> modelClass)
Finds the last record by the cluster parameters.
|
<T> T |
findLast(java.lang.Class<T> modelClass,
boolean isEager)
It is mostly same as
findLast(Class) but an isEager
parameter. |
ClusterQuery |
limit(int value)
Limits the number of rows returned by the query.
|
<T> T |
max(java.lang.Class<?> modelClass,
java.lang.String columnName,
java.lang.Class<T> columnType)
Calculates the maximum value on a given column.
|
<T> T |
max(java.lang.String tableName,
java.lang.String columnName,
java.lang.Class<T> columnType)
Calculates the maximum value on a given column.
|
<T> T |
min(java.lang.Class<?> modelClass,
java.lang.String columnName,
java.lang.Class<T> columnType)
Calculates the minimum value on a given column.
|
<T> T |
min(java.lang.String tableName,
java.lang.String columnName,
java.lang.Class<T> columnType)
Calculates the minimum value on a given column.
|
ClusterQuery |
offset(int value)
Declaring the offset of rows returned by the query.
|
ClusterQuery |
order(java.lang.String column)
Declaring how to order the rows queried from table.
|
ClusterQuery |
select(java.lang.String... columns)
Declaring to query which columns in table.
|
<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.
|
<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.
|
ClusterQuery |
where(java.lang.String... conditions)
Declaring to query which rows in table.
|
public ClusterQuery select(java.lang.String... columns)
DataSupport.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 ClusterQuery where(java.lang.String... conditions)
DataSupport.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 ClusterQuery order(java.lang.String column)
DataSupport.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 ClusterQuery limit(int value)
DataSupport.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 ClusterQuery offset(int value)
limit(int), or nothing will return.
DataSupport.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 <T> java.util.List<T> find(java.lang.Class<T> modelClass)
DataSupport.select("name").where("age > ?", "14").order("age").limit(1).offset(2)
.find(Person.class);
You can also do the same job with SQLiteDatabase like this:
getSQLiteDatabase().query("Person", "name", "age > ?", new String[] { "14" }, null, null, "age",
"2,1");
Obviously, the first way is much more semantic.find(Class, boolean).modelClass - Which table to query and the object type to return as a list.public <T> java.util.List<T> find(java.lang.Class<T> modelClass,
boolean isEager)
find(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 as a list.isEager - True to load the associated models, false not.public <T> T findFirst(java.lang.Class<T> modelClass)
DataSupport.select("name").where("age > ?", "14").order("age").limit(1).offset(2)
.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.public <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.public <T> T findLast(java.lang.Class<T> modelClass)
DataSupport.select("name").where("age > ?", "14").order("age").limit(1).offset(2)
.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.public <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.public int count(java.lang.Class<?> modelClass)
DataSupport.count(Person.class);This will count all rows in person table.
DataSupport.where("age > ?", "15").count(Person.class);
modelClass - Which table to query from by class.public int count(java.lang.String tableName)
DataSupport.count("person");
This will count all rows in person table.
DataSupport.where("age > ?", "15").count("person");
tableName - Which table to query from.public double average(java.lang.Class<?> modelClass,
java.lang.String column)
DataSupport.average(Person.class, "age");You can also specify a where clause when calculating.
DataSupport.where("age > ?", "15").average(Person.class, "age");
modelClass - Which table to query from by class.column - The based on column to calculate.public double average(java.lang.String tableName,
java.lang.String column)
DataSupport.average("person", "age");
You can also specify a where clause when calculating.
DataSupport.where("age > ?", "15").average("person", "age");
tableName - Which table to query from.column - The based on column to calculate.public <T> T max(java.lang.Class<?> modelClass,
java.lang.String columnName,
java.lang.Class<T> columnType)
DataSupport.max(Person.class, "age", int.class);You can also specify a where clause when calculating.
DataSupport.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.public <T> T max(java.lang.String tableName,
java.lang.String columnName,
java.lang.Class<T> columnType)
DataSupport.max("person", "age", int.class);
You can also specify a where clause when calculating.
DataSupport.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.public <T> T min(java.lang.Class<?> modelClass,
java.lang.String columnName,
java.lang.Class<T> columnType)
DataSupport.min(Person.class, "age", int.class);You can also specify a where clause when calculating.
DataSupport.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.public <T> T min(java.lang.String tableName,
java.lang.String columnName,
java.lang.Class<T> columnType)
DataSupport.min("person", "age", int.class);
You can also specify a where clause when calculating.
DataSupport.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.public <T> T sum(java.lang.Class<?> modelClass,
java.lang.String columnName,
java.lang.Class<T> columnType)
DataSupport.sum(Person.class, "age", int.class);You can also specify a where clause when calculating.
DataSupport.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.public <T> T sum(java.lang.String tableName,
java.lang.String columnName,
java.lang.Class<T> columnType)
DataSupport.sum("person", "age", int.class);
You can also specify a where clause when calculating.
DataSupport.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.