0

I am trying to use scriptella in my project to copy data from one db to another, now the application has a frontend which users can use to create mapping between tables and create dynamic queries, now currently once the user submits the frontend queries are passed via a query engine and a scriptella xml is created using freemarker template

however to execute the xml the executor expects a file instead of a xml string currently i am achieving this by creating a xml in temp directory and deleting it post execution of query, is there any way i can skip file creation and execute the query as a xml string

Ambuj Jauhari
  • 1,187
  • 4
  • 26
  • 46

2 Answers2

0

You can create a custom URLStreamHandler that will serve streams directly from memory. This is similar to what was done in AbstractTestCase. It can be registered by calling URL.setURLStreamHandlerFactory. See Registering and using a custom java.net.URL protocol or Is it possible to create an URL pointing to an in-memory object?

After that, use EtlExecutor.newExecutor(java.net.URL) with the new URI, e.g. new URL("memory://file")

ejboy
  • 4,081
  • 5
  • 30
  • 32
0

I had a similar use case. I downloaded the code and made a small change in the core. Due to some private functions I had no choice. in package scriptella.configuration.ConfigurationFactory I added the following function:

public ConfigurationEl createConfigurationFromTxt(String xml, final ParametersCallback externalParameters ) {
        try {
            DocumentBuilder db = DBF.newDocumentBuilder();
            db.setEntityResolver(ETL_ENTITY_RESOLVER);
            db.setErrorHandler(ETL_ERROR_HANDLER);

            final InputStream in = new ByteArrayInputStream(xml.getBytes());
            final Document document = db.parse(in);
            HierarchicalParametersCallback params = new HierarchicalParametersCallback(
                    externalParameters == null ? NullParametersCallback.INSTANCE : externalParameters, null);
            PropertiesSubstitutor ps = new PropertiesSubstitutor(params);

            return new ConfigurationEl(new XmlElement(
                    document.getDocumentElement(), resourceURL, ps), params);
        } catch (IOException e) {
            throw new ConfigurationException("Unable to load document: " + e, e);
        } catch (Exception e) {
            throw new ConfigurationException("Unable to parse document: " + e, e);
        }
    }

Then from my code I can do something like this:

ConfigurationFactory cf = new ConfigurationFactory();
ConfigurationEl conf = cf.createConfigurationFromTxt(FETCH_ETLS, p);
EtlExecutor exec = new EtlExecutor(conf);