• No se han encontrado resultados

MANTENIMIENTO DEL AGITADOR (CONDOR: S-12/75 / S-EM/75)

Since Java is the chosen programming language, we will in this section consider ways to implement the persistence layer in Java and with free and open source solutions.

Impedance mismatch

When the underlying permanent storage is a relational database management system

(RDBMS) (the chosen database management system type for DHIS), there is an impedance mismatch between the object model of Java and the database’s relational model. There are several differences between the two models that result in the mismatch [69]:

- Objects cannot be saved or retrieved directly from a relational database. An object has, in addition to data, also identity, state and behaviour, whereas a RDBMS only stores data. - Objects are traversed using direct references, whereas RDBMSs consist of tables related

through primary and foreign keys.

- Object-oriented design “models a business process by creating real-world objects with data and behaviour”, whereas the relational modelling goal is to normalize data. - Existing RDBMS don’t have a parallel to Java’s object inheritance for data and

behaviour.

An object-relational integration therefore requires a strategy for mapping the objects to the relational model, in order for the Java objects to become persistent to the RDBMS.

JDBC API

The most common approach to Java persistence, is for application programmers to work directly with SQL and JDBC. The JDBC API defines a standard way for Java code to save and retrieve data to/from a relational database, and is the industry standard for database-

independent connectivity between the Java programming language and a wider range of databases [70].

Even though the JDBC API is simple to use and hides the complexity of many data access tasks, it can be too low level for application developers to use productively. The application developers still need to do a lot of low-level work, and the work involved in hand-coding persistence for each domain class can be considerable. Another drawback is that when requirements change, manually coded persistence always requires more attention and maintenance effort. [71] Because of this, it can be desirable to use a sophisticated

Object/Relational Mapping tool to get a level of automation, and eliminate the need for hand- coding the persistence.

iBATIS

iBATIS SQL Maps is an example of an abstraction tool that work at a slightly higher level than JDBC frameworks, and that automates much of the JDBC-to-SQL mapping. [72] iBATIS is an open source object relational mapper that couples objects with stored procedures or SQL statements using a XML descriptor [73]. Simplicity is the biggest

advantage of iBATIS, but it requires writing of RDBMS dependant SQL code. Changing the underlying persistent storage therefore requires rewriting of the SQL Maps, which can take a lot of time.

Because of our database-independency requirement, iBATIS will be insufficient because of the rewriting of mappings that is needed when the underlying persistent storage changes.

Object/Relational Mapping tools

Object/Relational Mapping (ORM) products integrate RDBMS with the object programming language capabilities, and bridges the object/relational impedance mismatch. ORM is

performed by a persistence framework. The framework takes automatically care of querying the database to retrieve e.g. Java objects, and persisting of those objects back to their

representation in tables and columns in the RDBMS. ORM is done by using metadata that describes the mapping between objects and the database. If ORM tools are used

appropriately, it can reduce the development effort and improve maintainability. ORM tools ___________________________________________________________________________

can abstract database-specific SQL dialects, and thereby improve the portability between databases. As described earlier, database-independency is an important requirement for our application, and because ORM tools can improve this we choose to use one of these tools to implement the persistence layer. [72]

An ORM solution consists of 1) “An API for performing basic CRUD (create, read, update and delete) operations on objects of persistent classes”, 2) “A language or API for specifying queries that refer to classes and properties of classes”, 3) “A facility for specifying mapping metadata” and 4) “A technique for the ORM implementation to interact with transactional objects to perform dirty checking, lazy association fetching, and other optimisation functions” [71].

We will consider ORM tools that implement a full domain model mapping, which maps a whole layer of objects and behaviours to database tables.

Enterprise JavaBeans

Enterprise JavaBeans (EJB) have in recent years been a recommended way of persisting data, but are rapidly declining in popularity. Bean-managed persistence entity beans are prevented from performing efficiently because of design flaws in the EJB 2.0 specification. Container- managed persistence is a marginally more acceptable solution, but it doesn’t represent a solution to the object/relational mismatch. [71]

The EJB 3.0 specification (requires JDK 5.0) is developed by Sun. It introduces a new lightweight Plain Old Java Object (POJO) persistence model for Java Enterprise Edition, and is modelled after successful approaches to ORM like Hibernate, JDO and TopLink (described next). In EJB 3.0, the ORM is done using Java metadata annotations and/or XML.

