Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * Copyright 2007 Daniel Spiewak
  * Licensed under the Apache License, Version 2.0 (the "License"); 
  * you may not use this file except in compliance with the License. 
  * You may obtain a copy of the License at
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and
 * limitations under the License.

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:

 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(java.lang.Class,java.lang.String,java.lang.String,java.lang.Object[])) which will ignore the @Preload values and simply execute a vanilla query.

Daniel Spiewak
See also:
public @interface Preload
    String ALL = "*";

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"}).
    String[] value() default {};
New to GrepCode? Check out our FAQ X