Skip to content

Commit

Permalink
Merge pull request #7 from exasol/refactoring/6-improve_split_from_VS
Browse files Browse the repository at this point in the history
#280: Extract common JDBC parts to separate Maven module
  • Loading branch information
AnastasiiaSergienko authored Oct 21, 2019
2 parents 4349c58 + ee9da8f commit 9df8f2b
Show file tree
Hide file tree
Showing 23 changed files with 106 additions and 187 deletions.
2 changes: 1 addition & 1 deletion .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,4 @@ org.eclipse.jdt.core.formatter.wrap_before_relational_operator=true
org.eclipse.jdt.core.formatter.wrap_before_shift_operator=true
org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true
org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter
org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter
2 changes: 1 addition & 1 deletion .settings/org.eclipse.jdt.ui.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ sp_cleanup.use_parentheses_in_expressions=true
sp_cleanup.use_this_for_non_static_field_access=true
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=false
sp_cleanup.use_this_for_non_static_method_access=false
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Running the Virtual Schema requires a Java Runtime version 9 or later.
| [Exasol Script API](https://docs.exasol.com/database_concepts/udf_scripts.htm) | Accessing Exasol features | MIT License |
| JDBC driver(s), depending on data source | Connecting to the data source | Check driver documentation |

### Build Time Dependencies
### Test Dependencies

| Dependency | Purpose | License |
|-------------------------------------------------------------------------------------|--------------------------------------------------------|-------------------------------|
Expand All @@ -54,4 +54,16 @@ Running the Virtual Schema requires a Java Runtime version 9 or later.
| [JSONassert](http://jsonassert.skyscreamer.org/) | Compare JSON documents for semantic equality | Apache License 2.0 |
| [JUnit](https://junit.org/junit5) | Unit testing framework | Eclipse Public License 1.0 |
| [Mockito](http://site.mockito.org/) | Mocking framework | MIT License |
| [SnakeYaml](https://bitbucket.org/asomov/snakeyaml/src/default/) | YAML parsing | Apache License 2.0 |
| [SnakeYaml](https://bitbucket.org/asomov/snakeyaml/src/default/) | YAML parsing | Apache License 2.0 |

### Maven Plug-ins

| Plug-in | Purpose | License |
|-------------------------------------------------------------------------------------|--------------------------------------------------------|-------------------------------|
| [Maven Compiler Plugin](https://maven.apache.org/plugins/maven-compiler-plugin/) | Setting required Java version | Apache License 2.0 |
| [Maven GPG Plugin](https://maven.apache.org/plugins/maven-gpg-plugin/) | Code signing | Apache License 2.0 |
| [Maven Javadoc Plugin](https://maven.apache.org/plugins/maven-javadoc-plugin/) | Creating a Javadoc JAR | Apache License 2.0 |
| [Maven Jacoco Plugin](https://www.eclemma.org/jacoco/trunk/doc/maven.html) | Code coverage metering | Eclipse Public License 2.0 |
| [Maven JAR Plugin](https://maven.apache.org/plugins/maven-jar-plugin) | Creating an additional JAR with test classes | Apache License 2.0 |
| [Maven Source Plugin](https://maven.apache.org/plugins/maven-source-plugin/) | Creating a source code JAR | Apache License 2.0 |
| [Maven Surefire Plugin](https://maven.apache.org/surefire/maven-surefire-plugin/) | Unit testing | Apache License 2.0 |
27 changes: 20 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<version>${product.version}</version>
<name>Virtual Schema Common JDBC</name>
<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.0</product.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -39,14 +40,14 @@
<url>https://github.com/exasol/virtual-schema-common-jdbc/tree/master</url>
</scm>
<distributionManagement>
<repository>
<id>maven.exasol.com</id>
<url>https://maven.exasol.com/artifactory/exasol-releases</url>
</repository>
<snapshotRepository>
<id>maven.exasol.com</id>
<url>https://maven.exasol.com/artifactory/exasol-snapshots</url>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<repositories>
<repository>
Expand Down Expand Up @@ -145,7 +146,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.3</version>
<version>0.8.5</version>
<executions>
<execution>
<goals>
Expand Down Expand Up @@ -217,6 +218,18 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,11 @@ public interface SqlDialectFactory {
* @return SQL dialect name
*/
public String getSqlDialectName();

/**
* Get the version of the SQL dialect.
*
* @return SQL dialect version
*/
public String getSqlDialectVersion();
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public SqlDialect getDialectForName(final String name, final Connection connecti
final AdapterProperties properties) {
if (hasDialectWithName(name)) {
final SqlDialectFactory factory = this.registeredFactories.get(name);
LOGGER.config(() -> "Loading SQL dialect: " + factory.getSqlDialectName());
LOGGER.config(() -> "Loading SQL dialect: " + factory.getSqlDialectName() + " dialect adapter "
+ factory.getSqlDialectVersion());
return factory.createSqlDialect(connection, properties);
} else {
throw new IllegalArgumentException("Unknown SQL dialect \"" + name + "\" requested. " + describe());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,7 @@

import com.exasol.adapter.AdapterException;
import com.exasol.adapter.metadata.DataType;
import com.exasol.adapter.sql.AggregateFunction;
import com.exasol.adapter.sql.ScalarFunction;
import com.exasol.adapter.sql.SqlColumn;
import com.exasol.adapter.sql.SqlConstants;
import com.exasol.adapter.sql.SqlFunctionAggregate;
import com.exasol.adapter.sql.SqlFunctionAggregateGroupConcat;
import com.exasol.adapter.sql.SqlFunctionScalar;
import com.exasol.adapter.sql.SqlFunctionScalarCase;
import com.exasol.adapter.sql.SqlFunctionScalarCast;
import com.exasol.adapter.sql.SqlFunctionScalarExtract;
import com.exasol.adapter.sql.SqlGroupBy;
import com.exasol.adapter.sql.SqlJoin;
import com.exasol.adapter.sql.SqlLimit;
import com.exasol.adapter.sql.SqlLiteralBool;
import com.exasol.adapter.sql.SqlLiteralDate;
import com.exasol.adapter.sql.SqlLiteralDouble;
import com.exasol.adapter.sql.SqlLiteralExactnumeric;
import com.exasol.adapter.sql.SqlLiteralInterval;
import com.exasol.adapter.sql.SqlLiteralNull;
import com.exasol.adapter.sql.SqlLiteralString;
import com.exasol.adapter.sql.SqlLiteralTimestamp;
import com.exasol.adapter.sql.SqlLiteralTimestampUtc;
import com.exasol.adapter.sql.SqlNode;
import com.exasol.adapter.sql.SqlNodeType;
import com.exasol.adapter.sql.SqlNodeVisitor;
import com.exasol.adapter.sql.SqlOrderBy;
import com.exasol.adapter.sql.SqlPredicateAnd;
import com.exasol.adapter.sql.SqlPredicateBetween;
import com.exasol.adapter.sql.SqlPredicateEqual;
import com.exasol.adapter.sql.SqlPredicateInConstList;
import com.exasol.adapter.sql.SqlPredicateIsNotNull;
import com.exasol.adapter.sql.SqlPredicateIsNull;
import com.exasol.adapter.sql.SqlPredicateLess;
import com.exasol.adapter.sql.SqlPredicateLessEqual;
import com.exasol.adapter.sql.SqlPredicateLike;
import com.exasol.adapter.sql.SqlPredicateLikeRegexp;
import com.exasol.adapter.sql.SqlPredicateNot;
import com.exasol.adapter.sql.SqlPredicateNotEqual;
import com.exasol.adapter.sql.SqlPredicateOr;
import com.exasol.adapter.sql.SqlSelectList;
import com.exasol.adapter.sql.SqlStatementSelect;
import com.exasol.adapter.sql.SqlTable;
import com.exasol.adapter.sql.*;

/**
* This class has the logic to generate SQL queries based on a graph of {@link SqlNode} elements. It uses the visitor
Expand Down Expand Up @@ -173,8 +132,9 @@ protected String representAnyColumnInSelectList() {
*
* @param selectList list of columns (or expressions) in the <code>SELECT</code> part
* @return always <code>"true"</code>
* @throws AdapterException in case select list cannot be resolved.
*/
protected String representAsteriskInSelectList(final SqlSelectList selectList) {
protected String representAsteriskInSelectList(final SqlSelectList selectList) throws AdapterException {
return SqlConstants.ASTERISK;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

import static com.exasol.adapter.jdbc.RemoteMetadataReaderConstants.ANY_TABLE;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.sql.*;
import java.util.*;
import java.util.logging.Logger;

import com.exasol.adapter.AdapterProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ public DataType mapJdbcType(final JdbcTypeDescription jdbcTypeDescription) {
case Types.NVARCHAR:
case Types.LONGVARCHAR:
case Types.LONGNVARCHAR:
return convertVarChar(jdbcTypeDescription.getPrecisionOrSize(), jdbcTypeDescription.getCharOctetLength());
return convertVarChar(jdbcTypeDescription.getPrecisionOrSize(), jdbcTypeDescription.getByteSize());
case Types.CHAR:
case Types.NCHAR:
return convertChar(jdbcTypeDescription.getPrecisionOrSize(), jdbcTypeDescription.getCharOctetLength());
return convertChar(jdbcTypeDescription.getPrecisionOrSize(), jdbcTypeDescription.getByteSize());
case Types.DATE:
return DataType.createDate();
case Types.TIMESTAMP:
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/exasol/adapter/jdbc/JdbcAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ private SchemaMetadata readMetadata(final AdapterProperties properties, final Ex
}
}

protected SchemaMetadata readMetadata(final AdapterProperties properties, final List<String> whiteListedRemoteTables,
final ExaMetadata exasolMetadata) throws SQLException, PropertyValidationException {
protected SchemaMetadata readMetadata(final AdapterProperties properties,
final List<String> whiteListedRemoteTables, final ExaMetadata exasolMetadata)
throws SQLException, PropertyValidationException {
try (final Connection connection = this.connectionFactory.createConnection(exasolMetadata, properties)) {
final SqlDialect dialect = createDialect(connection, properties);
dialect.validateProperties();
Expand Down Expand Up @@ -154,7 +155,7 @@ private Map<String, String> mergeProperties(final Map<String, String> previousRa

private List<String> getTableFilter(final Map<String, String> properties) {
final String tableNames = properties.get(TABLES_PROPERTY);
if (tableNames != null && !tableNames.isEmpty()) {
if ((tableNames != null) && !tableNames.isEmpty()) {
final List<String> tables = Arrays.asList(tableNames.split(","));
for (int i = 0; i < tables.size(); ++i) {
tables.set(i, tables.get(i).trim());
Expand Down Expand Up @@ -237,4 +238,4 @@ public PushDownResponse pushdown(final ExaMetadata exaMetadata, final PushDownRe
exception);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public VirtualSchemaAdapter createAdapter() {
@Override
public String getAdapterVersion() {
final VersionCollector versionCollector = new VersionCollector(
"META-INF/maven/com.exasol/virtualschema-jdbc-adapter/pom.properties");
"META-INF/maven/com.exasol/virtual-schema-common-jdbc/pom.properties");
return versionCollector.getVersionNumber();
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/exasol/adapter/jdbc/JdbcTypeDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class JdbcTypeDescription {
private final int jdbcType;
private final int decimalScale;
private final int precisionOrSize;
private final int charOctetLength;
private final int byteSize;
private final String typeName;

/**
Expand All @@ -21,15 +21,15 @@ public class JdbcTypeDescription {
* @param jdbcType type identifier as presented by the JDBC driver of the database
* @param decimalScale number of digits behind the point
* @param precisionOrSize precision for numbers or size for size types (like <code>VARCHAR</code>)
* @param charOctetLength storage size the data type needs in bytes
* @param byteSize storage size the data type needs in bytes
* @param typeName original name the type has in the database
*/
public JdbcTypeDescription(final int jdbcType, final int decimalScale, final int precisionOrSize,
final int charOctetLength, final String typeName) {
final int byteSize, final String typeName) {
this.jdbcType = jdbcType;
this.decimalScale = decimalScale;
this.precisionOrSize = precisionOrSize;
this.charOctetLength = charOctetLength;
this.byteSize = byteSize;
this.typeName = typeName;
}

Expand Down Expand Up @@ -65,8 +65,8 @@ public int getPrecisionOrSize() {
*
* @return size in bytes
*/
public int getCharOctetLength() {
return this.charOctetLength;
public int getByteSize() {
return this.byteSize;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.jupiter.api.Assertions.assertAll;

import nl.jqno.equalsverifier.EqualsVerifier;
import org.junit.jupiter.api.Test;

import nl.jqno.equalsverifier.EqualsVerifier;

class SchemaAdapterNotesTest {
private static final String CATALOG_SEPARATOR = ".";
private static final String IDENTIFIER_QUOTE_STRING = "\"";
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,8 @@
import com.exasol.adapter.AdapterException;
import com.exasol.adapter.AdapterProperties;
import com.exasol.adapter.dialects.derby.DerbySqlDialect;
import com.exasol.adapter.metadata.ColumnMetadata;
import com.exasol.adapter.metadata.DataType;
import com.exasol.adapter.metadata.TableMetadata;
import com.exasol.adapter.sql.SqlColumn;
import com.exasol.adapter.sql.SqlNode;
import com.exasol.adapter.sql.SqlNodeVisitor;
import com.exasol.adapter.sql.SqlPredicateNot;
import com.exasol.adapter.sql.SqlSelectList;
import com.exasol.adapter.sql.SqlStatementSelect;
import com.exasol.adapter.sql.SqlTable;
import com.exasol.adapter.metadata.*;
import com.exasol.adapter.sql.*;
import com.exasol.sql.SqlNormalizer;

class CustomSqlGenerationVisitorTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.exasol.adapter.dialects;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.sameInstance;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

Expand Down
Loading

0 comments on commit 9df8f2b

Please sign in to comment.