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

Skip to content

Feature/params non nullable #65

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
Oct 23, 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
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.utplsql</groupId>
<artifactId>java-api</artifactId>
<version>3.1.1.1-SNAPSHOT</version>
<version>3.1.2-SNAPSHOT</version>
<packaging>jar</packaging>

<name>utPLSQL-java-api</name>
Expand Down Expand Up @@ -36,6 +36,11 @@
<version>12.2.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/org/utplsql/api/DBHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ private DBHelper() {}
* @throws SQLException any database error
*/
public static String newSysGuid(Connection conn) throws SQLException {
assert conn != null;
try (CallableStatement callableStatement = conn.prepareCall("BEGIN ? := sys_guid(); END;")) {
callableStatement.registerOutParameter(1, OracleTypes.RAW);
callableStatement.executeUpdate();
Expand All @@ -38,7 +37,6 @@ public static String newSysGuid(Connection conn) throws SQLException {
*/
@Deprecated
public static String getCurrentSchema(Connection conn) throws SQLException {
assert conn != null;
try (CallableStatement callableStatement = conn.prepareCall("BEGIN ? := sys_context('userenv', 'current_schema'); END;")) {
callableStatement.registerOutParameter(1, Types.VARCHAR);
callableStatement.executeUpdate();
Expand All @@ -55,7 +53,6 @@ public static String getCurrentSchema(Connection conn) throws SQLException {
*/
@Deprecated
public static Version getDatabaseFrameworkVersion( Connection conn ) throws SQLException {
Objects.requireNonNull(conn);
Version result = new Version("");
try (PreparedStatement stmt = conn.prepareStatement("select ut_runner.version() from dual"))
{
Expand Down Expand Up @@ -84,7 +81,6 @@ public static Version getDatabaseFrameworkVersion( Connection conn ) throws SQLE
*/
@Deprecated
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%'"))
{
Expand All @@ -102,7 +98,6 @@ public static String getOracleDatabaseVersion( Connection conn ) throws SQLExcep
* @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 @@ -115,7 +110,6 @@ 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
4 changes: 3 additions & 1 deletion src/main/java/org/utplsql/api/EnvironmentVariableUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.utplsql.api;

import javax.annotation.Nullable;

/**
* This class provides an easy way to get environmental variables.
* This is mainly to improve testability but also to standardize the way how utPLSQL API and CLI read from
Expand Down Expand Up @@ -37,7 +39,7 @@ public static String getEnvValue(String key) {
* @param defaultValue Default value if nothing found
* @return Environment value or defaultValue
*/
public static String getEnvValue(String key, String defaultValue) {
public static String getEnvValue(String key, @Nullable String defaultValue) {

String val = System.getProperty(key);
if (val == null || val.isEmpty()) val = System.getenv(key);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/utplsql/api/FileMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private void setObjectType(String objectType) {
}

@Override
public String getSQLTypeName() throws SQLException {
public String getSQLTypeName() {
return CustomTypes.UT_FILE_MAPPING;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/utplsql/api/JavaApiVersionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ private JavaApiVersionInfo() { }

private static final String BUILD_NO = "123";
private static final String MAVEN_PROJECT_NAME = "utPLSQL-java-api";
private static final String MAVEN_PROJECT_VERSION = "3.1.1.1-SNAPSHOT";
private static final String MAVEN_PROJECT_VERSION = "3.1.2-SNAPSHOT";

public static String getVersion() {
return MAVEN_PROJECT_VERSION + "." + BUILD_NO;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/utplsql/api/KeyValuePair.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public String getValue() {
}

@Override
public String getSQLTypeName() throws SQLException {
public String getSQLTypeName() {
return CustomTypes.UT_KEY_VALUE_PAIR;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/utplsql/api/TestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public TestRunner colorConsole(boolean colorConsole) {
}

public TestRunner addReporterList(List<Reporter> reporterList) {
if (options.reporterList != null) options.reporterList.addAll(reporterList);
options.reporterList.addAll(reporterList);
return this;
}

Expand Down Expand Up @@ -120,7 +120,7 @@ private void delayedAddReporters() {
throw new IllegalStateException("ReporterFactory must be set to add delayed Reporters!");
}

public void run(Connection conn) throws SomeTestsFailedException, SQLException, DatabaseNotCompatibleException, UtPLSQLNotInstalledException {
public void run(Connection conn) throws SQLException {

DatabaseInformation databaseInformation = new DefaultDatabaseInformation();

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/utplsql/api/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.utplsql.api.exception.InvalidVersionException;

import javax.annotation.Nullable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -105,7 +106,7 @@ public String getNormalizedString()
return "invalid";
}

private int compareToWithNulls( Integer i1, Integer i2 ) {
private int compareToWithNulls(@Nullable Integer i1, @Nullable Integer i2 ) {
if ( i1 == null && i2 == null )
return 0;
else if ( i1 == null )
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.utplsql.api.compatibility;

import org.utplsql.api.DBHelper;
import org.utplsql.api.TestRunnerOptions;
import org.utplsql.api.Version;
import org.utplsql.api.db.DatabaseInformation;
Expand All @@ -12,10 +11,8 @@
import org.utplsql.api.testRunner.TestRunnerStatement;
import org.utplsql.api.testRunner.TestRunnerStatementProvider;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Objects;

/** Class to check compatibility with database framework and also to give several specific implementations depending
Expand Down Expand Up @@ -120,13 +117,9 @@ private boolean versionCompatibilityCheckPre303(String requested )
Version requestedVersion = new Version(requested);

Objects.requireNonNull(databaseVersion.getMajor(), "Illegal database Version: " + databaseVersion.toString());
if (
databaseVersion.getMajor().equals(requestedVersion.getMajor())
&& (requestedVersion.getMinor() == null
|| requestedVersion.getMinor().equals(databaseVersion.getMinor())) )
return true;
else
return false;
return databaseVersion.getMajor().equals(requestedVersion.getMajor())
&& (requestedVersion.getMinor() == null
|| requestedVersion.getMinor().equals(databaseVersion.getMinor()));
}

/** Checks if actual API-version is compatible with utPLSQL database version and throws a DatabaseNotCompatibleException if not
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/utplsql/api/db/DatabaseInformation.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.utplsql.api.Version;

import javax.annotation.Nullable;
import java.sql.Connection;
import java.sql.SQLException;

Expand All @@ -17,5 +18,5 @@ public interface DatabaseInformation {

String getCurrentSchema( Connection conn ) throws SQLException;

int frameworkCompatibilityCheck(Connection conn, String requested, String current) throws SQLException;
int frameworkCompatibilityCheck(Connection conn, String requested, @Nullable String current) throws SQLException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import org.utplsql.api.Version;
import org.utplsql.api.exception.UtPLSQLNotInstalledException;

import javax.annotation.Nullable;
import java.sql.*;
import java.util.Objects;

public class DefaultDatabaseInformation implements DatabaseInformation {

@Override
public Version getUtPlsqlFrameworkVersion(Connection conn) throws SQLException {
Objects.requireNonNull(conn);
Version result = new Version("");
try (PreparedStatement stmt = conn.prepareStatement("select ut_runner.version() from dual"))
{
Expand All @@ -32,7 +32,6 @@ public Version getUtPlsqlFrameworkVersion(Connection conn) throws SQLException {

@Override
public String getOracleVersion(Connection conn) throws SQLException {
Objects.requireNonNull(conn);
String result = null;
try (PreparedStatement stmt = conn.prepareStatement("select version from product_component_version where product like 'Oracle Database%'"))
{
Expand All @@ -47,7 +46,6 @@ public String getOracleVersion(Connection conn) throws SQLException {

@Override
public String getCurrentSchema(Connection conn) throws SQLException {
Objects.requireNonNull(conn);
try (CallableStatement callableStatement = conn.prepareCall("BEGIN ? := sys_context('userenv', 'current_schema'); END;")) {
callableStatement.registerOutParameter(1, Types.VARCHAR);
callableStatement.executeUpdate();
Expand All @@ -56,7 +54,7 @@ public String getCurrentSchema(Connection conn) throws SQLException {
}

@Override
public int frameworkCompatibilityCheck(Connection conn, String requested, String current) throws SQLException {
public int frameworkCompatibilityCheck(Connection conn, String requested, @Nullable String current) throws SQLException {
try(CallableStatement callableStatement = conn.prepareCall("BEGIN ? := ut_runner.version_compatibility_check(?, ?); END;")) {
callableStatement.registerOutParameter(1, Types.SMALLINT);
callableStatement.setString(2, requested);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.utplsql.api.exception;

import javax.annotation.Nullable;
import java.sql.SQLException;

/**
Expand All @@ -9,7 +10,7 @@ public class SomeTestsFailedException extends SQLException {

public static final int ERROR_CODE = 20213;

public SomeTestsFailedException(String reason, Throwable cause) {
public SomeTestsFailedException(String reason, @Nullable Throwable cause) {
super(reason, cause);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public void printAvailable(Connection conn, List<PrintStream> printStreams) thro
}

@Override
public void fetchAvailable(Connection conn, Consumer<String> onLineFetched) throws SQLException {
public void fetchAvailable(Connection conn, Consumer<String> onLineFetched) {
onLineFetched.accept(null);
}

@Override
public List<String> fetchAll(Connection conn) throws SQLException {
public List<String> fetchAll(Connection conn) {
return new ArrayList<>();
}
}
4 changes: 4 additions & 0 deletions src/main/java/org/utplsql/api/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@ParametersAreNonnullByDefault
package org.utplsql.api;

import javax.annotation.ParametersAreNonnullByDefault;
3 changes: 2 additions & 1 deletion src/main/java/org/utplsql/api/reporter/ReporterFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import oracle.sql.ORADataFactory;
import org.utplsql.api.compatibility.CompatibilityProxy;

import javax.annotation.Nullable;
import java.sql.SQLException;
import java.sql.Struct;
import java.util.HashMap;
Expand Down Expand Up @@ -74,7 +75,7 @@ public synchronized boolean hasRegisteredFactoryMethodFor( String reporterName )
* @param attributes attributes from STRUCT
* @return A reporter
*/
public Reporter createReporter(String reporterName, Object[] attributes) {
public Reporter createReporter(String reporterName, @Nullable Object[] attributes) {

reporterName = reporterName.toUpperCase();
BiFunction<String, Object[], ? extends Reporter> supplier = DefaultReporter::new;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/utplsql/api/OutputBufferIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void fetchAllLines() throws SQLException {
}

@Test
public void getOutputFromSonarReporter() throws SQLException, InvalidVersionException {
public void getOutputFromSonarReporter() throws SQLException {
Reporter reporter = new DefaultReporter(CoreReporters.UT_SONAR_TEST_REPORTER.name(), null).init(newConnection());

new TestRunner()
Expand Down