Version 1.2
The
DAO-Generator generates java code for data access tier. It follows the Data
access object design pattern and completely generates extremely fine-grained
classes.
A
typical DAO implementation has the following components:
Ø A DAO
factory class
Ø A DAO
interface
Ø A
concrete class that implements the DAO interface
Ø Data
transfer objects (value object)
Data Access Object (DAO) pattern throughout the
applications enabled us to separate low-level data access logic from business
logic. We built DAO classes that provide CRUD (create, read, update, delete)
operations for each data source.
The concrete DAO class contains the logic for accessing
data from a specific data source.
DAOs are transactional objects. Each operation by a DAO
such as; creating, updating, or deleting data is associated with a transaction.
Transaction management gets done from where the generated DAO classes are
called. All the methods of DAO (generated) gets, connection object as parameter
and uses that for data insertion, updation and deletion. By this the
transaction demarcation code gets separated from the DAO code, the caller gets
responsible to demarcate a transaction and the DAO can participate in a global
transaction. The connection object can be received from any source and used.
The
DAO-Generator connects to a database and generates the following types of files
for each entity in that database.
Ø DAO
Interface
o
Insert method
o
Update method
o
Delete method
o
Finder methods
Ø DAO
Implementation
Ø Exception
Class
Ø Value
Object (Data Transfer Object)
Ø DAO
Factory Interface
Ø DAO
Factory
Ø Primary
Key class
Ø Record
count class
Ø Record
count interface
Ø Record
count implementation
DAO-Generator currently provides support for
all major SQL database management systems.
Ø
DB2
UDB
Ø
Informix
Ø
Ingres
Ø
Oracle
Ø
MS
Sql server
Ø
MySql
Ø
MaxDB
Ø
PostgreSQL
Ø
Mimer
SQL
Ø
Mckoi
Ø
Ms
Access
The JDBC jar/zip file
name/names can be added with complete path in the run.bat file.
Example: if the
JDBC driver jar file name is xyz.jar then add xyz.jar as mentioned below.
java
-classpath %CLASSPATH%.;lib/classes111.zip;lib/xyz.jar;…
DAO-Generator-log.properties file contains logging information for the tool. User is advised to change the
default log file name “./LogDAOGenerator.log” to any other name with changed path.
In order
to generate sample code, let us create tables in Oracle database by executing
the following sql statements.
CREATE TABLE
EMP(
EMPLOYEEID NUMBER NOT NULL,
NAME VARCHAR(20) NOT NULL,
BIRTHDATE DATE,
DEPTNO NUMBER
);
CREATE TABLE
DEPT(
DEPTNO NUMBER,
NAME VARCHAR(20),
LOC VARCHAR(20)
);
ALTER TABLE
EMP ADD CONSTRAINT EMP_PK PRIMARY KEY(EMPLOYEEID);
ALTER TABLE DEPT
ADD CONSTRAINT DEPT_PK PRIMARY KEY(DEPTNO);
ALTER TABLE
EMP ADD CONSTRAINT EMP_FK FOREIGN KEY(DEPTNO)REFERENCES DEPT (DEPTNO);
Execute
the run batch file after mentioning the JDBC connection detail in
DAO-Generator.properties file.
The
package for DAO interface contains DAO interfaces and count record interfaces.
The DAO interface contains method signatures for creating, updating and
deleting record and finder methods. The record count interface contains a
single method signature for getting the total number of records in a table.
Click on the links to see the generated java code for EmpDAO interface and EmpRecordCount interface.
The package for
exception contains user defined exceptions for each entity in a database. Click
on the links to see the generated java code for EmpException and EmpRecordCountException
classes.
The third type of
generated classes and interfaces are factory interface and factory interface
implementation. Click on the links to see the generated
java code for DAOFactory and DAOFactoryImpl .
The
Value object package contains the generated classes for
Ø Entity value object,
Ø Entity primary key class
Ø Entity record count
Click on the links to see the generated
java code for Emp value object, Emp Primary key and Emp Record Count classes.
The implementation
package contains the implementation of DAO interfaces and record count
interfaces.
Click on the links to see the generated
java code for Emp DAO Implementation and Emp Record Count DAO Implementation.
Example:
Sample
code to show the use of generated code is available here for you.
.
Ø
This tool does not
generate any code for a table, which does not have a primary key
Ø
Current version of this
tool does not generate code for executing stored procedures
Hope you found this document helpful. Any
comments are welcome.
Kindly write your feedback at www.akcess.in.
This page lists the databases and JDBC drivers that has been tested with DAO-Generator. Information about what file(s) to be included in the CLASSPATH as well as information about driver classes and URL formats are also provided.
Oracle JDBC Driver |
|
The Oracle JDBC driver is part
of the Oracle software |
|
Files |
Classes111.zip |
Driver Class: |
oracle.jdbc.driver.OracleDriver |
URL: |
jdbc:oracle:thin:@<host>:<port1521>:<sid> Example:-jdbc:oracle:thin:@localhost:1521:orcl |
Links: Driver
Download |
SQL Server 2000 JDBC Driver
by Microsoft |
|
Download and install setup.exe
(Windows) |
|
Files |
mssqlserver.jar, msbase.jar, msutil.jar |
Driver Class: |
com.microsoft.jdbc.sqlserver.SQLServerDriver |
URL: |
jdbc:microsoft:sqlserver://<<host>>:<<port
number 1433>>;DatabaseName=<database> Example :- dbc:microsoft:sqlserver://HELLO:1433;DatabaseName=Northwind |
Links: Download
Driver |
MySQL JDBC Driver |
|
Files |
mysql-connector-java-3_1.1.8a.zip |
Driver Class: |
com.mysql.jdbc.Driver |
URL: |
jdbc:mysql://<machineName>:<port3306>/<databaseName> Example :- jdbc:mysql://hello:3306/test |
Links: Download Driver |
PostgreSql JDBC Driver |
|
The PostgreSql JDBC driver is part of the PostgreSql software |
|
Files |
postgresql-8.0.309.jdbc2ee.jar |
Driver Class: |
org.postgresql.Driver |
URL: |
jdbc:postgresql://<host>:<port,
default 5432>/<DB Name> Example :- jdbc:postgresql://hello:5432/test |
MaxDB JDBC Driver |
|
The MaxDB JDBC driver is part
of the MaxDB software |
|
Files |
sapdbc.jar |
Driver Class: |
com.sap.dbtech.jdbc.DriverSapDB |
URL: |
jdbc:sapdb://<database_server>[:<port>]/<database_name>[<options>] Example :- jdbc:sapdb://localhost/demodb |
Links: Download
Driver |
Mimer SQL JDBC Driver |
|
The Mimer SQL JDBC driver is
part of the Mimer SQL software |
|
Files |
mimjdbc3.jar |
Driver Class: |
com.mimer.jdbc.Driver |
URL: |
jdbc:mimer:[URL-field-list][property-list] Example :- jdbc:mimer://hello/testDB |
Ingres JDBC Driver |
|
The Ingres JDBC driver is part
of the Ingres software |
|
Files |
iijdbc.jar |
Driver Class: |
ca.ingres.jdbc.IngresDriver |
URL: |
jdbc:ingres://host:port/db;attr=value Example :- jdbc:ingres://hello:II7/testdb |
The URL parameters are as follows: host—the network name or address of the host on which the target DAS is
running. port—the network port used by the DAS . This can be a numeric port number or
an Ingres symbolic port address such as II7. db—the target database specification. Any valid Ingres database designation
can be used including vnode and server class (that is,
vnode::dbname/server_class). attr=value—optional attribute name and value pair. Multiple attribute pairs
are separated by a semi-colon. Note: Please refer the Ingres r3 Connectivity guide(comes along with the software) |
DB2 UDB JDBC Driver |
|
The DB2 UDB JDBC driver is part
of the DB2 UDB software |
|
Files |
db2jcc.jar,
db2jcc_license_cu.jar |
Driver Class: |
com.ibm.db2.jcc.DB2Driver |
URL: |
jdbc:db2://host:port_number/database_name Example :- jdbc:db2://HELLO:50000/TestDB |
The URL parameters: host
- The network name or address
of the host on which the target database server is running. port_number -The port number used to connect to the server. To determine the port number, enter the following command from the DB2 command line at the server machine: db2jstrt port# database_name -The database to which you are connecting. |
Mckoi JDBC Driver |
|
The McKoi JDBC driver is part of the Mckoi software |
|
Files |
mkjdbc.jar |
Driver Class: |
com.mckoi.JDBCDriver |
URL: |
Example :- jdbc:mckoi://localhost/ |
The URL parameters: host
- The network name or address
of the host on which the target database server is running. port -The port number used to connect to the server. The :port is optional and if not given the driver will attempt to connect to the default port of 9157.
schema-The /schema part is also
optional. If the schema part is included, the JDBCTM driver will attempt to
initialize the connection in the given schema after successfully connecting
to the database. If the schema is not included in the URL, the engine
will attempt to initialize the connection in a schema with the same name as
the username. If the engine is unable to find the schema, the connection will
default to the ' |
Informix JDBC Driver |
|
Unzip the JDBC.2.21.JC6.zip file and execute
setup.jar |
|
Files |
ifxjdbc.jar |
Driver Class: |
com.informix.jdbc.IfxDriver |
URL: |
jdbc:informix-sqli://<host>:<port>/<database>:informixserver=<dbservername> Ex:-jdbc:informix-sqli://hello:1527/stores_demo:informixserver=ol_hello1 |
Link The URL parameters: host
- The network name or address
of the host on which the target database server is running. port -The port number used to connect to the server. database -The database to which you are connecting.. dbservername -The database server name Notes: Follow the instructions provided with the downloaded file |
Ø
SQL
insert statement does not include auto-increment column
Ø
New
methods for executing dynamic query are added
Ø
More
comments in generated code are added
Ø
Additional
databases the tool supports are DB2 UDB, Informix, Ingres, MaxDB, Mimer SQL
and Mckoi
Ø
Provided
GUI
Ø
Facilitates
to generate code for selective tables
Ø
Provides
facility to generate classes for selective attributes
Ø
Provides
facility to make class name and attribute name different from table name and
field name respectively
Ø
Facilitates
to import database schema to local computer
Ø
Facilitates
to load the JDBC driver at run time
Ø
Supports
Ms Access