37
37
public class ContainerDatabaseDriver implements Driver {
38
38
39
39
private static final Pattern URL_MATCHING_PATTERN = Pattern .compile ("jdbc:tc:([a-z]+)(:([^:]+))?://[^\\ ?]+(\\ ?.*)?" );
40
+ private static final Pattern DAEMON_MATCHING_PATTERN = Pattern .compile (".*([\\ ?&]?)TC_DAEMON=([^\\ ?&]+).*" );
40
41
private static final Pattern INITSCRIPT_MATCHING_PATTERN = Pattern .compile (".*([\\ ?&]?)TC_INITSCRIPT=([^\\ ?&]+).*" );
41
42
private static final Pattern INITFUNCTION_MATCHING_PATTERN = Pattern .compile (".*([\\ ?&]?)TC_INITFUNCTION=" +
42
43
"((\\ p{javaJavaIdentifierStart}\\ p{javaJavaIdentifierPart}*\\ .)*\\ p{javaJavaIdentifierStart}\\ p{javaJavaIdentifierPart}*)" +
@@ -186,6 +187,9 @@ private Map<String, String> getContainerParameters(String url) {
186
187
* @return the connection, wrapped
187
188
*/
188
189
private Connection wrapConnection (final Connection connection , final JdbcDatabaseContainer container , final String url ) {
190
+ final Matcher matcher = DAEMON_MATCHING_PATTERN .matcher (url );
191
+ final boolean isDaemon = matcher .matches () ? Boolean .parseBoolean (matcher .group (2 )) : false ;
192
+
189
193
Set <Connection > connections = containerConnections .get (container .getContainerId ());
190
194
191
195
if (connections == null ) {
@@ -199,7 +203,7 @@ private Connection wrapConnection(final Connection connection, final JdbcDatabas
199
203
200
204
return new ConnectionWrapper (connection , () -> {
201
205
finalConnections .remove (connection );
202
- if (finalConnections .isEmpty ()) {
206
+ if (! isDaemon && finalConnections .isEmpty ()) {
203
207
container .stop ();
204
208
jdbcUrlContainerCache .remove (url );
205
209
}
0 commit comments