8000 Adding get connection method to connectioninfo · Pazus/utPLSQL-cli@9d50741 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9d50741

Browse files
committed
Adding get connection method to connectioninfo
1 parent 28c87e9 commit 9d50741

File tree

2 files changed

+38
-54
lines changed

2 files changed

+38
-54
lines changed

src/main/java/io/github/utplsql/cli/ConnectionInfo.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import com.beust.jcommander.ParameterException;
44

5+
import java.sql.Connection;
6+
import java.sql.DriverManager;
7+
import java.sql.SQLException;
58
import java.util.regex.Matcher;
69
import java.util.regex.Pattern;
710

@@ -32,6 +35,10 @@ public class ConnectionInfo {
3235
public ConnectionInfo() {
3336
}
3437

38+
public Connection getConnection() throws SQLException {
39+
return DriverManager.getConnection(getConnectionUrl(), getUser(), getPassword());
40+
}
41+
3542
public ConnectionInfo parseConnectionString(String connectionString) throws ParameterException {
3643
Pattern p = Pattern.compile(CONNSTR_PATTERN);
3744
Matcher m = p.matcher(connectionString);

src/main/java/io/github/utplsql/cli/RunCommand.java

Lines changed: 31 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
import com.beust.jcommander.Parameter;
44
import com.beust.jcommander.Parameters;
55
import io.github.utplsql.api.OutputBuffer;
6-
import io.github.utplsql.api.OutputBufferLines;
76
import io.github.utplsql.api.TestRunner;
87
import io.github.utplsql.api.types.BaseReporter;
98
import io.github.utplsql.api.types.DocumentationReporter;
10-
import io.github.utplsql.api.utPLSQL;
119

1210
import java.sql.Connection;
1311
import java.sql.SQLException;
@@ -24,15 +22,23 @@ public class RunCommand {
2422

2523
@Parameter(
2624
required = true, converter = ConnectionStringConverter.class,
25+
arity = 1,
2726
description = "user/pass@[[host][:port]/]db")
2827
private List<ConnectionInfo> connectionInfoList;
2928

3029
@Parameter(
3130
names = {"-p", "--path"},
3231
description = "run suites/tests by path, format: \n" +
33-
"schema or schema:[suite ...][.test] or schema[.suite ...][.test]")
32+
"-p schema or schema:[suite ...][.test] or schema[.suite ...][.test]")
3433
private List<String> testPaths;
3534

35+
@Parameter(
36+
names = {"-f", "--format"},
37+
variableArity = true,
38+
description = "output reporter format: \n" +
39+
"-f reporter_name [output_file] [console_output]")
40+
private List<String> reporterParams;
41+
3642
public ConnectionInfo getConnectionInfo() {
3743
return connectionInfoList.get(0);
3844
}
@@ -44,78 +50,49 @@ public String getTestPaths() {
4450
return (testPaths == null) ? null : String.join(",", testPaths);
4551
}
4652

53+
public List<String> getReporterParams() {
54+
return reporterParams;
55+
}
56+
4757
public void run() throws Exception {
48-
ConnectionInfo ci = getConnectionInfo();
58+
final ConnectionInfo ci = getConnectionInfo();
4959
System.out.println("Running Tests For: " + ci.toString());
5060

51-
utPLSQL.init(ci.getConnectionUrl(), ci.getUser(), ci.getPassword());
52-
5361
String tempTestPaths = getTestPaths();
5462
if (tempTestPaths == null) tempTestPaths = ci.getUser();
5563

56-
final BaseReporter reporter = createDocumentationReporter();
64+
final BaseReporter reporter = new DocumentationReporter();
5765
final String testPaths = tempTestPaths;
5866

67+
try (Connection conn = ci.getConnection()) {
68+
reporter.init(conn);
69+
} catch (SQLException e) {
70+
// TODO
71+
e.printStackTrace();
72+
}
73+
5974
ExecutorService executorService = Executors.newFixedThreadPool(2);
6075

6176
executorService.submit(() -> {
62-
Connection conn = null;
63-
try {
64-
conn = utPLSQL.getConnection();
77+
try (Connection conn = ci.getConnection()){
6578
new TestRunner().run(conn, testPaths, reporter);
66-
67-
OutputBufferLines outputLines = new OutputBuffer(reporter.getReporterId())
68-
.fetchAll(conn);
69-
70-
if (outputLines.getLines().size() > 0)
71-
System.out.println(outputLines.toString());
7279
} catch (SQLException e) {
7380
// TODO
7481
e.printStackTrace();
75-
} finally {
76-
if (conn != null)
77-
try { conn.close(); } catch (SQLException ignored) {}
7882
}
7983
});
8084

81-
// executorService.submit(() -> {
82-
// Connection conn = null;
83-
// try {
84-
// conn = utPLSQL.getConnection();
85-
// OutputBufferLines outputLines;
86-
// do {
87-
// outputLines = new OutputBuffer(reporter.getReporterId())
88-
// .fetchAvailable(conn);
89-
//
90-
// Thread.sleep(500);
91-
//
92-
// if (outputLines.getLines().size() > 0)
93-
// System.out.println(outputLines.toString());
94-
// } while (!outputLines.isFinished());
95-
// } catch (SQLException | InterruptedException e) {
96-
// // TODO
97-
// e.printStackTrace();
98-
// } finally {
99-
// if (conn != null)
100-
// try { conn.close(); } catch (SQLException ignored) {}
101-
// }
102-
// });
85+
executorService.submit(() -> {
86+
try (Connection conn = ci.getConnection()){
87+
new OutputBuffer(reporter).printAvailable(conn, System.out);
88+
} catch (SQLException e) {
89+
// TODO
90+
e.printStackTrace();
91+
}
92+
});
10393

10494
executorService.shutdown();
10595
executorService.awaitTermination(60, TimeUnit.MINUTES);
10696
}
10797

108-
private BaseReporter createDocumentationReporter() throws SQLException {
109-
Connection conn = null;
110-
try {
111-
conn = utPLSQL.getConnection();
112-
BaseReporter reporter = new DocumentationReporter();
113-
reporter.setReporterId(utPLSQL.newSysGuid(conn));
114-
return reporter;
115-
} finally {
116-
if (conn != null)
117-
try { conn.close(); } catch (SQLException ignored) {}
118-
}
119-
}
120-
12198
}

0 commit comments

Comments
 (0)
0