Skip to content

22. Conclusion

Let’s review what we’ve done in this document. We examined two [DAO] layers using one of the following two architectures:

The [DAO1] layer was implemented with Spring JDBC, and the [DAO2] layer with Spring JPA. The [DAO1] and [DAO2] layers implemented the same [IDAO] interface, which made it possible towrite a single test [JUnitTestDao] to test both layers [DAO];

Once this was done, we exposed the [IDAO] interface on the web as follows:

  • In [1], the [IDAO] layer was exposed on the web through a [2] web layer implemented by Spring MVC. It is indeed the [IDAO] interface that is exposed, and we have built two versions of the web service depending on whether this interface is implemented with a [DAO-JDBC] or [DAO-JPA-JDBC] architecture;
  • In [B], a remote client uses the URL exposed by the web service, which provide access to the methods of the [IDAO-serveur] layer. We ensured that the [DAO-Client] [3] layer implements the [IDAO-serveur] [1] interface. This allowed us to reuse the same [JUnitTestDao] test that had already been used twice;
  • in [3], the [DAO-client] layer was implemented with Spring RestTemplate;

With that done, we secured access to the web service:

  • In [5], the client’s request HTTP passes through an authentication layer implemented with Spring Security;

With that done, we have evolved the previous architecture into the following:

  1. In [3], the client application is itself a web application served by the web server [4]. The client application displays a [5] form in the browser that allows querying the URL of the secure web service. Access to the secure web service is achieved through a layer implemented in Javascript. This architecture implements what are known as cross-domain requests:
    1. the web service presents URL in the form [http://machine1:port1/];
    2. the client web application is downloaded from a URL to a [http://machine2:port2/]. If [http://machine2:port2/] is not identical to [http://machine1:port1/] (same machine, same port), then the client browser will block HTTP calls from the [DAO-client-js] layer. To resolve this issue, the web service must allow cross-domain requests;

The projects presented have been tested with the following six databases:

  1. MySQL 5 Community Edition;
  2. SQL Server 2014 Express;
  3. PostgreSQL 9.4;
  4. Oracle Express 11g Release 2;
  5. IBM DB2 Express-C 10.5;
  6. Firebird 2.5.4;

For each of these SGBD, four different [DAO] layers have been developed:

  • a layer implemented with Spring JDBC;
  • a layer implemented with Spring JPA and the Hibernate provider JPA;
  • a layer implemented with Spring JPA and the JPA EclipseLink provider;
  • a layer implemented with Spring JPA and the provider JPA OpenJPA;

Thus, a set of twenty-four different configurations was presented. A major effort was made to factorize the code:

  1. most of the code is written only once. It is based on two Maven configuration projects:
    1. one configures the JDBC layer;
    2. the other configures the JPA layer;

The Maven configuration project for the JDBC [1] layer of a specific SGBD allows:

  • import the driver archive JDBC;
  • to define the access credentials for the database being used and the various SQL commands that the [DAO1] layer will send to the JDBC driver. Although SQL is standardized, portability issues have arisen primarily due to the presence in queries of table/column names that turned out to be prohibited keywords in certain SGBD (table ROLES for DB2, column PASSWORD for Firebird). Furthermore, although a column name is normally case-insensitive (upper/lowercase), we encountered an issue with PostgreSQL regarding the ID column of the tables’ primary key. It required that it be named id in lowercase;

The three Maven configuration projects for the JPA, [2], and SGBD layers of a specific SGBD allow:

  1. import the archive for the JPA implementation;
  2. configure the JPA implementation used for the specific connected SGBD. In fact, it is the JPA layer that sends the SQL commands to the JDBC layer. To be effective, it must know the SGBD in order to send it the SQL commands that it will recognize. These commands can utilize the SQL that owns this SGBD, as well as its specific characteristics (data types, sequences, triggers, procedures, automatic generation of primary keys, etc.);

We thus created twenty-four Maven configuration projects (4 configurations × 6 SGBD) on which all other database operation projects were based. In the diagrams above, since the [DAO1] and [DAO2] layers provide the same interface, the 24 configurations of the two architectures above were tested using the single test class [JUnitTestDao]. Once these architectures were verified, there were no further issues:

  1. the Maven project for publishing the database on the web is based on these two architectures. There are therefore also 24 possible configurations here;
  2. the Maven project for securing access to the web service builds on the previous project and also has 24 possible configurations;
  3. finally, the Maven project enabling cross-domain requests to the secure web service builds on the previous project and also has 24 possible configurations;

Although this document does not cover all the capabilities of the Java language or all its areas of application, it can be used as a learning resource for the language. Readers who have mastered the content of this course will have reached an “advanced Java” level in both the use of the language and the Spring framework. They can then continue their Java training with the following books:

  • [Spring MVC et Thymeleaf par l'exemple] [http://tahe.developpez.com/java/springmvc-thymeleaf], which continues the exploration of the Spring ecosystem by introducing its "web programming" branch (MVC). It uses a more complex database than the one studied here;
  • [Tutoriel AngularJS / Spring MVC] [http://tahe.developpez.com/angularjs-spring4], which presents a client/server web architecture, where the client is implemented using the [AngularJS] framework and the server using [Spring MVC];
  • [Introduction à Java EE] [http://tahe.developpez.com/java/javaee], which moves away from the Spring ecosystem to a web architecture based on JSF (Java Server Faces) and EJB (Enterprise Java Bean);
  • [Introduction à la programmation des tablettes Android] [http://tahe.developpez.com/android/exemples-intellij-aa], which describes a client/server architecture, where the client is an Android tablet programmed in Java and the server is a web service implemented by Spring MVC;