[#6971] Add <onError/> to generator's <configuration/>

Using the new <onError/> (which accepts the values FAIL (default), LOG,
and SILENT) the generator's behavior on an encountered exceptions can be
controlled.
This commit is contained in:
Knut Wannheden 2019-04-10 12:20:17 +02:00
parent 929529ec7a
commit df2ec439bc
5 changed files with 98 additions and 1 deletions

View File

@ -120,6 +120,14 @@ public class Plugin extends AbstractMojo {
)
private org.jooq.meta.jaxb.Logging logging;
/**
* The on-error behavior.
*/
@Parameter(
property = "jooq.codegen.onError"
)
private org.jooq.meta.jaxb.OnError onError;
/**
* The jdbc settings.
*/
@ -180,6 +188,7 @@ public class Plugin extends AbstractMojo {
Configuration configuration = new Configuration();
configuration.setLogging(logging);
configuration.setOnError(onError);
configuration.setJdbc(jdbc);
configuration.setGenerator(generator);
@ -224,6 +233,7 @@ public class Plugin extends AbstractMojo {
in = new FileInputStream(f);
Configuration configuration = GenerationTool.load(in);
logging = MiniJAXB.append(logging, configuration.getLogging());
onError = MiniJAXB.append(onError, configuration.getOnError());
jdbc = MiniJAXB.append(jdbc, configuration.getJdbc());
generator = MiniJAXB.append(generator, configuration.getGenerator());
}

View File

@ -82,6 +82,7 @@ import org.jooq.meta.jaxb.Generate;
import org.jooq.meta.jaxb.Jdbc;
import org.jooq.meta.jaxb.Logging;
import org.jooq.meta.jaxb.Matchers;
import org.jooq.meta.jaxb.OnError;
import org.jooq.meta.jaxb.Property;
import org.jooq.meta.jaxb.SchemaMappingType;
import org.jooq.meta.jaxb.Strategy;
@ -224,8 +225,29 @@ public class GenerationTool {
new GenerationTool().run(configuration);
}
@SuppressWarnings("unchecked")
public void run(Configuration configuration) throws Exception {
try {
run0(configuration);
}
catch (Exception e) {
OnError onError = configuration.getOnError();
if (onError == null) {
onError = OnError.FAIL;
}
switch (onError) {
case SILENT:
break;
case LOG:
log.warn("Code generation failed", e);
break;
case FAIL:
throw e;
}
}
}
@SuppressWarnings("unchecked")
private void run0(Configuration configuration) throws Exception {
if (Boolean.getBoolean("jooq.codegen.skip")) {
log.info("Skipping jOOQ code generation");
return;

View File

@ -239,6 +239,12 @@
</bindings>
<bindings if-exists="true" scd="~tns:OnError">
<typesafeEnumClass ref="org.jooq.meta.jaxb.OnError"/>
</bindings>
<bindings if-exists="true" scd="~tns:MatcherTransformType">
<typesafeEnumClass ref="org.jooq.meta.jaxb.MatcherTransformType"/>

View File

@ -28,6 +28,7 @@ import javax.xml.bind.annotation.XmlType;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;all&gt;
* &lt;element name="logging" type="{http://www.jooq.org/xsd/jooq-codegen-3.12.0.xsd}Logging" minOccurs="0"/&gt;
* &lt;element name="onError" type="{http://www.jooq.org/xsd/jooq-codegen-3.12.0.xsd}OnError" minOccurs="0"/&gt;
* &lt;element name="jdbc" type="{http://www.jooq.org/xsd/jooq-codegen-3.12.0.xsd}Jdbc" minOccurs="0"/&gt;
* &lt;element name="generator" type="{http://www.jooq.org/xsd/jooq-codegen-3.12.0.xsd}Generator"/&gt;
* &lt;/all&gt;
@ -52,6 +53,8 @@ public class Configuration implements Serializable
private final static long serialVersionUID = 31200L;
@XmlSchemaType(name = "string")
protected Logging logging;
@XmlSchemaType(name = "string")
protected OnError onError;
protected Jdbc jdbc;
@XmlElement(required = true)
protected Generator generator;
@ -80,6 +83,30 @@ public class Configuration implements Serializable
this.logging = value;
}
/**
* The action to be taken by the generator as the consequence of an encountered exception.
*
* @return
* possible object is
* {@link OnError }
*
*/
public OnError getOnError() {
return onError;
}
/**
* Sets the value of the onError property.
*
* @param value
* allowed object is
* {@link OnError }
*
*/
public void setOnError(OnError value) {
this.onError = value;
}
/**
* The JDBC configuration element contains information about how to set up the database connection used for source code generation.
*
@ -133,6 +160,11 @@ public class Configuration implements Serializable
return this;
}
public Configuration withOnError(OnError value) {
setOnError(value);
return this;
}
public Configuration withJdbc(Jdbc value) {
setJdbc(value);
return this;
@ -151,6 +183,11 @@ public class Configuration implements Serializable
sb.append(logging);
sb.append("</logging>");
}
if (onError!= null) {
sb.append("<onError>");
sb.append(onError);
sb.append("</onError>");
}
if (jdbc!= null) {
sb.append("<jdbc>");
sb.append(jdbc);
@ -185,6 +222,15 @@ public class Configuration implements Serializable
return false;
}
}
if (onError == null) {
if (other.onError!= null) {
return false;
}
} else {
if (!onError.equals(other.onError)) {
return false;
}
}
if (jdbc == null) {
if (other.jdbc!= null) {
return false;
@ -211,6 +257,7 @@ public class Configuration implements Serializable
final int prime = 31;
int result = 1;
result = ((prime*result)+((logging == null)? 0 :logging.hashCode()));
result = ((prime*result)+((onError == null)? 0 :onError.hashCode()));
result = ((prime*result)+((jdbc == null)? 0 :jdbc.hashCode()));
result = ((prime*result)+((generator == null)? 0 :generator.hashCode()));
return result;

View File

@ -13,6 +13,10 @@
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[The logging configuration element specifies the code generation logging threshold.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="onError" type="tns:OnError" minOccurs="0" maxOccurs="1" default="FAIL">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[The action to be taken by the generator as the consequence of an encountered exception. Defaults to FAIL.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="jdbc" type="tns:Jdbc" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[The JDBC configuration element contains information about how to set up the database connection used for source code generation.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
@ -35,6 +39,14 @@
</restriction>
</simpleType>
<simpleType name="OnError">
<restriction base="string">
<enumeration value="FAIL"/>
<enumeration value="LOG"/>
<enumeration value="SILENT"/>
</restriction>
</simpleType>
<complexType name="Jdbc">
<annotation><appinfo><jxb:class><jxb:javadoc><![CDATA[JDBC connection configuration.]]></jxb:javadoc></jxb:class></appinfo></annotation>
<all>