0

I'm using Grails Audit Logging plugin which populates a database table with changes in grails domain classes.

Now, I need to display those data(rows) persisted by plugin to a view.

How can I use data from a database table (not a domain class) in grails?

TheKojuEffect
  • 20,103
  • 19
  • 89
  • 125

2 Answers2

2

Without knowing what you mean by "use information" it's hard to say. However, if you want to query that table it's simple enough using the sql package in Groovy. A controller might look like this:

package com.example

import groovy.sql.GroovyRowResult
import groovy.sql.Sql

class MyController {
  def dataSource // injected data source from application

  def index() {
    def db = new Sql(dataSource)
    def results = db.rows("SELECT col1, col2, col3 FROM my_table")
    render view: 'index', model: results
}

Then of course you can display the results in your GSP as you see fit.

Joshua Moore
  • 24,706
  • 6
  • 50
  • 73
0

I created a grails domain which would make same database table as the grails-audit-plugin made.

Then I used this newly created domain to retrieve data in the database table populated by the plugin.

The domain I made is as follows.

class AuditLog {

    String actor
    String className
    Date dateCreated
    String eventName
    Date lastUpdated
    String newValue
    String oldValue
    String persistedObjectId
    Long persistedObjectVersion
    String propertyName
    String uri

    static constraints = {
        dateCreated nullable: false
        lastUpdated nullable: false
        newValue nullable: true
        oldValue nullable: true
        persistedObjectVersion nullable: true
    }

    static mapping = {
        version false
    }
}
TheKojuEffect
  • 20,103
  • 19
  • 89
  • 125
  • You can use the plugin class itself. `org.codehaus.groovy.grails.plugins.orm.auditable.AuditLogEvent.list()` should give you the events. Also the plugin provides its own view at `/auditLogEvent` (not well documented) – aldrin Nov 07 '14 at 06:05