1616import hudson .tasks .junit .TrendTestResultSummary ;
1717import io .jenkins .plugins .junit .storage .JunitTestResultStorage ;
1818import io .jenkins .plugins .junit .storage .JunitTestResultStorageDescriptor ;
19- import io .jenkins .plugins .junit .storage .database .Messages ;
2019import io .jenkins .plugins .junit .storage .TestResultImpl ;
2120import java .io .IOException ;
2221import java .sql .Connection ;
@@ -41,14 +40,21 @@ public class DatabaseTestResultStorage extends JunitTestResultStorage {
4140
4241 static final String CASE_RESULTS_TABLE = "caseResults" ;
4342
44- private transient final ConnectionSupplier connectionSupplier = new LocalConnectionSupplier () ;
43+ private transient ConnectionSupplier connectionSupplier ;
4544
4645 @ DataBoundConstructor
4746 public DatabaseTestResultStorage () {}
4847
48+ public ConnectionSupplier getConnectionSupplier () {
49+ if (connectionSupplier == null ) {
50+ connectionSupplier = new LocalConnectionSupplier ();
51+ }
52+ return connectionSupplier ;
53+ }
54+
4955 @ Override public RemotePublisher createRemotePublisher (Run <?, ?> build ) throws IOException {
5056 try {
51- connectionSupplier .connection (); // make sure we start a local server and create table first
57+ getConnectionSupplier () .connection (); // make sure we start a local server and create table first
5258 } catch (SQLException x ) {
5359 throw new IOException (x );
5460 }
@@ -74,7 +80,7 @@ private interface Querier<T> {
7480 return new TestResultImpl () {
7581 private <T > T query (Querier <T > querier ) {
7682 try {
77- Connection connection = connectionSupplier .connection ();
83+ Connection connection = getConnectionSupplier () .connection ();
7884 return querier .run (connection );
7985 } catch (SQLException x ) {
8086 throw new RuntimeException (x );
0 commit comments