[jOOQ/jOOQ#17752] Add jdbc/urlProperty as a way to specify which system property to look up in code generation configuration for the JDBC URL
This commit is contained in:
parent
e496cda754
commit
bf1047305b
@ -336,20 +336,16 @@ public class GenerationTool {
|
||||
setConnection(dataSource.getConnection());
|
||||
}
|
||||
else {
|
||||
String url = System.getProperty("jooq.codegen.jdbc.url");
|
||||
j = defaultIfNull(j, new Jdbc());
|
||||
|
||||
if (url != null) {
|
||||
j = defaultIfNull(j, new Jdbc());
|
||||
|
||||
set(j, propertyOverride, "jooq.codegen.jdbc.driver", Jdbc::getDriver, Jdbc::setDriver);
|
||||
set(j, propertyOverride, "jooq.codegen.jdbc.url", Jdbc::getUrl, Jdbc::setUrl);
|
||||
set(j, propertyOverride, "jooq.codegen.jdbc.user", Jdbc::getUser, Jdbc::setUser);
|
||||
set(j, propertyOverride, "jooq.codegen.jdbc.username", Jdbc::getUsername, Jdbc::setUsername);
|
||||
set(j, propertyOverride, "jooq.codegen.jdbc.password", Jdbc::getPassword, Jdbc::setPassword);
|
||||
set(j, propertyOverride, "jooq.codegen.jdbc.autoCommit", Jdbc::isAutoCommit, Jdbc::setAutoCommit, Boolean::valueOf);
|
||||
set(j, propertyOverride, "jooq.codegen.jdbc.initScript", Jdbc::getInitScript, Jdbc::setInitScript);
|
||||
set(j, propertyOverride, "jooq.codegen.jdbc.initSeparator", Jdbc::getInitSeparator, Jdbc::setInitSeparator);
|
||||
}
|
||||
set(j, propertyOverride, o -> null, "jooq.codegen.jdbc.driver", Jdbc::getDriver, Jdbc::setDriver);
|
||||
set(j, propertyOverride, Jdbc::getUrlProperty, "jooq.codegen.jdbc.url", Jdbc::getUrl, Jdbc::setUrl);
|
||||
set(j, propertyOverride, o -> null, "jooq.codegen.jdbc.user", Jdbc::getUser, Jdbc::setUser);
|
||||
set(j, propertyOverride, o -> null, "jooq.codegen.jdbc.username", Jdbc::getUsername, Jdbc::setUsername);
|
||||
set(j, propertyOverride, o -> null, "jooq.codegen.jdbc.password", Jdbc::getPassword, Jdbc::setPassword);
|
||||
set(j, propertyOverride, o -> null, "jooq.codegen.jdbc.autoCommit", Jdbc::isAutoCommit, Jdbc::setAutoCommit, Boolean::valueOf);
|
||||
set(j, propertyOverride, o -> null, "jooq.codegen.jdbc.initScript", Jdbc::getInitScript, Jdbc::setInitScript);
|
||||
set(j, propertyOverride, o -> null, "jooq.codegen.jdbc.initSeparator", Jdbc::getInitSeparator, Jdbc::setInitSeparator);
|
||||
|
||||
if (j != null && !StringUtils.isBlank(j.getUrl())) {
|
||||
try {
|
||||
@ -724,10 +720,10 @@ public class GenerationTool {
|
||||
if (isBlank(g.getTarget().getEncoding()))
|
||||
g.getTarget().setEncoding(DEFAULT_TARGET_ENCODING);
|
||||
|
||||
set(g.getTarget(), propertyOverride, "jooq.codegen.target.packageName", Target::getPackageName, Target::setPackageName, identity(), DEFAULT_TARGET_PACKAGENAME::equals);
|
||||
set(g.getTarget(), propertyOverride, "jooq.codegen.target.directory", Target::getDirectory, Target::setDirectory, identity(), DEFAULT_TARGET_DIRECTORY::equals);
|
||||
set(g.getTarget(), propertyOverride, "jooq.codegen.target.encoding", Target::getEncoding, Target::setEncoding, identity(), DEFAULT_TARGET_ENCODING::equals);
|
||||
set(g.getTarget(), propertyOverride, "jooq.codegen.target.locale", Target::getLocale, Target::setLocale);
|
||||
set(g.getTarget(), propertyOverride, o -> null, "jooq.codegen.target.packageName", Target::getPackageName, Target::setPackageName, identity(), DEFAULT_TARGET_PACKAGENAME::equals);
|
||||
set(g.getTarget(), propertyOverride, o -> null, "jooq.codegen.target.directory", Target::getDirectory, Target::setDirectory, identity(), DEFAULT_TARGET_DIRECTORY::equals);
|
||||
set(g.getTarget(), propertyOverride, o -> null, "jooq.codegen.target.encoding", Target::getEncoding, Target::setEncoding, identity(), DEFAULT_TARGET_ENCODING::equals);
|
||||
set(g.getTarget(), propertyOverride, o -> null, "jooq.codegen.target.locale", Target::getLocale, Target::setLocale);
|
||||
|
||||
// [#2887] [#9727] Patch relative paths to take plugin execution basedir into account
|
||||
if (!new File(g.getTarget().getDirectory()).isAbsolute())
|
||||
@ -1097,34 +1093,48 @@ public class GenerationTool {
|
||||
private <O> void set(
|
||||
O configurationObject,
|
||||
boolean override,
|
||||
String property,
|
||||
Function<? super O, ? extends String> property,
|
||||
String defaultProperty,
|
||||
Function<? super O, ? extends String> get,
|
||||
BiConsumer<? super O, ? super String> set
|
||||
) {
|
||||
set(configurationObject, override, property, get, set, Function.identity());
|
||||
set(configurationObject, override, property, defaultProperty, get, set, Function.identity());
|
||||
}
|
||||
|
||||
private <O, T> void set(
|
||||
O configurationObject,
|
||||
boolean override,
|
||||
String property,
|
||||
Function<? super O, ? extends String> property,
|
||||
String defaultProperty,
|
||||
Function<? super O, ? extends T> get,
|
||||
BiConsumer<? super O, ? super T> set,
|
||||
Function<? super String, ? extends T> convert
|
||||
) {
|
||||
set(configurationObject, override, property, get, set, convert, t -> t == null);
|
||||
set(configurationObject, override, property, defaultProperty, get, set, convert, t -> t == null);
|
||||
}
|
||||
|
||||
private <O, T> void set(
|
||||
O configurationObject,
|
||||
boolean override,
|
||||
String property,
|
||||
Function<? super O, ? extends String> propertyGetter,
|
||||
String defaultProperty,
|
||||
Function<? super O, ? extends T> get,
|
||||
BiConsumer<? super O, ? super T> set,
|
||||
Function<? super String, ? extends T> convert,
|
||||
Predicate<? super T> checkDefault
|
||||
) {
|
||||
String p = System.getProperty(property);
|
||||
String property = propertyGetter.apply(configurationObject);
|
||||
String p = null;
|
||||
|
||||
if (property != null) {
|
||||
p = System.getProperty(property);
|
||||
|
||||
if (p != null)
|
||||
override = true;
|
||||
}
|
||||
|
||||
if (p == null)
|
||||
p = System.getProperty(defaultProperty);
|
||||
|
||||
if (p != null && (override || checkDefault.test(get.apply(configurationObject))))
|
||||
set.accept(configurationObject, convert.apply(p));
|
||||
|
||||
@ -35,10 +35,11 @@ public class Jdbc implements Serializable, XMLAppendable
|
||||
private final static long serialVersionUID = 32000L;
|
||||
@XmlJavaTypeAdapter(StringAdapter.class)
|
||||
protected String driver;
|
||||
@XmlElement(required = true)
|
||||
@XmlJavaTypeAdapter(StringAdapter.class)
|
||||
protected String url;
|
||||
@XmlJavaTypeAdapter(StringAdapter.class)
|
||||
protected String urlProperty;
|
||||
@XmlJavaTypeAdapter(StringAdapter.class)
|
||||
protected String schema;
|
||||
@XmlJavaTypeAdapter(StringAdapter.class)
|
||||
protected String user;
|
||||
@ -87,6 +88,22 @@ public class Jdbc implements Serializable, XMLAppendable
|
||||
this.url = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* The system property name that describes the JDBC connection URL.
|
||||
*
|
||||
*/
|
||||
public String getUrlProperty() {
|
||||
return urlProperty;
|
||||
}
|
||||
|
||||
/**
|
||||
* The system property name that describes the JDBC connection URL.
|
||||
*
|
||||
*/
|
||||
public void setUrlProperty(String value) {
|
||||
this.urlProperty = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use database schema configuration elements instead.
|
||||
*
|
||||
@ -238,6 +255,15 @@ public class Jdbc implements Serializable, XMLAppendable
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The system property name that describes the JDBC connection URL.
|
||||
*
|
||||
*/
|
||||
public Jdbc withUrlProperty(String value) {
|
||||
setUrlProperty(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use database schema configuration elements instead.
|
||||
*
|
||||
@ -327,6 +353,7 @@ public class Jdbc implements Serializable, XMLAppendable
|
||||
public final void appendTo(XMLBuilder builder) {
|
||||
builder.append("driver", driver);
|
||||
builder.append("url", url);
|
||||
builder.append("urlProperty", urlProperty);
|
||||
builder.append("schema", schema);
|
||||
builder.append("user", user);
|
||||
builder.append("username", username);
|
||||
@ -374,6 +401,15 @@ public class Jdbc implements Serializable, XMLAppendable
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (urlProperty == null) {
|
||||
if (other.urlProperty!= null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!urlProperty.equals(other.urlProperty)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (schema == null) {
|
||||
if (other.schema!= null) {
|
||||
return false;
|
||||
@ -455,6 +491,7 @@ public class Jdbc implements Serializable, XMLAppendable
|
||||
int result = 1;
|
||||
result = ((prime*result)+((driver == null)? 0 :driver.hashCode()));
|
||||
result = ((prime*result)+((url == null)? 0 :url.hashCode()));
|
||||
result = ((prime*result)+((urlProperty == null)? 0 :urlProperty.hashCode()));
|
||||
result = ((prime*result)+((schema == null)? 0 :schema.hashCode()));
|
||||
result = ((prime*result)+((user == null)? 0 :user.hashCode()));
|
||||
result = ((prime*result)+((username == null)? 0 :username.hashCode()));
|
||||
|
||||
@ -82,10 +82,14 @@
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[The JDBC driver class.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
|
||||
<element name="url" type="string" minOccurs="1" maxOccurs="1">
|
||||
<element name="url" type="string" minOccurs="0" maxOccurs="1">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[The JDBC connection URL.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
|
||||
<element name="urlProperty" type="string" minOccurs="0" maxOccurs="1">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[The system property name that describes the JDBC connection URL.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
|
||||
<element name="schema" type="string" minOccurs="0" maxOccurs="1">
|
||||
<annotation>
|
||||
<appinfo>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user