|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.javalite.activejdbc.AbstractLazyList<T>
org.javalite.activejdbc.LazyList<T>
public class LazyList<T extends Model>
While this class is public, it is never instantiated directly. This class provides a number of APIs for augmenting the query.
| Field Summary |
|---|
| Fields inherited from class org.javalite.activejdbc.AbstractLazyList |
|---|
delegate |
| Constructor Summary | |
|---|---|
protected |
LazyList()
|
protected |
LazyList(boolean forPaginator,
MetaModel metaModel,
String fullQuery,
Object... params)
|
protected |
LazyList(String subQuery,
MetaModel metaModel,
Object... params)
|
| Method Summary | ||
|---|---|---|
List |
collect(String attributeName)
Collects values from a result set that correspond to a attribute name. |
|
List |
collect(String attributeName,
String filterAttribute,
Object filterValue)
|
|
Set |
collectDistinct(String attributeName)
|
|
Set |
collectDistinct(String attributeName,
String filterAttribute,
Object filterValue)
|
|
void |
dump()
Dumps contents of this list to System.out. |
|
void |
dump(OutputStream out)
Dumps content of list to a stream. |
|
protected void |
hydrate()
|
|
|
include(Class<? extends Model>... classes)
This method includes associated objects. |
|
|
limit(long limit)
This method limits the number of results in the resultset. |
|
|
load()
This method exists to force immediate load from DB. |
|
|
offset(long offset)
This method sets an offset of a resultset. |
|
|
orderBy(String orderBy)
Use this method to order results by a column. |
|
String |
toJson(boolean pretty,
String... attrs)
Generates JSON from content of this list |
|
List<Map> |
toMaps()
Converts the resultset to list of maps, where each map represents a row in the resultset keyed off column names. |
|
String |
toSql()
Same as toSql(true), see toSql(boolean); |
|
String |
toSql(boolean showParameters)
Use to see what SQL will be sent to the database. |
|
String |
toXml(boolean pretty,
boolean declaration,
String... attrs)
Generates a XML document from content of this list. |
|
String |
toXml(int spaces,
boolean declaration,
String... attrs)
Deprecated. Use toXml(boolean, boolean, String...) instead |
|
| Methods inherited from class org.javalite.activejdbc.AbstractLazyList |
|---|
add, add, addAll, addAll, clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, retainAll, set, size, subList, toArray, toArray, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
protected LazyList(String subQuery,
MetaModel metaModel,
Object... params)
protected LazyList(boolean forPaginator,
MetaModel metaModel,
String fullQuery,
Object... params)
metaModel - fullQuery - forPaginator - true is this list should not check usage of limit() and offset() methods.params - protected LazyList()
| Method Detail |
|---|
public <E extends Model> LazyList<E> limit(long limit)
List<Event> events = Event.find("mnemonic = ?", "GLUC").offset(101).limit(20).orderBy("history_event_id");
This will produce 20 records, starting from record 101. This is an efficient method, it will only retrieve records
that are necessary.
limit - how many records to retrieve.
LazyListpublic <E extends Model> LazyList<E> offset(long offset)
List events = Event.find("mnemonic = ?", "GLUC").offset(101).limit(20).orderBy("history_event_id");
This will produce 20 records, starting from record 101. This is an efficient method, it will only retrieve records
that are necessary.
offset -
LazyListpublic <E extends Model> LazyList<E> orderBy(String orderBy)
Person.find(...).orderBy("department").orderBy("age")
orderBy - order by clause. Examples: "department", "age desc", etc.
LazyListpublic <E extends Model> LazyList<E> include(Class<? extends Model>... classes)
Author, Post
and Comment, where Author has many Posts and Post
has many Comments, then this query:
Listwill generate only three queries to database - one per model. All the dependencies (includes) will be eagerly loaded, and iteration via thetodayPosts = Post.where("post_date = ?", today).include(Author.class, Comment.class);
todayPosts list will not generate any more queries,
even when a post author and comments are requested. Use this with caution as this method can allocate
a lot of memory (obviously).
This method will not follow relationships of related models, but rather only relationships of the current
one.
classes - list of dependent classes. These classes represent models with which a current model has a
relationship.
LazyListpublic List<Map> toMaps()
public String toXml(boolean pretty,
boolean declaration,
String... attrs)
pretty - pretty format (human readable), or one line text.declaration - true to include XML declaration at the topattrs - list of attributes to include. No arguments == include all attributes.
@Deprecated
public String toXml(int spaces,
boolean declaration,
String... attrs)
toXml(boolean, boolean, String...) instead
spaces - by how many spaces to indent.declaration - true to include XML declaration at the topattrs - list of attributes to include. No arguments == include all attributes.
public String toJson(boolean pretty,
String... attrs)
pretty - true if you want pretty format, false if notattrs - attributes to include, not providing any will include all.
public <E extends Model> LazyList<E> load()
Person.find("name = ?", "Smith").load();.
It is not possible to call other methods after load(). The load() method should be the last to be called in the chain:
Person.find("name = ?", "Smith").limit(10).load();.
This: will generate exception: Person.find("name = ?", "Smith").load().limit();.
public String toSql()
toSql(true), see toSql(boolean);
public String toSql(boolean showParameters)
showParameters - true to see parameter values, false not to.
protected void hydrate()
hydrate in class AbstractLazyList<T extends Model>public List collect(String attributeName)
Person models, then
you can collect first names like this:
List firstNames = Person.findAll().collect("first_name");
provided that the corresponding table has a column first_name.
Keep in mind, that if all you need is a one column data, this method of getting it is not
the most efficient (because since you are using a model, you will query all columns from a table,
but will use only one). In these cases, you might want to consider Base.firstColumn(String, Object...) and
DB.firstColumn(String, Object...).
attributeName - name of attribute to collect.
public Set collectDistinct(String attributeName)
public List collect(String attributeName,
String filterAttribute,
Object filterValue)
public Set collectDistinct(String attributeName,
String filterAttribute,
Object filterValue)
public void dump()
System.out.
public void dump(OutputStream out)
out -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||