HibernateDaoSupport Model Class for my Spring Hibernate Solution
Content about : Model with HibernateDaoSupport
Advertisements
Concept MVC is Model and view Controller my solution use Model to provide all Business Logic get Requestparam from Controller
and Collect data send back to controller. My Solution provide Base Class for all Model Class for Example
Example Master MasterModel
package com.en.model;
import java.io.Serializable;
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.en.dto.MasterDto;
import com.en.sap.MasterSAP;
import com.en.ws.client.WebServiceClientMaster;
public class MasterModel extends HibernateDaoSupport implements Serializable{
private static final long serialVersionUID = 1L;
protected WebServiceClientMaster wsClient;
protected MasterSAP sap;
public void insertData(MasterDto dto){}
public void deleteData(MasterDto dto){}
public void updateData(MasterDto dto){}
public MasterDto getDataObj(Serializable pk){return null;}
public List<MasterDto> getDataList(){return null;}
public WebServiceClientMaster getWsClient() {
return wsClient;
}
public void setWsClient(WebServiceClientMaster wsClient) {
this.wsClient = wsClient;
}
public MasterSAP getSap() {
return sap;
}
public void setSap(MasterSAP sap) {
this.sap = sap;
}
}
Example Model Class
package com.en.model;
import java.io.Serializable;
import org.hibernate.LockMode;
import com.en.dto.ExampleDto;
import com.en.dto.MasterDto;
import com.en.hibernate.Example;
import com.en.ws.client.ExampleWSClient;
public class ExampleModel extends MasterModel{
private static final long serialVersionUID = 1L;
@Override
public void insertData(MasterDto dto) {
Example example =new Example();
this.transferData(dto,example);
this.getHibernateTemplate().save(example);
}
@Override
public void deleteData(MasterDto dto) {
Example example =new Example();
this.transferData(dto,example);
this.getHibernateTemplate().delete(example);
}
@Override
public MasterDto getDataObj(Serializable pk) {
Example example=(Example)this.getHibernateTemplate().load(Example.class, pk,LockMode.READ);
ExampleDto dto=new ExampleDto();
dto.setCodeId(example.getCodeId());
dto.setTdesc(example.getTdesc());
dto.setEdesc(example.getEdesc());
return dto;
}
public MasterDto getDataWS(Serializable pk){
ExampleWSClient client=(ExampleWSClient)this.wsClient;
client.process();
MasterDto dto= client.getData((String)pk);
return dto;
}
public void callSAPDummy1(){
this.sap.dummyMethod1(null);
}
private void transferData(MasterDto dto,Example example){
ExampleDto dtoObj=(ExampleDto)dto;
example.setCodeId(dtoObj.getCodeId());
example.setTdesc(dtoObj.getTdesc());
example.setEdesc(dtoObj.getEdesc());
}
}
Note: Example Model Class is an example for using Hibernate with HibernateDaoSupport