The EJB 3.0 specification has not been released yet, but since the EJB 3.0 public draft was released, it has gotten a lot of attention and a preliminary support in JBoss (and their persistence framework, Hibernate).

Oracle TopLink

TopLink is one of the most mature ORM products, and was first developed in 1994 for Smalltalk, but has since 1997 had its main focus on Java. Even though TopLink is now owned and supported by Oracle, it works with any major database. Because TopLink is a commercial product licensed under Oracle’s OTN6 licence, it will not meet our requirement for products to be free and open source and is therefore not of current interest.

Java Data Objects

Java Data Objects (JDO) API is a standard interface-based Java model abstraction of persistence. JDO is a specification developed by Sun, and is implemented by multiple vendors, both commercial and non-commercial. JDO is used to directly store Java domain model instances into a persistent store (database). [74]

The specification requires that vendors provide the JDO query language, named JDOQL. An application that uses JDO therefore becomes database independent, because it doesn’t have to use the query language of a specific database. JDO also provides an application that uses it, with portability to run on multiple implementations, since it is a Java API.

Some of the open source implementations of JDO are JDOInstruments, Speedo, Jakarta OJB, Triactive JDO, XORM and JPOX. All these implementations support JDOQL and a variety of the major RDBMSs on the market today.

The JDO specification will not include the EJB 3.0 specification, and they will be two

separate persistence APIs. Because of this, Sun expect that JDO developers and vendors over time will shift their focus to the new persistence API, EJB 3.0 [53].

Hibernate

Hibernate is a free and open source object/relational persistence and query framework, and provides an ODMG 3 7 interface alongside a custom API. Hibernate is released under the Lesser GNU Public License, and can thus be used in both commercial as well as free and

6 Oracle Tecnology Network

7 ODMG 3 is a specification developed by the Object Data Management Group. ODMG 3.0 is a portability specification designed to allow for portable applications that can run on more than one product.

open source applications. Hibernate only provides mapping to relational databases, but supports all major RDBMS. The framework can use native SQL, but also provides a rich query language (Hibernate Query Language - HQL) that bridges the object and relational model. Hibernate is currently the most popular ORM solution for Java. [75]

Hibernate 3.0 is Hibernate’s implementation of EJB 3.0. By combining Hibernate 3 with Hibernate Annotations, “developers can achieve an EJB 3.0 style of programming outside of the EJB 3.0 container and within standalone Java applications” [76].

Hibernate has a flexible mapping that can be declared with XML-mapping files, or with annotations. The framework provides transparency through reflection and runtime byte-code generation, and SQL generation occurs at system start-up time, something that ensures that it does not impact upon IDE debugging and incremental compile. In addition to ORM, the framework also includes other features such as transaction management and concurrency control.

JDO or Hibernate?

The table in figure 6.5 shows how the considered ORM solutions are evaluated after the criterions we decided in one of the previous chapters, and that JDO and Hibernate are evaluated as the top candidates.

Product License Community Activity Documentation Comments Candidate

Enterprise

JavaBeans Expected to be included in J2EE

- - - Not released yet. -

Oracle TopLink Commercial – thus not evaluated - - - - - Java Data

Objects Multiple vendors Vendors have active communities Stable versions are released continuously Reference manuals Web forum Commercial Difficult to find an appropriate vendor implementation X

Hibernate LGPL Active and large community Last stable version 3.1.3 released 20.03.06 Reference manual Web forum Commercial A very popular ORM framework X Figure 6.5 Evaluation of ORM solutions after the criterions for evaluating FOSS.

JDO and Hibernate both have a persistence framework with ORM that meets our requirements, that is, database-independency and they both have free and open source implementations.

One of the drawbacks by choosing to use JDO is that it is implemented by so many vendors, and it can take some time to evaluate the implementations that are most suited for an free and open source application. Hibernate only has one vendor. Another drawback with JDO is that it won’t implement the new EJB 3.0 specification, and it’s expected to be replaced with the new standard for persistence in Java over the next years. Hibernate is at this point the first persistence framework that implements EJB 3.0. Because of all this, but mainly because DHIS uses Hibernate, we chose Hibernate as the persistence framework for Joly.

6.2 Domain layer

Documento similar