[jOOQ/jOOQ#12759] Additional SQL statements after JDBC connection
This commit is contained in:
parent
0a5ecc33bf
commit
2b54cf7f1c
@ -42,6 +42,7 @@ import static java.lang.Boolean.TRUE;
|
||||
import static java.util.Comparator.comparing;
|
||||
import static org.jooq.SQLDialect.HSQLDB;
|
||||
import static org.jooq.impl.DSL.selectOne;
|
||||
import static org.jooq.tools.StringUtils.defaultIfBlank;
|
||||
import static org.jooq.tools.StringUtils.defaultIfNull;
|
||||
import static org.jooq.tools.StringUtils.defaultString;
|
||||
import static org.jooq.tools.StringUtils.isBlank;
|
||||
@ -347,6 +348,11 @@ public class GenerationTool {
|
||||
if (a != null)
|
||||
j.setAutoCommit(Boolean.valueOf(a));
|
||||
}
|
||||
|
||||
if (j.getInitScript() == null)
|
||||
j.setInitScript(System.getProperty("jooq.codegen.jdbc.initScript"));
|
||||
if (j.getInitSeparator() == null)
|
||||
j.setInitSeparator(System.getProperty("jooq.codegen.jdbc.initSeparator"));
|
||||
}
|
||||
|
||||
if (j != null) {
|
||||
@ -360,6 +366,11 @@ public class GenerationTool {
|
||||
properties.put("password", defaultString(j.getPassword()));
|
||||
|
||||
setConnection(driver.newInstance().connect(defaultString(j.getUrl()), properties));
|
||||
|
||||
if (j.getInitScript() != null)
|
||||
for (String sql : j.getInitScript().split(defaultIfBlank(j.getInitSeparator(), ";")))
|
||||
if (!StringUtils.isBlank(sql))
|
||||
ctx.execute(sql);
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (databaseName != null)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -47,6 +47,10 @@ public class Jdbc implements Serializable, XMLAppendable
|
||||
@XmlJavaTypeAdapter(StringAdapter.class)
|
||||
protected String password;
|
||||
protected Boolean autoCommit;
|
||||
@XmlJavaTypeAdapter(StringAdapter.class)
|
||||
protected String initScript;
|
||||
@XmlJavaTypeAdapter(StringAdapter.class)
|
||||
protected String initSeparator;
|
||||
@XmlElementWrapper(name = "properties")
|
||||
@XmlElement(name = "property")
|
||||
protected List<Property> properties;
|
||||
@ -102,7 +106,7 @@ public class Jdbc implements Serializable, XMLAppendable
|
||||
}
|
||||
|
||||
/**
|
||||
* The JDBC connection user. Be sure this user has all required GRANTs to the dictionary views/tables to generate the desired artefacts
|
||||
* The JDBC connection user. Be sure this user has all required GRANTs to the dictionary views/tables to generate the desired artefacts.
|
||||
*
|
||||
*/
|
||||
public String getUser() {
|
||||
@ -110,7 +114,7 @@ public class Jdbc implements Serializable, XMLAppendable
|
||||
}
|
||||
|
||||
/**
|
||||
* The JDBC connection user. Be sure this user has all required GRANTs to the dictionary views/tables to generate the desired artefacts
|
||||
* The JDBC connection user. Be sure this user has all required GRANTs to the dictionary views/tables to generate the desired artefacts.
|
||||
*
|
||||
*/
|
||||
public void setUser(String value) {
|
||||
@ -173,6 +177,38 @@ public class Jdbc implements Serializable, XMLAppendable
|
||||
this.autoCommit = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* A script to run after creating the JDBC connection, and before running the code generator.
|
||||
*
|
||||
*/
|
||||
public String getInitScript() {
|
||||
return initScript;
|
||||
}
|
||||
|
||||
/**
|
||||
* A script to run after creating the JDBC connection, and before running the code generator.
|
||||
*
|
||||
*/
|
||||
public void setInitScript(String value) {
|
||||
this.initScript = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* The separator used to separate statements in the initScript.
|
||||
*
|
||||
*/
|
||||
public String getInitSeparator() {
|
||||
return initSeparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* The separator used to separate statements in the initScript.
|
||||
*
|
||||
*/
|
||||
public void setInitSeparator(String value) {
|
||||
this.initSeparator = value;
|
||||
}
|
||||
|
||||
public List<Property> getProperties() {
|
||||
if (properties == null) {
|
||||
properties = new ArrayList<Property>();
|
||||
@ -213,7 +249,7 @@ public class Jdbc implements Serializable, XMLAppendable
|
||||
}
|
||||
|
||||
/**
|
||||
* The JDBC connection user. Be sure this user has all required GRANTs to the dictionary views/tables to generate the desired artefacts
|
||||
* The JDBC connection user. Be sure this user has all required GRANTs to the dictionary views/tables to generate the desired artefacts.
|
||||
*
|
||||
*/
|
||||
public Jdbc withUser(String value) {
|
||||
@ -244,6 +280,24 @@ public class Jdbc implements Serializable, XMLAppendable
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* A script to run after creating the JDBC connection, and before running the code generator.
|
||||
*
|
||||
*/
|
||||
public Jdbc withInitScript(String value) {
|
||||
setInitScript(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The separator used to separate statements in the initScript.
|
||||
*
|
||||
*/
|
||||
public Jdbc withInitSeparator(String value) {
|
||||
setInitSeparator(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Jdbc withProperties(Property... values) {
|
||||
if (values!= null) {
|
||||
for (Property value: values) {
|
||||
@ -274,6 +328,8 @@ public class Jdbc implements Serializable, XMLAppendable
|
||||
builder.append("username", username);
|
||||
builder.append("password", password);
|
||||
builder.append("autoCommit", autoCommit);
|
||||
builder.append("initScript", initScript);
|
||||
builder.append("initSeparator", initSeparator);
|
||||
builder.append("properties", "property", properties);
|
||||
}
|
||||
|
||||
@ -359,6 +415,24 @@ public class Jdbc implements Serializable, XMLAppendable
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (initScript == null) {
|
||||
if (other.initScript!= null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!initScript.equals(other.initScript)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (initSeparator == null) {
|
||||
if (other.initSeparator!= null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!initSeparator.equals(other.initSeparator)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (properties == null) {
|
||||
if (other.properties!= null) {
|
||||
return false;
|
||||
@ -382,6 +456,8 @@ public class Jdbc implements Serializable, XMLAppendable
|
||||
result = ((prime*result)+((username == null)? 0 :username.hashCode()));
|
||||
result = ((prime*result)+((password == null)? 0 :password.hashCode()));
|
||||
result = ((prime*result)+((autoCommit == null)? 0 :autoCommit.hashCode()));
|
||||
result = ((prime*result)+((initScript == null)? 0 :initScript.hashCode()));
|
||||
result = ((prime*result)+((initSeparator == null)? 0 :initSeparator.hashCode()));
|
||||
result = ((prime*result)+((properties == null)? 0 :properties.hashCode()));
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -77,7 +77,7 @@
|
||||
</element>
|
||||
|
||||
<element name="user" type="string" minOccurs="0" maxOccurs="1">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[The JDBC connection user. Be sure this user has all required GRANTs to the dictionary views/tables to generate the desired artefacts]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[The JDBC connection user. Be sure this user has all required GRANTs to the dictionary views/tables to generate the desired artefacts.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
|
||||
<element name="username" type="string" minOccurs="0" maxOccurs="1">
|
||||
@ -93,7 +93,15 @@
|
||||
</element>
|
||||
|
||||
<element name="properties" type="tns:Properties" minOccurs="0" maxOccurs="1">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Enlist custom JDBC driver properties that are provided to the java.sql.DriverManager when fetching a connection]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Enlist custom JDBC driver properties that are provided to the java.sql.DriverManager when fetching a connection.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
|
||||
<element name="initScript" type="string" minOccurs="0" maxOccurs="1">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[A script to run after creating the JDBC connection, and before running the code generator.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
|
||||
<element name="initSeparator" type="string" minOccurs="0" maxOccurs="1">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[The separator used to separate statements in the initScript.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
</all>
|
||||
</complexType>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user