Creator Data Matrix 2d barcode in Java MIDDLEGEN

Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.

www.OnBarcode.com

Having <ejbdoclet> generate all the EJB support code and descriptors is great, but the common practice of going from a database to the EJB models takes time. By using XDoclet, we can save an enormous amount of effort by simply creating a single Java file for each bean with the appropriate tags. Perhaps you already have an existing database that you want to reverse engineer into entity beans. This is precisely the purpose of a great tool called Middlegen, created by Aslak Helles y, who is also a member of the XDoclet development team. See figure 14.3.

The <middlegen> task works in two modes, based on the gui switch: classes may be generated automatically or interactively (the latter through the user interface shown in figure 14.3). Our database schema simply has two tables, Product and Order, which are linked with a one-to-many relationship. The Middlegen task creates a single-entity bean class for each table processed. The code contains the necessary @tags to be further processed by XDoclet s <ejbdoclet> task. Listing 14.3 shows a sample class generated for our Product table.

The next step is to have XDoclet process these generated files and build all of the other necessary pieces, including vendor-specific deployment descriptors. In section 14.8, a complete build incorporating Middlegen, XDoclet, compilation, and building the EJB JAR and EAR files is shown.

MIDDLEGEN

Middlegen in practice Middlegen is still in its infancy and has a few notable issues that may preclude out-ofthe-box use: It is geared to EJB 2.0, so it does not generate EJB 1.x-compliant code. At the time of writing, only WebLogic and JBoss vendor-specific tags are being generated, although this will change quickly. We ran into issues with JDBC drivers and were unable to use Hypersonic SQL and Microsoft Access.3 Middlegen was unable to determine the table relationships with those databases. Some JDBC metadata calls that Middlegen uses are unsupported by at least a few drivers. We finally got our example relationships working against Microsoft SQL Server 2000. Even if Middlegen does not work out of the box for a particular database or EJB container vendor, the time invested in tweaking Middlegen s freely available source code or XDoclet entity bean template is likely to be well spent. The combination of Middlegen and XDoclet is a great benefit to EJB developers. There are many database EJB reverse-engineering tools available, but the open-source and easily tweakable nature of these two products make them very attractive. The community support available is unlikely to be matched by any commercial product vendors. It s quite common for developers to write their own code generators, but it might just be time to roll up your sleeves and contribute to efforts such as Middlegen instead! To use Middlegen effectively, we recommend that you explore its capabilities gradually, starting with a few tables in a simple database. If you send it up against a 30table database with lots of relations between the entries, you will be intimidated by the amount of code that it generates. The generated code should be left alone, if at all possible; if you do change it, copy it away to safety first. You do not want an automated tool stomping on your source.