Skip to content

Commit

Permalink
[jOOQ#5561] Log warnings when users misconfigure forceType / customTy…
Browse files Browse the repository at this point in the history
…pe elements
  • Loading branch information
lukaseder committed Sep 22, 2016
1 parent 666b8cb commit ee07ae3
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions jOOQ-meta/src/main/java/org/jooq/util/AbstractDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -893,23 +893,33 @@ public final CustomType getConfiguredCustomType(String typeName) {

if (StringUtils.isBlank(type.getName())) {
if (StringUtils.isBlank(type.getUserType())) {
StringWriter writer = new StringWriter();
JAXB.marshal(type, writer);
log.warn("Bad configuration for <forcedType/>. Either <name/> or <userType/> is required: " + writer.toString());
log.warn("Bad configuration for <forcedType/>. Either <name/> or <userType/> is required: " + toString(type));

it2.remove();
continue;
}

if (StringUtils.isBlank(type.getBinding()) && StringUtils.isBlank(type.getConverter())) {
StringWriter writer = new StringWriter();
JAXB.marshal(type, writer);
log.warn("Bad configuration for <forcedType/>. Either <binding/> or <converter/> is required: " + writer);
log.warn("Bad configuration for <forcedType/>. Either <binding/> or <converter/> is required: " + toString(type));

it2.remove();
continue;
}
}
else {
if (!StringUtils.isBlank(type.getUserType())) {
log.warn("Bad configuration for <forcedType/>. <userType/> is not allowed when <name/> is provided: " + toString(type));
type.setUserType(null);
}
if (!StringUtils.isBlank(type.getBinding())) {
log.warn("Bad configuration for <forcedType/>. <binding/> is not allowed when <name/> is provided: " + toString(type));
type.setBinding(null);
}
if (!StringUtils.isBlank(type.getConverter())) {
log.warn("Bad configuration for <forcedType/>. <converter/> is not allowed when <name/> is provided: " + toString(type));
type.setConverter(null);
}
}

if (type.getUserType() != null && StringUtils.equals(type.getUserType(), typeName)) {
return customType(this, type);
Expand All @@ -919,6 +929,12 @@ public final CustomType getConfiguredCustomType(String typeName) {
return null;
}

private final String toString(ForcedType type) {
StringWriter writer = new StringWriter();
JAXB.marshal(type, writer);
return writer.toString();
}

@Override
public final void setConfiguredForcedTypes(List<ForcedType> configuredForcedTypes) {
this.configuredForcedTypes = configuredForcedTypes;
Expand Down

0 comments on commit ee07ae3

Please sign in to comment.