(Quick Reference)

3 Usage - Reference Documentation

Authors: Diego Toharia

Version: 0.4

3 Usage

Basic usage

Using the plugin is fairly simple. You just need to annotate the domain classes as Timestamped and the dateCreated and lastUpdated properties will be injected at compile time:

package my.awesome.grails.app

import com.tado.timestamped.transform.Timestamped

@Timestamped class Car { Brand brand String modelName }

Specifiying the properties to inject

By default, all the autotimestamping properties will be injected (at the moment, Grails provides support for dateCreated and lastUpdated ), but you can specify which one you want to avoid:

  • If you don't want the lastUpdated property to be injected, you can specify to ignore the update event:

package my.awesome.grails.app

import com.tado.timestamped.transform.Timestamped

@Timestamped(update=false) // We won't update this, so we don't need the last updated date class Brand { String name Logo logo }

  • Accordingly If you don't want the dateCreated property to be injected, you can specify to ignore the update event:

package my.awesome.grails.app

import com.tado.timestamped.transform.Timestamped

@Timestamped(create=false) // We don't care about the creation date class Car { Brand brand String modelName }

Specifiying the class of the properties to inject

The Timestamped plugin will try to use the joda-time org.joda.time.Instant class for the timestamped properties, and will fallback to the old and not so good java.util.Date if the previous one is not found, but you can specify your own class:

package my.awesome.grails.app

import com.tado.timestamped.transform.Timestamped

@Timestamped(clazz='java.lang.Long') class Brand { String name Logo logo }

Of course, this only make sense if you provide the mechanisms to manage the autostamping persistence of the specified class, as the joda-time plugin does. The Timestamped plugin will search for the specified class using the default classloader, and if not found, it will try to use one of the supported ones. The priority is then:

  1. Your own specified class
  2. org.joda.time.Instant class
  3. java.util.Date class