Skip to content

Commit bae1d00

Browse files
simplify, use methods from DatabaseTools
1 parent fde1909 commit bae1d00

File tree

1 file changed

+8
-31
lines changed

1 file changed

+8
-31
lines changed

sqldev/src/main/java/org/utplsql/sqldev/runner/UtplsqlRunner.java

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.awt.Dimension;
1919
import java.awt.Toolkit;
2020
import java.sql.Connection;
21-
import java.sql.SQLException;
2221
import java.text.SimpleDateFormat;
2322
import java.util.Arrays;
2423
import java.util.Date;
@@ -30,7 +29,7 @@
3029

3130
import org.utplsql.sqldev.dal.RealtimeReporterDao;
3231
import org.utplsql.sqldev.dal.RealtimeReporterEventConsumer;
33-
import org.utplsql.sqldev.exception.GenericDatabaseAccessException;
32+
import org.utplsql.sqldev.model.DatabaseTools;
3433
import org.utplsql.sqldev.model.runner.PostRunEvent;
3534
import org.utplsql.sqldev.model.runner.PostSuiteEvent;
3635
import org.utplsql.sqldev.model.runner.PostTestEvent;
@@ -45,10 +44,6 @@
4544
import org.utplsql.sqldev.ui.runner.RunnerPanel;
4645
import org.utplsql.sqldev.ui.runner.RunnerView;
4746

48-
import oracle.dbtools.raptor.utils.Connections;
49-
import oracle.javatools.db.DBException;
50-
import oracle.jdeveloper.db.ConnectionException;
51-
5247
public class UtplsqlRunner implements RealtimeReporterEventConsumer {
5348
private static final Logger logger = Logger.getLogger(UtplsqlRunner.class.getName());
5449

@@ -80,34 +75,16 @@ private void setConnection(final String connectionName) {
8075
if (connectionName == null) {
8176
throw new NullPointerException("Cannot initialize a RealtimeConsumer without a ConnectionName");
8277
} else {
83-
try {
84-
producerConn = Connections.getInstance()
85-
.cloneConnection(Connections.getInstance().getConnection(connectionName));
86-
consumerConn = Connections.getInstance()
87-
.cloneConnection(Connections.getInstance().getConnection(connectionName));
88-
} catch (ConnectionException | DBException e) {
89-
final String msg = "Error creating producer and consumer connections due to " + e.getMessage();
90-
logger.severe(() -> msg);
91-
throw new GenericDatabaseAccessException(msg, e);
92-
}
78+
producerConn = DatabaseTools.cloneConnection(connectionName);
79+
consumerConn = DatabaseTools.cloneConnection(connectionName);
9380
}
9481
this.connectionName = connectionName;
9582
}
96-
97-
private void closeConnection(Connection conn) {
98-
try {
99-
if (!conn.isClosed()) {
100-
conn.close();
101-
}
102-
} catch (SQLException e) {
103-
logger.warning(() -> "could not close connection");
104-
}
105-
}
10683

10784
public void dispose() {
10885
// running in SQL Developer
109-
closeConnection(producerConn);
110-
closeConnection(consumerConn);
86+
DatabaseTools.closeConnection(producerConn);
87+
DatabaseTools.closeConnection(consumerConn);
11188
}
11289

11390
@Override
@@ -267,7 +244,7 @@ private void produce() {
267244
logger.fine(() -> "All events produced for reporter id " + reporterId + ".");
268245
} catch (Exception e) {
269246
logger.severe(() -> "Error while producing events for reporter id " + reporterId + ": "
270-
+ (e != null ? e.getMessage() : ""));
247+
+ (e != null ? e.getMessage() : "???"));
271248
}
272249
}
273250

@@ -277,9 +254,9 @@ private void consume() {
277254
final RealtimeReporterDao dao = new RealtimeReporterDao(consumerConn);
278255
dao.consumeReport(reporterId, this);
279256
logger.fine(() -> "All events consumed.");
280-
} catch (final Exception e) {
257+
} catch (Exception e) {
281258
logger.severe(() -> "Error while consuming events for reporter id " + reporterId + ": "
282-
+ (e != null ? e.getMessage() : ""));
259+
+ (e != null ? e.getMessage() : "???"));
283260
}
284261
if (run.getTotalNumberOfTests() < 0) {
285262
run.setStatus(UtplsqlResources.getString("RUNNER_NO_TESTS_FOUND_TEXT"));

0 commit comments

Comments
 (0)