-
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.
#134: Allowed specifying charset for MySQL tables
- Loading branch information
1 parent
2f4ab44
commit c565bf9
Showing
9 changed files
with
214 additions
and
27 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
51 changes: 51 additions & 0 deletions
51
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,51 @@ | ||
package com.exasol.dbbuilder.dialects.mysql; | ||
|
||
import com.exasol.db.Identifier; | ||
import com.exasol.dbbuilder.dialects.*; | ||
|
||
public class MySqlTable extends Table { | ||
|
||
private final String charset; | ||
|
||
protected MySqlTable(final MySqlTableBuilder builder) { | ||
super(builder); | ||
this.charset = builder.charset; | ||
} | ||
|
||
public String getCharset() { | ||
return charset; | ||
} | ||
|
||
public static MySqlTableBuilder builder(final DatabaseObjectWriter writer, final Schema parentSchema, | ||
final Identifier tableName) { | ||
return new MySqlTableBuilder(writer, parentSchema, tableName); | ||
} | ||
|
||
public static class MySqlTableBuilder extends Table.Builder { | ||
|
||
private String charset; | ||
|
||
private MySqlTableBuilder(final DatabaseObjectWriter writer, final Schema parentSchema, | ||
final Identifier tableName) { | ||
super(writer, parentSchema, tableName); | ||
} | ||
|
||
@Override | ||
public MySqlTableBuilder column(final String columnName, final String columnType) { | ||
super.column(columnName, columnType); | ||
return this; | ||
} | ||
|
||
public MySqlTableBuilder charset(final String charset) { | ||
this.charset = charset; | ||
return this; | ||
} | ||
|
||
@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
34 changes: 34 additions & 0 deletions
34
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,34 @@ | ||
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")); | ||
} | ||
} |