Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Kenneth A. Kousen - Making Java Groovy - 2014.pdf
Скачиваний:
50
Добавлен:
19.03.2016
Размер:
15.36 Mб
Скачать

226

CHAPTER 8 Database access

It’s hard to be much simpler than that. Working with MongoDB20 is just as easy as using a traditional relational database.21

8.6Summary

Virtually every significant application requires persistent data. The vast majority of those are based on relational databases. In the Java world, relational persistence uses either JDBC or an object-relational mapping tool like Hibernate or JPA. This chapter reviewed both approaches and examined how Groovy can simplify them.

The Groovy Sql class removes most of the clutter that accompanies raw JDBC. Any code that uses JDBC directly can be significantly simplified using the Sql class.

Many modern applications use JPA for persistence, especially with Hibernate as the underlying API and the Spring framework to handle singletons and transactions. Just configuring such an application is a nontrivial task. On the other hand, the Grails framework handles all of it elegantly and with a minimum of effort.

Finally, many so-called NoSQL databases have a Java API. Some, like MongoDB, include a Groovy wrapper that makes working with the underlying databases simple.

20A detailed treatment of MongoDB is contained in the book MongoDB in Action (Manning, 2011) by Kyle Banker: www.manning.com/banker/.

21For some reason, none of the Twilight movies were returned from the “vampire” query. I thought about fixing that, and ultimately decided it wasn’t a bug, but a feature.

www.it-ebooks.info

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]