views:

68

answers:

2

Hi,

I need to add a JNDI datasource from a legacy database to my Grails (1.2.2) application. So far, the resource is added to my Tomcat (5.5) and DataSource.groovy contains:

development {
    dataSource {
      jndiName = "jdbc/lrc_legacy_db"
    }
}

I also created some domain objects mapping the different tables to comfortably load and handle data from the DB with GORM. But I now want to assure, that every connection to this DB is really read-only. My biggest concern here is the dbCreate- property and the automatic database manipulation through GORM and the GORM classes.

Is it enough to just skip dbCreate? How do I assure that the database will only be read and never ever manipulated in any way?

+2  A: 

You should use the validate option for dbCreate.

Blacktiger
Wow, a good point and fast! So this validates my exiting scheme with the DB and the doc tells me also skipping the property is an option for me, too; do you know if this works in Grails 1.2.2, as this is never mentioned in the 1.2.2 doc, or do I have to update?
air_blob
I think you have to update for the validate option. That option does not appear in the docs until 1.3. It might also make sense to use the update option as it will allow you to add new columns but won't damage any existing data (so new development can continue).
Blacktiger
+2  A: 

According to the Grails documentation:

If your application needs to read but never modify instances of a persistent class, a read-only cache may be used

A read-only cache for a domain class can be configured by

1. Enable Caching

Add something like the following to DataSource.groovy

hibernate {
    cache.use_second_level_cache=true
    cache.use_query_cache=true
    cache.provider_class='org.hibernate.cache.EhCacheProvider'
}

2. Make Cache Read-Only

For each domain class, you will need to add the following to the mapping closure:

  static mapping = {
      cache usage:'read-only', include:'non-lazy'
  }
Don
Thanks for this, answered my second question. I think i should have RTFM of the latest version ;)
air_blob
why RTFM when you can AFSO? (ask f****g stack overflow) :)
Don