Java Reference
In-Depth Information
<flushOnExecute statement="insertPerson"/>
<flushOnExecute statement="deletePerson"/>
</cacheModel>
That completes the custom cache implementation. Remember, though, this was a
simple example. You probably want to look into other caching alternatives to plug
into iBATIS , as writing your own may cost you more time than writing the rest of
your application!
12.4 Configuring an unsupported DataSource
iBATIS includes support for the most common DataSource alternatives, including
JNDI (application server-managed DataSource ), Apache DBCP , and a built-in
DataSource implementation called SimpleDataSource . You also have the option of
adding support for additional DataSource implementations.
To configure a new DataSource implementation, you need to provide iBATIS
with a factory that will supply the framework with an instance of the DataSource .
This factory class must implement the DataSourceFactory interface, which looks
like this:
public interface DataSourceFactory {
public void initialize(Map map);
public DataSource getDataSource();
}
The DataSourceFactory has only two methods: one to initialize the DataSource ,
and another to access the DataSource . The initialize() method provides a Map
instance which contains configuration information, such as the JDBC driver name,
database URL , username, and password.
The getDataSource() method simply needs to return the configured Data-
Source . This is a simple interface, and the implementation only gets as complex as
the DataSource implementation you plug into it. The following is an example
taken from the iBATIS source code. This is the DataSourceFactory for the Simple-
DataSource implementation. As you can see, it truly is “simple.”
public class SimpleDataSourceFactory
implements DataSourceFactory {
private DataSource dataSource;
public void initialize(Map map) {
Search WWH ::




Custom Search