-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#43: implemented create schema logic
- Loading branch information
1 parent
97e135b
commit 456ed9b
Showing
17 changed files
with
276 additions
and
22 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.exasol.sql.ddl; | ||
|
||
import com.exasol.sql.AbstractFragment; | ||
import com.exasol.sql.Fragment; | ||
import com.exasol.sql.ddl.create.CreateSchemaVisitor; | ||
|
||
/** | ||
* This class represents a {@link Schema} in an SQL Statement | ||
*/ | ||
public class Schema extends AbstractFragment { | ||
private String name; | ||
|
||
/** | ||
* Create a new {@link Schema} | ||
* | ||
* @param root SQL statement this schema belongs to | ||
* @param schemaName schema name | ||
*/ | ||
public Schema(Fragment root, String schemaName) { | ||
super(root); | ||
this.name = schemaName; | ||
} | ||
|
||
/** | ||
* Get a schema name | ||
* | ||
* @return schema name | ||
*/ | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void accept(CreateSchemaVisitor visitor) { | ||
visitor.visit(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.exasol.sql.ddl.create; | ||
|
||
import com.exasol.sql.AbstractFragment; | ||
import com.exasol.sql.SqlStatement; | ||
import com.exasol.sql.ddl.Schema; | ||
|
||
/** | ||
* This class implements an SQL {@link CreateSchema} statement | ||
*/ | ||
public class CreateSchema extends AbstractFragment implements SqlStatement, CreateSchemaFragment { | ||
private Schema schema; | ||
|
||
/** | ||
* Create a new instance of an {@link CreateSchema} statement | ||
* | ||
* @param schemaName name of the table to create | ||
*/ | ||
public CreateSchema(final String schemaName) { | ||
super(null); | ||
this.schema = new Schema(this, schemaName); | ||
} | ||
|
||
/** | ||
* Get a schema name | ||
* | ||
* @return schema name | ||
*/ | ||
public String getSchemaName() { | ||
return schema.getName(); | ||
} | ||
|
||
@Override | ||
public void accept(CreateSchemaVisitor visitor) { | ||
visitor.visit(this); | ||
this.schema.accept(visitor); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/exasol/sql/ddl/create/CreateSchemaFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.exasol.sql.ddl.create; | ||
|
||
import com.exasol.sql.Fragment; | ||
|
||
/** | ||
* This is the common interface for all fragments of a CREATE SCHEMA statement. | ||
*/ | ||
public interface CreateSchemaFragment extends Fragment { | ||
/** | ||
* Accept a visitor (e.g. a renderer or validator) | ||
* | ||
* @param visitor visitor to accept | ||
*/ | ||
public void accept(CreateSchemaVisitor visitor); | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/exasol/sql/ddl/create/CreateSchemaVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.exasol.sql.ddl.create; | ||
|
||
import com.exasol.sql.ddl.Schema; | ||
|
||
public interface CreateSchemaVisitor { | ||
public void visit(CreateSchema createSchema); | ||
|
||
public void visit(Schema schema); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/com/exasol/sql/ddl/create/rendering/CreateSchemaRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.exasol.sql.ddl.create.rendering; | ||
|
||
import com.exasol.sql.ddl.Schema; | ||
import com.exasol.sql.ddl.create.CreateSchema; | ||
import com.exasol.sql.ddl.create.CreateSchemaVisitor; | ||
import com.exasol.sql.rendering.AbstractFragmentRenderer; | ||
import com.exasol.sql.rendering.StringRendererConfig; | ||
|
||
/** | ||
* The {@link CreateSchemaRenderer} turns SQL statement structures in to SQL strings. | ||
*/ | ||
public class CreateSchemaRenderer extends AbstractFragmentRenderer implements CreateSchemaVisitor { | ||
/** | ||
* Create a new {@link CreateSchemaRenderer} with custom render settings. | ||
* | ||
* @param config render configuration settings | ||
*/ | ||
public CreateSchemaRenderer(final StringRendererConfig config) { | ||
super(config); | ||
} | ||
|
||
/** | ||
* Create an {@link CreateSchemaRenderer} using the default renderer configuration | ||
* | ||
* @return insert renderer | ||
*/ | ||
public static CreateSchemaRenderer create() { | ||
return new CreateSchemaRenderer(StringRendererConfig.createDefault()); | ||
} | ||
|
||
/** | ||
* Create an {@link CreateSchemaRenderer} | ||
* | ||
* @param config renderer configuration | ||
* @return create schema renderer | ||
*/ | ||
public static CreateSchemaRenderer create(final StringRendererConfig config) { | ||
return new CreateSchemaRenderer(config); | ||
} | ||
|
||
@Override | ||
public void visit(CreateSchema createSchema) { | ||
appendKeyWord("CREATE SCHEMA "); | ||
setLastVisited(createSchema); | ||
} | ||
|
||
@Override | ||
public void visit(Schema schema) { | ||
appendAutoQuoted(schema.getName()); | ||
setLastVisited(schema); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/test/java/com/exasol/sql/ddl/create/TestCreateSchema.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.exasol.sql.ddl.create; | ||
|
||
import com.exasol.sql.StatementFactory; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
class TestCreateSchema { | ||
private static final String TEST_SCHEMA_NAME = "test schema name"; | ||
private CreateSchema createSchema; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
createSchema = StatementFactory.getInstance().createSchema(TEST_SCHEMA_NAME); | ||
} | ||
|
||
@Test | ||
void getTableName() { | ||
assertThat(this.createSchema.getSchemaName(), equalTo(TEST_SCHEMA_NAME)); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/test/java/com/exasol/sql/ddl/create/rendering/TestCreateSchemaRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.exasol.sql.ddl.create.rendering; | ||
|
||
import com.exasol.sql.StatementFactory; | ||
import com.exasol.sql.ddl.create.CreateSchema; | ||
import com.exasol.sql.rendering.StringRendererConfig; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.instanceOf; | ||
import static org.hamcrest.Matchers.startsWith; | ||
|
||
class TestCreateSchemaRenderer { | ||
@Test | ||
void testCreateWithDefaultConfig() { | ||
assertThat(CreateSchemaRenderer.create(), instanceOf(CreateSchemaRenderer.class)); | ||
} | ||
|
||
@Test | ||
void testCreateWithConfig() { | ||
final StringRendererConfig config = StringRendererConfig.builder().lowerCase(true).build(); | ||
final CreateSchemaRenderer renderer = CreateSchemaRenderer.create(config); | ||
final CreateSchema createSchema = StatementFactory.getInstance().createSchema("test name"); | ||
createSchema.accept(renderer); | ||
assertThat(renderer.render(), startsWith("create schema")); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/test/java/com/exasol/sql/ddl/create/rendering/TestCreateSchemaRendering.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.exasol.sql.ddl.create.rendering; | ||
|
||
import com.exasol.sql.StatementFactory; | ||
import com.exasol.sql.ddl.create.CreateSchema; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static com.exasol.hamcrest.SqlFragmentRenderResultMatcher.rendersTo; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
class TestCreateSchemaRendering { | ||
private static final String SCHEMA_NAME = "testName"; | ||
private CreateSchema createSchema; | ||
|
||
@BeforeEach | ||
void beforeEach() { | ||
this.createSchema = StatementFactory.getInstance().createSchema(SCHEMA_NAME); | ||
} | ||
|
||
|
||
@Test | ||
void testCreateSchema() { | ||
assertThat(this.createSchema, rendersTo("CREATE SCHEMA testName")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.