Package org.testcontainers.containers
Class JdbcDatabaseContainer<SELF extends JdbcDatabaseContainer<SELF>>
java.lang.Object
org.testcontainers.containers.GenericContainer<SELF>
org.testcontainers.containers.JdbcDatabaseContainer<SELF>
- All Implemented Interfaces:
AutoCloseable,org.testcontainers.containers.Container<SELF>,org.testcontainers.containers.ContainerState,org.testcontainers.containers.traits.LinkableContainer,org.testcontainers.containers.wait.strategy.WaitStrategyTarget,org.testcontainers.lifecycle.Startable
public abstract class JdbcDatabaseContainer<SELF extends JdbcDatabaseContainer<SELF>>
extends org.testcontainers.containers.GenericContainer<SELF>
implements org.testcontainers.containers.traits.LinkableContainer
Base class for containers that expose a JDBC connection
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.testcontainers.containers.Container
org.testcontainers.containers.Container.ExecResult -
Field Summary
FieldsModifier and TypeFieldDescriptionFields inherited from class org.testcontainers.containers.GenericContainer
CONTAINER_RUNNING_TIMEOUT_SEC, dependencies, dockerClient, INTERNAL_HOST_HOSTNAME, waitStrategyFields inherited from interface org.testcontainers.containers.ContainerState
STATE_HEALTHY -
Constructor Summary
ConstructorsConstructorDescriptionJdbcDatabaseContainer(@NonNull String dockerImageName) Deprecated.JdbcDatabaseContainer(@NonNull Future<String> image) JdbcDatabaseContainer(org.testcontainers.utility.DockerImageName dockerImageName) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddParameter(String paramName, String value) protected StringconstructUrlForConnection(String queryString) Template method for constructing the JDBC URL to be used for creatingConnections.protected StringconstructUrlParameters(String startCharacter, String delimiter) protected StringconstructUrlParameters(String startCharacter, String delimiter, String endCharacter) protected voidcontainerIsStarted(com.github.dockerjava.api.command.InspectContainerResponse containerInfo) createConnection(String queryString) Creates a connection to the underlying containerized database instance.createConnection(String queryString, Properties info) Creates a connection to the underlying containerized database instance.protected intDeprecated.should not be overridden anymore, usewithConnectTimeoutSeconds(int)in constructor insteadprotected org.testcontainers.delegate.DatabaseDelegateabstract StringObtain an instance of the correct JDBC driver for this particular database container typeabstract Stringabstract Stringprotected intDeprecated.should not be overridden anymore, usewithStartupTimeoutSeconds(int)in constructor insteadprotected abstract Stringabstract Stringprotected voidoptionallyMapResourceParameterAsVolume(@NotNull String paramName, @NotNull String pathNameInContainer, @NotNull String defaultResource) Deprecated.protected voidoptionallyMapResourceParameterAsVolume(@NotNull String paramName, @NotNull String pathNameInContainer, @NotNull String defaultResource, @Nullable Integer fileMode) protected voidLoad init script content and apply it to the database if initScriptPath is setvoidsetParameters(Map<String, String> parameters) protected voidwithConnectTimeoutSeconds(int connectTimeoutSeconds) Set time to allow for the database to start and establish an initial connection, in seconds.withDatabaseName(String dbName) withInitScript(String initScriptPath) Sets a script for initialization.withInitScripts(Iterable<String> initScriptPaths) Sets an ordered collection of scripts for initialization.withInitScripts(String... initScriptPaths) Sets an ordered array of scripts for initialization.withPassword(String password) withStartupTimeoutSeconds(int startupTimeoutSeconds) Set startup time to allow, including image pull time, in seconds.withUrlParam(String paramName, String paramValue) withUsername(String username) Methods inherited from class org.testcontainers.containers.GenericContainer
addEnv, addExposedPort, addExposedPorts, addFileSystemBind, addFixedExposedPort, addFixedExposedPort, addLink, canBeReused, configure, containerIsCreated, containerIsStarted, containerIsStarting, containerIsStarting, containerIsStopped, containerIsStopping, copyFileFromContainer, createVolumeDirectory, dependsOn, dependsOn, dependsOn, doStart, equals, getBinds, getCommandParts, getContainerId, getContainerInfo, getContainerName, getCopyToFileContainerPathMap, getCreateContainerCmdModifiers, getDependencies, getDockerClient, getDockerImageName, getEnv, getEnvMap, getExposedPorts, getExtraHosts, getImage, getIpAddress, getLabels, getLinkedContainers, getLivenessCheckPort, getLivenessCheckPortNumbers, getLivenessCheckPorts, getLogConsumers, getNetwork, getNetworkAliases, getNetworkMode, getPortBindings, getShmSize, getStartupAttempts, getStartupCheckStrategy, getTestHostIpAddress, getTmpFsMapping, getVolumesFroms, getWaitStrategy, getWorkingDirectory, hashCode, isHostAccessible, isPrivilegedMode, isShouldBeReused, logger, setBinds, setCommand, setCommand, setCommandParts, setContainerDef, setCopyToFileContainerPathMap, setDockerImageName, setEnv, setExposedPorts, setExtraHosts, setHostAccessible, setImage, setLabels, setLinkedContainers, setLogConsumers, setNetwork, setNetworkAliases, setNetworkMode, setPortBindings, setPrivilegedMode, setShmSize, setStartupAttempts, setStartupCheckStrategy, setTmpFsMapping, setVolumesFroms, setWaitStrategy, setWorkingDirectory, start, stop, toString, waitingFor, withAccessToHost, withClasspathResourceMapping, withClasspathResourceMapping, withCommand, withCommand, withCopyFileToContainer, withCopyToContainer, withCreateContainerCmdModifier, withEnv, withEnv, withExposedPorts, withExtraHost, withFileSystemBind, withImagePullPolicy, withLabel, withLabels, withLogConsumer, withMinimumRunningDuration, withNetwork, withNetworkAliases, withNetworkMode, withPrivilegedMode, withReuse, withSharedMemorySize, withStartupAttempts, withStartupCheckStrategy, withStartupTimeout, withTmpFs, withVolumesFrom, withWorkingDirectoryMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.testcontainers.containers.Container
addFileSystemBind, followOutput, followOutput, self, withEnv, withFileSystemBindMethods inherited from interface org.testcontainers.containers.ContainerState
copyFileFromContainer, copyFileToContainer, copyFileToContainer, execInContainer, execInContainer, execInContainer, execInContainer, execInContainerWithUser, execInContainerWithUser, getBoundPortNumbers, getContainerIpAddress, getCurrentContainerInfo, getFirstMappedPort, getHost, getLogs, getLogs, getMappedPort, isCreated, isHealthy, isRunningMethods inherited from interface org.testcontainers.containers.traits.LinkableContainer
getContainerNameMethods inherited from interface org.testcontainers.lifecycle.Startable
close
-
Field Details
-
parameters
-
urlParameters
-
-
Constructor Details
-
JdbcDatabaseContainer
Deprecated.useJdbcDatabaseContainer(DockerImageName)instead -
JdbcDatabaseContainer
-
JdbcDatabaseContainer
public JdbcDatabaseContainer(org.testcontainers.utility.DockerImageName dockerImageName)
-
-
Method Details
-
getDriverClassName
- Returns:
- the name of the actual JDBC driver to use
-
getJdbcUrl
- Returns:
- a JDBC URL that may be used to connect to the dockerized DB
-
getDatabaseName
- Returns:
- the database name
-
getUsername
- Returns:
- the standard database username that should be used for connections
-
getPassword
- Returns:
- the standard password that should be used for connections
-
getTestQueryString
- Returns:
- a test query string suitable for testing that this particular database type is alive
-
withUsername
-
withPassword
-
withDatabaseName
-
withUrlParam
-
withStartupTimeoutSeconds
Set startup time to allow, including image pull time, in seconds.- Parameters:
startupTimeoutSeconds- startup time to allow, including image pull time, in seconds- Returns:
- self
-
withConnectTimeoutSeconds
Set time to allow for the database to start and establish an initial connection, in seconds.- Parameters:
connectTimeoutSeconds- time to allow for the database to start and establish an initial connection in seconds- Returns:
- self
-
withInitScript
Sets a script for initialization.- Parameters:
initScriptPath- path to the script file- Returns:
- self
-
withInitScripts
Sets an ordered array of scripts for initialization.- Parameters:
initScriptPaths- paths to the script files- Returns:
- self
-
withInitScripts
Sets an ordered collection of scripts for initialization.- Parameters:
initScriptPaths- paths to the script files- Returns:
- self
-
waitUntilContainerStarted
protected void waitUntilContainerStarted()- Overrides:
waitUntilContainerStartedin classorg.testcontainers.containers.GenericContainer<SELF extends JdbcDatabaseContainer<SELF>>
-
containerIsStarted
protected void containerIsStarted(com.github.dockerjava.api.command.InspectContainerResponse containerInfo) - Overrides:
containerIsStartedin classorg.testcontainers.containers.GenericContainer<SELF extends JdbcDatabaseContainer<SELF>>
-
getJdbcDriverInstance
Obtain an instance of the correct JDBC driver for this particular database container type- Returns:
- a JDBC Driver
- Throws:
JdbcDatabaseContainer.NoDriverFoundException
-
createConnection
public Connection createConnection(String queryString) throws SQLException, JdbcDatabaseContainer.NoDriverFoundException Creates a connection to the underlying containerized database instance.- Parameters:
queryString- query string parameters that should be appended to the JDBC connection URL. The '?' character must be included- Returns:
- a Connection
- Throws:
SQLException- if there is a repeated failure to create the connectionJdbcDatabaseContainer.NoDriverFoundException
-
createConnection
public Connection createConnection(String queryString, Properties info) throws SQLException, JdbcDatabaseContainer.NoDriverFoundException Creates a connection to the underlying containerized database instance.- Parameters:
queryString- query string parameters that should be appended to the JDBC connection URL. The '?' character must be includedinfo- additional properties to be passed to the JDBC driver- Returns:
- a Connection
- Throws:
SQLException- if there is a repeated failure to create the connectionJdbcDatabaseContainer.NoDriverFoundException
-
constructUrlForConnection
Template method for constructing the JDBC URL to be used for creatingConnections. This should be overridden if the JDBC URL and query string concatenation or URL string construction needs to be different to normal.- Parameters:
queryString- query string parameters that should be appended to the JDBC connection URL. The '?' character must be included- Returns:
- a full JDBC URL including queryString
-
constructUrlParameters
-
constructUrlParameters
-
optionallyMapResourceParameterAsVolume
@Deprecated protected void optionallyMapResourceParameterAsVolume(@NotNull @NotNull String paramName, @NotNull @NotNull String pathNameInContainer, @NotNull @NotNull String defaultResource) Deprecated. -
optionallyMapResourceParameterAsVolume
-
runInitScriptIfRequired
protected void runInitScriptIfRequired()Load init script content and apply it to the database if initScriptPath is set -
setParameters
-
addParameter
-
getStartupTimeoutSeconds
Deprecated.should not be overridden anymore, usewithStartupTimeoutSeconds(int)in constructor instead- Returns:
- startup time to allow, including image pull time, in seconds
-
getConnectTimeoutSeconds
Deprecated.should not be overridden anymore, usewithConnectTimeoutSeconds(int)in constructor instead- Returns:
- time to allow for the database to start and establish an initial connection, in seconds
-
getDatabaseDelegate
protected org.testcontainers.delegate.DatabaseDelegate getDatabaseDelegate()
-
JdbcDatabaseContainer(DockerImageName)instead