Skip to content

Commit

Permalink
Refactor/102_refactor_ColumnsDefinitionRenderer (#120)
Browse files Browse the repository at this point in the history
* #102: Refactor ColumnsDefinitionRenderer to remove the leave() method

* Add tests with empty column list

* Update changelog

* Implement review findings

* Upgrade github-pages-deploy-action
  • Loading branch information
kaklakariada authored Sep 27, 2021
1 parent ab65afe commit f4338fb
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy_javadocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Build Javadocs
run: mvn javadoc:javadoc
- name: Deploy
uses: JamesIves/github-pages-deploy-action@4.1.1
uses: JamesIves/github-pages-deploy-action@4.1.5
with:
branch: gh-pages
folder: target/site/apidocs/
3 changes: 2 additions & 1 deletion doc/changes/changes_4.4.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Code name: Internal refactorings on "More Predicates"

## Refactoring

* [#117](https://github.com/exasol/sql-statement-builder/issues/117): Fixed sonar findings
* #117: Fixed sonar findings
* #102: Refactored ColumnsDefinitionRenderer

## Dependency Updates

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/exasol/sql/ColumnDefinitionVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
public interface ColumnDefinitionVisitor {
public void visit(final ColumnsDefinition columnsDefinition);

public void leave(final ColumnsDefinition columnsDefinition);

public void visit(final Column column);

public void visit(final Char charColumn);
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/com/exasol/sql/ColumnsDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public ColumnsDefinition(final SqlStatement root) {

/**
* Create an new instance of {@link ColumnsDefinition}.
*
*
* @param columns list of columns
*/
public ColumnsDefinition(final List<Column> columns) {
Expand All @@ -33,7 +33,7 @@ public ColumnsDefinition(final List<Column> columns) {

/**
* Create a new builder for {@link ColumnsDefinition}.
*
*
* @return new {@link Builder}
*/
public static Builder builder() {
Expand All @@ -52,7 +52,7 @@ public void add(final String name, final DataType dataType) {

/**
* Get a list of columns.
*
*
* @return list of columns
*/
public List<Column> getColumns() {
Expand All @@ -61,10 +61,6 @@ public List<Column> getColumns() {

public void accept(final ColumnDefinitionVisitor visitor) {
visitor.visit(this);
for (final Column column : this.columns) {
column.accept(visitor);
}
visitor.leave(this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.exasol.sql.rendering;

import java.util.List;

import com.exasol.datatype.type.*;
import com.exasol.datatype.type.Boolean;
import com.exasol.sql.*;
Expand All @@ -19,14 +21,10 @@ public ColumnsDefinitionRenderer(final StringRendererConfig config) {

@Override
public void visit(final ColumnsDefinition columnsDefinition) {
if (!columnsDefinition.getColumns().isEmpty()) {
final List<Column> columns = columnsDefinition.getColumns();
if (!columns.isEmpty()) {
append("(");
}
}

@Override
public void leave(final ColumnsDefinition columnsDefinition) {
if (!columnsDefinition.getColumns().isEmpty()) {
columns.forEach(col -> col.accept(this));
append(")");
}
setLastVisited(columnsDefinition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ void testCreateTableWithInvalidCharSizeColumn() {
assertThrows(IllegalArgumentException.class, () -> this.createTable.charColumn("a", -1));
}

@Test
// Not a requirement, just to see what happens
void testCreateTableWithoutColumn() {
assertThat(this.createTable, rendersTo("CREATE TABLE testName"));
}

@Test
void testCreateTableWithVarcharColumn() {
assertThat(this.createTable.varcharColumn("a", 3000), rendersTo("CREATE TABLE testName (a VARCHAR(3000))"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ void beforeEach() {
this.select = StatementFactory.getInstance().select();
}

@Test
// Not a requirement, just to see what happens
void testSelectWithoutFields() {
assertThat(this.select, rendersTo("SELECT "));
}

// [utest->dsn~rendering.sql.select~1]
@Test
void testSelectAll() {
Expand Down

0 comments on commit f4338fb

Please sign in to comment.