I started using the Play Framework a couple of months ago. It "redefines" many conventions from the traditional Java world (like the way of using static methods among other things). I was browsing the documentation when I found this piece of code in scala:
package controllers
import play.api.Play.current
import play.api.mvc._
import play.api.db._
object Application extends Controller {
def index = Action {
var outString = "Number is "
val conn = DB.getConnection()
try {
val stmt = conn.createStatement
val rs = stmt.executeQuery("SELECT 9 as testkey ")
while (rs.next()) {
outString += rs.getString("testkey")
}
} finally {
conn.close()
}
Ok(outString)
}
}
Basically, it is a controller with a database call on it. I understand that Play Framework is revolutionary in some aspects, but, isn't this against the very basic Layer Service Pattern? What's the rationale behind being fine to use a SQL call on a Controller?
EDIT:
The reason I got to this Play tutorial page is because I was looking for the most common practice in Play about this particular case, I've found more than one case in a real life application where this is happening. So my Question, to be more precise: Is this an accepted practice in Play? is this just "tolerated" in some circumstances (for a real life code, not in a tutorial)? or the SQL query simply must go in a "model" object?