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

org.etlunit.feature.database.DatabaseRuntimeSupportImpl Maven / Gradle / Ivy

There is a newer version: 1.6.9
Show newest version
package org.etlunit.feature.database;

import org.etlunit.RuntimeSupport;
import org.etlunit.feature.file.FileRuntimeSupport;
import org.etlunit.io.FileBuilder;
import org.etlunit.io.file.DataFileManager;
import org.etlunit.io.file.DataFileSchema;
import org.etlunit.parser.ETLTestValueObject;

import javax.inject.Inject;
import java.io.File;
import java.io.IOException;

public class DatabaseRuntimeSupportImpl implements DatabaseRuntimeSupport
{
	private RuntimeSupport runtimeSupport;
	private FileRuntimeSupport fileRuntimeSupport;
	private DataFileManager dataFileManager;

	@Inject
	public void setRuntimeSupport(RuntimeSupport runtimeSupport)
	{
		this.runtimeSupport = runtimeSupport;
	}

	@Inject
	public void receiveFileRuntimeSupport(FileRuntimeSupport manager)
	{
		fileRuntimeSupport = manager;
	}

	@Inject
	public void receiveDataFileManager(DataFileManager manager)
	{
		dataFileManager = manager;
	}

	public File getSourceDataDirectory(String package_)
	{
		return new FileBuilder(runtimeSupport.getSourceDirectory(package_)).subdir("data").mkdirs().file();
	}

	public File getSourceScriptsDirectory(String package_)
	{
		return new FileBuilder(runtimeSupport.getSourceDirectory(package_)).subdir("sql").mkdirs().file();
	}

	public File getSourceDataSet(String package_, String dataSetName, DatabaseImplementation.data_format format)
	{
		return new FileBuilder(getSourceDataDirectory(package_)).name(dataSetName + (format == null ? "" : format.getExtension())).file();
	}

	public File getSourceScript(String package_, String scriptName)
	{
		return new FileBuilder(getSourceScriptsDirectory(package_)).name(scriptName).file();
	}

	public File getGeneratedSourceDirectory(DatabaseConnection conn, String mode)
	{
		File dir = new FileBuilder(runtimeSupport.getGeneratedSourceDirectory("database")).subdir(conn.getId()).subdir(conn.getDatabaseName(mode)).mkdirs().file();

		return dir;
	}

	public File getGeneratedDataSet(DatabaseConnection conn, String mode, String dataSetName, DatabaseImplementation.data_format format)
	{
		File dir = new FileBuilder(getGeneratedSourceDirectory(conn, mode)).name(dataSetName + (format == null ? "" : format.getExtension())).file();

		return dir;
	}

	public DataFileSchema createRelationalMetaInfo(DatabaseConnection dbConn, String schema, String name)
	{
		return createRelationalMetaInfo(dbConn.getId(), schema, name);
	}

	private String createSchemaKey(String connId, String schema, String name)
	{
		return connId + "-" + schema + "-" + name;
	}

	public DataFileSchema createRelationalMetaInfo(String connId, String schema, String name)
	{
		return dataFileManager.createDataFileSchema(createSchemaKey(connId, schema, name));
	}

	public DataFileSchema getRelationalMetaInfo(DatabaseConnection dbConn, String schema, String name, String masterName, ETLTestValueObject etlObj)
	{
		return getRelationalMetaInfo(dbConn.getId(), schema, name, masterName, etlObj);
	}

	public DataFileSchema getRelationalMetaInfo(String connId, String schema, String name, String masterName, ETLTestValueObject etlObj)
	{
		return fileRuntimeSupport.locateReferenceFileSchema(masterName, createSchemaKey(connId, schema, name), etlObj);
	}

	public void persistDataFileSchema(DataFileSchema schema) throws IOException
	{
		fileRuntimeSupport.persistDataFileSchema(schema);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy