Annotation Type 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:
-
Optional Element Summary
Optional Elements -
Field Summary
Fields
-
Field Details
-
ALL
- See Also:
-
-
Element Details
-
value
String[] valueContains 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:
- {"*"}
-