com.jslsolucoes.db.migrate.se.config.MigrateConfigurationBuilder Maven / Gradle / Ivy
package com.jslsolucoes.db.migrate.se.config;
import java.nio.file.Path;
import java.sql.Driver;
import java.util.Properties;
import com.jslsolucoes.properties.PropertiesBuilder;
public class MigrateConfigurationBuilder {
private Path scripts;
private Properties properties;
private MigrateConfigurationBuilder() {
}
public static MigrateConfigurationBuilder newBuilder() {
return new MigrateConfigurationBuilder();
}
public MigrateConfigurationBuilder withScripts(Path scripts) {
this.scripts = scripts;
return this;
}
public MigrateConfigurationBuilder withProperties(Properties properties) {
this.properties = PropertiesBuilder.newBuilder().withProperties(properties).build();
return this;
}
public MigrateConfiguration build() {
MigrateConfiguration migrateConfig = new MigrateConfiguration();
migrateConfig.setScript(scripts);
migrateConfig.setDatabase(databaseConfiguration());
return migrateConfig;
}
private MigrateTableConfiguration tableConfiguration() {
MigrateTableConfiguration migrateTableConfig = new MigrateTableConfiguration();
migrateTableConfig.setSchema(properties.getProperty("db.table.schema"));
migrateTableConfig.setName(properties.getProperty("db.table.name"));
migrateTableConfig.setId(properties.getProperty("db.table.column.id"));
migrateTableConfig.setDescription(properties.getProperty("db.table.column.description"));
migrateTableConfig.setVersion(properties.getProperty("db.table.column.version"));
migrateTableConfig.setTimestamp(properties.getProperty("db.table.column.timestamp"));
return migrateTableConfig;
}
private MigrateDatabaseConfiguration databaseConfiguration() {
try {
MigrateDatabaseConfiguration migrateDatabaseConfig = new MigrateDatabaseConfiguration();
migrateDatabaseConfig.setDriver((Driver) Class.forName(properties.getProperty("db.driver")).newInstance());
migrateDatabaseConfig.setPassword(properties.getProperty("db.password"));
migrateDatabaseConfig.setTable(tableConfiguration());
migrateDatabaseConfig.setUrl(properties.getProperty("db.url"));
migrateDatabaseConfig.setUser(properties.getProperty("db.user"));
return migrateDatabaseConfig;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy