Skip to content

Commit

Permalink
Code Quality Improvement (#6)
Browse files Browse the repository at this point in the history
* Fixes SonarQube issues
* Code cleanup and cosmetics
  • Loading branch information
nouda authored Mar 5, 2020
1 parent dc4c971 commit b2fdfa2
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 103 deletions.
25 changes: 12 additions & 13 deletions src/main/java/org/polypheny/jdbc/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@
public class Driver extends UnregisteredDriver {

public static final String DRIVER_URL_SCHEMA = "jdbc:polypheny:";
@Deprecated
public static final String URL_SCHEMA = DRIVER_URL_SCHEMA;

public static final String DEFAULT_HOST = "localhost";
public static final int DEFAULT_PORT = 20591;
Expand Down Expand Up @@ -118,7 +116,7 @@ public boolean acceptsURL( final String url ) throws SQLException {


@Override
public Meta createMeta( AvaticaConnection connection ) {
public Meta createMeta( final AvaticaConnection connection ) {
final ConnectionConfig config = connection.config();
// Create a single Service and set it on the Connection instance
final Service service = createService( connection, config );
Expand All @@ -127,7 +125,7 @@ public Meta createMeta( AvaticaConnection connection ) {
}


protected Service createService( AvaticaConnection connection, ConnectionConfig config ) {
protected Service createService( final AvaticaConnection connection, final ConnectionConfig config ) {
final Service.Factory metaFactory = config.factory();
final Service service;
if ( metaFactory != null ) {
Expand All @@ -141,10 +139,10 @@ protected Service createService( AvaticaConnection connection, ConnectionConfig
service = new RemoteProtobufService( getHttpClient( connection, config ), new ProtobufTranslationImpl() );
break;
default:
throw new RuntimeException( new IllegalArgumentException( "\"serialization\" is not one of " + Arrays.toString( Serialization.values() ) ) );
throw new IllegalArgumentException( "\"serialization\" is not one of " + Arrays.toString( Serialization.values() ) );
}
} else {
throw new RuntimeException( new NullPointerException( "config.url() == null" ) );
throw new IllegalArgumentException( new NullPointerException( "config.url() == null" ) );
}
return service;
}
Expand All @@ -157,12 +155,12 @@ protected Service createService( AvaticaConnection connection, ConnectionConfig
* @param config The configuration.
* @return An {@link AvaticaHttpClient} implementation.
*/
protected AvaticaHttpClient getHttpClient( AvaticaConnection connection, ConnectionConfig config ) {
protected AvaticaHttpClient getHttpClient( final AvaticaConnection connection, final ConnectionConfig config ) {
URL url;
try {
url = new URL( config.url() );
} catch ( MalformedURLException e ) {
throw new RuntimeException( e );
throw new IllegalArgumentException( e );
}

AvaticaHttpClientFactory httpClientFactory = config.httpClientFactory();
Expand All @@ -189,7 +187,7 @@ protected String getFactoryClassName( final JdbcVersion jdbcVersion ) {


@Override
public Connection connect( String url, Properties info ) throws SQLException {
public Connection connect( final String url, Properties info ) throws SQLException {
if ( url == null ) {
throw new SQLException( new NullPointerException( "url == null" ) );
}
Expand Down Expand Up @@ -235,7 +233,9 @@ public Connection connect( String url, Properties info ) throws SQLException {


// packet-visible for testability
@SuppressWarnings("deprecated")
@SuppressWarnings({
"squid:S3776" // Cognitive Complexity
})
final Properties parseUrl( String url, final Properties defaults ) {
final Properties prop = (defaults == null) ? new Properties() : new Properties( defaults );

Expand Down Expand Up @@ -274,11 +274,10 @@ final Properties parseUrl( String url, final Properties defaults ) {
parameterValue = URLDecoder.decode( parameterValue, StandardCharsets.UTF_8.name() );
} catch ( UnsupportedEncodingException e ) {
// not going to happen - value came from JDK's own StandardCharsets
throw new RuntimeException( e );
throw new RuntimeException( e ); //NOSONAR "squid:S00112" - Justification: This is literally a problem with the runtime
} catch ( NoSuchMethodError e ) {
log.debug( "Cannot use the decode method with UTF-8. Using the fallback (deprecated) method.", e );
//noinspection deprecation
parameterValue = URLDecoder.decode( parameterValue );
parameterValue = URLDecoder.decode( parameterValue ); //NOSONAR "squid:CallToDeprecatedMethod" - Justification: This is the fallback if the superseded method does not exist.
}

prop.setProperty( parameterKey, parameterValue );
Expand Down
Loading

0 comments on commit b2fdfa2

Please sign in to comment.