传统关系型数据库定义了四种数据操作:1.插入Insert2.删除Delete3.更新Update4.查询QueryContentDAOpublic ContentDAO(java.sql.Connection conn)insertpublic int insert(ng.String sql,java.util.List values)throws .sinosoft.frame.exception.GeneralException增加一条记录到数据库通用DAO提供访问数据库的一般方法,直接在外部写SQL 语句Overrides:insert in class BaseDAOParameters:sql- sql 一个标准INSERT SLQ语句,For example: insert into table_name values(?,?,?)values - 一个LIST对象,包含将要插入的值,即一条数据。
数据值的顺序要与SQL 语句?的顺序一致Returns:被插入的行数Throws:java.sql.SQLException - 如果数据库发生异常,SQLException将被抛出.sinosoft.frame.exception.GeneralExceptionbatchInsertpublic int[] batchInsert(ng.String sql,java.util.List values)throws .sinosoft.frame.exception.GeneralException 批量增加数据到数据库通用DAO提供访问数据库的一般方法,直接在外部写SQL 语句Overrides:batchInsert in class BaseDAOParameters:sql - 一个标准INSERT SLQ语句,For example: insert into table_name values(?,?,?) values- 将要插入数据库的数据,他是一组二维数据。
LIST对象中的一个元素还是一个LIST对象。
内层的LIST对象代表一条数据。
Returns:返回每条数据插入数据库的情况Throws:java.sql.SQLException - 如果数据库发生异常,SQLException将被抛出.sinosoft.frame.exception.GeneralExceptionupdatepublic int update(ng.String sql,java.util.List values)throws .sinosoft.frame.exception.GeneralException更新数据库的一条记录通用DAO提供访问数据库的一般方法,直接在外部写SQL 语句Overrides:update in class BaseDAOParameters:sql - 一个标准的UPDA TE SQL语句,For example: update table_name set field1=?, field2=? where field1=?values - 一个LIST对象,包含将要更新的数据和条件Returns:被更新的行数Throws:java.sql.SQLException - 如果数据库发生异常,SQLException将被抛出.sinosoft.frame.exception.GeneralExceptionbatchUpdatepublic int[] batchUpdate(ng.String sql,java.util.List values)throws .sinosoft.frame.exception.GeneralException 批量更新数据库的数据通用DAO提供访问数据库的一般方法,直接在外部写SQL 语句Overrides:batchUpdate in class BaseDAOParameters:sql - 一个标准的UPDA TE SQL语句,For example: update table_name set field1=?, field2=? where field1=?values- 将要更新数据库的数据,他是一组二维数据。
LIST对象中的一个元素还是一个LIST对象。
内层的LIST对象代表一条数据和条件。
Returns:被更新的行数的数组Throws:java.sql.SQLException - 如果数据库发生异常,SQLException将被抛出.sinosoft.frame.exception.GeneralExceptiondeletepublic int delete(ng.String sql,java.util.List values)throws .sinosoft.frame.exception.GeneralException删除数据库的数据通用DAO提供访问数据库的一般方法,直接在外部写SQL语句Overrides:delete in class BaseDAOParameters:sql - 一个标准的DELETE SQL语句,For example: delete from table_name where field1=?values - 一个LIST对象,包含将要删除的数据的查询条件Returns:被删除数据的行数Throws:java.sql.SQLException - 如果数据库发生异常,SQLException将被抛出.sinosoft.frame.exception.GeneralExceptionsearchpublic javax.sql.RowSet search(ng.String sql,java.util.List values,int rowsPerPage,int page)throws java.sql.SQLException分页查询,目前只支持ORCALE 通用DAO提供访问数据库的一般方法,直接在外部写SQL语句Parameters:sql - 一个标准的SELECT SQL语句,For example: select * from table_name where field1=?values - 一个LIST对象,包含查询条件rowsPerPage - 每页行数page - 第几页Returns:返回一个RowSet结果集Throws:java.sql.SQLException - 如果数据库发生异常,SQLException将被抛出searchpublic javax.sql.RowSet search(ng.String sql,java.util.List values)throws java.sql.SQLException一般查询通用DAO提供访问数据库的一般方法,直接在外部写SQL语句Overrides:search in class BaseDAOParameters:sql - 一个标准的SELECT SQL语句,For example: select * from table_name where field1=?values - 一个LIST对象,包含查询条件Returns:返回一个RowSet结果集Throws:java.sql.SQLException - 如果数据库发生异常,SQLException将被抛出toSortpublic java.util.ArrayList toSort(java.util.ArrayList aList)列表排序Parameters:aList -Returns:addValueObjectpublic int addValueObject(ValueObject valueObject)throws .sinosoft.frame.exception.GeneralException 增加一条记录到数据库。
类似ENTITY BEANS的CREATE方法,只不过使用该方法可以向任何表里增加数据,通用DAO提供访问数据库的特有方法Parameters:valueObject - 增加数据,要求对应数据库中非空字段必须被付值Returns:返回增加行数,正常是1Throws:.sinosoft.frame.exception.GeneralExceptionaddValueObjectpublic int addValueObject(java.util.List valueObjectList)throws .sinosoft.frame.exception.GeneralException 批量增加记录到数据库。
通用DAO提供访问数据库的特有方法Parameters:valueObjectList - 增加数据集合Throws:.sinosoft.frame.exception.GeneralException- 如果数据库发生异常,GeneralException将被抛出updateVOByPrimaryKeypublic int updateVOByPrimaryKey(ValueObject valueObject)throws .sinosoft.frame.exception.GeneralException 根据主键更新值对象对象,主键字段必须被赋值。
如果存在同步字段,更新时会检测同步字段的值,如果数据被更新和删除,将报错。
Parameters:valueObject -Returns:更新行数Throws:.sinosoft.frame.exception.GeneralException updateVOByPrimaryKeypublic void updateVOByPrimaryKey(java.util.List valueObjectList)throws .sinosoft.frame.exception.GeneralException 根据主键批量更新值对象,主键字段必须被赋值Parameters:valueObjectList - 更新数据列表。
Throws:.sinosoft.frame.exception.GeneralException deleteVOByPrimaryKeypublic int deleteVOByPrimaryKey(ValueObject valueObject,boolean delAssociate)throws .sinosoft.frame.exception.GeneralException 根据主键删除一条记录通用DAO提供访问数据库的特有方法Parameters:valueObject - 该ValueObject对象的主键必须被付值delAssociate - 是否删除关联表信息,true删除,false不删Returns:返回删除行数Throws:.sinosoft.frame.exception.GeneralException- 如果发生异常,GeneralException将被抛出.deleteAssocVOpublic void deleteAssocVO(ValueObject valueObject)throws .sinosoft.frame.exception.GeneralException 级联删除,删除vo对象的子对象的数据。