EQUIP2 WebApp Defining the Dataspace

Chris Greenhalgh, 2007-01-30

Introduction

After creating a skeleton web application (in a suitable source repository) and specifying the applicaiton (first version, at least), the first EQUIP2-specific job is to define the Dataspace, in particular to

Defining the Data Classes

EQUIP2 can be viewed as (in part) an Object database. In a Web application the Hibernate-based dataspace implementation is normally used, so that the object dataspace is backed by a relational database (using Hibernate's Object to Relational mapping capabilities). Normally each class that may be persisted in the dataspace is defined using a simple XML schema, and XLST transformations are then used to generate a corresponding Java Bean, EQUIP2 helper class and Hibernate mapping file.

This is documented in the core EQUIP2 document Simple_Bean_Generator.html

For this tutorial application, from the specification EQUIP2_WebApp_Tutorial_Application_Specification.html three Data classes are required:

Note that:

Updating the Build

See also EQUIP2_WebApp_Configuring_and_Building.html

Generating Data Classes and Support

The 'generate' target of the project build.xml must be edited to generate the Java Beans, EQUIP2 helper classes and Hibernate mapping files for the specified data classes, e.g.

	    <java fork="true" classname="equip2.tools.j2se.xsltTransform" failonerror="true">
<classpath refid="classpath_tools"/>
<arg value="${equip2home}/etc/bean2java.xsl"/>
<arg value="etc/equip2.webapptutorial.db.Player.xml"/>
<arg value="${generated}/equip2/webapptutorial/db/Player.java"/>
<arg value="${equip2home}/etc/bean2javahelper.xsl"/>
<arg value="etc/equip2.webapptutorial.db.Player.xml"/>
<arg value="${generated}/equip2/webapptutorial/db/Player_helper.java"/>
<arg value="${equip2home}/etc/bean2hibernatehbm.xsl"/>
<arg value="etc/equip2.webapptutorial.db.Player.xml"/>
<arg value="${generated}/equip2/webapptutorial/db/Player.hbm.xml"/>
</java>

When the application is rebuilt (in particular the generate target) then the generated files should be output under generated/, e.g. for Player:

Configuring Hibernate

The main Hibernate configuration file, etc/hibernate.cfg.xml, must be edited to include the generate Hibernate mapping files, e.g.:
		<mapping resource="equip2/webapptutorial/db/Player.hbm.xml"/>
<mapping resource="equip2/webapptutorial/db/Topic.hbm.xml"/>
<mapping resource="equip2/webapptutorial/db/Comment.hbm.xml"/>

If the web application is now rebuilt and deployed Hibernate, at startup, should add the corresponding tables (player, topic and comment, as specified in the Bean XML files) to the database; use a standard database client to check (e.g. "list tables;", "describe table player;")

Customising the Web Form interface

In order to use the standard web form interface effectively some data-class-specific configuration is required; this is done in the webform configuration JSP webapp/WEB-INF/jsp/db/configuration.jsp.

The various facilities of the standard EQUIP2 database interface forms are described in EQUIP2_WebApp_Standard_Dataspace_Web_Interface.html

Minimal Customisation

At the minimum the classes to be shown in the web form must be specified:

  	_allClassNames = new String[] {
// all class names to appear on forms go here
"equip2.webapptutorial.db.Player",
"equip2.webapptutorial.db.Topic",
"equip2.webapptutorial.db.Comment"
};

The various class index pages should now give access to those classes in the database; try http://.../equip2tutorial/db/class_index.htm

Note that with further configuration, below, it is possible to set a default package name, so that they can appear as just 'Player', 'Topic' and 'Comment'.

JSP Customisation

The database forms for adding and editing individual objects in the dataspace can be significantly further customised in configuration.jsp, in particular to:

Spring Component Configuration

Further configuration is possible of the Java Controllers that underly the database forms interface. This is done in the Spring db servlet configuration, WEB-INF/db-servlet.xml: (see also EQUIP2_WebApp_Configuring_and_Building.html)
The web forms can also be configured to automatically allocate new (internally unique) IDs to objects that are added in the web forms with no ID specified; this is configured in WEB-INF/applicationContext.xml, via the idAllocations property of the dbIdAllocator bean, e.g. in this application we wish to have Player IDs of the form 'P123':
  <bean id="dbIdAllocator" class="equip2.spring.DbGenericIDAllocator">
...
<property name="idAllocations">
<map>
<entry key="equip2.webapptutorial.db.Player">
<bean class="equip2.spring.IDAllocationBean">
<property name="fixedPrefix" value="P"/>
</bean>
</entry>
...

Changes

2007-01-30