简体   繁体   中英

I am designing a web application using MVC and Three tier architecture. I have got design issue with three tier architecture

In DAO layer currently I am making methods for each type of database query like addDevice, deleteDevice, searchDevice, ifAlreadyRegistered ..... etc and It makes my DAO layer object very heavy .

Is there no way to have generic insert method , delete method , update method in DAO so that DAO layer will not be so heavy?

Are you using an ORM like Hibernate to interface with the database? If not, you might want to give ORM a try. It can make working with a database much easier since you express your logic in the "native" programming language (like Java in your case) instead of SQL, and the ORM figures out the SQL for you. In Hibernate, for example, object updates look like this (from this article ):

transaction = session.beginTransaction();
Course course = (Course) session.get(Course.class, courseId);
course.setCourseName(courseName);
transaction.commit();

...instead of raw SQL. In cases where using ORM makes sense (which is not all cases), it can make your code a lot cleaner and more straightforward.

In broad strokes, a good example of a program where ORM does make sense is something like a CRM where you're just pushing objects around and doing simple reports; a good example of a program where ORM probably does not make sense is something like an analysis tool where you'll use heavily customized and carefully optimized SQL queries, in which case you'd probably spend more time working around the ORM than actually using it.

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