Skip to content

Commit 45bf199

Browse files
committed
Handle deserialisation to recreating local connection
1 parent 62b90df commit 45bf199

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/main/java/io/jenkins/plugins/junit/storage/database/DatabaseTestResultStorage.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import hudson.tasks.junit.TrendTestResultSummary;
1717
import io.jenkins.plugins.junit.storage.JunitTestResultStorage;
1818
import io.jenkins.plugins.junit.storage.JunitTestResultStorageDescriptor;
19-
import io.jenkins.plugins.junit.storage.database.Messages;
2019
import io.jenkins.plugins.junit.storage.TestResultImpl;
2120
import java.io.IOException;
2221
import 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

Comments
 (0)