Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Only check for orai18n when we are on a 11g database
the library is not needed for 12c
  • Loading branch information
pesse authored and Samuel Nitsche committed Nov 12, 2017
commit 22a560311bf02819e78f026dfcb4d46f37a71236
40 changes: 40 additions & 0 deletions src/main/java/org/utplsql/cli/ConnectionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ConnectionInfo {

private String databaseVersion;

static {
String oracleHome = System.getenv("ORACLE_HOME");
if (oracleHome != null) {
Expand Down Expand Up @@ -42,4 +46,40 @@ public ConnectionInfo convert(String s) {
}
}

public String getOracleDatabaseVersion() throws SQLException
{
try ( Connection conn = getConnection() ) {
return getOracleDatabaseVersion(conn);
}
}

public String getOracleDatabaseVersion( Connection conn ) throws SQLException
{
if ( databaseVersion == null ) {
databaseVersion = getOracleDatabaseVersionFromConnection( conn );
}

return databaseVersion;
}

/** TODO: Outsource this to Java-API
*
* @param conn
* @return
* @throws SQLException
*/
public static String getOracleDatabaseVersionFromConnection( 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;
}

}
21 changes: 15 additions & 6 deletions src/main/java/org/utplsql/cli/RunCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public List<String> getTestPaths() {

public int run() throws Exception {

checkOracleLibrariesExist();
checkOracleJDBCExists();

final ConnectionInfo ci = getConnectionInfo();

Expand All @@ -110,6 +110,9 @@ public int run() throws Exception {
// Do the reporters initialization, so we can use the id to run and gather results.
try (Connection conn = ci.getConnection()) {

// Check if orai18n exists if database version is 11g
checkOracleI18nExists(ci.getOracleDatabaseVersion(conn));

// First of all do a compatibility check and fail-fast
checkFrameworkCompatibility(conn);

Expand Down Expand Up @@ -324,10 +327,10 @@ public FileMapperOptions getMapperOptions(List<String> mappingParams, List<Strin
}


/** Checks that necessary oracle libraries exist
/** Checks that ojdbc library exists
*
*/
private void checkOracleLibrariesExist()
private void checkOracleJDBCExists()
{
if ( !OracleLibraryChecker.checkOjdbcExists() )
{
Expand All @@ -337,11 +340,17 @@ private void checkOracleLibrariesExist()

throw new RuntimeException("Can't run utPLSQL-cli without Oracle JDBC driver");
}
}

if ( !OracleLibraryChecker.checkOrai18nExists() )
/** Checks that orai18n library exists if database is an oracle 11
*
*/
private void checkOracleI18nExists(String oracleDatabaseVersion )
{
if ( oracleDatabaseVersion.startsWith("11.") && !OracleLibraryChecker.checkOrai18nExists() )
{
System.out.println("Warning: Could not find Oracle i18n driver in classpath. Depending on your database " +
"version (11g) and used charset utPLSQL-cli might not run properly. It is recommended you download " +
System.out.println("Warning: Could not find Oracle i18n driver in classpath. Depending on the database charset " +
"utPLSQL-cli might not run properly. It is recommended you download " +
"the i18n driver from the Oracle website and copy it to the 'lib' folder of your utPLSQL-cli installation.");
System.out.println("Download from http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html");
}
Expand Down