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

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

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

import java.util.Objects;

public abstract class DockerDatabaseFactory implements BoxDatabaseFactory
{
    private final String name;

    protected DockerDatabaseFactory(String name)
    {
        Objects.requireNonNull(name, "name == null");
        this.name = name;
    }

    @Override
    public String name()
    {
        return name;
    }

    @Override
    public BoxDatabase create(BoxConfiguration boxConfiguration, ProjectConfiguration projectConfiguration, BoxContext context)
    throws BoxDatabaseException
    {
        Objects.requireNonNull(boxConfiguration, "boxConfiguration == null");
        Objects.requireNonNull(context, "context == null");

        initializeDefaults(boxConfiguration);
        return createDockerDatabase(boxConfiguration, projectConfiguration, context);
    }

    protected abstract DockerDatabase createDockerDatabase(BoxConfiguration boxConfiguration,
                                                           ProjectConfiguration projectConfiguration,
                                                           BoxContext context)
    throws BoxDatabaseException;

    protected void initializeDefaults(BoxConfiguration boxConfiguration)
    {
        if (boxConfiguration.getDatabaseUser() == null)
            boxConfiguration.setDatabaseUser(boxConfiguration.getAdminUser());
        if (boxConfiguration.getDatabasePassword() == null)
            boxConfiguration.setDatabasePassword(boxConfiguration.getAdminPassword());
        if (boxConfiguration.getContainerName() == null)
            boxConfiguration.setContainerName("boxdb-" + boxConfiguration.getDatabaseType() + "-" + boxConfiguration.getDatabaseVersion());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy