This section walks you through the entire process of creating an application that lets you display and modify the Employee data. See a step-by-step video of the process.
This sample application uses the MySQL database and deploys the application under the JRun application server. This tutorial assumes that you have the Eclipse IDE with the Flex Builder plug-in installed.
The complete source for the DaoFlex package and sample application is included in DaoFlex.zip (ZIP, 9.11MB).
If you unzip it to the c:\TheRiaBook\tools\DaoFlex folder, you shouldn't need to modify any settings. If you unzipped the file in a different directory, modify the build script file at examples\build.xml.
To start the code generation of a sample Employee application, open Eclipse IDE and create a new project in the Java perspective. Eclipse gives you an option to create a new project based on the preexisting Ant build script. DAOFlex includes this script in the examples subfolder of DaoFlex package.
To run the build.xml file from the examples directory:
Select the Ant task build-original.
The DaoFlex doclet automatically retrieves the database metadata related to the result of the query and combines it with the metadata provided by the Employee.java file.
By using this combined metadata and running prewritten XSLT stylesheets against it, DaoFlex will generate the following:
The entire process of generating the required files should not take more than a few seconds.
Next, let's examine the content of the examples folder, which contains the following subfolders and files:
The Employee.java file is located in the src directory and contains the source for the Employee.java class:
getEmployees(). Because getEmployees() is declared as an abstract method, it must be implemented in an Employee.java class descendent. getEmployees() has only one parameter, startDate. Notice (in Listing 1) that this parameter maps to a binding variable with the same name in the tag @daoflex:sql.getEmployees() returns a collection of DTO objects with a specified type of transferType=EmployeeDTO[]. The definition of this DTO is generated automatically.keyColumns=EMP_ID, which performs the same role as <identity property="EMP_ID"/> in the FDS descriptor.tablName=Employee attribute.pool=jdbc/theriabook. The name of the properties file must match the name used in the pool parameter. Individual methods can override this setting, and can use different connection pools.The build.xml script creates two .jar files:
The following code snippet from build.xml describes the location of the deployment directory within the JRun server that came with Flex Data Services:
<property name="deployment.web.root"
value="C:/fds/jrun4/servers/default/theriabook"/>
<property name="original.jar.destination"
value="${deployment.web.root}/WEB-INF/lib/daoflex-examples.jar"/>
<property name="generated.jar.destination"
value="${deployment.web.root}/WEB-INF/lib/daoflex-examples-
generated.jar"/>