Skip to content

Commit

Permalink
Merge pull request #1 from csetera/master
Browse files Browse the repository at this point in the history
Add support to pedal loader for file-system based scripts
  • Loading branch information
Eclectic Logic committed Jan 2, 2016
2 parents be7da27 + 27822d7 commit 7662ff2
Show file tree
Hide file tree
Showing 8 changed files with 581 additions and 403 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Minimum dependencies that you need to provide in your application:

#### Vanilla setup

Create an instance of `Loader` (concrete class `com.eclecticlogic.pedal.loader.impl.LoaderImpl`) and give it a reference to an `EntityManager`.
For classpath-based loading, create an instance of `Loader` (concrete class `com.eclecticlogic.pedal.loader.impl.LoaderImpl`) and give it a reference to an `EntityManager`. For filesystem-based loading, create an instance of `com.eclecticlogic.pedal.loader.impl.FileSystemLoaderImpl` instead of `com.eclecticlogic.pedal.loader.impl.LoaderImpl`.

#### Spring

Expand Down Expand Up @@ -62,7 +62,7 @@ The Loader interface provides a number of methods to specify your script and inp
```
loader.withScriptDirectory("myScripts").load("basicdata.groovy");
```
This specifies that the loader should read the script basicdata.groovy contained within a classpath directory called myScripts. The file could just as well have been specified with the directory as `myScripts\basicdata.groovy`. However, the withScriptDirectory allows you to setup a well known directory and have all other calls simply reference the script by name without worry about relative paths.
This specifies that the loader should read the script basicdata.groovy contained within a classpath or filesystem directory called myScripts. The file could just as well have been specified with the directory as `myScripts\basicdata.groovy`. However, the withScriptDirectory allows you to setup a well known directory and have all other calls simply reference the script by name without worry about relative paths.

### Script Format

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.eclecticlogic.pedal.loader.impl;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.eclecticlogic.pedal.loader.Loader;
import com.eclecticlogic.pedal.loader.LoaderExecutor;
import com.eclecticlogic.pedal.loader.Script;

import groovy.lang.Closure;

/**
*
* Abstract implementation for all of the {@link Loader} implementations
*
* @author kabram.
* @author Craig Setera
*
*/
public abstract class AbstractLoaderImpl implements Loader {

public AbstractLoaderImpl() {
super();
}

public AbstractLoaderImpl(EntityManager entityManager) {
super();
this.entityManager = entityManager;
}

protected String scriptDirectory;
protected Map<String, Closure<Object>> customMethods = new HashMap<>();

@PersistenceContext
protected EntityManager entityManager;

public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}

@Override
public Loader withScriptDirectory(String directory) {
scriptDirectory = directory;
return this;
}

@Override
public Loader withCustomMethod(String methodName, Closure<Object> closure) {
customMethods.put(methodName, closure);
return this;
}

@Override
public LoaderExecutor withInputs(Map<String, Object> inputs) {
AbstractScriptExecutor executor = createScriptExecutor();
executor.setInputs(inputs);
return executor;
}

@Override
public Map<String, Object> load(String loadScript, String... additionalScripts) {
return createScriptExecutor().load(loadScript, additionalScripts);
}

@Override
public Map<String, Object> load(Script script, Script... additionalScripts) {
return createScriptExecutor().load(script, additionalScripts);
}

@Override
public Map<String, Object> load(Collection<String> loadScripts) {
return createScriptExecutor().load(loadScripts);
}

@Override
public Map<String, Object> loadNamespaced(Collection<Script> loadScripts) {
return createScriptExecutor().loadNamespaced(loadScripts);
}

protected abstract AbstractScriptExecutor createScriptExecutor();
}
Loading

0 comments on commit 7662ff2

Please sign in to comment.