|
|
|
|
|
|
|
|
Introduction |
|
|
|
Communicating with databases is a base functionality in
enterprise systems, but it represents a non-trivial issue when is treated
in development phases. In common cases a relational database is used,
and access is given to Java™ applications through the JDBC connector API.
However, this technology just offers a set of “query-level”
functions that not solve the so called “impedance problem”,
i.e. the inherent incompatibility between objects and relational databases,
product of different approaches used in both models to treat identities,
identifiers and associations between entities.
As consequence of this lack of transparency in moving from the object-oriented
model to the relational schema (and vice versa), developers usually adopt
its own -and then- non-standard mapping operations. Furthermore, because
of the access to database isn’t generally the main functionality
of the system under development (it is not what the final user will appreciate),
adopted solutions rely on lightweight designs, that don’t cover
all the aspects that a reliable and scalable application should address.
The Persist framework is our Java™ instrument proposed for accessing relational
databases under Object-Oriented perspective. It is composed by a set of
classes built on the JDBC connection API, that offers high-level representation
of a database schema. Persist allows developers to omit writing SQL statements,
in favor of using an object oriented representation of the request. In
this way, programmers can access relational tables as they were object
collections, records as specific instances, and fields as their attributes.
Persist is organized in two levels:
- The meta-level, associated to the Data Definition Language (DDL)
of a database, where resides the representation of the relational schema,
that is, tables, relations, attributes and specific database-vendor
data types. Thanks to this information, Persist can be used to automatically
produce the database schema in a DBMS
- The statement-level, associated to the Data Manipulation Language
(DML) of a database, allows the creation and execution of queries exploiting
an object-oriented perspective. These queries can be executed in a transaction-oriented
context, with commit and rollback support
|
|
|
|
The Object model of the framework |
|
|
|
|
|
The dictionary of Classes |
|
|
DbConnection
It contains information about the connection and the type of database.
It holds the dictionary that maps standard SQL data types and specific
database vendor types. It encapsulates low-level operations for opening
and closing connections, and implements transaction management basic methods.
Relationships
- Aggregated by DbStatement
|
|
DbStatement
This is the base class used to build different types of database queries
under an objectified approach. It allows the construction of simple queries
(e.g. simple selects) or complex ones (e.g. nested selections with join
between tables). The DbStatement class encapsulates both an instance of
DbConnection and an instance of JDBC statement. This class also declares
the transaction management methods –internally mapped to DbConnection’s
transactional methods- that are inherited by the statement objects.
Relationships
- Generalization of WhereStatement
- Generalization of CallStatement
- Generalization of InsertStatement
- Generalization of SchemaStatement
- Aggregates DbConnection
|
SchemaStatement
It implements operations for creating and destroying tables and indexes
in the database.
Relationships
- Specialization of DbStatement
|
InsertStatement
It implements the operation “insert” in the database.
Relationships
- Specialization of DbStatement
|
CallStatement
It allows the invocation of DBMS “stored procedures”.
Relationships
- Specialization of DbStatement
|
WhereStatement
This is an abstract class used to enable filtering conditions (associated
to the “where” clause in a SQL statement) in classes that
perform accesses to the database (SelectStatement, UpdateStatement and
DeleteStatement).
Relationships
- Generalization of SelectStatement
- Generalization of DeleteStatement
- Generalization of UpdateStatement
- Specialization of DbStatement
|
DeleteStatement
It implements the operation for deleting one or more records from the
database. The filtering mechanism of the records to delete is inherited
from WhereStatement. Operations of commit/rollback are also available
(inherited from DbStatement).
Relationships
- Specialization of WhereStatement
|
SelectStatement
It implements the operation for selecting fields or entire records from
the database. The filtering mechanism of the records to select is inherited
from WhereStatement. Operations of commit/rollback are also available
(inherited from DbStatement).
Relationships
- Specialization of WhereStatement
|
UpdateStatement
It implements the operation for updating fields or entire records in
the database. The filtering mechanism of the records to update is inherited
from WhereStatement. Operations of commit/rollback are also available
(inherited from DbStatement).
Relationships
- Specialization of WhereStatement
|
DbRecordSelection
It represents the SQL statement for selection of entire records or just
subsets of fields. It inherits from WhereStatement.
Relationships
- Specialization of WhereStatement
|
DbField
DbField is one the most important classes because it pertains to the
meta-level of the framework. Each instance of DbField describes a single
table field value and its type (name, type, length).
Relationships
- Aggregated by DbRecord
- Generalization of DbReferenceField
|
DbRecord
Correspond to the Object Oriented representation of a database record.
A DbRecord is composed of a collection of DbFields that represent a database
table structure. Operations for selecting, inserting, deleting, creating
tables, dropping tables are implemented in this class.
Relationships
- Generalization of DbIdRecord
- Generalization of DbReferenceRecord
- Generalization of DbCounter
- Aggregates DbField
|
DbIdRecord
It is an extension of DbRecord used to represent records with an internal
numerical identifier. It adds to the inherited methods operations for
updating data, and for managing internal identifiers (including the search
operation).
Relationships
- Generalization of DbRelazRecord
- Specialization of DbRecord
|
DbCounter
It represents a service table used for automatic generation of internal
identifiers for all the tables inheriting from DbIdRecord.
Relationships
- Specialization of DbRecord
|
DbReferenceField
It corresponds to the Object Oriented representation of “foreign
keys” that maps references to records pertaining to other tables.
Relationships
- Specialization of DbField
|
DbReferenceRecord
It is a class used to support two-way references between classes.
Relationships
- Specialization of DbRecord
|
DbRelazRecord
It represents all relational tables with an internal numerical identifier
key.
Relationships
- Specialization of DbIdRecord
|