S2Dao: The most powerfull database access framework

S2Dao is a database access framework based on the Seasar2 and AOP solution. Today, I introduce this great framework to you.

S2Dao makes DAO from Java interface using AOP at runtime. We have to write only Java interface such as:

public interface UserInfoDao {
  public List<UserInfo> selectAllUserInfos();
  public void insertUserInfo(UserInfo userInfo);
  public void updateUserInfo(UserInfo userInfo);
  public void deleteUserInfo(UserInfo userInfo);

SQLs are generated automatically by the entity definition (which is specified by @S2Dao) and DAO method names. So we don't have to write SQL in simple cases such as CRUD to the single table.

Of course, we can use complex SQL instead of auto generated SQL. We can specify WHERE and ORDER BY using @Query:

public List<UserInfo> selectUserInfoByDeptId(int deptId); 

And using @Sql, we can specify all parts of SQL:

public int getCount(); 

These are parts of S2Dao great features. If we have to use complex and large SQL, we can write it as an external SQL file named "classname_methodname.sql" and S2Dao also support dynamic query using SQL comment. I will talk about them as another entries.

0 件のコメント: