Skip to content

Commit c4c6e08

Browse files
author
Samuel Nitsche
committed
Merge branch 'feature/version_check' of https://github.com/utPLSQL/utPLSQL-java-api into feature/version_check
2 parents a1113b8 + 35b73eb commit c4c6e08

File tree

3 files changed

+100
-7
lines changed

3 files changed

+100
-7
lines changed

README.md

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,73 @@
11
[![Build Status](https://img.shields.io/travis/utPLSQL/utPLSQL-java-api/develop.svg?label=develop-branch)](https://travis-ci.org/utPLSQL/utPLSQL-java-api)
22
[![Build Status](https://img.shields.io/travis/utPLSQL/utPLSQL-java-api/master.svg?label=master-branch)](https://travis-ci.org/utPLSQL/utPLSQL-java-api)
33

4-
##### Configuring the Oracle Maven Repository #####
4+
# utPLSQL-java-api
5+
This is a collection of classes, that makes easy to access the [utPLSQL v3](https://github.com/utPLSQL/utPLSQL/) database objects using Java.
6+
7+
* Uses [ut_runner.run](https://github.com/utPLSQL/utPLSQL/blob/develop/docs/userguide/running-unit-tests.md#ut_runnerrun-procedures) methods to execute tests.
8+
* Can gather results asynchronously from multiple reporters.
9+
10+
## Downloading
11+
This is a Maven Library project, you can add on your Java project as a dependency. At the moment, it's not available in any public Maven repository, but you can clone it and install as a local dependency (follow the Contributing session).
12+
13+
```xml
14+
<dependency>
15+
<groupId>org.utplsql</groupId>
16+
<artifactId>java-api</artifactId>
17+
<version>1.0-SNAPSHOT</version>
18+
<scope>compile</scope>
19+
</dependency>
20+
```
21+
22+
## Usage
23+
24+
Executing tests using default parameters:
25+
```java
26+
try (Connection conn = DriverManager.getConnection(url)) {
27+
new TestRunner().run(conn);
28+
} catch (SQLException e) {
29+
e.printStackTrace();
30+
}
31+
```
32+
33+
Executing tests and printing results to screen:
34+
```java
35+
try (Connection conn = DriverManager.getConnection(url)) {
36+
Reporter documentationReporter = new DocumentationReporter().init(conn);
37+
38+
new TestRunner()
39+
.addReporter(documentationReporter)
40+
.run(conn);
41+
42+
new OutputBuffer(documentationReporter)
43+
.printAvailable(conn, System.out);
44+
} catch (SQLException e) {
45+
e.printStackTrace();
46+
}
47+
```
48+
49+
## Contributing
50+
To develop it locally, you need to setup your maven environment.
51+
52+
### Maven Installation
53+
That's the easy part, you just need to download the Maven binaries and extract it somewhere, then put the maven/bin folder on your PATH.
54+
55+
https://maven.apache.org/install.html
56+
57+
*Don't forget to configure your JAVA_HOME environment variable.*
58+
59+
### Oracle Maven Repository
60+
The library uses OJDBC Driver to connect to the database, it's added as a maven dependency. To be able to download the Oracle dependencies, you need to configure your access to Oracle's Maven Repository:
61+
562
http://docs.oracle.com/middleware/1213/core/MAVEN/config_maven_repo.htm#MAVEN9010
6-
https://blogs.oracle.com/dev2dev/entry/how_to_get_oracle_jdbc#pom
763

8-
##### IntelliJ IDEA Maven Module #####
9-
https://www.jetbrains.com/help/idea/2017.1/maven.html
64+
*Sections 6.1 and 6.5 are the more important ones, and the only ones you need if you're using the latest Maven version.*
65+
66+
After configuring your access to Oracle's Maven repository, you will be able to successfully build this API.
67+
68+
```bash
69+
cd utPLSQL-java-api
70+
mvn clean package install -DskipTests
71+
```
72+
73+
The cmd above is ignoring unit tests because it needs a database connection with the latest utPLSQL v3 installed. Please take a look on .travis.yml and .travis folder to see how testing was configured.

src/main/java/org/utplsql/api/DBHelper.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
public final class DBHelper {
1414

15-
public static final String UTPLSQL_VERSION = "3.0.3";
15+
public static final String UTPLSQL_COMPATIBILITY_VERSION = "3.0.3";
1616

1717
private DBHelper() {}
1818

@@ -93,7 +93,31 @@ public static boolean versionCompatibilityCheck(Connection conn, String requeste
9393

9494
public static boolean versionCompatibilityCheck(Connection conn)
9595
throws SQLException {
96-
return versionCompatibilityCheck(conn, UTPLSQL_VERSION);
96+
return versionCompatibilityCheck(conn, UTPLSQL_COMPATIBILITY_VERSION);
97+
}
98+
99+
/**
100+
* Enable the dbms_output buffer with unlimited size.
101+
* @param conn the connection
102+
*/
103+
public static void enableDBMSOutput(Connection conn) {
104+
try (CallableStatement call = conn.prepareCall("BEGIN dbms_output.enable(NULL); END;")) {
105+
call.execute();
106+
} catch (SQLException e) {
107+
System.out.println("Failed to enable dbms_output.");
108+
}
109+
}
110+
111+
/**
112+
* Disable the dbms_output buffer.
113+
* @param conn the connection
114+
*/
115+
public static void disableDBMSOutput(Connection conn) {
116+
try (CallableStatement call = conn.prepareCall("BEGIN dbms_output.disable(); END;")) {
117+
call.execute();
118+
} catch (SQLException e) {
119+
System.out.println("Failed to disable dbms_output.");
120+
}
97121
}
98122

99123
/** Checks if actual API-version is compatible with utPLSQL database version and throws a RuntimeException if not

src/main/java/org/utplsql/api/TestRunner.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public void run(Connection conn) throws SomeTestsFailedException, SQLException {
107107
OracleConnection oraConn = conn.unwrap(OracleConnection.class);
108108
CallableStatement callableStatement = null;
109109
try {
110+
DBHelper.enableDBMSOutput(conn);
111+
110112
callableStatement = conn.prepareCall(
111113
"BEGIN " +
112114
"ut_runner.run(" +
@@ -176,8 +178,11 @@ public void run(Connection conn) throws SomeTestsFailedException, SQLException {
176178
throw e;
177179
}
178180
} finally {
179-
if (callableStatement != null)
181+
if (callableStatement != null) {
180182
callableStatement.close();
183+
}
184+
185+
DBHelper.disableDBMSOutput(conn);
181186
}
182187
}
183188

0 commit comments

Comments
 (0)