Tuesday, February 2, 2010

Version 1.0 is out !

Yesterday we launched version 1.0 at http://audao.spoledge.com

And what is it ?

AuDAO is a tool for Java developers.

AuDAO let's you to generate Data Access Objects (DAO) layer for Java. So instead of using directly JDBC, JDO or other database access APIs, you can easily call abstract DAO layer methods like findByPrimaryKey(), insert(), update() or delete().

Simple Example ?

Certainly. First you must configure a source file to tell AuDAO how the DAO layer should look like. The source file is a well-formed XML (see also XSD):
<?xml version="1.0" encoding="utf-8"?>
<database xmlns="http://www.spoledge.com/audao" version="1.0">
<table name="users">
<column name="user_id">
<column name="user_name">
<type max-length="32">String</type>
<column name="full_name">
<type max-length="128">String</type>
<column name="created_date">
<column name="last_login_date">
<index name="inx_user_name">
<column name="user_name"/>
<index name="inx_user_name"/>
<find name="latestLoggedIn">
<query><![CDATA[last_login_date > ?]]></query>
<query dbtype="gae"><![CDATA[lastLoginDate > :1]]></query>
<column name="last_login_date"/>

Then you use AuDAO tool to generate DAO layer - source Java files. You can either user the online generator or purchase a standalone version.

The generated DAO layer contains Data Transfer Object (DTO) - class User.java, abstract DAO interface UserDao.java and its hidden implementation UserDaoImpl.java. It also contains DaoFactory.java class which helps you to instantiate the DAO class.

The implementation classes vary by the target database type (Oracle, MySQL or Google App Engine), but the DTO and abstract DAO interface is still the same:

public long insert( User dto ) throws DaoException;
public void update( long userId, User dto) throws DaoException;
public int countAll();
public User findByPrimaryKey( long userId );
public User findByUserName( String userName );
public User[] findLatestLoggedIn( java.sql.Timestamp lastLoginDate )
public int deleteDynamic( String condition, Object... params )

How the generated DAO layer is used ?

To instantiate DAO interface just call DaoFactory methods. DaoFactory finds the right implementation class for you:
UserDao dao = DaoFactory.createUsedDao();

After that you can insert new records:
User dto = new User();
dto.setFullName("Vaclav Bartacek");
long userId = dao.insert( dto );

count or find one or more records:
int total = dao.countAll();
User user1 = dao.findByPrimaryKey( userId );
User user2 = dao.findByUserName( "vaclav" );
User[] lastHourUsers = dao.findByLatestLoggedIn( new Timestamp(System.currentTimeMillis()-3600000);

update records:
User dto2 = new User();
dto2.setLastLoginDate(new Timestamp(System.currentTimeMillis());
dao.update( userId, dto2 );

delete records (not logged within 90 days):
int totalDeleted = dao.deleteDynamic( "last_login_date < ?", new Timestamp(System.currentTimeMillis()-3600000L*24*90));

You can see that no JDBC or other database API calls are visible to you. The abstract layer allows you to develop for multiple database platforms.

No comments:

Post a Comment