1.0

Table Of Contents
Chapter 31
Using a RowLoader to Load Existing Data
When you use SQLFire as a cache, you can congure a SQL data loader that is triggered to load data from a backend
repository on a miss in SQLFire.
When an incoming query request for a uniquely-identied row cannot be satised by the distributed cache, the loader
is invoked to retrieve the data from an external source. SQLFire locks the associated row and prevents concurrent
readers that are trying to fetch the same row from overloading the backend database.
Note: When a loader is congured for a table, performing a select statement against the table internally fetches
and inserts data into a SQLFire table. Because of this behavior, it is possible to receive a constraint violation
when you query a table that is congured with a loader (for example, if the loader attempts to insert data from
a backend database that violates a table constraint in SQLFire).
How SQLFire Invokes a RowLoader
SQLFire only invokes a congured RowLoader when certain conditions are met.
SQLFire invokes a congured RowLoader when:
A SELECT query is executed against a table with a WHERE clause that includes an equality (=) test for every
component that is part of the table's primary key, and
A row for the specied primary key does not exist in memory.
Note that it does not matter which columns are requested or used from the resulting rows.
For example, consider the following example table denition:
CREATE TABLE LoaderTest(id INTEGER, name VARCHAR(10), result
VARCHAR(10), primary key (id, name));
In the "LoaderTest" table, columns "id" and "name" form the primary key. Queries that use an equality test on
the primary key invoke an attached loader implementation for the table, if the data was not already available in
SQLFire. For example, these queries would invoke a loader:
SELECT * FROM LoaderTest WHERE id = 5 AND name='Joe';
SELECT result FROM LoaderTest WHERE id = 6 AND name='Sam';
However, these queries would not invoke an attached loader:
SELECT result FROM LoaderTest WHERE id < 6 AND name='Sam';
SELECT * FROM LoaderTest;
SELECT * FROM LoaderTest WHERE id = 5;
In the above examples, none of the SELECT statements use an equality test for all components of the primary
key (both "id" and "name").
175