All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.eclecticlogic.pedal.loader.impl.AbstractLoaderImpl Maven / Gradle / Ivy

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> customMethods = new HashMap<>();
	
	
	protected EntityManager entityManager;

	@PersistenceContext
	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 closure) {
	    customMethods.put(methodName, closure);
	    return this;
	}

	@Override
	public LoaderExecutor withInputs(Map inputs) {
		AbstractScriptExecutor executor = createScriptExecutor();
	    executor.setInputs(inputs);
	    return executor;
	}

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

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

	@Override
	public Map load(Collection loadScripts) {
	    return createScriptExecutor().load(loadScripts);
	}

	@Override
	public Map loadNamespaced(Collection