Class Db2Container.Builder

java.lang.Object
io.ebean.test.containers.Db2Container.Builder
All Implemented Interfaces:
ContainerBuilder<Db2Container,Db2Container.Builder>, ContainerBuilderDb<Db2Container,Db2Container.Builder>
Enclosing class:
Db2Container

public static class Db2Container.Builder extends Object
Builder for Db2Container.
  • Field Details

    • characterSet

      protected String characterSet
      The character set to use.
    • collation

      protected String collation
      The collation to use.
    • platform

      protected final String platform
      The database platform.

      Expected to be one of 'postgres','mysql', 'oracle' or 'sqlserver'.

    • containerName

      protected String containerName
      Container name.
    • host

      protected String host
      The host name. When running in Docker this is often set to 172.17.0.1invalid input: '<'/code.
    • port

      protected int port
      The exposed port.
    • internalPort

      protected int internalPort
      The internal port.
    • adminPort

      protected int adminPort
      The exposed port.
    • adminInternalPort

      protected int adminInternalPort
      The internal port.
    • mirror

      protected String mirror
      Define a mirror for images to use with CI builds.
    • image

      protected String image
      Image name.
    • startMode

      protected StartMode startMode
      The mode used when starting (create, dropCreate, container [only]).
    • shutdownMode

      protected StopMode shutdownMode
      By default, via JVM shutdown hook stop and remove the container unless there is a ~/.ebean/ignore-docker-shutdown marker file.
    • maxReadyAttempts

      protected int maxReadyAttempts
      Maximum number of attempts to find the 'database ready to accept connections' log message in the container.

      100 attempts equates to 10 seconds.

    • docker

      protected String docker
      Docker command.
    • version

      protected final String version
  • Method Details

    • extraProperties

      protected void extraProperties(Properties properties)
      Override to configure extra properties.
    • buildJdbcUrl

      protected String buildJdbcUrl()
      Override to build appropriate jdbc url.
    • createOptions

      public Db2Container.Builder createOptions(String createOptions)
      Sets additional create options specified in https://www.ibm.com/docs/en/db2/11.5?topic=commands-create-database Example: 'USING CODESET UTF-8 TERRITORY DE COLLATE USING IDENTITY PAGESIZE 32768'
    • configOptions

      public Db2Container.Builder configOptions(String configOptions)
      Sets DB2 config options. See https://www.ibm.com/docs/en/db2/11.5?topic=commands-update-database-configuration for details Example 'USING STRING_UNITS CODEUNITS32
    • build

      public Db2Container build()
      Description copied from interface: ContainerBuilder
      Build the container.
    • start

      public Db2Container start()
      Description copied from interface: ContainerBuilder
      Build and start the container.
    • getDbName

      protected String getDbName()
    • properties

      public Db2Container.Builder properties(Properties properties)
      Load configuration from properties.
      Specified by:
      properties in interface ContainerBuilder<C,SELF extends io.ebean.test.containers.BaseDbBuilder<C,SELF>>
    • adminUser

      public Db2Container.Builder adminUser(String dbAdminUser)
      Set the password for the DB admin user.
      Specified by:
      adminUser in interface ContainerBuilderDb<C,SELF extends io.ebean.test.containers.BaseDbBuilder<C,SELF>>
    • adminPassword

      public Db2Container.Builder adminPassword(String adminPassword)
      Set the password for the DB admin user.
      Specified by:
      adminPassword in interface ContainerBuilderDb<C,SELF extends io.ebean.test.containers.BaseDbBuilder<C,SELF>>
    • tmpfs

      public Db2Container.Builder tmpfs(String tmpfs)
      Set the temp fs for in-memory use.
      Specified by:
      tmpfs in interface ContainerBuilderDb<C,SELF extends io.ebean.test.containers.BaseDbBuilder<C,SELF>>
    • fastStartMode

      public Db2Container.Builder fastStartMode(boolean fastStartMode)
      Defaults to true - If true ONLY check the existence of the DB and if present skip the other usual checks (does user exist, create extensions if not exists etc).
      Specified by:
      fastStartMode in interface ContainerBuilderDb<C,SELF extends io.ebean.test.containers.BaseDbBuilder<C,SELF>>
    • dbName

      public Db2Container.Builder dbName(String dbName)
      Set the DB name - e.g. my_app1, my_app2, my_app3 etc. Defaults to test_db.

      The DB name should not have any special characters (alpha and underscore) and should be unique for the project.

      ebean-test-docker is designed to share the same container across multiple projects. The way this works is that each project should have a unique db name. This means that as developers testing is faster as containers stay running and are shared and running tests for a project means setting up unique "database" using the dbName.

      Specified by:
      dbName in interface ContainerBuilderDb<C,SELF extends io.ebean.test.containers.BaseDbBuilder<C,SELF>>
    • user

      public Db2Container.Builder user(String user)
      Set the DB user. Defaults to being the same as the dbName.
      Specified by:
      user in interface ContainerBuilderDb<C,SELF extends io.ebean.test.containers.BaseDbBuilder<C,SELF>>
    • password

      public Db2Container.Builder password(String password)
      Set the DB password. Defaults to test.
      Specified by:
      password in interface ContainerBuilderDb<C,SELF extends io.ebean.test.containers.BaseDbBuilder<C,SELF>>
    • schema

      public Db2Container.Builder schema(String schema)
      Set the DB schema.
      Specified by:
      schema in interface ContainerBuilderDb<C,SELF extends io.ebean.test.containers.BaseDbBuilder<C,SELF>>
    • characterSet

      public Db2Container.Builder characterSet(String characterSet)
      Set the character set to use.
      Specified by:
      characterSet in interface ContainerBuilderDb<C,SELF extends io.ebean.test.containers.BaseDbBuilder<C,SELF>>
    • collation

      public Db2Container.Builder collation(String collation)
      Set the collation to use.
      Specified by:
      collation in interface ContainerBuilderDb<C,SELF extends io.ebean.test.containers.BaseDbBuilder<C,SELF>>
    • extensions

      public Db2Container.Builder extensions(String extensions)
      Set the DB extensions to install in comma delimited form.

      Postgres hstore, pgcrypto etc.

      Example: .extensions("hstore,pgcrypto,uuid-ossp")

      Specified by:
      extensions in interface ContainerBuilderDb<C,SELF extends io.ebean.test.containers.BaseDbBuilder<C,SELF>>
    • initSqlFile

      public Db2Container.Builder initSqlFile(String initSqlFile)
      Set the SQL file to execute after creating the database.
      Specified by:
      initSqlFile in interface ContainerBuilderDb<C,SELF extends io.ebean.test.containers.BaseDbBuilder<C,SELF>>
    • seedSqlFile

      public Db2Container.Builder seedSqlFile(String seedSqlFile)
      Set the SQL file to execute after creating the database and initSqlFile.
      Specified by:
      seedSqlFile in interface ContainerBuilderDb<C,SELF extends io.ebean.test.containers.BaseDbBuilder<C,SELF>>
    • extraDb

      public Db2Container.Builder extraDb(String extraDb)
      Set the name of an extra database to create.

      Use this when the application being tested uses 2 databases.

      Specified by:
      extraDb in interface ContainerBuilderDb<C,SELF extends io.ebean.test.containers.BaseDbBuilder<C,SELF>>
    • extraDbUser

      public Db2Container.Builder extraDbUser(String extraDbUser)
      Set the name of an extra user to create. If an extra database is also created this would be the owner of that extra database.

      Use this when the application being tested uses 2 databases.

      Specified by:
      extraDbUser in interface ContainerBuilderDb<C,SELF extends io.ebean.test.containers.BaseDbBuilder<C,SELF>>
    • extraDbPassword

      public Db2Container.Builder extraDbPassword(String extraDbPassword)
      Set the password for an extra user. If nothing is set this would default to be the same as the main users password.

      Use this when the application being tested uses 2 databases.

      Specified by:
      extraDbPassword in interface ContainerBuilderDb<C,SELF extends io.ebean.test.containers.BaseDbBuilder<C,SELF>>
    • extraDbExtensions

      public Db2Container.Builder extraDbExtensions(String extraDbExtensions)
      Description copied from interface: ContainerBuilderDb
      Set extra database extensions.
      Specified by:
      extraDbExtensions in interface ContainerBuilderDb<C,SELF extends io.ebean.test.containers.BaseDbBuilder<C,SELF>>
    • extraDbInitSqlFile

      public Db2Container.Builder extraDbInitSqlFile(String extraDbInitSqlFile)
      Set a file to execute after creating the extra database.
      Specified by:
      extraDbInitSqlFile in interface ContainerBuilderDb<C,SELF extends io.ebean.test.containers.BaseDbBuilder<C,SELF>>
    • extraDbSeedSqlFile

      public Db2Container.Builder extraDbSeedSqlFile(String extraDbSeedSqlFile)
      Set a file to execute after creating the extra database.
      Specified by:
      extraDbSeedSqlFile in interface ContainerBuilderDb<C,SELF extends io.ebean.test.containers.BaseDbBuilder<C,SELF>>
    • inMemory

      public Db2Container.Builder inMemory(boolean inMemory)
      Set to true to run using in memory storage for data via tmpfs.
      Specified by:
      inMemory in interface ContainerBuilderDb<C,SELF extends io.ebean.test.containers.BaseDbBuilder<C,SELF>>
    • initDefaultSchema

      protected void initDefaultSchema()
      Set the schema if it hasn't already set. Some databases (NuoDB) effectively require a default schema and it is reasonable for this to default to the username.
    • buildSummary

      protected String buildSummary()
      Return summary of the port db name and other details.
    • deriveUsername

      protected String deriveUsername()
    • internalConfig

      protected io.ebean.test.containers.InternalConfigDb internalConfig()
      Return the internal configuration.
    • docker

      protected String docker()
    • getHost

      protected String getHost()
    • getPort

      protected int getPort()
    • self

      protected Db2Container.Builder self()
    • startMode

      public Db2Container.Builder startMode(StartMode startMode)
      Description copied from interface: ContainerBuilder
      Set the start mode. One of create, dropCreate, or container [only].
      Specified by:
      startMode in interface ContainerBuilder<C,SELF extends io.ebean.test.containers.BaseBuilder<C,SELF>>
    • shutdownMode

      public Db2Container.Builder shutdownMode(StopMode shutdownMode)
      Description copied from interface: ContainerBuilder
      Set the shutdown hook mode to automatically stop/remove the container on JVM shutdown.
      Specified by:
      shutdownMode in interface ContainerBuilder<C,SELF extends io.ebean.test.containers.BaseBuilder<C,SELF>>
    • prop

      protected String prop(Properties properties, String key, String defaultValue)
    • prop

      protected int prop(Properties properties, String key, int defaultValue)
    • containerName

      public Db2Container.Builder containerName(String containerName)
      Set the container name.
      Specified by:
      containerName in interface ContainerBuilder<C,SELF extends io.ebean.test.containers.BaseBuilder<C,SELF>>
    • mirror

      public Db2Container.Builder mirror(String mirror)
      Set a container mirror for images to use with CI builds.

      For example "my.ecr/mirror".

      The mirror is not used when deemed to be running locally. Typically determined via a ~/.ebean/ignore-docker-shutdown file or alternative marker file set via system property ebean.test.localDevelopment>.

      Specified by:
      mirror in interface ContainerBuilder<C,SELF extends io.ebean.test.containers.BaseBuilder<C,SELF>>
    • port

      public Db2Container.Builder port(int port)
      Set the exposed port with 0 meaning use a random port.

      When the port is set to `0` then docker will assign a random port. This port is available after the container has started.

      
      
        LocalstackContainer container = LocalstackContainer.builder("0.14")
          .port(0)
          .build();
      
        container.start();
      
        int assignedPort = container.port();
      
        AmazonDynamoDB amazonDynamoDB = container.dynamoDB();
      
       
      Specified by:
      port in interface ContainerBuilder<C,SELF extends io.ebean.test.containers.BaseBuilder<C,SELF>>
    • internalPort

      public Db2Container.Builder internalPort(int internalPort)
      Set the internal (to the container) port.
      Specified by:
      internalPort in interface ContainerBuilder<C,SELF extends io.ebean.test.containers.BaseBuilder<C,SELF>>
    • adminPort

      public Db2Container.Builder adminPort(int adminPort)
      Set the exposed admin port.
      Specified by:
      adminPort in interface ContainerBuilder<C,SELF extends io.ebean.test.containers.BaseBuilder<C,SELF>>
    • adminInternalPort

      public Db2Container.Builder adminInternalPort(int adminInternalPort)
      Set the internal admin (to the container) port.
      Specified by:
      adminInternalPort in interface ContainerBuilder<C,SELF extends io.ebean.test.containers.BaseBuilder<C,SELF>>
    • image

      public Db2Container.Builder image(String image)
      Set the docker image to use.
      Specified by:
      image in interface ContainerBuilder<C,SELF extends io.ebean.test.containers.BaseBuilder<C,SELF>>
    • maxReadyAttempts

      public Db2Container.Builder maxReadyAttempts(int maxReadyAttempts)
      Set the max attempts to wait for DB ready.
      Specified by:
      maxReadyAttempts in interface ContainerBuilder<C,SELF extends io.ebean.test.containers.BaseBuilder<C,SELF>>
    • docker

      public Db2Container.Builder docker(String docker)
      Set the docker command to use (defaults to 'docker').
      Specified by:
      docker in interface ContainerBuilder<C,SELF extends io.ebean.test.containers.BaseBuilder<C,SELF>>
    • buildExtraJdbcUrl

      protected String buildExtraJdbcUrl()
      Override to build jdbc url for extraDb.
    • buildJdbcAdminUrl

      protected String buildJdbcAdminUrl()