public abstract class JdbcDatabaseContainer<SELF extends JdbcDatabaseContainer<SELF>>
extends org.testcontainers.containers.GenericContainer<SELF>
implements org.testcontainers.containers.traits.LinkableContainer
Modifier and Type | Class and Description |
---|---|
static class |
JdbcDatabaseContainer.NoDriverFoundException |
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.String,java.lang.String> |
parameters |
protected java.util.Map<java.lang.String,java.lang.String> |
urlParameters |
Constructor and Description |
---|
JdbcDatabaseContainer(org.testcontainers.utility.DockerImageName dockerImageName) |
JdbcDatabaseContainer(@NonNull java.util.concurrent.Future<java.lang.String> image) |
JdbcDatabaseContainer(@NonNull java.lang.String dockerImageName)
Deprecated.
use
JdbcDatabaseContainer(DockerImageName) instead |
Modifier and Type | Method and Description |
---|---|
void |
addParameter(java.lang.String paramName,
java.lang.String value) |
protected java.lang.String |
constructUrlForConnection(java.lang.String queryString)
Template method for constructing the JDBC URL to be used for creating
Connection s. |
protected java.lang.String |
constructUrlParameters(java.lang.String startCharacter,
java.lang.String delimiter) |
protected java.lang.String |
constructUrlParameters(java.lang.String startCharacter,
java.lang.String delimiter,
java.lang.String endCharacter) |
protected void |
containerIsStarted(com.github.dockerjava.api.command.InspectContainerResponse containerInfo) |
java.sql.Connection |
createConnection(java.lang.String queryString)
Creates a connection to the underlying containerized database instance.
|
protected int |
getConnectTimeoutSeconds()
Deprecated.
should not be overridden anymore, use
withConnectTimeoutSeconds(int) in constructor instead |
protected org.testcontainers.delegate.DatabaseDelegate |
getDatabaseDelegate() |
java.lang.String |
getDatabaseName() |
abstract java.lang.String |
getDriverClassName() |
java.sql.Driver |
getJdbcDriverInstance()
Obtain an instance of the correct JDBC driver for this particular database container type
|
abstract java.lang.String |
getJdbcUrl() |
abstract java.lang.String |
getPassword() |
protected int |
getStartupTimeoutSeconds()
Deprecated.
should not be overridden anymore, use
withStartupTimeoutSeconds(int) in constructor instead |
protected abstract java.lang.String |
getTestQueryString() |
abstract java.lang.String |
getUsername() |
protected void |
optionallyMapResourceParameterAsVolume(@NotNull java.lang.String paramName,
@NotNull java.lang.String pathNameInContainer,
@NotNull java.lang.String defaultResource) |
protected void |
runInitScriptIfRequired()
Load init script content and apply it to the database if initScriptPath is set
|
void |
setParameters(java.util.Map<java.lang.String,java.lang.String> parameters) |
protected void |
waitUntilContainerStarted() |
SELF |
withConnectTimeoutSeconds(int connectTimeoutSeconds)
Set time to allow for the database to start and establish an initial connection, in seconds.
|
SELF |
withDatabaseName(java.lang.String dbName) |
SELF |
withInitScript(java.lang.String initScriptPath) |
SELF |
withPassword(java.lang.String password) |
SELF |
withStartupTimeoutSeconds(int startupTimeoutSeconds)
Set startup time to allow, including image pull time, in seconds.
|
SELF |
withUrlParam(java.lang.String paramName,
java.lang.String paramValue) |
SELF |
withUsername(java.lang.String username) |
addEnv, addExposedPort, addExposedPorts, addFileSystemBind, addFixedExposedPort, addFixedExposedPort, addLink, apply, canBeReused, configure, containerIsCreated, containerIsStarted, containerIsStarting, containerIsStarting, containerIsStopped, containerIsStopping, copyFileFromContainer, createVolumeDirectory, dependsOn, dependsOn, dependsOn, doStart, equals, failed, finished, 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, isPrivilegedMode, isShouldBeReused, logger, setBinds, setCommand, setCommand, setCommandParts, setCopyToFileContainerPathMap, setDockerImageName, setEnv, setExposedPorts, setExtraHosts, setImage, setLabels, setLinkedContainers, setLogConsumers, setNetwork, setNetworkAliases, setNetworkMode, setPortBindings, setPrivilegedMode, setShmSize, setStartupAttempts, setStartupCheckStrategy, setTmpFsMapping, setVolumesFroms, setWaitStrategy, setWorkingDirectory, start, starting, stop, succeeded, toString, waitingFor, withClasspathResourceMapping, withClasspathResourceMapping, withCommand, withCommand, withCopyFileToContainer, withCreateContainerCmdModifier, withEnv, withEnv, withExposedPorts, withExtraHost, withFileSystemBind, withImagePullPolicy, withLabel, withLabels, withLogConsumer, withMinimumRunningDuration, withNetwork, withNetworkAliases, withNetworkMode, withPrivilegedMode, withReuse, withSharedMemorySize, withStartupAttempts, withStartupCheckStrategy, withStartupTimeout, withTmpFs, withVolumesFrom, withWorkingDirectory
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getContainerName
addFileSystemBind, followOutput, followOutput, self, withEnv, withFileSystemBind
copyFileFromContainer, copyFileToContainer, copyFileToContainer, execInContainer, execInContainer, getBoundPortNumbers, getContainerIpAddress, getCurrentContainerInfo, getFirstMappedPort, getHost, getLogs, getLogs, getMappedPort, isCreated, isHealthy, isRunning
protected java.util.Map<java.lang.String,java.lang.String> parameters
protected java.util.Map<java.lang.String,java.lang.String> urlParameters
public JdbcDatabaseContainer(@NonNull @NonNull java.lang.String dockerImageName)
JdbcDatabaseContainer(DockerImageName)
insteadpublic JdbcDatabaseContainer(@NonNull @NonNull java.util.concurrent.Future<java.lang.String> image)
public JdbcDatabaseContainer(org.testcontainers.utility.DockerImageName dockerImageName)
public abstract java.lang.String getDriverClassName()
public abstract java.lang.String getJdbcUrl()
public java.lang.String getDatabaseName()
public abstract java.lang.String getUsername()
public abstract java.lang.String getPassword()
protected abstract java.lang.String getTestQueryString()
public SELF withUsername(java.lang.String username)
public SELF withPassword(java.lang.String password)
public SELF withDatabaseName(java.lang.String dbName)
public SELF withUrlParam(java.lang.String paramName, java.lang.String paramValue)
public SELF withStartupTimeoutSeconds(int startupTimeoutSeconds)
startupTimeoutSeconds
- startup time to allow, including image pull time, in secondspublic SELF withConnectTimeoutSeconds(int connectTimeoutSeconds)
connectTimeoutSeconds
- time to allow for the database to start and establish an initial connection in secondspublic SELF withInitScript(java.lang.String initScriptPath)
protected void waitUntilContainerStarted()
waitUntilContainerStarted
in class org.testcontainers.containers.GenericContainer<SELF extends JdbcDatabaseContainer<SELF>>
protected void containerIsStarted(com.github.dockerjava.api.command.InspectContainerResponse containerInfo)
containerIsStarted
in class org.testcontainers.containers.GenericContainer<SELF extends JdbcDatabaseContainer<SELF>>
public java.sql.Driver getJdbcDriverInstance() throws JdbcDatabaseContainer.NoDriverFoundException
JdbcDatabaseContainer.NoDriverFoundException
public java.sql.Connection createConnection(java.lang.String queryString) throws java.sql.SQLException, JdbcDatabaseContainer.NoDriverFoundException
queryString
- query string parameters that should be appended to the JDBC connection URL.
The '?' character must be includedjava.sql.SQLException
- if there is a repeated failure to create the connectionJdbcDatabaseContainer.NoDriverFoundException
protected java.lang.String constructUrlForConnection(java.lang.String queryString)
Connection
s.
This should be overridden if the JDBC URL and query string concatenation or URL string
construction needs to be different to normal.queryString
- query string parameters that should be appended to the JDBC connection URL.
The '?' character must be includedprotected java.lang.String constructUrlParameters(java.lang.String startCharacter, java.lang.String delimiter)
protected java.lang.String constructUrlParameters(java.lang.String startCharacter, java.lang.String delimiter, java.lang.String endCharacter)
protected void optionallyMapResourceParameterAsVolume(@NotNull @NotNull java.lang.String paramName, @NotNull @NotNull java.lang.String pathNameInContainer, @NotNull @NotNull java.lang.String defaultResource)
protected void runInitScriptIfRequired()
public void setParameters(java.util.Map<java.lang.String,java.lang.String> parameters)
public void addParameter(java.lang.String paramName, java.lang.String value)
@Deprecated protected int getStartupTimeoutSeconds()
withStartupTimeoutSeconds(int)
in constructor instead@Deprecated protected int getConnectTimeoutSeconds()
withConnectTimeoutSeconds(int)
in constructor insteadprotected org.testcontainers.delegate.DatabaseDelegate getDatabaseDelegate()