codeporn
codeporn

Reputation: 990

Is it possible to use a JNDI dataSource read only in Grails?

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?

Upvotes: 0

Views: 1234

Answers (2)

Blacktiger
Blacktiger

Reputation: 1275

You should use the validate option for dbCreate.

EDIT: The documentation is quite a bit different than when I first posted this answer so the link doesn't quite get you to where the validate option is explained. A quick find will get you to the right spot.

Upvotes: 4

Dónal
Dónal

Reputation: 187399

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'
  }

Upvotes: 3

Related Questions