Search code examples
hibernategrailsgrails-domain-classgrails-controller

Grails Temporary Domain


Is there a best way for solving this using Grails-

  • Creating a "temporary" table based on multiple tables when user login (session created).
  • It should be possible to access the "temporary" table from all controllers
  • When http session ends, the temporary table should be dropped / truncated
  • GORM features should be available
  • Truncate all data and insert new when certain actions happen during an http session. (The data is dynamic)

I guess that this can be solved somehow by a Domain class. But I haven't succeeded with finding a good example.

The base of the data construction for the "temporary" table is very complex (performance) to generate and will be used often. And it is very important that the data only can be access by the owner (the user).


Solution

  • Although there is a grails plugin that can create domain classes dynamically and there is a blog by Burt that explains how you can create dynamic domain classes. But these have their own limitations and are not suggested to be used in production environment.

    One thing that you can do is create a domain class that also stores the session object. It would be unique per session and you can insert/update entries using the session object. For each finder call you would have to add the condition for including the session object also. When session gets invalidated you can delete the user specific data from the table.