Skip to content

Commit

Permalink
#10: Automatted dialect list detection
Browse files Browse the repository at this point in the history
  • Loading branch information
redcatbear committed Nov 12, 2019
1 parent 3bef8ec commit 80d409e
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 121 deletions.
48 changes: 24 additions & 24 deletions launch/vsc-jdbc all test.launch
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/virtual-schema-common-jdbc"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
<listAttribute key="org.eclipse.eclemma.core.SCOPE_IDS">
<listEntry value="=virtual-schema-common-jdbc/src\/main\/java"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=virtual-schema-common-jdbc"/>
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit5"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="virtual-schema-common-jdbc"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea -Djava.util.logging.config.file=src/test/resources/logging.properties"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/virtual-schema-common-jdbc"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
<listAttribute key="org.eclipse.eclemma.core.SCOPE_IDS">
<listEntry value="=virtual-schema-common-jdbc/src\/main\/java"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=virtual-schema-common-jdbc"/>
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit5"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="virtual-schema-common-jdbc"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea -Djava.util.logging.config.file=src/test/resources/logging.properties"/>
</launchConfiguration>
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
<description>Common module for JDBC-based data access from Virtual Schemas.</description>
<url>https://github.com/exasol/virtual-schema-common-jdbc</url>
<properties>
<product.version>1.0.1</product.version>
<product.version>1.0.2</product.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>9</java.version>
<junit.version>5.4.2</junit.version>
<junit.platform.version>1.4.2</junit.platform.version>
<maven.surefire.version>2.22.1</maven.surefire.version>
<vscommon.version>7.5.0</vscommon.version>
<vscommon.version>7.5.1</vscommon.version>
<gpg.skip>true</gpg.skip>
</properties>
<licenses>
Expand Down Expand Up @@ -228,6 +228,12 @@
<goals>
<goal>test-jar</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*Test.class</exclude>
<exclude>**/*IT.class</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/com/exasol/adapter/dialects/SqlDialectRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,24 @@
*/
public final class SqlDialectRegistry {
private static final Logger LOGGER = Logger.getLogger(SqlDialectRegistry.class.getName());
private static final SqlDialectRegistry instance = new SqlDialectRegistry();
private static SqlDialectRegistry instance;
private final Map<String, SqlDialectFactory> registeredFactories = new HashMap<>();

/**
* Get the singleton instance of the {@link SqlDialectRegistry}.
*
* @return singleton instance
*/
public static SqlDialectRegistry getInstance() {
public static final synchronized SqlDialectRegistry getInstance() {
if (instance == null) {
LOGGER.finer(() -> "Instanciating SQL dialect registry and loading adapter factories.");
instance = new SqlDialectRegistry();
instance.loadSqlDialectFactories();
}
return instance;
}

/**
* Load available dialect factories.
*/
public void loadSqlDialectFactories() {
private void loadSqlDialectFactories() {
final ServiceLoader<SqlDialectFactory> serviceLoader = ServiceLoader.load(SqlDialectFactory.class);
final Iterator<SqlDialectFactory> factories = serviceLoader.iterator();
while (factories.hasNext()) {
Expand All @@ -42,7 +44,7 @@ public void loadSqlDialectFactories() {
*
* @param factory factory that creates an {@link SqlDialect}
*/
public void registerSqlDialectFactory(final SqlDialectFactory factory) {
private void registerSqlDialectFactory(final SqlDialectFactory factory) {
this.registeredFactories.put(factory.getSqlDialectName(), factory);
}

Expand Down Expand Up @@ -119,9 +121,10 @@ public String describe() {
* @return comma-separated string containing list of SQL dialect names
*/
public String listRegisteredSqlDialectNames() {
return this.registeredFactories.keySet() //
final String dialectNamesAsString = this.registeredFactories.keySet() //
.stream() //
.sorted().map(name -> "\"" + name + "\"") //
.collect(Collectors.joining(", "));
return dialectNamesAsString.isEmpty() ? "none" : dialectNamesAsString;
}
}
9 changes: 0 additions & 9 deletions src/main/java/com/exasol/adapter/jdbc/JdbcAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,10 @@ public class JdbcAdapter implements VirtualSchemaAdapter {
private static final String PREDICATE_PREFIX = "FN_PRED_";
private static final String AGGREGATE_FUNCTION_PREFIX = "FN_AGG_";
private static final String LITERAL_PREFIX = "LITERAL_";

private static final String TABLES_PROPERTY = "TABLE_FILTER";

private static final Logger LOGGER = Logger.getLogger(JdbcAdapter.class.getName());
private final RemoteConnectionFactory connectionFactory = new RemoteConnectionFactory();

/**
* Create a new instance of type {@link JdbcAdapter}.
*/
public JdbcAdapter() {
SqlDialectRegistry.getInstance().loadSqlDialectFactories();
}

@Override
public CreateVirtualSchemaResponse createVirtualSchema(final ExaMetadata exasolMetadata,
final CreateVirtualSchemaRequest request) throws AdapterException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.exasol.adapter.jdbc.JdbcAdapterFactory

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.exasol.adapter.AdapterProperties;
import com.exasol.adapter.sql.SqlStatement;

public abstract class AbstractQueryRewriterTest {
public abstract class AbstractQueryRewriterTestBase {
protected static final String CONNECTION_NAME = "the_connection";
private static final String CONNECTION_USER = "connection_user";
private static final String CONNECTION_PW = "connection_secret";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.exasol.adapter.jdbc.BaseRemoteMetadataReader;
import com.exasol.adapter.sql.TestSqlStatementFactory;

class BaseQueryRewriterTest extends AbstractQueryRewriterTest {
class BaseQueryRewriterTest extends AbstractQueryRewriterTestBase {
@BeforeEach
void beforeEach() {
this.exaConnectionInformation = mock(ExaConnectionInformation.class);
Expand Down
50 changes: 0 additions & 50 deletions src/test/java/com/exasol/adapter/dialects/DialectTestData.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@

import java.util.Set;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;

import com.exasol.adapter.dialects.derby.DerbySqlDialect;
import com.exasol.adapter.dialects.derby.DerbySqlDialectFactory;
import com.exasol.adapter.dialects.dummy.DummySqlDialect;
import com.exasol.adapter.dialects.dummy.DummySqlDialectFactory;

class SqlDialectRegistryTest {
final SqlDialectRegistry registry = SqlDialectRegistry.getInstance();

@AfterEach
void afterEach() {
this.registry.clear();
}

@Test
void testGetInstance() {
final SqlDialectRegistry dialects = SqlDialectRegistry.getInstance();
Expand All @@ -34,14 +27,12 @@ void testGetInstanceTwiceYieldsSameInstance() {

@Test
void testLoadSqlDialectFactories() {
this.registry.loadSqlDialectFactories();
assertThat(this.registry.getRegisteredAdapterFactories(), hasItem(instanceOf(DerbySqlDialectFactory.class)));
}

@Test
void testIsSupported() {
this.registry.registerSqlDialectFactory(new DummySqlDialectFactory());
assertThat(this.registry.hasDialectWithName("DUMMYDIALECT"), is(true));
assertThat(this.registry.hasDialectWithName("DERBY"), is(true));
}

@Test
Expand All @@ -51,23 +42,18 @@ void testIsNotSupported() {

@Test
void testGetSqlDialectForName() {
this.registry.registerSqlDialectFactory(new DummySqlDialectFactory());
assertThat(SqlDialectRegistry.getInstance().getDialectForName("DUMMYDIALECT", null, null),
instanceOf(DummySqlDialect.class));
assertThat(SqlDialectRegistry.getInstance().getDialectForName("DERBY", null, null),
instanceOf(DerbySqlDialect.class));
}

@Test
void testListRegisteredDialects() {
this.registry.registerSqlDialectFactory(new DerbySqlDialectFactory());
this.registry.registerSqlDialectFactory(new DummySqlDialectFactory());
final String dialectNames = this.registry.listRegisteredSqlDialectNames();
assertThat(dialectNames, equalTo("\"DERBY\", \"DUMMYDIALECT\""));
}

@Test
void testGetRegisteredDialectNames() {
this.registry.registerSqlDialectFactory(new DerbySqlDialectFactory());
this.registry.registerSqlDialectFactory(new DummySqlDialectFactory());
final Set<String> dialectNames = this.registry.getRegisteredAdapterNames();
assertThat(dialectNames, containsInAnyOrder("DERBY", "DUMMYDIALECT"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import com.exasol.adapter.metadata.DataType;

public abstract class AbstractColumnMetadataReaderTest {
public abstract class AbstractColumnMetadataReaderTestBase {
protected ColumnMetadataReader columnMetadataReader;

protected DataType mapJdbcType(final int type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.exasol.ExaConnectionInformation;
import com.exasol.adapter.AdapterProperties;

public abstract class AbstractConnectionDefinitionBuilderTest {
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 + "'";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import com.exasol.ExaConnectionInformation;

class BaseConnectionDefinitionBuilderTest extends AbstractConnectionDefinitionBuilderTest {
class BaseConnectionDefinitionBuilderTest extends AbstractConnectionDefinitionBuilderTestBase {
@BeforeEach
void beforeEach() {
this.exaConnectionInformation = mock(ExaConnectionInformation.class);
Expand Down
38 changes: 38 additions & 0 deletions src/test/java/com/exasol/adapter/jdbc/JdbcAdapterIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.exasol.adapter.jdbc;

import static com.exasol.adapter.AdapterProperties.*;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertThat;

import java.util.List;

import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import com.exasol.ExaMetadata;
import com.exasol.adapter.*;

class JdbcAdapterIT {
@Test
public void testRegisteredDialects() throws AdapterException {
final String rawRequest = "{\n" //
+ " \"type\" : \"getCapabilities\",\n" //
+ " \"schemaMetadataInfo\" :\n" //
+ " {\n" //
+ " \"name\" : \"foo\",\n" //
+ " \"properties\" :\n" //
+ " {\n" //
+ " \"" + SQL_DIALECT_PROPERTY + "\" : \"DERBY\"\n," //
+ " \"" + CONNECTION_STRING_PROPERTY + "\" : \"jdbc:derby:memory:test;create=true;\"\n," //
+ " \"" + USERNAME_PROPERTY + "\" : \"\"\n," //
+ " \"" + PASSWORD_PROPERTY + "\" : \"\"\n" //
+ " }\n" //
+ " }\n" //
+ "}";
final ExaMetadata exaMetadata = Mockito.mock(ExaMetadata.class);
RequestDispatcher.adapterCall(exaMetadata, rawRequest);
final List<AdapterFactory> registeredFactories = AdapterRegistry.getInstance().getRegisteredAdapterFactories();
assertThat(registeredFactories, hasItem(instanceOf(JdbcAdapterFactory.class)));
}
}
7 changes: 3 additions & 4 deletions src/test/java/com/exasol/adapter/jdbc/JdbcAdapterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
import org.junit.jupiter.api.Test;

import com.exasol.ExaMetadata;
import com.exasol.adapter.AdapterException;
import com.exasol.adapter.AdapterProperties;
import com.exasol.adapter.*;
import com.exasol.adapter.capabilities.*;
import com.exasol.adapter.metadata.*;
import com.exasol.adapter.request.*;
Expand All @@ -28,7 +27,7 @@
class JdbcAdapterTest {
private static final String SCHEMA_NAME = "THE_SCHEMA";
private static final String TEST_DIALECT_NAME = "DERBY";
private final JdbcAdapter adapter = new JdbcAdapter();
private final VirtualSchemaAdapter adapter = new JdbcAdapterFactory().createAdapter();
private Map<String, String> rawProperties;

@BeforeEach
Expand Down Expand Up @@ -115,7 +114,7 @@ void testGetCapabilitiesWithExcludedCapabilitiesList() throws AdapterException {
}

@Test
void testDropVirtualSchemaMustSucceedEvenIfDebugAddressIsInvalid() {
void testDropVirtualSchemaMustSucceedEvenIfDebugAddressIsInvalid() throws AdapterException {
setTestSqlDialectProperty();
setDerbyConnectionProperties();
final ExaMetadata exaMetadataMock = mock(ExaMetadata.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
com.exasol.adapter.dialects.derby.DerbySqlDialectFactory
com.exasol.adapter.dialects.dummy.DummySqlDialectFactory

0 comments on commit 80d409e

Please sign in to comment.