Skip to content

Commit

Permalink
Merge pull request #15 from oryanmoshe/fix/alonr/add-optional-column-…
Browse files Browse the repository at this point in the history
…check-and-logging

Use a new SchemaBuilder every time in order to avoid changing 'Already set' options
  • Loading branch information
Alonreznik authored May 19, 2021
2 parents ab2ab1b + 10a2847 commit e8dc33e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class TimestampConverter implements CustomConverter<SchemaBuilder, Relati
public String strDatetimeFormat, strDateFormat, strTimeFormat;
public Boolean debug;

private final SchemaBuilder datetimeSchema = SchemaBuilder.string().optional().name("oryanmoshe.time.DateTimeString");
// private final SchemaBuilder datetimeSchema = SchemaBuilder.string().optional().name("oryanmoshe.time.DateTimeString");

private SimpleDateFormat simpleDatetimeFormatter, simpleDateFormatter, simpleTimeFormatter;

Expand Down Expand Up @@ -70,8 +70,15 @@ public void converterFor(RelationalColumn column, ConverterRegistration<SchemaBu
column.name(), column.typeName(), column.hasDefaultValue(), column.defaultValue(), column.isOptional());
if (SUPPORTED_DATA_TYPES.stream().anyMatch(s -> s.equalsIgnoreCase(column.typeName()))) {
boolean isTime = "time".equalsIgnoreCase(column.typeName());
registration.register(datetimeSchema, rawValue -> {
// Use a new SchemaBuilder every time in order to avoid changing "Already set" options
// in the schema builder between tables.
registration.register(SchemaBuilder.string().optional(), rawValue -> {
if (rawValue == null) {
// DEBUG
if (this.debug) {
System.out.printf("[TimestampConverter.converterFor] rawValue of %s is null.%n", column.name());
}

if (column.isOptional()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public String typeName() {

@Override
public String name() {
return null;
return "datecolumn";
}

@Override
Expand Down Expand Up @@ -199,7 +199,7 @@ public String typeName() {

@Override
public String name() {
return null;
return "timecolumn";
}

@Override
Expand Down Expand Up @@ -259,7 +259,7 @@ public String typeName() {

@Override
public String name() {
return null;
return "datetimecolumn";
}

@Override
Expand Down Expand Up @@ -319,7 +319,7 @@ public String typeName() {

@Override
public String name() {
return null;
return "datetime2column";
}

@Override
Expand Down Expand Up @@ -379,7 +379,7 @@ public String typeName() {

@Override
public String name() {
return null;
return "timestampcolumn";
}

@Override
Expand Down

0 comments on commit e8dc33e

Please sign in to comment.