The standard model for building such a site is to start with a database like MySQL, and a servlet engine like Tomcat. Then we use SQL scripts to create a database schema, and we write some JDBC code in JavaBeans to create, modify, and delete records from tables in the database. Finally we write a layer of JSP pages or servlets which execute queries and render the results along with HTML markup, invoke methods on the Beans, and dispatch forms and links to other servlets and pages.
What problems arise when working in this mode? We can group them into several categories.
ResultSet#getString(String)
), changing a query can cause downstream code to unexpectedly fail when named values can't be found.
emailAddress
column in a DB table. However, there is no mechanism for validating the elements in a form against the columns of the table. The form can easily omit data that is necessary for a valid record, or add extra data that is not stored in the database.
The database library includes built-in integration to DbConnectionBroker.
Problem | How Addressed |
---|---|
Fragile queries which can be easily broken when the database schema changes | Queries are declared in an XML document. Query results are type-checked against the database schema. Typed Java classes are generated for each query, so that changes to the database schema cause compile-time errors in Java code. |
Changes to schema cause run-time errors in code which accesses ResultSets | Dovetail generates a Java class for each query with typed and named accessor methods, so that changes to queries or the database schema cause compile-time errors rather than run-time exceptions. |
Consistent detection and reporting of database errors caused by constraint violations (e.g. primary key, unique index, NOT NULL) is difficult | Dovetail includes centralized handling of SQLExceptions which can convert them to specialized exception types such as DuplicateKeyException and MissingValueException. It also includes a standard form error reporting and rendering mechanism which makes it easy to report such errors back to the user in a human-readable way |
HTML forms which are meant to create or update database records may be mismatched with the database, or may break when the database schema is changed | Dovetail can check the declarations of form input elements against database columns. It also warns (through the error log) of any form input elements which are declared in the site XML document but not rendered in the page or servlet. And for each form it generates a Java class with a named accessor method for each input element. Dovetail also includes a standard way to inform the user which inputs are required and which are optional. |
Pages can easily render broken links to other pages. | The site XML document includes a name for each page, and a format for defining links between pages which uses the page names. Links to non-existant pages are caught at compile-time, and when JSP pages are renamed, the site links are automatically updated with a recompile. |
Form behavior must be tested via cumbersome & costly HTML testing tools | Dovetail includes an IRequestContext abstraction which insulates the pages and forms from the details of the HTTP Servlet implementation. This makes it possible to write page, query, and form tests which can be run in a single Java process, without a web server or browser. In addition, Dovetail includes an XML DTD for writing test cases which can then be run and verified by a simple Java program. |
Performance of queries used by pages and servlets is hard to analyze | Dovetail includes a simple mechanism to execute the queries defined in the site XML document and output timing information which can be used to find bottelnecks. |
Database connections are mis-managed | Any web application with any hope of resonable scalability will need to use a connection pool. However, using a connection pool introduces new problems because failure to free a connection will eventually cause the site to run out of connections and crash. Dovetail is integrated with DbConnectionBroker, and includes a standard mechanism for getting a database connection for each page request, and a standard mechanism for freeing them. |
Links can be easily broken when pages are removed or renamed, or when query parameters are required for a link to work properly. | Since all the pages, parameters, and links are described in the site XML document, Dovetail can check each link at compile-time to ensure that all links are valid, and that all required query parameters have been specified |
And here are some planned future enhancements to Dovetail:
Problem | How Addressed |
---|---|
Website load tests can be difficult, cumbersome, and expensive to set up and run | Dovetail can leverage its site testing functionality to provide a robust mechanism for load-testing and profiling. |
These libraries are distributed under a variety of licenses. You can read the licenses and see which libraries they apply to in this folder.
To run a web site, you will of course also need a web server and servlet runner. The examples included with this distribution have been tested with Jakarta-Tomcat 3.2.1. To run a real web site you'll want to front it with Apache.
And, you'll need a JDBC driver and a SQL database. While I have run Dovetail against Microsoft SQL Server 7 and PostgreSQL, it is currently fully functional and tested only with MySQL 3.23.24 and the MM MySQL JDBC driver 2.0.