Reputation: 622
This is my UserDAO bean defined in spring context
public class UserDAO{
public boolean isUserAlreadyExists(User user){
//some logic
}
public void createUser(User user){
//logic to add user to database
}
}
This is my spring service bean
@Component
@Transactional(readonly="true",propagation=Propation.SUPPORTD)
public class UserService{
@Autowired
UserDAO userDAO;
public void createUser(User){
if(!userDAO.isUserAlreadyExists(user)){
userDAO.createUser(user);
}
}
}
should i call isUserAlreadyExists from within UserDAO.createUser like this
//UserDAO.java
public void createUser(User user){
if(!isAlreadyUserExists(user)){
//user adding to database
}
}
OR
Above Service bean implementation is ok.
Upvotes: 1
Views: 1206
Reputation: 5123
That logic seems like it should be in your service layer; as in the former example. Your createUser()
function in the DAO should only have to worry about creating, or adding the user. Let the service layer worry about what to do if the User
already exists.
Upvotes: 3