Part I. Model Driven Architecture
3.5 Build and Deploy
Application building is done by running maven on a command prompt window. During this task, model is validated and files are generated accordingly to model elements. Figure 3.14 gives a partial list of the most important files that are mainly created in two groups of folders. Target folders contain source files that do not need manual editing and that are always overwritten. On the other hand, src folders collect files that should be edited manually and are only be generated once.
Figure 3.14 Generated files after building Generated source code could be regrouped in 13 types of files:
<Entity>.hbm.xml files define the Hibernate mappings which bind entities and database tables.
<Entity>.java files are abstract classes that implement the corresponding entity. They have to be instantiated using their own entity factory.
3 HelloWorld goes (Andro-)MDA Build and Deploy
<Entity>Impl.java files are concrete implementations of the corresponding <Entity> classes. If entity operations have been modeled, they should be implemented here.
<Entity>Dao.java files are interfaces for classes that access data of the corresponding object (DAO).
<Entity>DaoBase.java files implement methods of the *Dao interfaces and delegate business logic to concrete implementations.
<Entity>DaoImpl.java files are concrete extensions of *DaoBase classes. They will contain custom code to extend the <Entity> data access object. Particularly, they define how entities are transformed into valu e objects. *VO.java files represent embedded value objects as described in Section
3.4.1.
*Service.java files are interfaces that specify service methods.
*ServiceBase.java files implement interface methods by performing first validation on parameters and then delegating concrete implementation to the ―handle‖-starting methods of *ServiceImpl classes.
*ServiceImpl.java files are concrete extensions of *ServiceBase classes. Business logic should be implemented here.
*ControllerImpl.java files are intermediate classes to propagate data between presentation and business layer.
*.sql files allow dropping and creating database schema.
*.jsp, *.jspf and *.css files are front-end relative resources and form web pages.
Note that all files of the presentation tier, i.e. inside the web folder, are generated in the target folder. In fact, web resources do not need necessarily to be modified unless you want to customize rendering or provide more advanced Javascript functionalities. In that case, files have to be imported to the src folder before being edited in order to avoid overwriting next time the application is compiled. A source file that is present in the src folder will no more be re-generated in the target folder. Browse the HelloWorld folder located in the CD-ROM resource of Appendix E to view the source code of the HelloWorld application at different development stages.
Database can now be initialized by running the maven create-schema1 command. This takes as input the schema-create.sql file and creates the necessary tables for the entities defined before. Inversely, database schema can be dropped using the maven drop-schema1
, which executes the schema-drop.sql script. The contents of these two files are reported by Listing 3.1 and Listing 3.2.
1 -- SKIP alter table MESSAGE drop constraint MESSAGE_SENDER_FKC; 2 -- SKIP drop table MESSAGE;
1
The drop sequence instruction inside sql files does not seem to be compliant with latest PostgreSQL JDBC drivers. Removing corresponding line should solve the problem.
3 HelloWorld goes (Andro-)MDA Build and Deploy
3 -- SKIP drop table PERSON; 4 drop sequence hibernate_sequence; 5 create table MESSAGE (
6 ID BIGINT not null, 7 DATE DATE not null,
8 TEXT CHARACTER VARYING(1024) not null, 9 SENDER_FK BIGINT not null,
10 primary key (ID) 11 );
12 create table PERSON ( 13 ID BIGINT not null,
14 NAME CHARACTER VARYING(1024) not null, 15 BIRTHDAY DATE not null,
16 primary key (ID) 17 );
18 alter table MESSAGE
19 add constraint MESSAGE_SENDER_FKC 20 foreign key (SENDER_FK)
21 references PERSON;
22 create sequence hibernate_sequence;
Listing 3.1 Contents of the schema-create.sql file
1 alter table MESSAGE drop constraint MESSAGE_SENDER_FKC; 2 drop table MESSAGE;
3 drop table PERSON;
4 drop sequence hibernate_sequence;
Listing 3.2 Contents of the schema-drop.sql file
At this stage, the HelloWorld application can be deployed into Tomcat using the created war archive. Accessing application URL through your web browser will display the web page shown in Figure 3.15. As you may have noticed, the browser
has been automatically redirected to the
/HelloWorldUsecase/HelloWorldUsecase.do action. This is because the HelloWorld usecase has been specified as the application entry point with the FrontEndApplica- tion stereotype in Section 3.4.2.
The reader can observe how the tagged parameters have been rendered in the web page and also that some field have been filled with sample data. Especia lly, the messages table has been completed with extra functionalities, like sorting or data exporting. In fact, this rendering is performed by the Display tag library [Dis08] which has been integrated in the Bpm4Struts cartridg e. We will see in next Section that skeletons of method controllers have already been implemented to send dummy data to the client.
3 HelloWorld goes (Andro-)MDA Logic Implementation
Figure 3.15 The web page of the HelloWorld application after modeling