/** * 在修改Bean操作之前进行的逻辑验证(本方法子类一般需要重写) * @param bean 实体Bean * @return 验证成功返回StatusType.DEFAULT,如果失败则返回自定义的状态码(小于0) * @throws Exception 1.逻辑验证发生异常 */ protected int validateEdit(Object bean) throws Exception{ return StatusType.DEFAULT ; } /** * 在添加Bean操作之前进行的逻辑验证(本方法子类一般需要重写) * @param bean 实体Bean * @return 验证成功返回StatusType.DEFAULT,如果失败则返回自定义的状态码(小于0) * @throws Exception 1.逻辑验证发生异常 */ protected int validateAdd(Object bean ) throws Exception{ return StatusType.DEFAULT; } /** * 在删除(逻辑删除或物理删除)Bean操作之前进行的逻辑验证 * @param bean 实体Bean * @return 验证成功返回StatusType.DEFAULT,如果失败则返回自定义的状态码(小于0) * @throws Exception 1.逻辑验证发生异常 */ protected int validateDelete(Object bean) throws Exception{ return StatusType.DEFAULT ; } public int check(Object bean , Map<String,Object> modelMap) throws Exception{ int result = 0 ; ValidatePersistence persistence = this.validater(bean); result = persistence.check( this.daoProvider() ); if( result < 0 ){ String text = persistence.getText(); modelMap.put(ContextArgument.PROMPT_ERROR, text); } return result ; } public int add(Object bean) throws Exception { int result = StatusType.DEFAULT ; result = this.validateAdd(bean); if(result == StatusType.DEFAULT ){ result = this.daoProvider().insert(bean); } return result ; } public int modify(Object bean) throws Exception { int result = StatusType.DEFAULT ; result = this.validateEdit(bean); if(result == StatusType.DEFAULT ){ result = this.daoProvider().modify(bean); } return result ; } public int delete(Object bean) throws Exception { int result = StatusType.DEFAULT ; result = this.validateDelete(bean); if(result == StatusType.DEFAULT ){ result = this.daoProvider().delete(bean); } return result ; } public int batchDelete(List<?> beans) throws Exception { int result = StatusType.DEFAULT ; if( this.daoProvider().batchDelete(beans) ){ result = StatusType.SUCCESS ; } return result; } public int batchDelete(Object bean , String ids ) throws Exception{ int result = StatusType.DEFAULT ; List<?> beans = Persistence.beans(bean.getClass(), ids); if( !NoneType.isNullOrEmpty(beans) ){ result = this.batchDelete(beans); } return result ; } public <T> T bean(Object bean) throws Exception { T result = this.daoProvider().fectchObject(bean); return result ; } public <T> T bean(Object bean,List<Class<?>> parentBeanTypes) throws Exception { T result = null ; List<T> beans = this.daoProvider().relatedQueryObject(bean, parentBeanTypes); if (!NoneType.isNullOrEmpty(beans)) { result = beans.get(0); } return result ; } public <T> List<T> beans(Object bean)throws Exception { List<T> result = this.daoProvider().queryObject(bean) ; return result ; } public <T> List<T> beans(Object bean, String orderBy, DataPage dataPage)throws Exception { List<T> result = new ArrayList<T>() ; int count = this.daoProvider().sum(bean); if( count == 0 ){ return result; } if( dataPage != null ){ dataPage.setCount(count); } SqlCriteria criteria = new SqlCriteria(); criteria.setOrderBy(orderBy); criteria.setPager(dataPage); result = this.daoProvider().queryObject(bean, criteria); return result; } public <T> List<T> beans(Class<?> sqlClass, Object bean, String orderBy, DataPage dataPage)throws Exception { List<T> result = null ; Field sqlField = sqlClass.getField("beans"); String sql = ""; if( sqlField != null ){ sql = sqlField.get(null).toString(); SqlCommand command = new SqlCommand(sql); command.getCriteria().setOrderBy(orderBy); command.getCriteria().setPager(dataPage); result = this.daoProvider().queryObject(command, bean); } return result; } public DataTable table(Object bean)throws Exception { DataTable result = this.daoProvider().query(bean) ; return result ; } public DataTable table(Object bean, String orderBy, DataPage dataPage) throws Exception{ DataTable result = null; int count = this.daoProvider().sum(bean); if (count == 0) { result = new DataTable(); return result; } if (dataPage != null) { dataPage.setCount(count); } SqlCriteria criteria = new SqlCriteria(); criteria.setOrderBy(orderBy); criteria.setPager(dataPage); result = this.daoProvider().query(bean, criteria); return result; } public DataTable table(Class<?> sqlClass, Object bean, String orderBy, DataPage dataPage)throws Exception { DataTable result = null ; Field sqlField = sqlClass.getField("table"); String sql = ""; if( sqlField != null ){ sql = sqlField.get(null).toString(); SqlCommand command = new SqlCommand(sql); command.getCriteria().setOrderBy(orderBy); command.getCriteria().setPager(dataPage); result = this.daoProvider().query(command, bean); } return result ; }