Class EmbeddedPostgres
java.lang.Object
de.softwareforge.testing.postgres.embedded.EmbeddedPostgres
- All Implemented Interfaces:
AutoCloseable
Manages an embedded PostgreSQL server instance.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Creates a newEmbeddedPostgres
instance and starts it.static interface
Deprecated. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The version of postgres used if no specific version has been given. -
Method Summary
Modifier and TypeMethodDescriptionstatic EmbeddedPostgres.Builder
builder()
Returns a newEmbeddedPostgres.Builder
.static EmbeddedPostgres.Builder
Returns a builder with defaultEmbeddedPostgres.Builder.withDefaults()
configuration already applied.void
close()
Closing anEmbeddedPostgres
instance shuts down the connected database instance.createDataSource
(String user, String databaseName) Creates aDataSource
with a specific user and database name.Creates aDataSource
object that connects to the default database.Creates aDataSource
object that connects to the standard system database.static EmbeddedPostgres
Returns an instance that has been started and configured.boolean
int
getPort()
Returns the network (TCP) port for the PostgreSQL server instance.int
hashCode()
Returns the instance id for the PostgreSQL server instance.toString()
-
Field Details
-
DEFAULT_POSTGRES_VERSION
The version of postgres used if no specific version has been given.- See Also:
-
-
Method Details
-
defaultInstance
Returns an instance that has been started and configured. TheEmbeddedPostgres.Builder.withDefaults()
configuration has been applied.- Throws:
IOException
-
builderWithDefaults
Returns a builder with defaultEmbeddedPostgres.Builder.withDefaults()
configuration already applied. -
builder
Returns a newEmbeddedPostgres.Builder
. -
createTemplateDataSource
Creates aDataSource
object that connects to the standard system database.The standard system database is the
template1
database.Any modification to this database will be propagated to any new database that is created with
CREATE DATABASE...
unless another database is explicitly named as the template..- Throws:
SQLException
-
createDefaultDataSource
Creates aDataSource
object that connects to the default database.The default database is the
postgres
database.- Throws:
SQLException
-
createDataSource
@NonNull public DataSource createDataSource(@NonNull String user, @NonNull String databaseName) throws SQLException Creates aDataSource
with a specific user and database name.Creating the DataSource does not create the database or the user itself. This must be done by the calling code (e.g. with a
EmbeddedPostgresPreparer
).- Throws:
SQLException
-
getPort
Returns the network (TCP) port for the PostgreSQL server instance. -
instanceId
Returns the instance id for the PostgreSQL server instance. This id is an alphanumeric string that can be used to differentiate between multiple embedded PostgreSQL server instances. -
toString
-
equals
-
hashCode
-
close
Closing anEmbeddedPostgres
instance shuts down the connected database instance.- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
-
EmbeddedPostgresPreparer
withEmbeddedPostgres.Builder
as type parameter.