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

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

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

import org.etlunit.parser.ETLTestValueObject;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class DatabaseConfiguration {
	private final DatabaseConnection defaultConnection;
	private final String defaultImplementationId;

	private final String dataFileColumnDelimiter;
	private final String dataFileRowDelimiter;
	private final String dataFileNullToken;

	public static final String ALL_MODES = "####_ALL_MODES_####";
	private final Map connectionMap = new HashMap();

	public DatabaseConfiguration(ETLTestValueObject featureConfiguration, String projectName, String projectVersion, String userName, String projectUid) {
		ETLTestValueObject def = featureConfiguration.query("default-implementation-id");

		if (def != null) {
			defaultImplementationId = def.getValueAsString();
		} else {
			defaultImplementationId = null;
		}

		def = featureConfiguration.query(DatabaseFeatureModuleConfiguration.DATAFILECOLUMNDELIMITER_JSON_NAME);

		if (def != null) {
			dataFileColumnDelimiter = def.getValueAsString();
		} else {
			dataFileColumnDelimiter = "\t";
		}

		def = featureConfiguration.query(DatabaseFeatureModuleConfiguration.DATAFILEROWDELIMITER_JSON_NAME);

		if (def != null) {
			dataFileRowDelimiter = def.getValueAsString();
		} else {
			dataFileRowDelimiter = "\n";
		}

		def = featureConfiguration.query(DatabaseFeatureModuleConfiguration.DATAFILENULLDELIMITER_JSON_NAME);

		if (def != null) {
			dataFileNullToken = def.getValueAsString();
		} else {
			dataFileNullToken = "null";
		}

		ETLTestValueObject definition = featureConfiguration.query("database-definitions");

		if (definition == null) {
			throw new IllegalArgumentException("Database configuration missing database definitions");
		}

		Map vmap = definition.getValueAsMap();

		Set> eset = vmap.entrySet();

		for (Map.Entry entry : eset) {
			String id = entry.getKey();
			ETLTestValueObject value = entry.getValue();

			DatabaseConnection dc = new DatabaseConnectionImpl(id, value, defaultImplementationId, projectName, projectVersion, userName, projectUid);

			connectionMap.put(id, dc);
		}


		def = featureConfiguration.query("default-connection-id");

		if (def != null) {
			String defaultConnectionId = def.getValueAsString();

			defaultConnection = connectionMap.get(defaultConnectionId);

			if (defaultConnection == null)
			{
				throw new IllegalArgumentException("Default connection id " + defaultConnectionId + " not found");
			}
		} else {
			defaultConnection = null;
		}
	}

	public boolean hasDefaultConnection()
	{
		return getDefaultConnection() != null;
	}

	public DatabaseConnection getDefaultConnection() {
		return defaultConnection;
	}

	public String getDefaultImplementationId() {
		return defaultImplementationId;
	}

	public DatabaseConnection getDatabaseConnection(String id)
	{
		return connectionMap.get(id);
	}

	public String getDataFileColumnDelimiter()
	{
		return dataFileColumnDelimiter;
	}

	public String getDataFileRowDelimiter()
	{
		return dataFileRowDelimiter;
	}

	public String getDataFileNullToken()
	{
		return dataFileNullToken;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy