The Database Managers, Inc.

Contact The Database Managers, Inc.

Use an RSS enabled news reader to read these articles.Use an RSS enabled news reader to read these articles.


Generate Java Code for Databases

by Curtis Krauskopf

Developing a Web-enabled database isn't easy. Changes inevitably creep into the schema after the Java classes have been coded. Likewise, propagating changes to the architecture of a class structure is very tedious. In most nontextbook situations, the net result is a set of Java classes that don't exactly reflect the database schema and lack consistency in their architecture.

Quick Facts

SourceCafe is a time-saving tool that creates Java Servlets, JavaBeans, JSP, and HTML code and generates compilable code that communicates intelligently with databases.

EJD Technologies
7825 Bayview Ave., Suite 622
Thornhill, ON L3T 7N2
PRICE: $499.00 per user

SourceCafe simplifies database-driven Web development by creating Java Servlets, JavaBeans, JavaServer Pages (JSPs), and HTML code. Its biggest strengths are its abilities to connect to any JDBC-compliant database, determine the structure of the database automatically, and then generate compilable code that is able to communicate intelligently with that database.

The SourceCafe GUI interface allows you to choose from hundreds of variations of database architectures. This feature, by itself, becomes an excellent tutorial for Java beginners that want to try different modeling techniques. Overall, the GUI is wonderfully laid out, and the oversize shortcut icons are very easy to hit (see Figure 1)

The technical support from EJD Technologies is first-rate. When I encountered a problem in which SourceCafe would throw a null exception when I tried to load the GUI, they were very responsive to my questions, and they seemed genuinely concerned that I was having trouble. After following their instructions and providing some configuration files, EJD was able to publish a patch that did fix the problem. That's what I call excellent support. And unlike most products, the online help for SourceCafe really is helpful. Almost all of the properties and their effects are clearly documented.

Figure 1. SourceCafe GUI

Although the demo version is limited to three tables, I was able to adequately test SourceCafe's ability to handle different Java data types automatically because I picked tables that consisted of a variety of common MySQL data types.

The source code generated by SourceCafe is excellent. The code contains both JavaDoc comments and regular comments. The code is well organized into blocks separated by blank lines, contains meaningful parameters, and follows standard code-formatting conventions. Best of all, it compiles without needing manual changes. Installing the code can be somewhat of a problem, though. A certain level of experience is expected from the user in being able to segregate generated files into appropriate directories. A wizard that places code in the right place would certainly be helpful in this step.

When using SourceCafe the first thing you need to determine is which of the many property settings generates code that most closely matches a database methodology that you want to use. You might find a methodology that closely matches what you want, or you might not care and just want to generate some Java code that allows you to interface with the database. In either of these cases, this product is a real time-saver and generates code automatically that is compilable without manual changes.

SourceCafe generates a preview of the source code. This feature definitely helps you determine which property settings should be used. The preview comes in two forms. In one form a static sample code page on the GUI shows a short sample of applying the most important property settings. In the other form a more comprehensive view of all generated Java source is available on a special Previews page.

A Quandary

A tool like this, though, can't possibly account for every methodology permutation that you could want. In this case, you can have your own custom code-generation engine by modifying a template called a FooBarGenerator. However, this template leads us to the biggest quandary when trying to determine whether SourceCafe is useful or not: if I don't like any of the techniques programmed into SourceCafe and I have to modify the FooBarGenerator, it's not much more difficult to add a dozen lines of Java code that interrogate a database schema, and then I don't have to use SourceCafe at all.

Using SourceCafe in the long run can be problematic. Currently, manual changes to generated code are lost the next time code is regenerated. Also, changes in the database schema cannot be imported into an existing project. Both of these limitations relegate SourceCafe to a roll of generating code for prototyping, debugging, or testing.

If your goal is to be able to generate code quickly that is able to interface with an existing database schema, SourceCafe is definitely the best tool to use. SourceCafe will pay for itself the first time you use it because it will save you the hassle of creating hand-generated source files for every table in the schema.

About the Author

This article was originally published
in the July 2003 issue of JavaPro

Curtis Krauskopf is a software engineer and the president of The Database Managers. He has been writing code professionally for over 20 years. His prior projects include multiple Web e-commerce Web applications, decompilers for the DataFlex language, aircraft simulators, an automated Y2K conversion program for over 3 million compiled DataFlex programs, and inventory control projects. This article was written by Curtis Krauskopf (email at ).

Services | Programming | Contact Us | Recent Updates
Send feedback to: