Skip to content

Commit

Permalink
Feature/38 builder for capabilities (#39)
Browse files Browse the repository at this point in the history
* #38: Builder for Capabilities
* #38: Updated launch configurations
* #38: Removed superfluous JUnit4 dependency
  • Loading branch information
AnastasiiaSergienko authored Mar 6, 2019
1 parent d9258fb commit b0e184a
Show file tree
Hide file tree
Showing 10 changed files with 367 additions and 120 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Please note that the artifact name changed from "virtualschema-common" to "virtu
| Dependency | Purpose | License |
|------------------------------------------------------------------------------|--------------------------------------------------------|-------------------------------|
| [JSON-P](https://javaee.github.io/jsonp/) | JSON Processing | CDDL-1.0 |
| [Exasol Script API](https://www.exasol.com/portal/display/DOC/User+Manual+6.1.0 (Sections 3.6, 3.7)) |Accessing objects | MIT License |
| [Exasol Script API](https://www.exasol.com/portal/display/DOC/User+Manual+6.1.0 (Sections 3.6, 3.7)) | Accessing Exasol features | MIT License |
| [Google Guava](https://github.com/google/guava/) | Open-source set of common libraries for Java | Apache License 2.0 |

### Build Time Dependencies
Expand Down
24 changes: 24 additions & 0 deletions launch/virtual-schema-common all tests.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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-java"/>
</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.eclemma.ui.launchGroup.coverage"/>
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=virtual-schema-common-java"/>
<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_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-java"/>
<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"/>
</launchConfiguration>
3 changes: 3 additions & 0 deletions launch/virtual-schema-common clean.launch
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
<booleanAttribute key="M2_UPDATE_SNAPSHOTS" value="false"/>
<stringAttribute key="M2_USER_SETTINGS" value=""/>
<booleanAttribute key="M2_WORKSPACE_RESOLUTION" value="false"/>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:/virtual-schema-common-java}"/>
</launchConfiguration>
3 changes: 3 additions & 0 deletions launch/virtual-schema-common install.launch
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
<booleanAttribute key="M2_UPDATE_SNAPSHOTS" value="false"/>
<stringAttribute key="M2_USER_SETTINGS" value=""/>
<booleanAttribute key="M2_WORKSPACE_RESOLUTION" value="false"/>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:/virtual-schema-common-java}"/>
</launchConfiguration>
3 changes: 3 additions & 0 deletions launch/virtual-schema-common package.launch
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
<booleanAttribute key="M2_UPDATE_SNAPSHOTS" value="false"/>
<stringAttribute key="M2_USER_SETTINGS" value=""/>
<booleanAttribute key="M2_WORKSPACE_RESOLUTION" value="false"/>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:/virtual-schema-common-java}"/>
</launchConfiguration>
33 changes: 12 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.exasol</groupId>
<artifactId>virtual-schema-common-java</artifactId>
<version>1.1.1</version>
<version>2.0.0</version>
<name>Common module of Exasol Virtual Schemas Adapters</name>
<description>This is one of the modules of Virtual Schemas Adapters. The libraries provided by this project are the foundation of the adapter development, i.e. adapters must be implemented on top of them.</description>
<url>https://github.com/exasol/virtual-schema-common-java</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<junit.version>5.4.0</junit.version>
<junit.platform.version>1.3.2</junit.platform.version>
<maven.surefire.version>3.0.0-M3</maven.surefire.version>
<gpg.skip>true</gpg.skip>
</properties>
<licenses>
Expand Down Expand Up @@ -75,17 +78,6 @@
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.24.0</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-junit</artifactId>
Expand All @@ -101,20 +93,19 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.2</version>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.3.2</version>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.3.2</version>
<scope>test</scope>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.24.0</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Expand Down Expand Up @@ -156,7 +147,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<version>${maven.surefire.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -207,4 +198,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
202 changes: 137 additions & 65 deletions src/main/java/com/exasol/adapter/capabilities/Capabilities.java
Original file line number Diff line number Diff line change
@@ -1,91 +1,163 @@
package com.exasol.adapter.capabilities;

import java.util.HashSet;
import java.util.EnumSet;
import java.util.Set;

/**
* Manages a set of supported Capabilities
* Manages a set of supported capabilities
*/
public class Capabilities {
private final Set<MainCapability> mainCapabilities = new HashSet<>();
private final Set<ScalarFunctionCapability> scalarFunctionCaps = new HashSet<>();
private final Set<PredicateCapability> predicateCaps = new HashSet<>();
private final Set<AggregateFunctionCapability> aggregateFunctionCaps = new HashSet<>();
private final Set<LiteralCapability> literalCaps = new HashSet<>();

public void supportAllCapabilities() {
for (final MainCapability cap : MainCapability.values()) {
supportMainCapability(cap);
}
for (final ScalarFunctionCapability function : ScalarFunctionCapability.values()) {
supportScalarFunction(function);
}
for (final PredicateCapability pred : PredicateCapability.values()) {
supportPredicate(pred);
}
for (final AggregateFunctionCapability function : AggregateFunctionCapability.values()) {
supportAggregateFunction(function);
}
for (final LiteralCapability cap : LiteralCapability.values()) {
supportLiteral(cap);
}
}
private final Set<MainCapability> mainCapabilities;
private final Set<LiteralCapability> literalCapabilities;
private final Set<PredicateCapability> predicateCapabilities;
private final Set<ScalarFunctionCapability> scalarFunctionCapabilities;
private final Set<AggregateFunctionCapability> aggregateFunctionCapabilities;

public void subtractCapabilities(final Capabilities capabilitiesToSubtract) {
for (final MainCapability cap : capabilitiesToSubtract.mainCapabilities) {
mainCapabilities.remove(cap);
}
for (final ScalarFunctionCapability cap : capabilitiesToSubtract.getScalarFunctionCapabilities()) {
scalarFunctionCaps.remove(cap);
}
for (final PredicateCapability cap : capabilitiesToSubtract.getPredicateCapabilities()) {
predicateCaps.remove(cap);
}
for (final AggregateFunctionCapability cap : capabilitiesToSubtract.getAggregateFunctionCapabilities()) {
aggregateFunctionCaps.remove(cap);
}
for (final LiteralCapability cap : capabilitiesToSubtract.getLiteralCapabilities()) {
literalCaps.remove(cap);
}
private Capabilities(final Builder builder) {
this.mainCapabilities = EnumSet.copyOf(builder.mainCapabilities);
this.literalCapabilities = EnumSet.copyOf(builder.literalCapabilities);
this.predicateCapabilities = EnumSet.copyOf(builder.predicateCapabilities);
this.scalarFunctionCapabilities = EnumSet.copyOf(builder.scalarFunctionCapabilities);
this.aggregateFunctionCapabilities = EnumSet.copyOf(builder.aggregateFunctionCapabilities);
}

public void supportMainCapability(final MainCapability cap) {
mainCapabilities.add(cap);
/**
* Get the Virtual Schema's adapters main capabilities
*
* @return main capabilities
*/
public Set<MainCapability> getMainCapabilities() {
return this.mainCapabilities;
}

public void supportScalarFunction(final ScalarFunctionCapability functionType) {
scalarFunctionCaps.add(functionType);
/**
* Get the Virtual Schema's adapters literal capabilities
*
* @return scalar literal capabilities
*/
public Set<LiteralCapability> getLiteralCapabilities() {
return this.literalCapabilities;
}

public void supportPredicate(final PredicateCapability predicate) {
predicateCaps.add(predicate);
/**
* Get the Virtual Schema's adapters predicate capabilities
*
* @return predicate capabilities
*/
public Set<PredicateCapability> getPredicateCapabilities() {
return this.predicateCapabilities;
}

public void supportAggregateFunction(final AggregateFunctionCapability functionType) {
aggregateFunctionCaps.add(functionType);
/**
* Get the Virtual Schema's adapters scalar function capabilities
*
* @return scalar function capabilities
*/
public Set<ScalarFunctionCapability> getScalarFunctionCapabilities() {
return this.scalarFunctionCapabilities;
}

public void supportLiteral(final LiteralCapability literal) {
literalCaps.add(literal);
/**
* Get the Virtual Schema's adapters aggregate function capabilities
*
* @return aggregate function capabilities
*/
public Set<AggregateFunctionCapability> getAggregateFunctionCapabilities() {
return this.aggregateFunctionCapabilities;
}

public Set<MainCapability> getMainCapabilities() {
return mainCapabilities;
/**
* Get a {@link Capabilities} builder
*
* @return builder instance
*/
public static Builder builder() {
return new Builder();
}

public Set<ScalarFunctionCapability> getScalarFunctionCapabilities() {
return scalarFunctionCaps;
}
/**
* Builder for {@link Capabilities}
*/
public static final class Builder {
final Set<MainCapability> mainCapabilities = EnumSet.noneOf(MainCapability.class);
final Set<LiteralCapability> literalCapabilities = EnumSet.noneOf(LiteralCapability.class);
final Set<PredicateCapability> predicateCapabilities = EnumSet.noneOf(PredicateCapability.class);
final Set<ScalarFunctionCapability> scalarFunctionCapabilities = EnumSet.noneOf(ScalarFunctionCapability.class);
final Set<AggregateFunctionCapability> aggregateFunctionCapabilities = EnumSet
.noneOf(AggregateFunctionCapability.class);

public Set<PredicateCapability> getPredicateCapabilities() {
return predicateCaps;
}
/**
* Create new capability instance
*
* @return new capability instance
*/
public Capabilities build() {
return new Capabilities(this);
}

public Set<AggregateFunctionCapability> getAggregateFunctionCapabilities() {
return aggregateFunctionCaps;
}
/**
* Add one or more main capabilities
*
* @param capabilities capabilities to be added
* @return builder instance for fluent programming
*/
public Builder addMain(final MainCapability... capabilities) {
for (final MainCapability capability : capabilities) {
this.mainCapabilities.add(capability);
}
return this;
}

public Set<LiteralCapability> getLiteralCapabilities() {
return literalCaps;
/**
* Add one or more literal capabilities
*
* @param capabilities capabilities to be added
* @return builder instance for fluent programming
*/
public Builder addLiteral(final LiteralCapability... capabilities) {
for (final LiteralCapability capability : capabilities) {
this.literalCapabilities.add(capability);
}
return this;
}

/**
* Add one or more predicate capabilities
*
* @param capabilities capabilities to be added
* @return builder instance for fluent programming
*/
public Builder addPredicate(final PredicateCapability... capabilities) {
for (final PredicateCapability capability : capabilities) {
this.predicateCapabilities.add(capability);
}
return this;
}

/**
* Add one or more scalar function capabilities
*
* @param capabilities capabilities to be added
* @return builder instance for fluent programming
*/
public Builder addScalarFunction(final ScalarFunctionCapability... capabilities) {
for (final ScalarFunctionCapability capability : capabilities) {
this.scalarFunctionCapabilities.add(capability);
}
return this;
}

/**
* Add one or more aggregate function capabilities
*
* @param capabilities capabilities to be added
* @return builder instance for fluent programming
*/
public Builder addAggregateFunction(final AggregateFunctionCapability... capabilities) {
for (final AggregateFunctionCapability capability : capabilities) {
this.aggregateFunctionCapabilities.add(capability);
}
return this;
}
}
}
}
Loading

0 comments on commit b0e184a

Please sign in to comment.