-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Sebastian Bär <[email protected]>
- Loading branch information
1 parent
6985f32
commit 53de628
Showing
10 changed files
with
251 additions
and
29 deletions.
There are no files selected for viewing
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
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
87 changes: 87 additions & 0 deletions
87
src/main/java/com/exasol/dbbuilder/dialects/mysql/MySqlTable.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,87 @@ | ||
package com.exasol.dbbuilder.dialects.mysql; | ||
|
||
import com.exasol.db.Identifier; | ||
import com.exasol.dbbuilder.dialects.*; | ||
|
||
/** | ||
* A MySql table that allows specifying a character set. | ||
*/ | ||
public class MySqlTable extends Table { | ||
private final String charset; | ||
|
||
/** | ||
* Create a new MySql table based on a given builder. | ||
* | ||
* @param builder builder from which to copy the values | ||
*/ | ||
protected MySqlTable(final Builder builder) { | ||
super(builder); | ||
this.charset = builder.charset; | ||
} | ||
|
||
/** | ||
* Get the table's character set. | ||
* | ||
* @return charset or {@code null} for the default charset | ||
*/ | ||
public String getCharset() { | ||
return charset; | ||
} | ||
|
||
/** | ||
* Create a builder for a {@link MySqlTable}. | ||
* | ||
* @param writer database object writer | ||
* @param parentSchema parent schema | ||
* @param tableName name of the database table | ||
* @return new {@link Builder} instance | ||
*/ | ||
public static Builder builder(final DatabaseObjectWriter writer, final Schema parentSchema, | ||
final Identifier tableName) { | ||
return new Builder(writer, parentSchema, tableName); | ||
} | ||
|
||
/** | ||
* Builder for {@link MySqlTable}s. | ||
*/ | ||
public static class Builder extends Table.Builder { | ||
private String charset; | ||
|
||
private Builder(final DatabaseObjectWriter writer, final Schema parentSchema, final Identifier tableName) { | ||
super(writer, parentSchema, tableName); | ||
} | ||
|
||
@Override | ||
// Overriding this so that returned builder has the right type and users don't need to cast. | ||
public Builder column(final String columnName, final String columnType) { | ||
return (Builder) super.column(columnName, columnType); | ||
} | ||
|
||
/** | ||
* Set a custom character set for the new table. Defaults to UTF-8. | ||
* <p> | ||
* This character set is then used for the whole table down to the columns. Additionally the standard collation | ||
* rules for this dataset are applied. | ||
* </p> | ||
* | ||
* @param charset custom charset, e.g. {@code ascii} | ||
* @return {@code this} for fluent programming | ||
*/ | ||
public Builder charset(final String charset) { | ||
this.charset = charset; | ||
return this; | ||
} | ||
|
||
/** | ||
* Build a new {@link MySqlTable} instance. | ||
* | ||
* @return new {@link MySqlTable} instance | ||
*/ | ||
@Override | ||
public MySqlTable build() { | ||
final MySqlTable table = new MySqlTable(this); | ||
this.writer.write(table); | ||
return table; | ||
} | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
src/test/java/com/exasol/dbbuilder/dialects/mysql/MySqlTableTest.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,33 @@ | ||
package com.exasol.dbbuilder.dialects.mysql; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import com.exasol.dbbuilder.dialects.DatabaseObjectWriter; | ||
import com.exasol.dbbuilder.dialects.Schema; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class MySqlTableTest { | ||
@Mock | ||
DatabaseObjectWriter writerMock; | ||
@Mock | ||
Schema schemaMock; | ||
|
||
@Test | ||
void createWithoutCharset() { | ||
final MySqlTable table = MySqlTable.builder(writerMock, schemaMock, MySQLIdentifier.of("tableName")).build(); | ||
assertThat(table.getCharset(), is(nullValue())); | ||
} | ||
|
||
@Test | ||
void createWithCharset() { | ||
final MySqlTable table = MySqlTable.builder(writerMock, schemaMock, MySQLIdentifier.of("tableName")) | ||
.charset("myCharset").build(); | ||
assertThat(table.getCharset(), equalTo("myCharset")); | ||
} | ||
} |