[jOOQ/jOOQ#2530] Allow for matching tables in <embeddable/> config

This commit is contained in:
Lukas Eder 2020-08-18 14:50:42 +02:00
parent 7e03b13d49
commit c47897b514
3 changed files with 47 additions and 0 deletions

View File

@ -1879,7 +1879,12 @@ public abstract class AbstractDatabase implements Database {
Map<Name, EmbeddableDefinition> result = new LinkedHashMap<>();
for (TableDefinition table : getTables()) {
embeddableLoop:
for (Embeddable embeddable : getConfiguredEmbeddables()) {
if (embeddable.getTables() != null && !matches(patterns.pattern(embeddable.getTables()), table))
continue embeddableLoop;
List<ColumnDefinition> columns = new ArrayList<>();
List<String> names = new ArrayList<>();

View File

@ -37,6 +37,8 @@ public class Embeddable implements Serializable, XMLAppendable
protected String name;
@XmlJavaTypeAdapter(StringAdapter.class)
protected String referencingName;
@XmlJavaTypeAdapter(StringAdapter.class)
protected String tables;
@XmlElement(defaultValue = "false")
protected Boolean replacesFields = false;
@XmlElementWrapper(name = "fields")
@ -75,6 +77,22 @@ public class Embeddable implements Serializable, XMLAppendable
this.referencingName = value;
}
/**
* A regular expression matching the tables to which to apply the embeddable definition.
*
*/
public String getTables() {
return tables;
}
/**
* A regular expression matching the tables to which to apply the embeddable definition.
*
*/
public void setTables(String value) {
this.tables = value;
}
/**
* Specify that the embeddable field replaces its underlying fields in code generation output, and when working with asterisks.
*
@ -128,6 +146,15 @@ public class Embeddable implements Serializable, XMLAppendable
return this;
}
/**
* A regular expression matching the tables to which to apply the embeddable definition.
*
*/
public Embeddable withTables(String value) {
setTables(value);
return this;
}
public Embeddable withReplacesFields(Boolean value) {
setReplacesFields(value);
return this;
@ -158,6 +185,7 @@ public class Embeddable implements Serializable, XMLAppendable
public final void appendTo(XMLBuilder builder) {
builder.append("name", name);
builder.append("referencingName", referencingName);
builder.append("tables", tables);
builder.append("replacesFields", replacesFields);
builder.append("fields", "field", fields);
}
@ -199,6 +227,15 @@ public class Embeddable implements Serializable, XMLAppendable
return false;
}
}
if (tables == null) {
if (other.tables!= null) {
return false;
}
} else {
if (!tables.equals(other.tables)) {
return false;
}
}
if (replacesFields == null) {
if (other.replacesFields!= null) {
return false;
@ -226,6 +263,7 @@ public class Embeddable implements Serializable, XMLAppendable
int result = 1;
result = ((prime*result)+((name == null)? 0 :name.hashCode()));
result = ((prime*result)+((referencingName == null)? 0 :referencingName.hashCode()));
result = ((prime*result)+((tables == null)? 0 :tables.hashCode()));
result = ((prime*result)+((replacesFields == null)? 0 :replacesFields.hashCode()));
result = ((prime*result)+((fields == null)? 0 :fields.hashCode()));
return result;

View File

@ -1020,6 +1020,10 @@ for Oracle.]]></jxb:javadoc></jxb:property></appinfo></annotation>
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[The referencing name of the embeddable type, defaulting to the defining name.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="tables" type="string" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[A regular expression matching the tables to which to apply the embeddable definition.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="fields" type="tns:EmbeddableFields" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[A set of field specifications for the embeddable type.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>