au.net.causal.maven.plugins.boxdb.db.PostgresFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of boxdb-maven-plugin Show documentation
Show all versions of boxdb-maven-plugin Show documentation
Maven plugin to start databases using Docker and VMs
package au.net.causal.maven.plugins.boxdb.db;
@BoxDbBundled
public class PostgresFactory extends DockerDatabaseFactory
{
public PostgresFactory()
{
super("postgres");
}
@Override
protected void initializeDefaults(BoxConfiguration boxConfiguration)
{
if (boxConfiguration.getAdminUser() == null)
boxConfiguration.setAdminUser("postgres");
if (boxConfiguration.getAdminPassword() == null)
boxConfiguration.setAdminPassword("postgresbox");
if (boxConfiguration.getDatabaseName() == null)
boxConfiguration.setDatabaseName("app");
if (boxConfiguration.getDatabaseVersion() == null)
boxConfiguration.setDatabaseVersion("9.6");
if (boxConfiguration.getDatabasePort() <= 0)
boxConfiguration.setDatabasePort(5433);
if (boxConfiguration.getDatabaseUser() == null)
boxConfiguration.setDatabaseUser(boxConfiguration.getDatabaseName());
if (boxConfiguration.getDatabasePassword() == null)
boxConfiguration.setDatabasePassword(boxConfiguration.getDatabaseUser());
EncodingTranslator encodingTranslator = new EncodingTranslator("UTF8", this::mapCommonEncoding);
encodingTranslator.processEncoding(boxConfiguration);
CollationTranslator collationTranslator = new CollationTranslator("C", col -> mapCommonCollation(col, boxConfiguration.getDatabaseEncoding()));
collationTranslator.processCollation(boxConfiguration);
super.initializeDefaults(boxConfiguration);
}
private String mapCommonEncoding(CommonEncoding encoding)
{
switch (encoding)
{
case UNICODE:
return "UTF8";
case ASCII:
return "LATIN1";
default:
throw new Error("Unknown common encoding: " + encoding);
}
}
private String mapCommonCollation(CommonCollation collation, String normalizedEncoding)
{
switch (collation)
{
case BINARY:
return "C";
case CASE_INSENSITIVE:
return "en_US." + normalizedEncoding;
default:
throw new Error("Unknown common collation: " + collation);
}
}
@Override
protected PostgresDatabase createDockerDatabase(BoxConfiguration boxConfiguration, ProjectConfiguration projectConfiguration, BoxContext context)
throws BoxDatabaseException
{
return new PostgresDatabase(boxConfiguration, projectConfiguration, context);
}
}