Figure 5.2, “Basic classes of the database layer” shows an overview of basic classes and subsets of their methods.
DriverManager
is a central part of the driver model. A single instance of this class holds references to all drivers loaded in a user application. Users can obtain reference to a database driver by calling its method getDriver(name)
. Database driver is represented as an instance of the Driver
class.
Next three classes - the Database
, Connection
and Cursor
can be found in all previous versions of the IOPC and POLiTe libraries. Their interfaces were slightly modified in IOPC 2 and implementation were moved from their subclasses to subclasses of the abstract classes (interfaces) DatabaseImpl
, ConnectionImpl
and CursorImpl
. Each database driver must implement these interfaces.
The reason for almost duplicating the Database
and Cursor
interfaces is that they are used in a decorator pattern to modify effects of the methods they provide. As you may see in Figure 5.3, “Using the decorator pattern”, the classes CachedDatabase
and CachedConnection
are designed to decorate the BasicDatabase
and BasicConnection
classes. BasicConnection
and BasicDatabase
implement the basic database independent functionality, mostly the connection and cursor management. Database dependent operations are delegated to database drivers using the -Impl
interface classes. The CachedDatabase
and CachedConnection
classes decorate behaviour of several fundamental methods such as commit or rollback by performing a caching related operations - e.g. writing modified local copies to a database before commit.
Example 5.1, “Connecting to an Oracle database in IOPC 2” shows how a connection to Oracle database instance "XE" can be made. First we create only a simple connection allowing only basic SQL statements to be executed, then we release this connection and create a new one using the CachedConnection
decorator class. This connection can be used with the O/R mapping features, see later.
Figure 5.4, “Oracle 10g database driver extensions and driver features” illustrates how the driver features and extensions are used by the Oracle 10g database driver.