-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from csetera/master
Add support to pedal loader for file-system based scripts
- Loading branch information
Showing
8 changed files
with
581 additions
and
403 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/main/java/com/eclecticlogic/pedal/loader/impl/AbstractLoaderImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
Oops, something went wrong.