« April 2005 | Main | June 2005 »

May 08, 2005

Using Dynamic SQL with Custom DAO

As of version 2.4 build 149 (now available for download) it is now possible to execute Custom Data Access Objects with dynamic SQL. Effectively this means that the same DTO and DAO mapping can now be used with multiple SQL statements.

A typical use-case for using Dynamic SQL statements with a Custom DAO is where a multi-table SELECT is implemented as a Custom DAO but there is a need for multiple "finder" methods.

For example, in an accounting database there would be separate tables for "Department", "Customer", and "Invoice" but a Custom DAO called "InvoiceSummary" is implemented to perform a join across these tables to bring back a list of invoices complete with department and customer details.

In the past, FireStorm/DAO would generate a single execute method with the following signature:


InvoiceSummary[] execute() throws InvoiceSummaryDaoException;

FireStorm/DAO now generates an additional method:


InvoiceSummary[] executeDynamicSQL(String sql) throws InvoiceSummaryDaoException;

Also, the SQL statement contained in the generated DAO implementation is now a protected member variable, making it easy to sublass the DAO implementation to provide additional execute methods.

An example of extending the Custom DAO:


public class InvoiceSummaryDaoExtended extends InvoiceSummaryDaoImpl {

  public InvoiceSummary[] findLargeInvoices() throws InvoiceSummaryDaoException {

    return executeDynamicSQL( SQL + " AND amount > 5000 ORDER BY amount DESC" );
  }

}

This assumes that the SQL in the generated DAO has a WHERE clause for performing the join but does not have any other SQL directives (such as ORDER BY) so it is simply a case of appending additional criteria on the end of the SQL statement.

For further information on using this new feature please feel free to email our support team.

May 04, 2005

FireStorm/DAO 2.4 build 146

FireStorm/DAO 2.4 build 146 is now available to download from:

http://www.codefutures.com/products/firestorm/download

Changes since 2.4 GA (build 99)

ReferenceDescription
20050504-1Number of lines of generated code now displayed for both J2SE and J2EE code generation modules
20050429-4Bundled JDK updated to 1.4.2_07
20050429-3Fixed bug in J2EE code generator that caused code generation to stop prematurely when generating EJB code
20050429-2Changed jndi format generated to jboss-cmp.xml to be jndi:/dsname rather than jndi:/comp/env/dsname
20050429-1Option to prefix table name with schema name is now honoured when generating jbosscmp-jdbc.xml.
20050428-3Scope of userConn member variable in custom DAO classes is not protected rather than private.
20050428-5Fixed bug that stopped FireStorm from automatically recognizing SQL Server IDENTITY columns and also caused the Auto-Increment checkbox to be disabled in the user interface.
20050428-4Project file format and user interface updated to support setting name and cardinality on foreign keys.
20050428-2Logging preferences are now always complied with (previously there were a few instances of generated code containing printStackTrace() calls despite log4j being chosen as the preference).
20050428-1Removed "Apply" button from all editors and changes are now saved automatically.
20050412-1Catalog name and schema name have now been broken out into two separate fields throughout the product, allowing better control of which tables to import, particulary with SQL Server and Sybase databases.
20050409-1Added support for seeMore databases.
20050405-1Minor changes to packaging and documentation, upgrade of Install4j to version 3.1.4.
20050404-1The Custom SQL DAO and Stored Procedure DAO editors now record changes correctly on losing focus.
20050301-1It is now possible to create a default finder for a column by right-clicking on the column node in the tree view and choosing the 'Create Default Finder' menu option.
20050329-1Fixed ArrayIndexOutOfBounds exception that occurred during validation if the project contained more stored procedures than views (problem was introduced as a result of 20050316-8).
20050324-1When generating for J2EE, choosing the Plain JSP web application, the generated code did not compile in build 118. This was due to the generated servlet being renamed from FireStormServlet to WebController. Unfortunately the change was not implemented fully. This is now resolved .
20050318-5When generating for J2EE, using JDBC persistence, and generating a session bean facade, the correct session bean descriptors are now generated in ejb-jar.xml (they were missing before unless Entity Bean persistence was selected).
20050318-4SQL scripts created by Oracle Designer can now be imported. Previously, the unterminated PROMPT commands were causing all CREATE TABLE statements to be ignored.
20050318-3Changed spelling of non-existant to non-existent in several places.
20050318-2Fixed error in Plain JSP code generation where finders that had arguments with complex types (e.g. byte[]) were generated but failed at runtime.
20050318-1Foreign keys that are incomplete once evaluation license restrictions are applied are now removed from the in-memory cloned project so that validation does not fail.
20050316-7Validation rules now check for tables with no columns
20050316-8Validation rules now check for table/view/procedure DAOs with duplicate SQL names
20050315-1During code generation, Subversion control directories (.svn) are no longer deleted if the user chooses the option to delete files in the output directory.
20050315-2Two wizard pages in the J2EE code generation wizard were missing meaningful descriptions. Descriptions now added.
20050310-1When creating new Stored Procedure DAOs and new Custom SQL DAOs via the tree view, duplicate names were being used (PROCEDURE_1 and CUSTOM_1). Defect resolved.
20050310-2Views and Procedures were not correctly being deleted from the project file when deleting via the tree view. Defect resolved.