Skip to content

Feature/small improvements refactoring #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 30 additions & 16 deletions src/main/java/org/utplsql/api/DBHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@ private DBHelper() {}
* @throws SQLException any database error
*/
public static String newSysGuid(Connection conn) throws SQLException {
CallableStatement callableStatement = null;
try {
callableStatement = conn.prepareCall("BEGIN ? := sys_guid(); END;");
assert conn != null;
try (CallableStatement callableStatement = conn.prepareCall("BEGIN ? := sys_guid(); END;")) {
callableStatement.registerOutParameter(1, OracleTypes.RAW);
callableStatement.executeUpdate();
return callableStatement.getString(1);
} finally {
if (callableStatement != null)
callableStatement.close();
}
}

Expand All @@ -39,26 +35,22 @@ public static String newSysGuid(Connection conn) throws SQLException {
* @throws SQLException any database error
*/
public static String getCurrentSchema(Connection conn) throws SQLException {
CallableStatement callableStatement = null;
try {
callableStatement = conn.prepareCall("BEGIN ? := sys_context('userenv', 'current_schema'); END;");
assert conn != null;
try (CallableStatement callableStatement = conn.prepareCall("BEGIN ? := sys_context('userenv', 'current_schema'); END;")) {
callableStatement.registerOutParameter(1, Types.VARCHAR);
callableStatement.executeUpdate();
return callableStatement.getString(1);
} finally {
if (callableStatement != null)
callableStatement.close();
}
}

/** Returns the Frameworks version string of the given connection
*
* @param conn Active db connection
* @return
* @throws SQLException
* @return Version-string of the utPLSQL framework
* @throws SQLException any database error
*/
public static Version getDatabaseFrameworkVersion( Connection conn )
throws SQLException {
public static Version getDatabaseFrameworkVersion( Connection conn ) throws SQLException {
assert conn != null;
Version result = new Version("");
try (PreparedStatement stmt = conn.prepareStatement("select ut_runner.version() from dual"))
{
Expand All @@ -78,11 +70,32 @@ public static Version getDatabaseFrameworkVersion( Connection conn )
return result;
}

/** Returns the Oracle database Version from a given connection object
*
* @param conn Connection-Object
* @return Returns version-string of the Oracle Database product component
* @throws SQLException any database error
*/
public static String getOracleDatabaseVersion( Connection conn ) throws SQLException {
assert conn != null;
String result = null;
try (PreparedStatement stmt = conn.prepareStatement("select version from product_component_version where product like 'Oracle Database%'"))
{
ResultSet rs = stmt.executeQuery();

if ( rs.next() )
result = rs.getString(1);
}

return result;
}

/**
* Enable the dbms_output buffer with unlimited size.
* @param conn the connection
*/
public static void enableDBMSOutput(Connection conn) {
assert conn != null;
try (CallableStatement call = conn.prepareCall("BEGIN dbms_output.enable(NULL); END;")) {
call.execute();
} catch (SQLException e) {
Expand All @@ -95,6 +108,7 @@ public static void enableDBMSOutput(Connection conn) {
* @param conn the connection
*/
public static void disableDBMSOutput(Connection conn) {
assert conn != null;
try (CallableStatement call = conn.prepareCall("BEGIN dbms_output.disable(); END;")) {
call.execute();
} catch (SQLException e) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/utplsql/api/JavaApiVersionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public class JavaApiVersionInfo {
public static String getVersion() {
return MAVEN_PROJECT_VERSION + "." + BUILD_NO;
}
public static String getInfo() { return MAVEN_PROJECT_NAME + " " + getVersion(); }

}
7 changes: 7 additions & 0 deletions src/test/java/org/utplsql/api/DBHelperIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.sql.SQLException;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class DBHelperIT extends AbstractDatabaseTest {

Expand All @@ -14,4 +15,10 @@ public void getFrameworkVersion() throws SQLException {
assertEquals(true, v.isValid());
}

@Test
public void getOracleDatabaseVersion() throws SQLException {
String databaseVersion = DBHelper.getOracleDatabaseVersion(getConnection());
assertNotNull(databaseVersion);
}

}