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

au.net.causal.maven.plugins.boxdb.db.BoxConfiguration Maven / Gradle / Ivy

There is a newer version: 3.3
Show newest version
package au.net.causal.maven.plugins.boxdb.db;

import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;

/**
 * Configures a boxed database.
 * 

* * Depending on the {@linkplain #setDatabaseType(String) database type}, some settings may be overridden. * For example, some container databases might not allow the port to be changed. */ public class BoxConfiguration { private String databaseType; private String databaseVersion; private int databasePort; private String adminUser; private String adminPassword; private String databaseName; private String databaseUser; private String databasePassword; private String containerName; private Path databaseFile; private Path restoreFile; private boolean initializeDatabase = true; private final List scriptExecutions = new ArrayList<>(); private final Map configuration = new LinkedHashMap<>(); /** * The password for the admin or system database, used typically to create additional databases * and users. * * @see #getAdminUser() */ public String getAdminPassword() { return adminPassword; } public void setAdminPassword(String adminPassword) { this.adminPassword = adminPassword; } /** * The name of the admin or system user, used typically to create additional databases and users. * * @see #getAdminPassword() */ public String getAdminUser() { return adminUser; } public void setAdminUser(String adminUser) { this.adminUser = adminUser; } /** * The name of the database container. Depending on the database type, this could become the name * of a docker container or the name of a directory containing a file-based database. */ public String getContainerName() { return containerName; } public void setContainerName(String containerName) { this.containerName = containerName; } /** * The database port that will be exposed on the host system. This is not necessarily the port the * database runs on inside the container. */ public int getDatabasePort() { return databasePort; } public void setDatabasePort(int databasePort) { this.databasePort = databasePort; } /** * The database type. For example, 'postgres', 'oracle'. Required. */ public String getDatabaseType() { return databaseType; } public void setDatabaseType(String databaseType) { this.databaseType = databaseType; } /** * The version of the database to use. If not specified, a default version will be used. */ public String getDatabaseVersion() { return databaseVersion; } public void setDatabaseVersion(String databaseVersion) { this.databaseVersion = databaseVersion; } /** * The name of the target database to create. When creating the boxed database, this database is created, owned * by the {@linkplain #getDatabaseUser() database user}. *

* * Typically this database is created with a CREATE DATABASE SQL statement. */ public String getDatabaseName() { return databaseName; } public void setDatabaseName(String databaseName) { this.databaseName = databaseName; } /** * The password to use for the user that will own the target database. This user will typically only * have access to the target database - for system access use the {@linkplain #getAdminUser() admin user}. * * @see #getDatabaseUser() */ public String getDatabasePassword() { return databasePassword; } public void setDatabasePassword(String databasePassword) { this.databasePassword = databasePassword; } /** * The name of the user that will own the target database. This user will typically only * have access to the target database - for system access use the {@linkplain #getAdminUser() admin user}. * This user is created when setting up the database. */ public String getDatabaseUser() { return databaseUser; } public void setDatabaseUser(String databaseUser) { this.databaseUser = databaseUser; } /** * SQL scripts to execute when setting up the database. */ public List getScriptExecutions() { return scriptExecutions; } public void setScriptExecutions(List scriptExecutions) { this.scriptExecutions.clear(); this.scriptExecutions.addAll(scriptExecutions); } /** * Returns all the script executions to execute at a particular state. * * @param stage the stage. */ public List scriptExecutions(DatabaseStage stage) { return getScriptExecutions().stream() .filter(execution -> execution.getStage() == stage) .collect(Collectors.toList()); } /** * @return true if the database will be setup by the plugin, false if all setup should be performed by user scripts. */ public boolean isInitializeDatabase() { return initializeDatabase; } public void setInitializeDatabase(boolean initializeDatabase) { this.initializeDatabase = initializeDatabase; } /** * @return additional database-specific configuration. */ public Map getConfiguration() { return configuration; } public void setConfiguration(Map configuration) { this.configuration.clear(); this.configuration.putAll(configuration); } /** * @return the file or directory to use for file-based databases. Ignored for other types of databases. */ public Path getDatabaseFile() { return databaseFile; } public void setDatabaseFile(Path databaseFile) { this.databaseFile = databaseFile; } public Path getRestorePath() { return restoreFile; } /** * If specified, restores the database from a backup file. */ public void setRestoreFile(File restoreFile) { this.restoreFile = restoreFile.toPath(); } /** * Saves configuration properties to a properties object. * * @param properties the properties object to save properties to. */ public void toProperties(Properties properties) { if (getDatabaseName() != null) { properties.setProperty("box.databaseName", getDatabaseName()); properties.setProperty("box.databaseName.upperCase", getDatabaseName().toUpperCase(Locale.ENGLISH)); } if (getDatabaseUser() != null) { properties.setProperty("box.databaseUser", getDatabaseUser()); properties.setProperty("box.databaseUser.upperCase", getDatabaseUser().toUpperCase(Locale.ENGLISH)); } if (getDatabasePassword() != null) properties.setProperty("box.databasePassword", getDatabasePassword()); if (getAdminUser() != null) { properties.setProperty("box.adminUser", getAdminUser()); properties.setProperty("box.adminUser.upperCase", getAdminUser().toUpperCase(Locale.ENGLISH)); } if (getAdminPassword() != null) properties.setProperty("box.adminPassword", getAdminPassword()); if (getDatabaseVersion() != null) properties.setProperty("box.databaseVersion", getDatabaseVersion()); if (getDatabaseFile() != null) properties.setProperty("box.databaseFile", getDatabaseFile().toAbsolutePath().toString()); properties.setProperty("box.databasePort", String.valueOf(getDatabasePort())); configuration.forEach((k, v) -> properties.setProperty("box.configuration." + k, v)); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy