private Connection wrapConnection(
        final Connection connection,
        final JdbcDatabaseContainer container,
        final ConnectionUrl connectionUrl
    ) {
        final boolean isDaemon = connectionUrl.isInDaemonMode() || connectionUrl.isReusable();

        Set<Connection> connections = containerConnections.computeIfAbsent(
            container.getContainerId(),
            k -> new HashSet<>()
        );

        connections.add(connection);

        final Set<Connection> finalConnections = connections;

        return new ConnectionWrapper(
            connection,
            () -> {
                finalConnections.remove(connection);
                if (!isDaemon && finalConnections.isEmpty()) {
                    synchronized (jdbcUrlContainerCache) {
                        container.stop();
                        jdbcUrlContainerCache.remove(connectionUrl.getUrl());
                    }
                }
            }
        );
    }
Wrap the connection, setting up a callback to be called when the connection is closed.
<p>
When there are no more open connections, the container itself will be stopped.

@param connection    the new connection to be wrapped
@param container     the container which the connection is associated with
@param connectionUrl {@link ConnectionUrl} instance representing JDBC Url for this connection
@return the connection, wrapped
modules/jdbc/src/main/java/org/testcontainers/jdbc/ContainerDatabaseDriver.java