Class SuperLazyList<T extends Model>

All Implemented Interfaces:
Externalizable, Serializable, Iterable<T>, Collection<T>, List<T>, RandomAccess

public class SuperLazyList<T extends Model> extends LazyList<T>
The purpose of this class is to provide toMaps() method in cases of eager loading of dependencies. This class is never used by application code directly, rather as a return value from Model.getAll(..) methods.
Author:
Igor Polevoy
See Also:
Serialized Form
  • Constructor Details

    • SuperLazyList

      protected SuperLazyList()
  • Method Details

    • add

      public boolean add(T o)
      Specified by:
      add in interface Collection<T extends Model>
      Specified by:
      add in interface List<T extends Model>
      Overrides:
      add in class AbstractLazyList<T extends Model>
    • hydrate

      protected void hydrate()
      Overrides:
      hydrate in class LazyList<T extends Model>
    • load

      public <E extends Model> LazyList<E> load()
      Description copied from class: LazyList
      This method exists to force immediate load from DB. Example; 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();.
      Overrides:
      load in class LazyList<T extends Model>
      Returns:
      fully loaded list.
    • include

      public <E extends Model> LazyList<E> include(Class<? extends Model>... classes)
      Description copied from class: LazyList
      This method includes associated objects. It will eagerly load associated models of models selected by the query. For instance, if there are models Author, Post and Comment, where Author has many Posts and Post has many Comments, then this query:
       List todayPosts = Post.where("post_date = ?", today).include(Author.class, Comment.class);
       
      or:
       List todayPosts = Post.where("post_date = ?", today).include(Author.class).include(Comment.class);
       
      will generate only three queries to database - one per model. All the dependencies (includes) will be eagerly loaded, and iteration via the 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.
      Overrides:
      include in class LazyList<T extends Model>
      Parameters:
      classes - list of dependent classes. These classes represent models with which a current model has a relationship.
      Returns:
      instance of this LazyList
    • orderBy

      public <E extends Model> LazyList<E> orderBy(String orderBy)
      Description copied from class: LazyList
      Use this method to order results by a column. These methods can be chained: Person.find(...).orderBy("department").orderBy("age")
      Overrides:
      orderBy in class LazyList<T extends Model>
      Parameters:
      orderBy - order by clause. Examples: "department", "age desc", etc.
      Returns:
      instance of this LazyList
    • offset

      public <E extends Model> LazyList<E> offset(long offset)
      Description copied from class: LazyList
      This method sets an offset of a resultset. For instance, if the offset is 101, then the resultset will skip the first 100 records. It can be used in combination wit the limit like this: 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.
      Overrides:
      offset in class LazyList<T extends Model>
      Returns:
      instance of this LazyList
    • limit

      public <E extends Model> LazyList<E> limit(long limit)
      Description copied from class: LazyList
      This method limits the number of results in the resultset. It can be used in combination with the offset like this: 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.
      Overrides:
      limit in class LazyList<T extends Model>
      Parameters:
      limit - how many records to retrieve.
      Returns:
      instance of this LazyList