Griffon: to SQL or NoSQL - No Fluff Just Stuff

Griffon: to SQL or NoSQL

Posted by: Andres Almiray on October 24, 2011

A common question asked in the Griffon mailing list is: can GORM be used with Griffon? Sadly the answer is no, not yet. However this doesn't mean there's no persistence support for Griffon at all, quite the opposite, there are 17 active plugins at the moment with a few more in the pipeline.

Regardless of where you stand in the SQL/NoSQL debate Griffon has you covered. Let's begin with what could be said is the most familiar type of storage so far: relational databases.

First stop is the Datasource plugin. This little guy enables access to any java.sql.DataSource compatible datastore. An additional configuration file named DataSource.groovy will be added to the configuration directory of your application when you install this plugin. If the name rings a bell with Grails' conventions wait until you see its contents as created by the default template

Quite similar to Grails' own DataSource.groovy -- that happened by design of course. But the good news do not stop there. This plugin injects a new dynamic method to controllers by default; you can opt to inject this method to other artifacts as well, as long as you configure that option ;-). This method understands the multiple datasource option supported by the plugin. Oh, did I fail to mention this plugin supports more than one DataSource from the get go? Well, it does :-D Here's how typical invocations look when the method has been injected to a Service

Not bad, not bad at all. Did you know you can rewrite the whole thing in plain Java? Let me show you how it can be done

Definitely more verbose that Groovy but gets the job done as well. This plugin is usually used in tandem with the GSQL plugin as the latter enables a data bootstrap mechanism similar to GORM's. At this point some of you may be thinking "OK, I can make raw SQL calls to any datasource but why would I do that if there are plenty of ORM solutions out there?". And you may be right. Love it or hate it, Hibernate is perhaps the most well known ORM in the Java space. This is the same technology that GORM uses under the covers to do its thing. There's as a matter of fact, an incubating hibernate plugin; we hope we can release it soon. In the meantime you may want to explore other options

  • ActiveJDBC - a port of Rails' ActiveRecord. This is a good fit as long as your database is MySQL, Postgresql, Oracle or H2. For all others you're out of luck.
  • Ebean - a light, JPA compatible alternative.
  • MyBatis - formerly know as iBatis. A long standing option for those that think Hibernate is too big.
  • Carbonado - made by Amazon. It can also query BerkeleyDB data stores.
All of these plugins share the same traits with the datasource plugin, that is, there's a Java friendly API that can be used with any JVM language supported by Griffon (Groovy, Java, Scala, Clojure, Mirah, Jython). All of them support multiple datasources with the exception of Carbonado.

Moving onto NoSQL, we now know that Carbonado may work with BerkeleyDB. If you're thinking there's a high chance that BerkeleyDB could be used separate from Carbonado then you're right. The following list enumerates all NoSQL options currently supported by Griffon via plugins:

The first 7 are Key/Value stores. Neo4j is a Graph based database. The last two are object stores. All of them support multiple datasources, data bootstrap and a Java friendly API similar to the one shown earlier.

This is by no means an exhaustive coverage of all NoSQL options that either have a Java or REST based API. We chose those two constraints as they allow us to avoid dealing with platform dependent libraries. If you're aware of other choices that should be in this list then please drop us a message at the mailing lists and we'll see what can be done about it.

Keep on Groovying!

Andres Almiray

About Andres Almiray

Andres is a Java/Groovy developer and a Java Champion with more than 20 years of experience in software design and development. He has been involved in web and desktop application development since the early days of Java. Andres is a true believer in open source and has participated on popular projects like Groovy, Griffon, and DbUnit, as well as starting his own projects (Json-lib, EZMorph, GraphicsBuilder, JideBuilder). Founding member of the Griffon framework and Hackergarten community event. https://ch.linkedin.com/in/aalmiray

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »