Before getting started, you must have created your database tables in an Oracle database. While Workbrain is made to work with multiple types of databases, I've found the ModelGenerator only works on Oracle.
To create the DAO template files, first create a .bat file with the following command:
%JAVA_HOME%\bin\java -classpath "%WB_CLASSPATH%" com.workbrain2.platform.tool.codegen.ModelGenerator -DRIVERCLASS oracle.jdbc.driver.OracleDriver -DBURL jdbc:oracle:thin:@<dbhostname>:<port>:<dbname> -USERID workbrain -PASSWORD <password> -TABLENAME <CUSTOM_TABLE_NAME> -MODULE <moduleName> -ROOTDIR c:/<clientName>/dao -OVERWRITE > wbCodeGen.log 2>&1
Ensure the following variables are setup as described:
JAVA_HOME - Your local Java JDK location
WB_CLASSPATH - should include your wbclasspath.jar as well as the db driver jar
<CUSTOM_TABLE_NAME> - should be the name of your custom table needing Spring access
<moduleName> - should be the module name used in the last post. This is used in creating the package structure.
ROOTDIR - This is a temporary storage location for your DAO files.
Now run the bat file and if it is successful, you'll find the files that created in c:/<clientName>/dao. If unsuccessful, check the wbCodeGen.log file that was created for errors. You'll notice that all the all the Java objects were created under the com.workbrain2.<moduleName> package. That's probably not what you want, so let's just move these files now into our custom src directory under com.<clientName>.app.modules.<moduleName>. You'll also have to individually edit some of the files to fit your package naming schema. Your IDE will hopefully help you out by redlining these errors.
Also, the template XML files created can later be edited to load data in a more complex manner, but for now, we'll keep them just as they are.
Next, edit the data-config.xml to have the following, replacing the values inside the brackets as you did above:
<beans>
<bean id="<moduleName>Dao" parent="platform-daoBase"
class="com.<clientName>.app.modules.<moduleName>.db.impl.<CUSTOM_TABLE_NAME>DaoImpl">
</bean>
</beans>
The bean extends from platform-daoBase so that transactions are properly handled. Your basic data layer is now accessible via Spring.
0 comments:
Post a Comment