From b476045a86ae41a41d93a6d8bb85768940a3c6fe Mon Sep 17 00:00:00 2001
From: Anastasiia Sergienko
<46891819+AnastasiiaSergienko@users.noreply.github.com>
Date: Thu, 23 Apr 2020 13:37:15 +0200
Subject: [PATCH 1/3] #41: removed the deleted properties usage (#42)
* #41: Removed the deleted properties usage
---
pom.xml | 4 +-
.../adapter/dialects/AbstractSqlDialect.java | 26 +++------
.../jdbc/BaseConnectionDefinitionBuilder.java | 49 ++---------------
.../jdbc/RemoteConnectionException.java | 11 +++-
.../adapter/jdbc/RemoteConnectionFactory.java | 41 ++++++--------
.../dialects/AbstractSqlDialectTest.java | 53 ++-----------------
.../dialects/derby/DerbySqlDialect.java | 5 +-
.../dialects/dummy/DummySqlDialect.java | 5 +-
.../dialects/stubdialect/StubSqlDialect.java | 5 +-
...ctConnectionDefinitionBuilderTestBase.java | 27 ----------
.../BaseConnectionDefinitionBuilderTest.java | 34 +++---------
.../exasol/adapter/jdbc/JdbcAdapterIT.java | 9 ++--
.../exasol/adapter/jdbc/JdbcAdapterTest.java | 48 ++++++++++-------
.../jdbc/RemoteConnectionFactoryTest.java | 23 +-------
14 files changed, 91 insertions(+), 249 deletions(-)
diff --git a/pom.xml b/pom.xml
index e4dd9b5..044f129 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,14 +9,14 @@
Common module for JDBC-based data access from Virtual Schemas.
https://github.com/exasol/virtual-schema-common-jdbc
- 4.0.0
+ 5.0.0
UTF-8
UTF-8
11
5.6.1
1.6.1
3.0.0-M4
- 9.0.0
+ 10.0.0
true
diff --git a/src/main/java/com/exasol/adapter/dialects/AbstractSqlDialect.java b/src/main/java/com/exasol/adapter/dialects/AbstractSqlDialect.java
index 524a0b4..1dec06a 100644
--- a/src/main/java/com/exasol/adapter/dialects/AbstractSqlDialect.java
+++ b/src/main/java/com/exasol/adapter/dialects/AbstractSqlDialect.java
@@ -130,7 +130,7 @@ public String getStringLiteral(final String value) {
@Override
public void validateProperties() throws PropertyValidationException {
validateSupportedPropertiesList();
- validateConnectionProperties();
+ validateConnectionNameProperty();
validateCatalogNameProperty();
validateSchemaNameProperty();
validateDebugOutputAddress();
@@ -141,8 +141,7 @@ protected void validateSupportedPropertiesList() throws PropertyValidationExcept
final List allProperties = new ArrayList<>(this.properties.keySet());
for (final String property : allProperties) {
if (!getSupportedProperties().contains(property)) {
- final String unsupportedElement = property;
- throw new PropertyValidationException(createUnsupportedElementMessage(unsupportedElement, property));
+ throw new PropertyValidationException(createUnsupportedElementMessage(property, property));
}
}
}
@@ -156,24 +155,13 @@ protected void validateSupportedPropertiesList() throws PropertyValidationExcept
protected String createUnsupportedElementMessage(final String unsupportedElement, final String property) {
return "The dialect " + this.properties.getSqlDialect() + " does not support " + unsupportedElement
- + " property. Please, do not set the " + property + " property.";
+ + " property. Please, do not set the \"" + property + "\" property.";
}
- private void validateConnectionProperties() throws PropertyValidationException {
- if (this.properties.containsKey(CONNECTION_NAME_PROPERTY)) {
- if (this.properties.containsKey(CONNECTION_STRING_PROPERTY)
- || this.properties.containsKey(USERNAME_PROPERTY)
- || this.properties.containsKey(PASSWORD_PROPERTY)) {
- throw new PropertyValidationException("You specified a connection using the property "
- + CONNECTION_NAME_PROPERTY + " and therefore should not specify the properties "
- + CONNECTION_STRING_PROPERTY + ", " + USERNAME_PROPERTY + " and " + PASSWORD_PROPERTY);
- }
- } else {
- if (!this.properties.containsKey(CONNECTION_STRING_PROPERTY)) {
- throw new PropertyValidationException(
- "You did not specify a connection using the property " + CONNECTION_NAME_PROPERTY
- + " and therefore have to specify the property " + CONNECTION_STRING_PROPERTY);
- }
+ private void validateConnectionNameProperty() throws PropertyValidationException {
+ if (!this.properties.hasConnectionName()) {
+ throw new PropertyValidationException(
+ "Please specify a connection using the property \"" + CONNECTION_NAME_PROPERTY + "\".");
}
}
diff --git a/src/main/java/com/exasol/adapter/jdbc/BaseConnectionDefinitionBuilder.java b/src/main/java/com/exasol/adapter/jdbc/BaseConnectionDefinitionBuilder.java
index ee903b7..f5de6ea 100644
--- a/src/main/java/com/exasol/adapter/jdbc/BaseConnectionDefinitionBuilder.java
+++ b/src/main/java/com/exasol/adapter/jdbc/BaseConnectionDefinitionBuilder.java
@@ -1,8 +1,6 @@
package com.exasol.adapter.jdbc;
-import static com.exasol.adapter.AdapterProperties.*;
-
-import java.util.logging.Logger;
+import static com.exasol.adapter.AdapterProperties.CONNECTION_NAME_PROPERTY;
import com.exasol.ExaConnectionInformation;
import com.exasol.adapter.AdapterProperties;
@@ -13,15 +11,6 @@
* @see IMPORT (Exasol documentation)
*/
public class BaseConnectionDefinitionBuilder implements ConnectionDefinitionBuilder {
- private static final Logger LOGGER = Logger.getLogger(BaseConnectionDefinitionBuilder.class.getName());
- private static final String MISSING_CONNECTION_DETAILS_ERROR = "Incomplete remote connection information."
- + " Please specify either a named connection with " + CONNECTION_NAME_PROPERTY
- + " or individual connetion properties " + CONNECTION_STRING_PROPERTY + ", " + USERNAME_PROPERTY + " and "
- + PASSWORD_PROPERTY + ".";
- protected static final String CONFLICTING_CONNECTION_DETAILS_ERROR = "Mixing named connections in property "
- + CONNECTION_NAME_PROPERTY + " and individual conneciton properties " + CONNECTION_STRING_PROPERTY + ", "
- + USERNAME_PROPERTY + " and " + PASSWORD_PROPERTY + " is not allowed.";
-
/**
* Get the connection definition part of a push-down query.
*
@@ -32,44 +21,16 @@ public class BaseConnectionDefinitionBuilder implements ConnectionDefinitionBuil
@Override
public String buildConnectionDefinition(final AdapterProperties properties,
final ExaConnectionInformation exaConnectionInformation) {
- if (hasIndividualConnectionPropertiesOnly(properties)) {
- return getConnectionFromPropertiesOnly(properties);
- } else if (hasConflictingConnectionProperties(properties)) {
- throw new IllegalArgumentException(CONFLICTING_CONNECTION_DETAILS_ERROR);
- } else if (properties.hasConnectionName()) {
- return getNamedConnection(properties);
+ if (properties.hasConnectionName()) {
+ return "AT " + properties.getConnectionName();
} else {
- throw new IllegalArgumentException(MISSING_CONNECTION_DETAILS_ERROR);
+ throw new IllegalArgumentException(
+ "Please, provide a mandatory property \"" + CONNECTION_NAME_PROPERTY + "\".");
}
}
- private String getConnectionFromPropertiesOnly(final AdapterProperties properties) {
- warnConnectionPropertiesDeprecated();
- return getConnectionDefinition(properties.getConnectionString(), properties.getUsername(),
- properties.getPassword());
- }
-
- protected void warnConnectionPropertiesDeprecated() {
- LOGGER.warning(() -> "Defining credentials individually with properties is deprecated."
- + " Provide a connection name instead in property " + CONNECTION_NAME_PROPERTY + ".");
- }
-
protected String getConnectionDefinition(final String connectionString, final String username,
final String password) {
return "AT '" + connectionString + "' USER '" + username + "' IDENTIFIED BY '" + password + "'";
}
-
- protected boolean hasIndividualConnectionPropertiesOnly(final AdapterProperties properties) {
- return !properties.hasConnectionName() && properties.hasConnectionString() && properties.hasUsername()
- && properties.hasPassword();
- }
-
- protected boolean hasConflictingConnectionProperties(final AdapterProperties properties) {
- return properties.hasConnectionName()
- && (properties.hasConnectionString() || properties.hasUsername() || properties.hasPassword());
- }
-
- private String getNamedConnection(final AdapterProperties properties) {
- return "AT " + properties.getConnectionName();
- }
}
\ No newline at end of file
diff --git a/src/main/java/com/exasol/adapter/jdbc/RemoteConnectionException.java b/src/main/java/com/exasol/adapter/jdbc/RemoteConnectionException.java
index eb9e5ea..aaa39b9 100644
--- a/src/main/java/com/exasol/adapter/jdbc/RemoteConnectionException.java
+++ b/src/main/java/com/exasol/adapter/jdbc/RemoteConnectionException.java
@@ -4,7 +4,7 @@
* Exception for remote connection problems.
*/
public class RemoteConnectionException extends RuntimeException {
- private static final long serialVersionUID = 550162141981742445L;
+ private static final long serialVersionUID = 2818034094289319833L;
/**
* Create a new instance of a {@link RemoteConnectionException}.
@@ -15,4 +15,13 @@ public class RemoteConnectionException extends RuntimeException {
public RemoteConnectionException(final String message, final Throwable cause) {
super(message, cause);
}
+
+ /**
+ * Create a new instance of a {@link RemoteConnectionException}.
+ *
+ * @param message error message
+ */
+ public RemoteConnectionException(final String message) {
+ super(message);
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/exasol/adapter/jdbc/RemoteConnectionFactory.java b/src/main/java/com/exasol/adapter/jdbc/RemoteConnectionFactory.java
index 304fb9b..be7af06 100644
--- a/src/main/java/com/exasol/adapter/jdbc/RemoteConnectionFactory.java
+++ b/src/main/java/com/exasol/adapter/jdbc/RemoteConnectionFactory.java
@@ -1,5 +1,7 @@
package com.exasol.adapter.jdbc;
+import static com.exasol.adapter.AdapterProperties.CONNECTION_NAME_PROPERTY;
+
import java.sql.*;
import java.util.Properties;
import java.util.logging.Logger;
@@ -35,35 +37,13 @@ public synchronized Connection getConnection() throws SQLException {
if ((connectionName != null) && !connectionName.isEmpty()) {
this.cachedConnection = createConnection(connectionName, this.exaMetadata);
} else {
- this.cachedConnection = createConnectionWithUserCredentials(this.properties.getUsername(),
- this.properties.getPassword(), this.properties.getConnectionString());
+ throw new RemoteConnectionException("\"" + CONNECTION_NAME_PROPERTY
+ + "\" property is missing or empty. Please, check the property and try to connect again.");
}
}
return this.cachedConnection;
}
- private Connection createConnectionWithUserCredentials(final String username, final String password,
- final String connectionString) throws SQLException {
- logConnectionAttempt(username, password);
- final long start = System.currentTimeMillis();
- final Connection connection = DriverManager.getConnection(connectionString, username, password);
- logRemoteDatabaseDetails(connection, System.currentTimeMillis() - start);
- return connection;
- }
-
- protected void logConnectionAttempt(final String address, final String username) {
- LOGGER.fine(
- () -> "Connecting to \"" + address + "\" as user \"" + username + "\" using password authentication.");
- }
-
- protected void logRemoteDatabaseDetails(final Connection connection, final long connectionTime)
- throws SQLException {
- final String databaseProductName = connection.getMetaData().getDatabaseProductName();
- final String databaseProductVersion = connection.getMetaData().getDatabaseProductVersion();
- LOGGER.info(() -> "Connected to " + databaseProductName + " " + databaseProductVersion + " in " + connectionTime
- + " milliseconds.");
- }
-
private Connection createConnection(final String connectionName, final ExaMetadata exaMetadata)
throws SQLException {
try {
@@ -101,6 +81,14 @@ private void logConnectionAttemptWithKerberos(final String address, final String
() -> "Connecting to \"" + address + "\" as user \"" + username + "\" using Kerberos authentication.");
}
+ protected void logRemoteDatabaseDetails(final Connection connection, final long connectionTime)
+ throws SQLException {
+ final String databaseProductName = connection.getMetaData().getDatabaseProductName();
+ final String databaseProductVersion = connection.getMetaData().getDatabaseProductVersion();
+ LOGGER.info(() -> "Connected to " + databaseProductName + " " + databaseProductVersion + " in " + connectionTime
+ + " milliseconds.");
+ }
+
private Connection establishConnectionWithRegularCredentials(final String password, final String username,
final String address) throws SQLException {
logConnectionAttempt(address, username);
@@ -109,4 +97,9 @@ private Connection establishConnectionWithRegularCredentials(final String passwo
logRemoteDatabaseDetails(connection, System.currentTimeMillis() - start);
return connection;
}
+
+ protected void logConnectionAttempt(final String address, final String username) {
+ LOGGER.fine(
+ () -> "Connecting to \"" + address + "\" as user \"" + username + "\" using password authentication.");
+ }
}
\ No newline at end of file
diff --git a/src/test/java/com/exasol/adapter/dialects/AbstractSqlDialectTest.java b/src/test/java/com/exasol/adapter/dialects/AbstractSqlDialectTest.java
index 0b19f9d..0f22893 100644
--- a/src/test/java/com/exasol/adapter/dialects/AbstractSqlDialectTest.java
+++ b/src/test/java/com/exasol/adapter/dialects/AbstractSqlDialectTest.java
@@ -37,24 +37,15 @@ void afterEach() {
}
@Test
- void testNoCredentials() {
+ void testNoConnectionName() {
this.rawProperties.put(SQL_DIALECT_PROPERTY, "GENERIC");
this.rawProperties.put(SCHEMA_NAME_PROPERTY, "MY_SCHEMA");
final AdapterProperties adapterProperties = new AdapterProperties(this.rawProperties);
final SqlDialect sqlDialect = new DummySqlDialect(null, adapterProperties);
final PropertyValidationException exception = assertThrows(PropertyValidationException.class,
sqlDialect::validateProperties);
- assertThat(exception.getMessage(), containsString(
- "You did not specify a connection using the property CONNECTION_NAME and therefore have to specify the "
- + "property " + "CONNECTION_STRING"));
- }
-
- @Test
- void testUserNamePasswordOptional() throws PropertyValidationException {
- getMinimumMandatory();
- final AdapterProperties adapterProperties = new AdapterProperties(this.rawProperties);
- final SqlDialect sqlDialect = new DummySqlDialect(null, adapterProperties);
- sqlDialect.validateProperties();
+ assertThat(exception.getMessage(),
+ containsString("Please specify a connection using the property \"" + CONNECTION_NAME_PROPERTY + "\"."));
}
private void getMinimumMandatory() {
@@ -62,42 +53,6 @@ private void getMinimumMandatory() {
this.rawProperties.put(CONNECTION_NAME_PROPERTY, "MY_CONN");
}
- @Test
- void testRedundantCredentialsUserName() {
- getMinimumMandatory();
- this.rawProperties.put(USERNAME_PROPERTY, "MY_USER");
- final AdapterProperties adapterProperties = new AdapterProperties(this.rawProperties);
- final SqlDialect sqlDialect = new DummySqlDialect(null, adapterProperties);
- final PropertyValidationException exception = assertThrows(PropertyValidationException.class,
- sqlDialect::validateProperties);
- assertThat(exception.getMessage(), containsString(
- "You specified a connection using the property CONNECTION_NAME and therefore should not specify"));
- }
-
- @Test
- void testRedundantCredentialsPassword() {
- getMinimumMandatory();
- this.rawProperties.put(PASSWORD_PROPERTY, "MY_PASSWORD");
- final AdapterProperties adapterProperties = new AdapterProperties(this.rawProperties);
- final SqlDialect sqlDialect = new DummySqlDialect(null, adapterProperties);
- final PropertyValidationException exception = assertThrows(PropertyValidationException.class,
- sqlDialect::validateProperties);
- assertThat(exception.getMessage(), containsString(
- "You specified a connection using the property CONNECTION_NAME and therefore should not specify"));
- }
-
- @Test
- void testRedundantCredentialsConnectionString() {
- getMinimumMandatory();
- this.rawProperties.put(CONNECTION_STRING_PROPERTY, "MY_CONN");
- final AdapterProperties adapterProperties = new AdapterProperties(this.rawProperties);
- final SqlDialect sqlDialect = new DummySqlDialect(null, adapterProperties);
- final PropertyValidationException exception = assertThrows(PropertyValidationException.class,
- sqlDialect::validateProperties);
- assertThat(exception.getMessage(), containsString(
- "You specified a connection using the property CONNECTION_NAME and therefore should not specify"));
- }
-
@Test
void testValidatePropertiesWithWherePortIsString() throws PropertyValidationException {
this.rawProperties.put(DEBUG_ADDRESS_PROPERTY, "host:port_should_be_a_number");
@@ -186,7 +141,7 @@ void testGetTableCatalogAndSchemaSeparator() {
@Test
void testGetSqlGenerationVisitor() {
final SqlDialect sqlDialect = new DummySqlDialect(null, AdapterProperties.emptyProperties());
- SqlGenerationContext context = new SqlGenerationContext("catalogName", "schemaName", false);
+ final SqlGenerationContext context = new SqlGenerationContext("catalogName", "schemaName", false);
assertThat(sqlDialect.getSqlGenerationVisitor(context), instanceOf(SqlGenerationVisitor.class));
}
diff --git a/src/test/java/com/exasol/adapter/dialects/derby/DerbySqlDialect.java b/src/test/java/com/exasol/adapter/dialects/derby/DerbySqlDialect.java
index fae0afb..8af15d4 100644
--- a/src/test/java/com/exasol/adapter/dialects/derby/DerbySqlDialect.java
+++ b/src/test/java/com/exasol/adapter/dialects/derby/DerbySqlDialect.java
@@ -20,9 +20,8 @@ public class DerbySqlDialect extends AbstractSqlDialect {
static final String NAME = "DERBY";
private static final Capabilities CAPABILITIES = createCapabilityList();
private static final List SUPPORTED_PROPERTIES = Arrays.asList(SQL_DIALECT_PROPERTY,
- CONNECTION_NAME_PROPERTY, CONNECTION_STRING_PROPERTY, USERNAME_PROPERTY, PASSWORD_PROPERTY,
- CATALOG_NAME_PROPERTY, SCHEMA_NAME_PROPERTY, TABLE_FILTER_PROPERTY, EXCLUDED_CAPABILITIES_PROPERTY,
- DEBUG_ADDRESS_PROPERTY, LOG_LEVEL_PROPERTY);
+ CONNECTION_NAME_PROPERTY, CATALOG_NAME_PROPERTY, SCHEMA_NAME_PROPERTY, TABLE_FILTER_PROPERTY,
+ EXCLUDED_CAPABILITIES_PROPERTY, DEBUG_ADDRESS_PROPERTY, LOG_LEVEL_PROPERTY);
private static Capabilities createCapabilityList() {
return Capabilities.builder().addMain(MainCapability.ORDER_BY_EXPRESSION)
diff --git a/src/test/java/com/exasol/adapter/dialects/dummy/DummySqlDialect.java b/src/test/java/com/exasol/adapter/dialects/dummy/DummySqlDialect.java
index bbca5db..6c95150 100644
--- a/src/test/java/com/exasol/adapter/dialects/dummy/DummySqlDialect.java
+++ b/src/test/java/com/exasol/adapter/dialects/dummy/DummySqlDialect.java
@@ -14,9 +14,8 @@
public class DummySqlDialect extends AbstractSqlDialect {
static final String NAME = "DUMMYDIALECT";
private static final List SUPPORTED_PROPERTIES = Arrays.asList(SQL_DIALECT_PROPERTY,
- CONNECTION_NAME_PROPERTY, SCHEMA_NAME_PROPERTY, CONNECTION_STRING_PROPERTY, USERNAME_PROPERTY,
- PASSWORD_PROPERTY, TABLE_FILTER_PROPERTY, EXCLUDED_CAPABILITIES_PROPERTY, DEBUG_ADDRESS_PROPERTY,
- LOG_LEVEL_PROPERTY, EXCEPTION_HANDLING_PROPERTY);
+ CONNECTION_NAME_PROPERTY, SCHEMA_NAME_PROPERTY, TABLE_FILTER_PROPERTY, EXCLUDED_CAPABILITIES_PROPERTY,
+ DEBUG_ADDRESS_PROPERTY, LOG_LEVEL_PROPERTY, EXCEPTION_HANDLING_PROPERTY);
public DummySqlDialect(final ConnectionFactory connectionFactory, final AdapterProperties properties) {
super(connectionFactory, properties);
diff --git a/src/test/java/com/exasol/adapter/dialects/stubdialect/StubSqlDialect.java b/src/test/java/com/exasol/adapter/dialects/stubdialect/StubSqlDialect.java
index 78297fa..886153c 100644
--- a/src/test/java/com/exasol/adapter/dialects/stubdialect/StubSqlDialect.java
+++ b/src/test/java/com/exasol/adapter/dialects/stubdialect/StubSqlDialect.java
@@ -17,9 +17,8 @@
public class StubSqlDialect extends AbstractSqlDialect {
static final String NAME = "STUB";
private static final List SUPPORTED_PROPERTIES = Arrays.asList(SQL_DIALECT_PROPERTY,
- CONNECTION_NAME_PROPERTY, CONNECTION_STRING_PROPERTY, USERNAME_PROPERTY, PASSWORD_PROPERTY,
- CATALOG_NAME_PROPERTY, SCHEMA_NAME_PROPERTY, TABLE_FILTER_PROPERTY, EXCLUDED_CAPABILITIES_PROPERTY,
- DEBUG_ADDRESS_PROPERTY, LOG_LEVEL_PROPERTY);
+ CONNECTION_NAME_PROPERTY, CATALOG_NAME_PROPERTY, SCHEMA_NAME_PROPERTY, TABLE_FILTER_PROPERTY,
+ EXCLUDED_CAPABILITIES_PROPERTY, DEBUG_ADDRESS_PROPERTY, LOG_LEVEL_PROPERTY);
public StubSqlDialect(final ConnectionFactory connectionFactory, final AdapterProperties properties) {
super(connectionFactory, properties);
diff --git a/src/test/java/com/exasol/adapter/jdbc/AbstractConnectionDefinitionBuilderTestBase.java b/src/test/java/com/exasol/adapter/jdbc/AbstractConnectionDefinitionBuilderTestBase.java
index e27b323..5ddca4c 100644
--- a/src/test/java/com/exasol/adapter/jdbc/AbstractConnectionDefinitionBuilderTestBase.java
+++ b/src/test/java/com/exasol/adapter/jdbc/AbstractConnectionDefinitionBuilderTestBase.java
@@ -12,9 +12,6 @@
public abstract class AbstractConnectionDefinitionBuilderTestBase {
protected static final String USER = "property_user";
protected static final String PW = "property_secret";
- protected static final String USER_IDENTIFIED_BY = "USER '" + USER + "' IDENTIFIED BY '" + PW + "'";
- protected static final String ADDRESS = "property_address";
- protected static final String ADDRESS_WITH_USER_IDENTIFIED_BY = "AT '" + ADDRESS + "' " + USER_IDENTIFIED_BY;
protected static final String CONNECTION_NAME = "the_connection";
protected static final String CONNECTION_USER = "connection_user";
protected static final String CONNECTION_PW = "connection_secret";
@@ -30,30 +27,6 @@ protected void mockExasolNamedConnection() {
when(this.exaConnectionInformation.getAddress()).thenReturn(CONNECTION_ADDRESS);
}
- protected Map createUsernameAndPasswordProperties() {
- final Map rawProperties = new HashMap<>();
- setUserNameProperty();
- setPasswordProperty();
- setAddressProperty();
- return rawProperties;
- }
-
- protected void setUserNameProperty() {
- this.rawProperties.put(AdapterProperties.USERNAME_PROPERTY, USER);
- }
-
- protected void setPasswordProperty() {
- this.rawProperties.put(AdapterProperties.PASSWORD_PROPERTY, PW);
- }
-
- private void setAddressProperty() {
- this.rawProperties.put(AdapterProperties.CONNECTION_STRING_PROPERTY, ADDRESS);
- }
-
- protected void setConnectionStringProperty(final String connectionString) {
- this.rawProperties.put(AdapterProperties.CONNECTION_STRING_PROPERTY, connectionString);
- }
-
protected void setConnectionNameProperty() {
this.rawProperties.put(AdapterProperties.CONNECTION_NAME_PROPERTY, CONNECTION_NAME);
}
diff --git a/src/test/java/com/exasol/adapter/jdbc/BaseConnectionDefinitionBuilderTest.java b/src/test/java/com/exasol/adapter/jdbc/BaseConnectionDefinitionBuilderTest.java
index 7980f09..9b529d9 100644
--- a/src/test/java/com/exasol/adapter/jdbc/BaseConnectionDefinitionBuilderTest.java
+++ b/src/test/java/com/exasol/adapter/jdbc/BaseConnectionDefinitionBuilderTest.java
@@ -1,7 +1,7 @@
package com.exasol.adapter.jdbc;
-import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
import static org.mockito.Mockito.mock;
import java.util.Collections;
@@ -32,36 +32,14 @@ void testBuildConnectionDefinitionForJDBCImportWithConnectionNameGiven() {
}
@Test
- void testBuildConnectionDefinitionForJDBCImportWithConnectionStringUsernamePasswordGiven() {
- setConnectionStringProperty(ADDRESS);
- setUserNameProperty();
- setPasswordProperty();
- assertThat(calculateConnectionDefinition(), equalTo(ADDRESS_WITH_USER_IDENTIFIED_BY));
- }
-
- @Test
- void testBuildConnectionDefinitionWithoutConnectionInfomationThrowsException() {
+ void testBuildConnectionDefinitionWithoutConnectionInformationThrowsException() {
assertIllegalPropertiesThrowsException(Collections.emptyMap());
}
@Test
- void testBuildConnectionDefinitionWithExtraUsernameThrowsException() {
- setConnectionNameProperty();
- setUserNameProperty();
- assertIllegalPropertiesThrowsException(this.rawProperties);
- }
-
- @Test
- void testBuildConnectionDefinitionWithExtraPasswordThrowsException() {
- setConnectionNameProperty();
- setPasswordProperty();
- assertIllegalPropertiesThrowsException(this.rawProperties);
- }
-
- @Test
- void testBuildConnectionDefinitionWithExtraConnectionStringThrowsException() {
- setConnectionNameProperty();
- setConnectionStringProperty("irrelevant");
- assertIllegalPropertiesThrowsException(this.rawProperties);
+ void testGetConnectionDefinition() {
+ final BaseConnectionDefinitionBuilder baseConnectionDefinitionBuilder = new BaseConnectionDefinitionBuilder();
+ assertThat(baseConnectionDefinitionBuilder.getConnectionDefinition("localhost:6666", "username", "password"),
+ equalTo("AT 'localhost:6666' USER 'username' IDENTIFIED BY 'password'"));
}
}
\ No newline at end of file
diff --git a/src/test/java/com/exasol/adapter/jdbc/JdbcAdapterIT.java b/src/test/java/com/exasol/adapter/jdbc/JdbcAdapterIT.java
index 2c606f2..ae89e59 100644
--- a/src/test/java/com/exasol/adapter/jdbc/JdbcAdapterIT.java
+++ b/src/test/java/com/exasol/adapter/jdbc/JdbcAdapterIT.java
@@ -1,9 +1,10 @@
package com.exasol.adapter.jdbc;
-import static com.exasol.adapter.AdapterProperties.*;
+import static com.exasol.adapter.AdapterProperties.CONNECTION_NAME_PROPERTY;
+import static com.exasol.adapter.AdapterProperties.SQL_DIALECT_PROPERTY;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
import java.util.List;
@@ -24,9 +25,7 @@ public void testRegisteredDialects() throws AdapterException {
+ " \"properties\" :\n" //
+ " {\n" //
+ " \"" + SQL_DIALECT_PROPERTY + "\" : \"DERBY\"\n," //
- + " \"" + CONNECTION_STRING_PROPERTY + "\" : \"jdbc:derby:memory:test;create=true;\"\n," //
- + " \"" + USERNAME_PROPERTY + "\" : \"\"\n," //
- + " \"" + PASSWORD_PROPERTY + "\" : \"\"\n" //
+ + " \"" + CONNECTION_NAME_PROPERTY + "\" : \"DERBY_CONNECTION\"\n" //
+ " }\n" //
+ " }\n" //
+ "}";
diff --git a/src/test/java/com/exasol/adapter/jdbc/JdbcAdapterTest.java b/src/test/java/com/exasol/adapter/jdbc/JdbcAdapterTest.java
index bc115b1..56b28a5 100644
--- a/src/test/java/com/exasol/adapter/jdbc/JdbcAdapterTest.java
+++ b/src/test/java/com/exasol/adapter/jdbc/JdbcAdapterTest.java
@@ -1,8 +1,8 @@
package com.exasol.adapter.jdbc;
import static com.exasol.adapter.AdapterProperties.*;
-import static org.hamcrest.Matchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
@@ -15,7 +15,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import com.exasol.ExaMetadata;
+import com.exasol.*;
import com.exasol.adapter.*;
import com.exasol.adapter.capabilities.*;
import com.exasol.adapter.metadata.*;
@@ -27,6 +27,11 @@
class JdbcAdapterTest {
private static final String SCHEMA_NAME = "THE_SCHEMA";
private static final String TEST_DIALECT_NAME = "DERBY";
+ private static final ExaConnectionInformation EXA_CONNECTION_INFORMATION = ExaConnectionInformationStub.builder() //
+ .user("") //
+ .password("") //
+ .address("jdbc:derby:memory:test;create=true;") //
+ .build();
private final VirtualSchemaAdapter adapter = new JdbcAdapterFactory().createAdapter();
private Map rawProperties;
@@ -36,22 +41,24 @@ void beforeEach() {
}
@Test
- void testPushdown() throws AdapterException {
+ void testPushdown() throws AdapterException, ExaConnectionAccessException {
final PushDownResponse response = pushStatementDown(TestSqlStatementFactory.createSelectOneFromSysDummy());
assertThat(response.getPushDownSql(), equalTo("IMPORT INTO (c1 DECIMAL(10, 0))" //
+ " FROM JDBC" //
- + " AT 'jdbc:derby:memory:test;create=true;' USER '' IDENTIFIED BY ''"//
+ + " AT DERBY_CONNECTION"//
+ " STATEMENT 'SELECT 1 FROM \"SYSIBM\".\"SYSDUMMY1\"'"));
}
- private PushDownResponse pushStatementDown(final SqlStatement statement) throws AdapterException {
+ private PushDownResponse pushStatementDown(final SqlStatement statement)
+ throws AdapterException, ExaConnectionAccessException {
setTestSqlDialectProperty();
- setDerbyConnectionProperties();
+ setDerbyConnectionNameProperty();
this.rawProperties.put(SCHEMA_NAME_PROPERTY, "SYSIBM");
final List involvedTablesMetadata = null;
final PushDownRequest request = new PushDownRequest(TEST_DIALECT_NAME, createSchemaMetadataInfo(), statement,
involvedTablesMetadata);
final ExaMetadata exaMetadataMock = mock(ExaMetadata.class);
+ when(exaMetadataMock.getConnection("DERBY_CONNECTION")).thenReturn(EXA_CONNECTION_INFORMATION);
return this.adapter.pushdown(exaMetadataMock, request);
}
@@ -59,10 +66,8 @@ private void setTestSqlDialectProperty() {
this.rawProperties.put(SQL_DIALECT_PROPERTY, TEST_DIALECT_NAME);
}
- private void setDerbyConnectionProperties() {
- this.rawProperties.put(CONNECTION_STRING_PROPERTY, "jdbc:derby:memory:test;create=true;");
- this.rawProperties.put(USERNAME_PROPERTY, "");
- this.rawProperties.put(PASSWORD_PROPERTY, "");
+ private void setDerbyConnectionNameProperty() {
+ this.rawProperties.put(CONNECTION_NAME_PROPERTY, "DERBY_CONNECTION");
}
private SchemaMetadataInfo createSchemaMetadataInfo() {
@@ -78,7 +83,7 @@ void testPushdownWithIllegalStatementThrowsException() {
@Test
void testGetCapabilities() throws AdapterException {
setTestSqlDialectProperty();
- setDerbyConnectionProperties();
+ setDerbyConnectionNameProperty();
this.rawProperties.put(SCHEMA_NAME_PROPERTY, "SYSIBM");
final GetCapabilitiesRequest request = new GetCapabilitiesRequest(TEST_DIALECT_NAME,
createSchemaMetadataInfo());
@@ -99,7 +104,7 @@ void testGetCapabilities() throws AdapterException {
@Test
void testGetCapabilitiesWithExcludedCapabilitiesList() throws AdapterException {
setTestSqlDialectProperty();
- setDerbyConnectionProperties();
+ setDerbyConnectionNameProperty();
this.rawProperties.put(SCHEMA_NAME_PROPERTY, "SYSIBM");
this.rawProperties.put(EXCLUDED_CAPABILITIES_PROPERTY,
"ORDER_BY_EXPRESSION, LITERAL_NULL, FN_AGG_COUNT_STAR, FN_PRED_AND, FN_ADD");
@@ -116,7 +121,7 @@ void testGetCapabilitiesWithExcludedCapabilitiesList() throws AdapterException {
@Test
void testDropVirtualSchemaMustSucceedEvenIfDebugAddressIsInvalid() throws AdapterException {
setTestSqlDialectProperty();
- setDerbyConnectionProperties();
+ setDerbyConnectionNameProperty();
final ExaMetadata exaMetadataMock = mock(ExaMetadata.class);
this.rawProperties.put(AdapterProperties.DEBUG_ADDRESS_PROPERTY, "this_is_an:invalid_debug_address");
final DropVirtualSchemaRequest dropRequest = new DropVirtualSchemaRequest(TEST_DIALECT_NAME,
@@ -126,14 +131,15 @@ void testDropVirtualSchemaMustSucceedEvenIfDebugAddressIsInvalid() throws Adapte
}
@Test
- void testSetPropertiesWithoutTablesFilter() throws AdapterException {
+ void testSetPropertiesWithoutTablesFilter() throws AdapterException, ExaConnectionAccessException {
setTestSqlDialectProperty();
- setDerbyConnectionProperties();
+ setDerbyConnectionNameProperty();
final Map newRawProperties = new HashMap<>();
newRawProperties.put(SCHEMA_NAME_PROPERTY, "NEW SCHEMA");
final SetPropertiesRequest request = new SetPropertiesRequest(TEST_DIALECT_NAME, createSchemaMetadataInfo(),
newRawProperties);
final ExaMetadata exaMetadataMock = mock(ExaMetadata.class);
+ when(exaMetadataMock.getConnection("DERBY_CONNECTION")).thenReturn(EXA_CONNECTION_INFORMATION);
final SetPropertiesResponse response = this.adapter.setProperties(exaMetadataMock, request);
assertThat(response.getSchemaMetadata().getTables(), emptyCollectionOf(TableMetadata.class));
}
@@ -145,7 +151,7 @@ void testSetPropertiesWithTablesFilter() throws AdapterException, SQLException {
when(adapter.readMetadata(any(), any(), any())).thenReturn(new SchemaMetadata("",
Arrays.asList(new TableMetadata("T1", "", null, ""), new TableMetadata("T2", "", null, ""))));
setTestSqlDialectProperty();
- setDerbyConnectionProperties();
+ setDerbyConnectionNameProperty();
final Map newRawProperties = new HashMap<>();
newRawProperties.put(SCHEMA_NAME_PROPERTY, "NEW SCHEMA");
newRawProperties.put(TABLE_FILTER_PROPERTY, "T1, T2");
@@ -160,12 +166,13 @@ void testSetPropertiesWithTablesFilter() throws AdapterException, SQLException {
}
@Test
- void testCreateVirtualSchema() throws AdapterException {
+ void testCreateVirtualSchema() throws AdapterException, ExaConnectionAccessException {
setTestSqlDialectProperty();
- setDerbyConnectionProperties();
+ setDerbyConnectionNameProperty();
final CreateVirtualSchemaRequest request = new CreateVirtualSchemaRequest(TEST_DIALECT_NAME,
createSchemaMetadataInfo());
final ExaMetadata exaMetadataMock = mock(ExaMetadata.class);
+ when(exaMetadataMock.getConnection("DERBY_CONNECTION")).thenReturn(EXA_CONNECTION_INFORMATION);
final CreateVirtualSchemaResponse response = this.adapter.createVirtualSchema(exaMetadataMock, request);
assertAll(() -> assertThat(response, instanceOf(CreateVirtualSchemaResponse.class)),
() -> assertThat(response.getSchemaMetadata(), instanceOf(SchemaMetadata.class)),
@@ -181,13 +188,14 @@ void testCreateVirtualSchema() throws AdapterException {
}
@Test
- void testRefreshSelectedTables() throws AdapterException {
+ void testRefreshSelectedTables() throws AdapterException, ExaConnectionAccessException {
setTestSqlDialectProperty();
- setDerbyConnectionProperties();
+ setDerbyConnectionNameProperty();
final List tablesList = new ArrayList<>();
tablesList.add("SYSDUMMY1");
final RefreshRequest request = new RefreshRequest(TEST_DIALECT_NAME, createSchemaMetadataInfo(), tablesList);
final ExaMetadata exaMetadataMock = mock(ExaMetadata.class);
+ when(exaMetadataMock.getConnection("DERBY_CONNECTION")).thenReturn(EXA_CONNECTION_INFORMATION);
final RefreshResponse response = this.adapter.refresh(exaMetadataMock, request);
assertAll(() -> assertThat(response, instanceOf(RefreshResponse.class)),
() -> assertThat(response.getSchemaMetadata(), instanceOf(SchemaMetadata.class)),
diff --git a/src/test/java/com/exasol/adapter/jdbc/RemoteConnectionFactoryTest.java b/src/test/java/com/exasol/adapter/jdbc/RemoteConnectionFactoryTest.java
index e636bf6..8b102cc 100644
--- a/src/test/java/com/exasol/adapter/jdbc/RemoteConnectionFactoryTest.java
+++ b/src/test/java/com/exasol/adapter/jdbc/RemoteConnectionFactoryTest.java
@@ -62,30 +62,11 @@ private Connection createConnection() throws SQLException {
}
@Test
- void testGetConnectionWithConnectionDetailsInProperties() throws ExaConnectionAccessException, SQLException {
- this.rawProperties.put("CONNECTION_STRING", DERBY_INSTANT_JDBC_CONNECTION_STRING);
- this.rawProperties.put("USERNAME", USER);
- this.rawProperties.put("PASSWORD", "testPassword");
- assertThat(createConnection().getMetaData().getUserName(), equalTo(USER));
- }
-
- @Test
- void testGetConnectionWithConnectionDetailsInPropertiesAndEmptyConnectionName()
- throws ExaConnectionAccessException, SQLException {
- this.rawProperties.put("CONNECTION_NAME", "");
- this.rawProperties.put("CONNECTION_STRING", DERBY_INSTANT_JDBC_CONNECTION_STRING);
- this.rawProperties.put("USERNAME", USER);
- this.rawProperties.put("PASSWORD", "testPassword");
- assertThat(createConnection().getMetaData().getUserName(), equalTo(USER));
- }
-
- @Test
- void testGetConnectionWithUnaccessibleNamedConnectionThrowsException()
- throws ExaConnectionAccessException, SQLException {
+ void testGetConnectionWithInaccessibleNamedConnectionThrowsException() throws ExaConnectionAccessException {
when(this.exaMetadataMock.getConnection(CONNECTION_NAME))
.thenThrow(new ExaConnectionAccessException("FAKE connection access exception"));
this.rawProperties.put("CONNECTION_NAME", CONNECTION_NAME);
- assertThrows(RemoteConnectionException.class, () -> createConnection());
+ assertThrows(RemoteConnectionException.class, this::createConnection);
}
@Test
From fe06238815bb087c76c57658a1a6c0ee79053ead Mon Sep 17 00:00:00 2001
From: Anastasiia Sergienko
<46891819+AnastasiiaSergienko@users.noreply.github.com>
Date: Fri, 24 Apr 2020 11:04:43 +0200
Subject: [PATCH 2/3] Refactoring/43 set mandatory properties (#44)
* #43: set common properties for all dialects in AbstractSqlDialect
* #43: removed `getAggregateFunctionAliases` settings from AbstractDialect
* #43: change an access to the getSupportedProperties to public
---
.../adapter/dialects/AbstractSqlDialect.java | 52 +++++++++++++------
.../adapter/dialects/SqlDialectTest.java | 7 +--
.../dialects/derby/DerbySqlDialect.java | 16 ++----
.../dialects/dummy/DummySqlDialect.java | 16 ++----
.../dialects/stubdialect/StubSqlDialect.java | 16 ++----
5 files changed, 48 insertions(+), 59 deletions(-)
diff --git a/src/main/java/com/exasol/adapter/dialects/AbstractSqlDialect.java b/src/main/java/com/exasol/adapter/dialects/AbstractSqlDialect.java
index 1dec06a..c3e6f8e 100644
--- a/src/main/java/com/exasol/adapter/dialects/AbstractSqlDialect.java
+++ b/src/main/java/com/exasol/adapter/dialects/AbstractSqlDialect.java
@@ -20,22 +20,41 @@
* Abstract implementation of a dialect. We recommend that every dialect should extend this abstract class.
*/
public abstract class AbstractSqlDialect implements SqlDialect {
+ private static final Logger LOGGER = Logger.getLogger(AbstractSqlDialect.class.getName());
+ private static final Pattern BOOLEAN_PROPERTY_VALUE_PATTERN = Pattern.compile("^TRUE$|^FALSE$",
+ Pattern.CASE_INSENSITIVE);
+ private static final Set COMMON_SUPPORTED_PROPERTIES = Set.of(SQL_DIALECT_PROPERTY,
+ CONNECTION_NAME_PROPERTY, TABLE_FILTER_PROPERTY, EXCLUDED_CAPABILITIES_PROPERTY, DEBUG_ADDRESS_PROPERTY,
+ LOG_LEVEL_PROPERTY);
protected Set omitParenthesesMap = EnumSet.noneOf(ScalarFunction.class);
protected AdapterProperties properties;
protected final ConnectionFactory connectionFactory;
- private static final Pattern BOOLEAN_PROPERTY_VALUE_PATTERN = Pattern.compile("^TRUE$|^FALSE$",
- Pattern.CASE_INSENSITIVE);
- private static final Logger LOGGER = Logger.getLogger(AbstractSqlDialect.class.getName());
+ private final Set supportedProperties;
/**
* Create a new instance of an {@link AbstractSqlDialect}.
*
- * @param connectionFactory factory for JDBC connection to remote data source
- * @param properties user properties
+ * @param connectionFactory factory for JDBC connection to remote data source
+ * @param properties user properties
+ * @param dialectSpecificProperties a set of properties that dialect supports additionally to the common set *
+ * {@link com.exasol.adapter.dialects.AbstractSqlDialect#COMMON_SUPPORTED_PROPERTIES}
*/
- public AbstractSqlDialect(final ConnectionFactory connectionFactory, final AdapterProperties properties) {
+ public AbstractSqlDialect(final ConnectionFactory connectionFactory, final AdapterProperties properties,
+ final Set dialectSpecificProperties) {
this.connectionFactory = connectionFactory;
this.properties = properties;
+ this.supportedProperties = new HashSet<>(COMMON_SUPPORTED_PROPERTIES);
+ this.supportedProperties.addAll(dialectSpecificProperties);
+ }
+
+ /**
+ * Add additional dialect-specific supported properties that are not in the
+ * {@link com.exasol.adapter.dialects.AbstractSqlDialect#COMMON_SUPPORTED_PROPERTIES} set.
+ *
+ * @param additionalPropertiesToSupport list of properties names
+ */
+ protected void addAdditionalSupportedProperties(final List additionalPropertiesToSupport) {
+ this.supportedProperties.addAll(additionalPropertiesToSupport);
}
/**
@@ -79,10 +98,7 @@ public Map getScalarFunctionAliases() {
@Override
public Map getAggregateFunctionAliases() {
- final Map aliases = new EnumMap<>(AggregateFunction.class);
- aliases.put(AggregateFunction.GEO_INTERSECTION_AGGREGATE, "ST_INTERSECTION");
- aliases.put(AggregateFunction.GEO_UNION_AGGREGATE, "ST_UNION");
- return aliases;
+ return new EnumMap<>(AggregateFunction.class);
}
@Override
@@ -95,6 +111,15 @@ public Map getBinaryInfixFunctionAliases() {
return aliases;
}
+ /**
+ * Get a set of adapter properties that the dialect supports.
+ *
+ * @return set of supported properties
+ */
+ public Set getSupportedProperties() {
+ return this.supportedProperties;
+ }
+
@Override
public Map getPrefixFunctionAliases() {
final Map aliases = new EnumMap<>(ScalarFunction.class);
@@ -146,13 +171,6 @@ protected void validateSupportedPropertiesList() throws PropertyValidationExcept
}
}
- /**
- * Get the list of user-defined adapter properties which the dialect supports.
- *
- * @return list of supported properties
- */
- protected abstract List getSupportedProperties();
-
protected String createUnsupportedElementMessage(final String unsupportedElement, final String property) {
return "The dialect " + this.properties.getSqlDialect() + " does not support " + unsupportedElement
+ " property. Please, do not set the \"" + property + "\" property.";
diff --git a/src/test/java/com/exasol/adapter/dialects/SqlDialectTest.java b/src/test/java/com/exasol/adapter/dialects/SqlDialectTest.java
index 4d88494..8bb1c7f 100644
--- a/src/test/java/com/exasol/adapter/dialects/SqlDialectTest.java
+++ b/src/test/java/com/exasol/adapter/dialects/SqlDialectTest.java
@@ -128,7 +128,7 @@ static class AliasesSqlDialect extends AbstractSqlDialect {
public AliasesSqlDialect(final Map aggregationAliases,
final Map scalarAliases, final Map infixAliases,
final Map prefixAliases) {
- super(null, AdapterProperties.emptyProperties());
+ super(null, AdapterProperties.emptyProperties(), Collections.emptySet());
this.aggregationAliases = aggregationAliases;
this.scalarAliases = scalarAliases;
@@ -185,11 +185,6 @@ public Map getPrefixFunctionAliases() {
}
}
- @Override
- protected List getSupportedProperties() {
- return null;
- }
-
@Override
public String getName() {
return "TEST";
diff --git a/src/test/java/com/exasol/adapter/dialects/derby/DerbySqlDialect.java b/src/test/java/com/exasol/adapter/dialects/derby/DerbySqlDialect.java
index 8af15d4..3ec2a65 100644
--- a/src/test/java/com/exasol/adapter/dialects/derby/DerbySqlDialect.java
+++ b/src/test/java/com/exasol/adapter/dialects/derby/DerbySqlDialect.java
@@ -1,10 +1,10 @@
package com.exasol.adapter.dialects.derby;
-import static com.exasol.adapter.AdapterProperties.*;
+import static com.exasol.adapter.AdapterProperties.CATALOG_NAME_PROPERTY;
+import static com.exasol.adapter.AdapterProperties.SCHEMA_NAME_PROPERTY;
import java.sql.SQLException;
-import java.util.Arrays;
-import java.util.List;
+import java.util.*;
import com.exasol.adapter.AdapterProperties;
import com.exasol.adapter.capabilities.*;
@@ -19,9 +19,6 @@
public class DerbySqlDialect extends AbstractSqlDialect {
static final String NAME = "DERBY";
private static final Capabilities CAPABILITIES = createCapabilityList();
- private static final List SUPPORTED_PROPERTIES = Arrays.asList(SQL_DIALECT_PROPERTY,
- CONNECTION_NAME_PROPERTY, CATALOG_NAME_PROPERTY, SCHEMA_NAME_PROPERTY, TABLE_FILTER_PROPERTY,
- EXCLUDED_CAPABILITIES_PROPERTY, DEBUG_ADDRESS_PROPERTY, LOG_LEVEL_PROPERTY);
private static Capabilities createCapabilityList() {
return Capabilities.builder().addMain(MainCapability.ORDER_BY_EXPRESSION)
@@ -37,7 +34,7 @@ private static Capabilities createCapabilityList() {
* @param properties user-defined adapter properties
*/
public DerbySqlDialect(final ConnectionFactory connectionFactory, final AdapterProperties properties) {
- super(connectionFactory, properties);
+ super(connectionFactory, properties, Set.of(CATALOG_NAME_PROPERTY, SCHEMA_NAME_PROPERTY));
}
@Override
@@ -101,9 +98,4 @@ protected RemoteMetadataReader createRemoteMetadataReader() {
protected QueryRewriter createQueryRewriter() {
return new BaseQueryRewriter(this, createRemoteMetadataReader(), this.connectionFactory);
}
-
- @Override
- protected List getSupportedProperties() {
- return SUPPORTED_PROPERTIES;
- }
}
\ No newline at end of file
diff --git a/src/test/java/com/exasol/adapter/dialects/dummy/DummySqlDialect.java b/src/test/java/com/exasol/adapter/dialects/dummy/DummySqlDialect.java
index 6c95150..2e7f3ef 100644
--- a/src/test/java/com/exasol/adapter/dialects/dummy/DummySqlDialect.java
+++ b/src/test/java/com/exasol/adapter/dialects/dummy/DummySqlDialect.java
@@ -1,10 +1,10 @@
package com.exasol.adapter.dialects.dummy;
-import static com.exasol.adapter.AdapterProperties.*;
+import static com.exasol.adapter.AdapterProperties.EXCEPTION_HANDLING_PROPERTY;
+import static com.exasol.adapter.AdapterProperties.SCHEMA_NAME_PROPERTY;
import java.sql.SQLException;
-import java.util.Arrays;
-import java.util.List;
+import java.util.Set;
import com.exasol.adapter.AdapterProperties;
import com.exasol.adapter.capabilities.Capabilities;
@@ -13,12 +13,9 @@
public class DummySqlDialect extends AbstractSqlDialect {
static final String NAME = "DUMMYDIALECT";
- private static final List SUPPORTED_PROPERTIES = Arrays.asList(SQL_DIALECT_PROPERTY,
- CONNECTION_NAME_PROPERTY, SCHEMA_NAME_PROPERTY, TABLE_FILTER_PROPERTY, EXCLUDED_CAPABILITIES_PROPERTY,
- DEBUG_ADDRESS_PROPERTY, LOG_LEVEL_PROPERTY, EXCEPTION_HANDLING_PROPERTY);
public DummySqlDialect(final ConnectionFactory connectionFactory, final AdapterProperties properties) {
- super(connectionFactory, properties);
+ super(connectionFactory, properties, Set.of(SCHEMA_NAME_PROPERTY, EXCEPTION_HANDLING_PROPERTY));
}
@Override
@@ -65,11 +62,6 @@ public NullSorting getDefaultNullSorting() {
return null;
}
- @Override
- protected List getSupportedProperties() {
- return SUPPORTED_PROPERTIES;
- }
-
@Override
protected RemoteMetadataReader createRemoteMetadataReader() {
try {
diff --git a/src/test/java/com/exasol/adapter/dialects/stubdialect/StubSqlDialect.java b/src/test/java/com/exasol/adapter/dialects/stubdialect/StubSqlDialect.java
index 886153c..ea71748 100644
--- a/src/test/java/com/exasol/adapter/dialects/stubdialect/StubSqlDialect.java
+++ b/src/test/java/com/exasol/adapter/dialects/stubdialect/StubSqlDialect.java
@@ -1,9 +1,9 @@
package com.exasol.adapter.dialects.stubdialect;
-import static com.exasol.adapter.AdapterProperties.*;
+import static com.exasol.adapter.AdapterProperties.CATALOG_NAME_PROPERTY;
+import static com.exasol.adapter.AdapterProperties.SCHEMA_NAME_PROPERTY;
-import java.util.Arrays;
-import java.util.List;
+import java.util.Set;
import com.exasol.adapter.AdapterProperties;
import com.exasol.adapter.capabilities.Capabilities;
@@ -16,12 +16,9 @@
*/
public class StubSqlDialect extends AbstractSqlDialect {
static final String NAME = "STUB";
- private static final List SUPPORTED_PROPERTIES = Arrays.asList(SQL_DIALECT_PROPERTY,
- CONNECTION_NAME_PROPERTY, CATALOG_NAME_PROPERTY, SCHEMA_NAME_PROPERTY, TABLE_FILTER_PROPERTY,
- EXCLUDED_CAPABILITIES_PROPERTY, DEBUG_ADDRESS_PROPERTY, LOG_LEVEL_PROPERTY);
public StubSqlDialect(final ConnectionFactory connectionFactory, final AdapterProperties properties) {
- super(connectionFactory, properties);
+ super(connectionFactory, properties, Set.of(CATALOG_NAME_PROPERTY, SCHEMA_NAME_PROPERTY));
}
@Override
@@ -44,11 +41,6 @@ public StructureElementSupport supportsJdbcSchemas() {
return StructureElementSupport.SINGLE;
}
- @Override
- protected List getSupportedProperties() {
- return SUPPORTED_PROPERTIES;
- }
-
@Override
protected RemoteMetadataReader createRemoteMetadataReader() {
return new StubMetadataReader();
From b4e9d08c5f75e6d2fb4aa6fa0610439d26bcc4d5 Mon Sep 17 00:00:00 2001
From: Anastasiia Sergienko
<46891819+AnastasiiaSergienko@users.noreply.github.com>
Date: Fri, 24 Apr 2020 12:27:30 +0200
Subject: [PATCH 3/3] #28: improved data types mapping in
BaseColumnMetadataReader (#47)
---
.../exasol/adapter/jdbc/BaseColumnMetadataReader.java | 5 +++--
.../adapter/jdbc/BaseColumnMetadataReaderTest.java | 6 +++---
.../exasol/adapter/jdbc/ColumnMetadataReaderTest.java | 10 ++--------
3 files changed, 8 insertions(+), 13 deletions(-)
diff --git a/src/main/java/com/exasol/adapter/jdbc/BaseColumnMetadataReader.java b/src/main/java/com/exasol/adapter/jdbc/BaseColumnMetadataReader.java
index 3fc3356..3667bea 100644
--- a/src/main/java/com/exasol/adapter/jdbc/BaseColumnMetadataReader.java
+++ b/src/main/java/com/exasol/adapter/jdbc/BaseColumnMetadataReader.java
@@ -228,11 +228,12 @@ public DataType mapJdbcType(final JdbcTypeDescription jdbcTypeDescription) {
case Types.BIT:
case Types.BOOLEAN:
return DataType.createBool();
- case Types.BINARY:
- case Types.CLOB:
case Types.TIME:
+ return DataType.createVarChar(100, DataType.ExaCharset.UTF8);
case Types.NUMERIC:
return fallBackToMaximumSizeVarChar();
+ case Types.BINARY:
+ case Types.CLOB:
case Types.OTHER:
case Types.BLOB:
case Types.NCLOB:
diff --git a/src/test/java/com/exasol/adapter/jdbc/BaseColumnMetadataReaderTest.java b/src/test/java/com/exasol/adapter/jdbc/BaseColumnMetadataReaderTest.java
index 7f1fbc9..882a8b7 100644
--- a/src/test/java/com/exasol/adapter/jdbc/BaseColumnMetadataReaderTest.java
+++ b/src/test/java/com/exasol/adapter/jdbc/BaseColumnMetadataReaderTest.java
@@ -33,9 +33,9 @@ void beforeEach() {
IdentifierCaseHandling.INTERPRET_CASE_SENSITIVE));
}
- @ValueSource(ints = { Types.OTHER, Types.BLOB, Types.NCLOB, Types.LONGVARBINARY, Types.VARBINARY, Types.JAVA_OBJECT,
- Types.DISTINCT, Types.STRUCT, Types.ARRAY, Types.REF, Types.DATALINK, Types.SQLXML, Types.NULL,
- Types.REF_CURSOR })
+ @ValueSource(ints = { Types.BINARY, Types.CLOB, Types.OTHER, Types.BLOB, Types.NCLOB, Types.LONGVARBINARY,
+ Types.VARBINARY, Types.JAVA_OBJECT, Types.DISTINCT, Types.STRUCT, Types.ARRAY, Types.REF, Types.DATALINK,
+ Types.SQLXML, Types.NULL, Types.REF_CURSOR })
@ParameterizedTest
void testMappingUnsupportedTypesReturnsUnsupportedType(final int jdbcType) {
final JdbcTypeDescription jdbcTypeDescription = new JdbcTypeDescription(jdbcType, 0, 0, 0, null);
diff --git a/src/test/java/com/exasol/adapter/jdbc/ColumnMetadataReaderTest.java b/src/test/java/com/exasol/adapter/jdbc/ColumnMetadataReaderTest.java
index 25f18a6..2be7a2c 100644
--- a/src/test/java/com/exasol/adapter/jdbc/ColumnMetadataReaderTest.java
+++ b/src/test/java/com/exasol/adapter/jdbc/ColumnMetadataReaderTest.java
@@ -1,7 +1,7 @@
package com.exasol.adapter.jdbc;
-import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.when;
@@ -256,13 +256,7 @@ void testNumeric() throws SQLException {
@Test
void testTime() throws SQLException {
- assertSqlTypeConvertedToExasolType(Types.TIME, TYPE_MAX_VARCHAR_UTF8);
- }
-
- @ValueSource(ints = { Types.BINARY, Types.CLOB })
- @ParameterizedTest
- void testBinary(final int typeId) throws SQLException {
- assertSqlTypeConvertedToExasolType(typeId, TYPE_MAX_VARCHAR_UTF8);
+ assertSqlTypeConvertedToExasolType(Types.TIME, DataType.createVarChar(100, ExaCharset.UTF8));
}
@CsvSource({ RemoteMetadataReaderConstants.JDBC_FALSE + ", false",