Home > Back-end > Write business logic Service layer, dao layer is the smallest unit of database operations, the trans
Write business logic Service layer, dao layer is the smallest unit of database operations, the trans
Time:09-19
Have a doubt, if it's not framework development, database using JDBC operation, then obtain the connection can only be written in the service method? An employee such as a new company, the employee list add a record, the number of personnel department list field value to add one, it involves the operation of the two tables, staff corresponding YuanGongDaoImpl table, department table corresponding BuMenDaoImpl. The Service layer code have to write like this:
Ygd. Insert (yg);//new employee records BMD, update (String SQL);//department staff number plus one
con.commit(); con.close();
} } But the above con't incoming ygd. Insert (yg) and BMD, update (String SQL), so these two methods can't to the database operation, if these two methods in their new a new con, that the transaction could not operation, if that's the way ygd. Insert (yg, con ") and (BMD), update (String SQL, con), as if no one such design! I see a lot of online tutorials, database operations, is the connection, or sqlsession designed to get in on the dao layer, of course, those examples are the database to add and delete, simple operation, I don't understand, if you want to use transaction, how to design ah, don't consider using framework!
CodePudding user response:
Suddenly thought of, if con storage to the thread in the service layer, and then to the dao layer, it is feasible?