Java DAO 框架:robotarm-dao
openkk
13年前
一、描述:
它是一个新颖的、轻量级的、独立的、易于使用的Java DAO Framework
二、目的:
- 定义简单
- 写DAO层不必像Hibernate或ibatis那样为每个数据实体都创建一个新的配置文件。:)
- 只需定义一个接口,集中了对数据库的操作、程序的调用、数据源的使用等。:)
- 使用简单
- 使用时只需为数据实体创建一个接口,不需对其实现 :)
- 使用主或从主库,指定数据源都在此接口中。 :)
- 不用拼写复杂的sql
- 不用程序拼写sql将参数加入进来,框架对参数自动填充处理。:)
- 除支持标准sql外,另外增加了动态操作语法:if/else、for 循环等。:)
- 主从分离
- 根据查找或更新操作自动的判断使用主或从库。 :)
- 执行sql时动态的切换主从数据库,不必为分库烦恼。 :)
- 也可在执行强制的使用主或从(暂未实现)。 :(
@DAO(catalog = "c1") public interface MailDAO { // 查询 @SQL(value = "select * from mail") public List<Mail> queryAll() throws Throwable; @SQL(value = "select * from mail where id=:1") public List<Mail> queryById(long id) throws Throwable; @SQL(value = "select * from mail where id in (:1)") public List<Mail> queryInIds(List<Long> ids) throws Throwable; @SQL(value = "select * from mail where mail_user = :1.mailUser and mail_smtp=:1.mailSmtp") public List<Mail> queryByUser(Mail mail) throws Throwable; // 更新 @SQL(value = "update mail set mail_user=:1, mail_password=:2") public UpdateResult upAll(String mailUser, String mailPassword) throws Throwable; @SQL(value = "update mail set mail_user='sunnymoon', mail_password='passwordhe' where id=:1") public UpdateResult upById(long id) throws Throwable; @SQL(value = "update mail set mail_password='passwordhe' where mail_name=:1") public UpdateResult upByName(String name) throws Throwable; // 插入 @SQL(value = "insert into mail (mail_user,mail_password,mail_smtp,mail_ssl) values ('ad','ff','dd','1')") public UpdateResult addMail() throws Throwable; @SQL(value = "insert into mail (mail_user,mail_password,mail_smtp) values (:1.mailUser, :1.mailPassword, :1.mailSmtp)") public UpdateResult addMail(Mail mail) throws Throwable; @SQL(value = "insert into mail (mail_user,mail_password,mail_smtp) values #for(mail in :1) { #if(:current){,} (:mail.mailUser, :mail.mailPassword, :mail.mailSmtp)}") public UpdateResult addMails(Collection<Mail> mails) throws Throwable; // 删除 @SQL(value = "delete from mail where id=:1") public UpdateResult delById(long id) throws Throwable; @SQL(value = "delete from mail where id in (:1)") public UpdateResult delInIds(List<Long> ids) throws Throwable; }