net.java.ao
Annotation Type Preload


@Retention(value=RUNTIME)
@Target(value=TYPE)
public @interface Preload

Specifies a list of fields which should be appended to the SELECT clause every time a row of the type in question is retrieved. If the developer knows that every time an entity of a certain type is retrieved, certain fields will be accessed, this is a prime candidate for preloading. For example:

@Preload("name")
 public interface Person extends Entity {
     public String getName();
     public void setName(String name);
     
     // ...
 }
 
 // ...
 manager.find(Person.class, "age > 12");

This code will run a query something like the following:

SELECT id,name FROM people WHERE age > 12

A list of fields may also be specified:

@Preload({"firstName", "lastName"})
 public interface Person extends Entity {
     public String getFirstName();
     public void setFirstName(String firstName);
     
     public String getLastName();
     public void setLastName(String lastName);
     
     // ...
 }
 
 // ...
 manager.find(Person.class, "age > 12");

This produces a query like the following:

SELECT id,firstName,lastName FROM people WHERE age > 12

* may also be specified to force queries to load all fields. As such, @Preload is the primary mechanism provided by ActiveObjects to override its lazy-loading underpinnings.

This flag is a hint. There are still queries (such as those executed by EntityManager.findWithSQL(Class, String, String, Object...)) which will ignore the @Preload values and simply execute a vanilla query.

Author:
Daniel Spiewak
See Also:
value()

Optional Element Summary
 String[] value
          Contains the list of fields to be preloaded.
 

value

public abstract String[] value
Contains the list of fields to be preloaded. This can be a single field (e.g. "name", "*", etc) or an array of fields (e.g. {"firstName", "lastName"}).

Default:
"*"


Copyright © 2007-2011. All Rights Reserved.