Feb 10th, 2012, 03:30 AM
Best practise to populate database after running Roo script
I am having a quite extensive Roo script to set up a domain model.
To use the application I need some initial data in the DB.
Ideally Roo should be able to call an external (bash)-script or maybe execute an SQL file.
How do you proceed if you need to automatically populate the DB after Roo ran its script?
Feb 22nd, 2012, 04:15 AM
I know there's such an "addon-oscommands" addon to let you run OS commands from within the Roo shell.
I guess commands can be run from within a script as well.
Feb 22nd, 2012, 04:19 AM
Thanks for the hint, I found it here: http://code.google.com/p/spring-roo-os-commands/
I will check it out.
Feb 24th, 2012, 10:17 AM
Not quite running an os script, but a possible alternative which is less OS dependent.
What we did in this situation was to have a class which implements ApplicationListener<ContextRefreshedEvent>. This allows us to do whatever setup we need when the application is starting up. Two caveats though. It ends up running several times during the start-up process so you need to handle the case where the DB is already initialized. It runs when starting the integration tests, for us this caused some tests to fail so we have a check in place in the code that checks if junit is in the call stack and skips the initialization if it is.
Hope that helps.
Feb 24th, 2012, 03:57 PM
Thanks for this hint. But since this is not possible with plain roo-script, I still believe it would be nice to have a roo-command like "call" or "run" or "exec" which lets you run an os command directly.
Originally Posted by angelog
Feb 25th, 2012, 10:39 AM
Actually the addon is described here: https://jira.springsource.org/browse/ROO-2457 (included on how to install it directly from the roo shell)
Originally Posted by Vito Meuli
Tags for this Thread