|
|
Developer DocumentationThis page information that would be useful to those that are interested in modifying or extending the functionality of MDAOG. It's a good idea to read and understand this page before attempting to make changes to MDAOG.Obtaining the Source Files via CVSThe source files for the project are available via anonymous cvs access to the SourceForge cvs repository. To obtain the source, use the following cvs commands:Using Netbeans to Develop MDAOGThe Netbeans IDE is a good, open source Java IDE. You can set up Netbeans to obtain the sources from the cvs repository and build and test MDAOG.Instructions for using Netbeans to develop MDAOG can be found here. Background/Design GoalsThe code for MDAOG started out as a test class to see what kind of metadata I could extract from the database that grew into a utility that could generate the DAO source files. When it was working I slapped on a GUI to make running it easier. The design and coding of MDAOG happened on the spot as was necessary. More emphasis was placed on architecting the generated code rather than the application that was generating it. Things could probably be a lot better, especially the Swing code. It's pretty simple and it works.The code is generated using simple string manipulation. There are some templating engines out there that could have been used but in this case I felt it would be a lot simpler to not deal with them. I wanted very little or no dependence on any other external libraries. This makes it easy for others to use and modify. The only requirement for running the application will be the MDAOG jar file and the JDBC driver. The development was done with Netbeans 4.0 and 4.1. The structure of the source code and build scripts reflect that. Netbeans uses Apache Ant build scripts that work without Netbeans as long as you have Ant to build the project. The source files are organized in three main packages that separate the main classes, output classes and gui classes. The best way to understand the MDAOG source code is to review it or the API documentation (JavaDoc output). GUI InfoSwing programming is not my strongest area. There are probably some better way of doing things in the GUI code but I managed to get it to work almost like I wanted it to. Things like the progress bars I had some difficulty with and I'm not sure that it's right but it works. This is one area I'm sure could use improvement by someone that has more experience with Swing.Ideally it would be nicer to also build a Netbeans or Eclipse plug in front ends so that MDAOG can benefit from being part of a larger IDE. That would make development of the web application a little more streamlined. Generated Code The most important aspect of the application is the structure of the code that is generated. MDAOG Generates Java code that conforms to the DAO Design Pattern. Right now, it only generates JDBC DAO classes for communicating with a PostgreSQL Database but it is possible to add functionality to MDAOG that will generate DAO objects for other JDBC databases, JDO, EJB, XML, LDAP, etc. if someone wants to build that functionality in.MDAOG creates 5 packages that contain the generated files. The packages are:
Editing the Generated CodeThe quickest, straight-forward way I could think of to allow users to add their own methods to DAO classes was to create a DAOBase that contains the generated and the DAO which extends the DAOBase. When MDAOG runs, it will overwrite the DAOBase files. If the DAO files exist it does nothing, if they don't it creates them. This also allows them to override methods if they choose to change the behavior.DAO MethodsMDAOG generates methods to insert, update, delete, select and count records in the table. The best way to understand the generated source files is to look at the generated source or to create JavaDoc files from the generated sources as they are fairly well documented. As a heads up, this is what you can expect to find in the generated DAOBase files.
|
Hosted on:
|