EWeb4J-1.9-继续改善ActiveRecord支持【级联】操作
老习惯:约定优于配置,配置覆盖约定,少侵入,开发者控制一切
由于之前已经封装好CascadeDAO接口。因此本次在ActiveRecord中增加级联操作就显得很简单了。
这个是使用的时候:
PetControl.java
@Validate(value={"pet.*"}, except={"pet.id"})@Transactionalpublic String create(Validation val, Map model) {if (val.hasErr())return JsonConverter.convert(val.getAllErr());pet.create();pet.cascade().select("fied1","field2");pet.cascade().insert("fied1","field2");pet.cascade().update("fied1","field2");pet.cascade().delete("fied1","field2");model.put("types", TYPES);return "index";}
public Cascade cascade(){Cascade cascade = new CascadeImpl(DAOFactory.getCascadeDAO(dsName), this);return cascade;}
public interface Cascade {void select(String... fields);void update(String... fields);void delete(String... fields);void insert(String... fields);}
public class CascadeImpl implements Cascade{private CascadeDAO cascadeDAO;private Model model;CascadeImpl(CascadeDAO cascadeDAO, Model model){this.cascadeDAO = cascadeDAO;this.model = model;}public void select(String... fields) {this.cascadeDAO.select(model, fields);}public void update(String... fields) {this.cascadeDAO.update(model, fields);}public void delete(String... fields) {this.cascadeDAO.delete(model, fields);}public void insert(String... fields) {this.cascadeDAO.insert(model, fields);}}