我的问题是:你的服务层是否受你使用的探测系统的约束?
例如,如果你使用秘密,你就会把一些只属于秘密特征的 h或标准序列置于你的服务层面,或者说简单地说,DAO(DAO(Dao有秘密执行,可能会被搁置执行等)?
我在为我的软件建造一个连接层的结构方面有一些困难。
EDIT This is a simple service...i think it s a service... without bound to tecnlogy i using (hibernate)
@Repository
public class PersonHibernateDAO implements PersonDAO {
@Autowired
SessionFactory sessionFactory;
... dao crud operations(implementation of PersonDAO interface) using sessionfactory ...
//and some hibernate features methods
public Person findByCriteria(Criterion criterion){
// code
}
}
@Service
public class PersonService {
@Autowired
private PersonDAO personDao;
@Autowired
private AccessDAO accessDao;
@Transactional
public boolean hasPermission(String username, String accessCode){
Person p=personDao.findByUsername(username);
Access a=accessDao.findByCode(accessCode);
... etc ...
}
}
这是一项使用Dao实施服务。
@Service
public class PersonService {
@Autowired
private PersonDAO personDao;
@Autowired
private AccessDAO accessDao;
@Transactional
public boolean hasPermission(String username, String password){
Person p=((PersonHibernateDao)personDao).findByCriteria(Restrictions.eq("username", username);
... etc ...
}
}
这两种做法是否正确?
<><><><>>>>>>
So, to summarize what I understood:
// BASE DAO INTERFACE
public interface DAOInterface<EntityClass, IDType extends Serializable> {
EntityClass get(IDType id);
EntityClass findById(IDType id);
EntityClass save(EntityClass entity);
EntityClass update(EntityClass entity);
void delete(EntityClass entity);
}
// AN HIBERNATE IMPLEMENTATION
public abstract class HibernateDAO<EntityClass, IDType extends Serializable> implements DAOInterface<EntityClass, IDType> {
@Autowired
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory){
this.sessionFactory=sessionFactory;
}
public void getSessionFactory(){
return this.sessionFactory;
}
// Implements all DAOInterface method using sessionFactory
}
// PERSON DAO INTERFACE
public interface PersonDAO extends DAOInterface<Person, Long>{
Person findByName(String name, String surname);
List<Person> getInAgeRange(int year1, int year2);
}
// PERSON HIBERNATE DAO IMPLEMENTATION
public PersonHDAO extends HibernateDAO<Person, Long> implements PersonDAO{
// Implements the methods of PersonDAO interface using sessionFactory
}
@Service
public class PersonService {
//spring inject the correct DAO by its xml config(in this case PersonHDAO
@Autowired
private PersonDAO personDAO;
// spring manage the transaction
@Transactional
public List<Person> getInAgeRange(int year1, int year2){
return personDAO.getInAgeRange(year1, year2);
}
}
// NOW... HOW USE IT
//let s assume i have a button, pressing it a table will be populated with all persons in age range
private void actionPerfom(ActionEvent e){
List<Person> list=personService.getInAgeRange(age1Spinner.getValue(), age2Spinner.getValue());
//Load a table with list
}
Sorry for this wall of text, maybe can be useful for others i hope, im go in the right direction? My service layer need an interface? Is all corectly layered? I need a control layer too?
感谢。