Expresso Database ObjectsExpresso Database objects use database connections to provide a means of mapping from objects to relational database tables. Database objects are similar to (and can be deployed as - see the Expresso Enterprise Project) BMP Entity Enterprise JavaBeans. They are primarily intended to provide persistence for business objects, but frequently include business logic as well. Database objects provide methods for add, update, delete, and a number of different retrieval methods. Expresso implements CRUD a la in Grand's book "Java Enterprise Pattern" Wiley 2001. The searchAndRetrieve method integrates the search process to retrieve records with a means to access the retrieved records, and is frequently used to apply some processing to a set of records.
Expresso Components Listing |
|||||||||||||
IntroductionThe system is organized around a number of database objects. A database object is simply a java object whose state can be preserved by storing in a database. In this way, a database object is analogous to a table in a relational database. The difference is that in addition to attributes (or "fields" or "columns"), the database object also has methods. For example, a database object called "Report" might have an attribute called "ReportNumber", and a method called "publish". In this way the storage of data is grouped with the actions to be performed on this data. Database Objects provide a means to map relational database tables to Java objects, as well as a way to associate the actions of business objects with their data storage. Database objects are mapped to one or more database tables in the external database (for example, Oracle). These mappings define which columns in the table store which attributes in the object, what the primary key of the table(s) are, and other information required to create a database on the external database. For example, an Invoice object can be defined as relating to a table "INVOICE" in the database, and the object then has an attribute "InvoiceNumber", "Customer", and all other columns in the table. The database object, unlike the database table, then has associated actions as well - such as "AcceptPayment" or "Ship". These actions operate directly on the data stored by the object, and bind the actions and their data together.A database object is similar to, (and soon to be compatible with) the Entity Enterprise JavaBean object. Expresso is intended to work both in the non-EJB environment as well as scale to EJB. Just as we have optional support for the 2.0 Servlet API in Expresso, we have support for both the non EJB and EJB environments. DB Objects are more "lightweight" than Entity beans, allowing applications to scale in BOTH directions. In Expresso there is the functionality to create a "database object" by reading the database & generating a java object that corresponds to a table. Then you can use the DBMaint servlet to automatically create an HTML form for add/update/delete/search capability on this new object (and the underlying table). This allows you to create basic database maintenance forms in a matter of minutes from an existing database. A database object can also span multiple
tables, so that it is a high-level object:
for example an Invoice object might also
contain data for the detail items on an invoice,
which are stored in an "INVOICEDETAIL"
table - rather than having many InvoiceDetail
database objects, which might create undue
performance load on the server. Instead,
the Invoice object would contain methods
for manipulating invoice details, such as
"AddDetail". Database objects also
make "virtual fields" easy to produce
- such as a "Total" field, which
is calculated on the fly, not stored in the
database itself. |
For more research material on mapping objects to relational databases please see Scott Ambler's paper at IBM's site. |
||||||||||||
Database Objects AdvantagesDatabase Objects provide a number of advantages, including:
By using Database Objects in your application, you can take advantage of all of these capabilities without writing additional code. Database objects provide a functionality that is similar to an extension to the Entity EJB specification, but do not require EJB's to be used, with the attendant complexities of an Application Server. Where EJB's are used, database objects can be implemented as Entity EJB's easily, allowing scaling both up AND down in size and complexity. FeaturesExpresso Framework Database ObjectsExpresso Framework provides ancestor objects for Database objects (DBObject), which provide means for defining attributes (columns to be stored in the database), defining keys, specifying relationships to other objects (referential integrity) and defining default values and valid values for columns (e.g. multi-valued columns, such as Yes and No, etc). Database objects also provide all basic operations, such as add, update, delete, search and retrieve. Methods are provided that allow objects to be searched for either by primary key or by any combination of field values (wild-card searches), and searches can be set up to return only a specific database object or a Vector of database objects. With a few lines of code you can create a database object that includes all of this functionality, allowing applications to be built extremely rapidly. Object/Relational MappingDatabase objects map capability between Java objects and a relational database (RDBMS) in a standard an highly extensible way, so that the objects themselves can be used in your application, removing the need to embed SQL code directly into your Java applications. Many enterprise applications require access to the data stored in multiple databases. The "Database Object Mapping" functionality in Expresso allows a developer to define a new DB context to describe a particular database, and then associate particular dbobjects with that DB context so that when that object is manipulated, it is always operating against the correct DB context. Expresso applications can now be run with a "split context", with one database handling the control tables (such as USERLOGIN, etc.), and one database storing the application data (like a data repository, shared by a few different Expresso applications). This allows you to create different "looks" or "views" to the same data, with completely independent logins, security groups, etc. The bottom line is that now you can specify many different database contexts, and define DBObjects as belonging to one of these contexts at the schema level. After this step, the system will always look to the right database when you use that DBObject.. Automatic GenerationDBObject code can be generated from an existing database, or the database required for an applications DB objects can be automatically created, making working with DB Objects in either new or existing environments extremely straightforward. DBMaintA servlet is supplied with Expresso that provides immediate database-maintenance capability for any database object (in fact, for any database table through the use of AutoDBObjects). This facility uses the security defined for the object and automatically generates forms to add, update, delete and search for data in the underlying database tables. SecuritySecurity can be specified for any operation on any database object in a database-independant layer of Expresso, again making your security portable between database engines and immediately usable to any Expresso application, including the DBMaint servlet discussed above. Hiding ChangesChanges made to a database table have no affect on code using the database object, as these changes only need be made to the database object itself. This decreases maintenance burden on code and enhances portability between different databases. Virtual Fields, Referential Integrity, Valid Values, Next NumberDatabase objects allow fields to be defined that are calculated by any specified method (and not stored in the database). They allow referential integrity (the relationships between objects that must be maintained (e.g. invoice master/detail) to be defined in a database-independant way, they allow a set of valid values to be defined for a field and verify field validation against that list automatically, they allow serial number fields to be automatically assigned correct values, and much more. Please see the detailed documentation in the Expresso developer's guide for details. MultiDBObjectA special extension of the DBObject, MultiDBObject, is provided which can also span multiple tables. As it is often necessary to deal with Join relationships between tables in relational databases - the MultiDBObject exists to handle this. If a DBObject is analogous to a table, a MultiDBObject is analogous to a view (of joined tables). For example an Invoice object might also contain data for the detail items
on an invoice, which are stored in an "INVOICEDETAIL" table -
rather than having many InvoiceDetail database objects, which might create
undue performance load on the server. Instead, the Invoice object would
contain methods for manipulating invoice details, such as "AddDetail".
Database objects also make "virtual fields" easy to produce -
such as a "Total" field, which is calculated on the fly, not
stored in the database itself. Schema ObjectsCollections of database objects can be gathered together into a "Schema" - for example, all of the database objects required for the Invoicing application could be gathered into a Schema. This schema can then be used to automatically generate the database tables required by each of the database objects (as well as setting up required configuration values and reports). This makes installing the application on a new server a matter of minutes, and eliminates the need to tediously create the database tables individually. AutoDBObjectThe AutoDBObject is the easiest way to get access to your database tables and can be very valuable for prototyping your application. AutoDBObject can populate its fields automatically from the schema information of its target table. This allows an AutoDBObject to be instantiated and used to access a table without any coding at all! Server-Side ObjectsThe Expresso Framework also contains server-side objects without data, similar to (and soon to be compatible with) Session Enterprise JavaBeans. Scaling to J2EEExpresso in a non-J2EE environment provides
pre-built services and components for putting
together database-based web applications.
The way we approach the J2EE environment
issue is that Expresso applications should
be able to scale, fairly "painlessly"
from a non-J2EE environment to a J2EE environment.
This actually involves very little redundancy
overall, although there is certainly some
overlap. In the areas of overlap, our goal
is to not re-invent any wheels, but to provide
app-server independant alternatives to things
that might bind an application to any single
application server implementation. ConclusionFor technical information about how to use dbobjects, please refer to the Expresso Developers Guide (EDG) or the Javadocs.
|
|
Home | Products | Services | Partners | Customers | About Us | Login | Forums | Contact Us |
Copyright © 2001-2002 Jcorporate Ltd. All rights reserved. Copyright Privacy
Last Modified: 07-Oct-02 6:57:53 PM