java.lang.Object
org.dbunit.dataset.AbstractDataSet
de.gmorling.scriptabledataset.ScriptableDataSet
All Implemented Interfaces:
org.dbunit.dataset.IDataSet

public class ScriptableDataSet extends org.dbunit.dataset.AbstractDataSet
An implementation of a DBUnit IDataSet, that allows the use of script expressions in its fields. In order to use a certain scripting language in a scriptable data set, a JSR 223 ("Scripting for the JavaTM Platform") compatible script engine has to exist for that language.

Using the JRuby engine e.g., a scriptable data set file could look like this:

 <dataset>
     <location num="jruby:12/2" addr="jruby:'Webster Street'.reverse" date="jruby:DateTime::now() - 14"/>
 </dataset>
 
A ScriptableDataSet can be created as follows:
 IDataSet wrapped = ...;

 List<ScriptInvocationHandler> handlers = new ArrayList<Class<? extends ScriptInvocationHandler>>();
 handlers.add(new JRubyImportAddingInvocationHandler());

 IDataSet scriptableDS = new ScriptableDataSet(
      wrapped, new ScriptableDataSetConfig("jruby", "jruby:", handlers));
 
where
  • jruby is the name of a scripting language as understood by ScriptEngineManager
  • jruby: is a prefix, that shall precede fields in that scripting language
  • handlers is an optional list of ScriptInvocationHandler s, that can be used to pre-process scripts (e.g. to add common imports) and post-process scripts (e.g. to convert results into data types understood by DBUnit).
  • Field Summary

    Fields inherited from class org.dbunit.dataset.AbstractDataSet

    _orderedTableNameMap
  • Constructor Summary

    Constructors
    Constructor
    Description
    ScriptableDataSet(org.dbunit.dataset.IDataSet wrapped, ScriptableDataSetConfig... configurations)
    Creates a new ScriptableDataSet.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected org.dbunit.dataset.ITableIterator
    createIterator(boolean reversed)
     

    Methods inherited from class org.dbunit.dataset.AbstractDataSet

    createTableNameMap, getTable, getTableMetaData, getTableNames, getTables, initialize, isCaseSensitiveTableNames, iterator, reverseIterator, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ScriptableDataSet

      public ScriptableDataSet(org.dbunit.dataset.IDataSet wrapped, ScriptableDataSetConfig... configurations)
      Creates a new ScriptableDataSet.
      Parameters:
      wrapped - Another data set to be wrapped by this scriptable data set. Must not be null.
      configurations - At least one scriptable data set configuration.
  • Method Details

    • createIterator

      protected org.dbunit.dataset.ITableIterator createIterator(boolean reversed) throws org.dbunit.dataset.DataSetException
      Specified by:
      createIterator in class org.dbunit.dataset.AbstractDataSet
      Throws:
      org.dbunit.dataset.DataSetException