|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractList<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 | |
|---|---|
protected ArrayList<T> |
delegate
|
| Fields inherited from class java.util.AbstractList |
|---|
modCount |
| Constructor Summary | |
|---|---|
protected |
LazyList()
|
protected |
LazyList(boolean forPaginator,
MetaModel metaModel,
String fullQuery,
Object[] params)
|
protected |
LazyList(String subQuery,
Object[] params,
MetaModel metaModel)
|
| Method Summary | ||
|---|---|---|
void |
add(int index,
T element)
|
|
boolean |
add(T o)
|
|
boolean |
addAll(Collection c)
|
|
boolean |
addAll(int index,
Collection c)
|
|
void |
clear()
|
|
List |
collect(String columnName)
Collects values from a result set that correspond to a column name. |
|
List |
collect(String columnName,
String filterColumn,
Object filterValue)
|
|
boolean |
contains(Object o)
|
|
boolean |
containsAll(Collection c)
|
|
void |
dump()
Dumps contents of this list to System.out. |
|
void |
dump(OutputStream out)
Dumps content of list to a stream. |
|
T |
get(int index)
|
|
int |
hashCode()
This is only to test caching. |
|
protected void |
hydrate()
|
|
|
include(Class<? extends Model>... classes)
Use this method includes associated objects. |
|
int |
indexOf(Object o)
|
|
boolean |
isEmpty()
|
|
Iterator<T> |
iterator()
|
|
int |
lastIndexOf(Object o)
|
|
|
limit(long limit)
This method limits the number of results in the resultset. |
|
ListIterator<T> |
listIterator()
|
|
ListIterator<T> |
listIterator(int index)
|
|
|
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. |
|
T |
remove(int index)
|
|
boolean |
remove(Object o)
|
|
boolean |
removeAll(Collection c)
|
|
boolean |
retainAll(Collection c)
|
|
T |
set(int index,
T element)
|
|
int |
size()
|
|
List<T> |
subList(int fromIndex,
int toIndex)
|
|
Object[] |
toArray()
|
|
|
toArray(T[] a)
|
|
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 |
toString()
|
|
String |
toXml(int spaces,
boolean declaration,
String... attrs)
Generates a XML document from content of this list. |
|
| Methods inherited from class java.util.AbstractList |
|---|
equals, removeRange |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected ArrayList<T extends Model> delegate
| Constructor Detail |
|---|
protected LazyList(String subQuery,
Object[] params,
MetaModel metaModel)
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(int spaces,
boolean declaration,
String... attrs)
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()
public List collect(String columnName)
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...).
columnName - name of column to collect.
public List collect(String columnName,
String filterColumn,
Object filterValue)
public T get(int index)
get in interface List<T extends Model>get in class AbstractList<T extends Model>public int size()
size in interface Collection<T extends Model>size in interface List<T extends Model>size in class AbstractCollection<T extends Model>public boolean isEmpty()
isEmpty in interface Collection<T extends Model>isEmpty in interface List<T extends Model>isEmpty in class AbstractCollection<T extends Model>public boolean contains(Object o)
contains in interface Collection<T extends Model>contains in interface List<T extends Model>contains in class AbstractCollection<T extends Model>public Iterator<T> iterator()
iterator in interface Iterable<T extends Model>iterator in interface Collection<T extends Model>iterator in interface List<T extends Model>iterator in class AbstractList<T extends Model>public Object[] toArray()
toArray in interface Collection<T extends Model>toArray in interface List<T extends Model>toArray in class AbstractCollection<T extends Model>public <T> T[] toArray(T[] a)
toArray in interface Collection<T extends Model>toArray in interface List<T extends Model>toArray in class AbstractCollection<T extends Model>public boolean add(T o)
add in interface Collection<T extends Model>add in interface List<T extends Model>add in class AbstractList<T extends Model>public boolean remove(Object o)
remove in interface Collection<T extends Model>remove in interface List<T extends Model>remove in class AbstractCollection<T extends Model>public boolean containsAll(Collection c)
containsAll in interface Collection<T extends Model>containsAll in interface List<T extends Model>containsAll in class AbstractCollection<T extends Model>public boolean addAll(Collection c)
addAll in interface Collection<T extends Model>addAll in interface List<T extends Model>addAll in class AbstractCollection<T extends Model>
public boolean addAll(int index,
Collection c)
addAll in interface List<T extends Model>addAll in class AbstractList<T extends Model>public boolean removeAll(Collection c)
removeAll in interface Collection<T extends Model>removeAll in interface List<T extends Model>removeAll in class AbstractCollection<T extends Model>public boolean retainAll(Collection c)
retainAll in interface Collection<T extends Model>retainAll in interface List<T extends Model>retainAll in class AbstractCollection<T extends Model>public void clear()
clear in interface Collection<T extends Model>clear in interface List<T extends Model>clear in class AbstractList<T extends Model>
public T set(int index,
T element)
set in interface List<T extends Model>set in class AbstractList<T extends Model>
public void add(int index,
T element)
add in interface List<T extends Model>add in class AbstractList<T extends Model>public T remove(int index)
remove in interface List<T extends Model>remove in class AbstractList<T extends Model>public int indexOf(Object o)
indexOf in interface List<T extends Model>indexOf in class AbstractList<T extends Model>public int lastIndexOf(Object o)
lastIndexOf in interface List<T extends Model>lastIndexOf in class AbstractList<T extends Model>public ListIterator<T> listIterator()
listIterator in interface List<T extends Model>listIterator in class AbstractList<T extends Model>public ListIterator<T> listIterator(int index)
listIterator in interface List<T extends Model>listIterator in class AbstractList<T extends Model>
public List<T> subList(int fromIndex,
int toIndex)
subList in interface List<T extends Model>subList in class AbstractList<T extends Model>public int hashCode()
hashCode in interface Collection<T extends Model>hashCode in interface List<T extends Model>hashCode in class AbstractList<T extends Model>public String toString()
toString in class AbstractCollection<T extends Model>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 | |||||||||