简体   繁体   中英

which part of function should go in DAO layer and which in service layer

Initially I had the all the DAO in service layer. But to go the proper way i am making the separate DAO layer but i am little bit confused as to which things come in DAO and which in service layer

I had this function in service layer

public void confirmUser(String id)
{
      logger.debug("Confirming existing person");
      Session session = sessionFactory.getCurrentSession();
      String query = "FROM Registration WHERE uuid=:myuuid";
      Query query2 = session.createQuery(query);
      query2.setString("myuuid",id);
      Registration person = (Registration) query2.uniqueResult();
      person.setConfirmed(true);
      session.save(person);

}

Now i want to ask that does this same function go as it is in DAO function or something will remain in service layer as well

Generally your DAO would do the work for storing and retrieving the entities, while your service would do the business logic.

So confirmUser(id) would be on the service, and would do the call to setConfirmed(..) on the user.

The DAO would have getUserById(id) and saveOrUpdateUser(User) -- or something to that affect, depending upon your needs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM