-
Notifications
You must be signed in to change notification settings - Fork 1
#134 MySql table charset #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ba2d7b3
#138: Upgrade dependencies
kaklakariada e18d0a3
Fix compiler warnings, upgrade databases
kaklakariada 80c99af
Update gitattributes
kaklakariada 956d262
Fix compile errors
kaklakariada 04013c4
Run PK fix
kaklakariada 728c368
#137: Use batch insert
kaklakariada e3cc5e5
Merge remote-tracking branch 'origin/main' into feature/#137-use-batc…
kaklakariada 2f4ab44
Increment minor version
kaklakariada c565bf9
#134: Allowed specifying charset for MySQL tables
kaklakariada 664df7e
Merge remote-tracking branch 'origin/main' into feature/#134-mysql-ta…
kaklakariada 277c5bd
Add missing javadoc
kaklakariada 61e2aa2
Apply suggestions from code review
kaklakariada 1d18674
Implement review finding
kaklakariada File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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")); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.