Autofetch

Download

Documentation

Javadoc API

News

Introduction

The goal of Autofetch is reduce the modularity penalty and programmer burden of specifying associations which should be loaded with an object query. These specifications are sometimes are called fetch profiles, prefetch directives, or joins. These specifications are an important performance optimization because they reduce the number of round-trips to a persistence store whether that be a relational database, object database, or flat file. Autofetch is a library which integrates with object persistence tools and automatically handles prefetching data. Using dynamic program profiling, Autofetch determines the right prefetch directives for each query a program executes.

For example, Autofetch integrates with Hibernate to eliminate the need for the programmer to specify fetch directives in queries and laziness in entity mappings. Autofetch currently only integrates with Hibernate. However, we are interested in integrating with other object persistence technologies including object databases and other object relation mappers.

Autofetch was developed at the University of Texas at Austin by Ali Ibrahim for research by Ali Ibrahim and William Cook. An initial implementation was used for a paper submission to the ECOOP conference in 2006. Subsequently it was rearchitected and improved for open source release. Autofetch is licensed under the LGPL license.

Why Autofetch?

Autofetch improves the modularity of your programs and makes them simpler to write. Here is a simple example:

public List getLazyEmployees() {
  ...
  // Invoke query we have built up and return list of employees
  return (List) criteria.list();
  ...
}

public void tellManagersAboutLazyEmployees() {
  for (Employee e : getLazyEmployees()) {
    sendWarningEmail(e.getManager(), e);
  }
}

public void printLazyEmployees() {
  for (Employee e : getLazyEmployees()) {
    System.out.println(e.getName());
  }
}
Here we have a single method getLazyEmployees which is invoked in two different places. In one invocation we would have liked to prefetch the manager association, while in the other no prefetch was necessary (assuming name is a primitive property of Employee). We have 3 options:
  1. Add an argument to the getLazyEmployees method which tells us what traversal will be run. This complicates our method signatures and defeats the idea of separation of concerns.
  2. Create multiple versions of the getLazyEmployees method. Unfortunately, duplicate code causes maintenance headaches.
  3. Pick one static prefetch specification to use all the time. This is probably the most popular option, but is difficult when you have recursive associations and may load a lot more data then needed for a particular use case.
Autofetch solves this problem by determining the right prefetch specification for a query in a given program context (the program stack). The problem above is exacerbated when the traversals and queries are separated in different architectural layer. The prefetch specifications create a subtle performance dependency between the different layers of the application.

References

Contact information

  1. Ali Ibrahim : aibrahim-at-cs.utexas.edu

SourceForge.net Logo