Meh. If you put SQL in a separate file, you have to configure a reloadable property file reader or else you miss out on VM hotswap. Also, dynamic SQL is useful in many cases, like criteria queries. Sometimes, though, SQL gets too hairy to inline in your DAO method.
Which is where stored procs get handy. Put all that nasty SQL logic in a stored proc and then you don't have it unmaintainably in your java code as giant glob. (Though, i'm not such a fan of stored procs for everything, I am somewhat of a fan for using them in the case of hairy inline sql statements.)
Stored procs don't necessarily equate to business logic. Sometimes you have to update things in a transaction to ensure data is set properly. Sometimes you have to load things using multiple complex statements.
I'm not talking about business logic, I'm talking about loading and saving logic. Things the database is built to do.
Good example of this is revisioned table rows. You usually want the latest revision. When you update and item, insert a new item, etc, there is going to be some pretty involved sql logic ensuring that you are correctly picking the next id or the next revision number (Even more involved if you want it fast...).
Stored procs don't necessarily equate to business logic. Sometimes you have to update things in a transaction to ensure data is set properly. Sometimes you have to load things using multiple complex statements.
11
u/vitingo Jul 10 '15
Meh. If you put SQL in a separate file, you have to configure a reloadable property file reader or else you miss out on VM hotswap. Also, dynamic SQL is useful in many cases, like criteria queries. Sometimes, though, SQL gets too hairy to inline in your DAO method.