[jOOQ/jOOQ#13434] Add <columns/> to <syntheticObjects/> to generate
synthetic columns
This commit is contained in:
parent
c47ce55f61
commit
dae57e01cd
@ -123,6 +123,7 @@ import org.jooq.meta.jaxb.Nullability;
|
||||
import org.jooq.meta.jaxb.OnError;
|
||||
import org.jooq.meta.jaxb.RegexFlag;
|
||||
import org.jooq.meta.jaxb.SchemaMappingType;
|
||||
import org.jooq.meta.jaxb.SyntheticColumnType;
|
||||
import org.jooq.meta.jaxb.SyntheticForeignKeyType;
|
||||
import org.jooq.meta.jaxb.SyntheticIdentityType;
|
||||
import org.jooq.meta.jaxb.SyntheticObjectsType;
|
||||
@ -212,6 +213,8 @@ public abstract class AbstractDatabase implements Database {
|
||||
private Set<EmbeddableDefinitionType> unusedEmbeddables = new HashSet<>();
|
||||
private List<CommentType> configuredComments = new ArrayList<>();
|
||||
private Set<CommentType> unusedComments = new HashSet<>();
|
||||
private List<SyntheticColumnType> configuredSyntheticColumns = new ArrayList<>();
|
||||
private Set<SyntheticColumnType> unusedSyntheticColumns = new HashSet<>();
|
||||
private List<SyntheticReadonlyColumnType> configuredSyntheticReadonlyColumns = new ArrayList<>();
|
||||
private Set<SyntheticReadonlyColumnType> unusedSyntheticReadonlyColumns = new HashSet<>();
|
||||
private List<SyntheticReadonlyRowidType> configuredSyntheticReadonlyRowids = new ArrayList<>();
|
||||
@ -3084,6 +3087,7 @@ public abstract class AbstractDatabase implements Database {
|
||||
// configured things programmatically, so we must not set the
|
||||
// list but append it.
|
||||
|
||||
getConfiguredSyntheticColumns().addAll(configuredSyntheticObjects.getColumns());
|
||||
getConfiguredSyntheticReadonlyColumns().addAll(configuredSyntheticObjects.getReadonlyColumns());
|
||||
getConfiguredSyntheticReadonlyRowids().addAll(configuredSyntheticObjects.getReadonlyRowids());
|
||||
getConfiguredSyntheticIdentities().addAll(configuredSyntheticObjects.getIdentities());
|
||||
@ -3092,6 +3096,7 @@ public abstract class AbstractDatabase implements Database {
|
||||
getConfiguredSyntheticForeignKeys().addAll(configuredSyntheticObjects.getForeignKeys());
|
||||
getConfiguredSyntheticViews().addAll(configuredSyntheticObjects.getViews());
|
||||
|
||||
unusedSyntheticColumns.addAll(configuredSyntheticObjects.getColumns());
|
||||
unusedSyntheticReadonlyColumns.addAll(configuredSyntheticObjects.getReadonlyColumns());
|
||||
unusedSyntheticReadonlyRowids.addAll(configuredSyntheticObjects.getReadonlyRowids());
|
||||
unusedSyntheticIdentities.addAll(configuredSyntheticObjects.getIdentities());
|
||||
@ -3105,6 +3110,8 @@ public abstract class AbstractDatabase implements Database {
|
||||
|
||||
|
||||
|
||||
if (!configuredSyntheticObjects.getColumns().isEmpty())
|
||||
log.info("Commercial feature", "Synthetic columns are a commercial only feature. Please upgrade to the jOOQ Professional Edition");
|
||||
if (!configuredSyntheticObjects.getReadonlyColumns().isEmpty())
|
||||
log.info("Commercial feature", "Synthetic read only columns are a commercial only feature. Please upgrade to the jOOQ Professional Edition");
|
||||
if (!configuredSyntheticObjects.getReadonlyRowids().isEmpty())
|
||||
@ -3116,6 +3123,14 @@ public abstract class AbstractDatabase implements Database {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SyntheticColumnType> getConfiguredSyntheticColumns() {
|
||||
if (configuredSyntheticColumns == null)
|
||||
configuredSyntheticColumns = new ArrayList<>();
|
||||
|
||||
return configuredSyntheticColumns;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SyntheticReadonlyColumnType> getConfiguredSyntheticReadonlyColumns() {
|
||||
if (configuredSyntheticReadonlyColumns == null)
|
||||
@ -3172,6 +3187,11 @@ public abstract class AbstractDatabase implements Database {
|
||||
return configuredSyntheticViews;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markUsed(SyntheticColumnType column) {
|
||||
unusedSyntheticColumns.remove(column);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markUsed(SyntheticReadonlyColumnType readonlyColumn) {
|
||||
unusedSyntheticReadonlyColumns.remove(readonlyColumn);
|
||||
@ -3207,6 +3227,11 @@ public abstract class AbstractDatabase implements Database {
|
||||
unusedSyntheticViews.remove(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SyntheticColumnType> getUnusedSyntheticColumns() {
|
||||
return new ArrayList<>(unusedSyntheticColumns);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SyntheticReadonlyColumnType> getUnusedSyntheticReadonlyColumns() {
|
||||
return new ArrayList<>(unusedSyntheticReadonlyColumns);
|
||||
|
||||
@ -49,7 +49,13 @@ import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.jooq.DataType;
|
||||
// ...
|
||||
import org.jooq.exception.SQLDialectNotSupportedException;
|
||||
import org.jooq.impl.DefaultDataType;
|
||||
import org.jooq.impl.ParserException;
|
||||
import org.jooq.impl.SQLDataType;
|
||||
import org.jooq.meta.jaxb.SyntheticColumnType;
|
||||
import org.jooq.meta.jaxb.SyntheticReadonlyRowidType;
|
||||
import org.jooq.tools.JooqLogger;
|
||||
import org.jooq.tools.StringUtils;
|
||||
@ -112,6 +118,35 @@ extends AbstractDefinition {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// [#2603] Filter exclude / include also for table columns
|
||||
@ -146,6 +181,22 @@ extends AbstractDefinition {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -59,6 +59,7 @@ import org.jooq.meta.jaxb.ForcedType;
|
||||
import org.jooq.meta.jaxb.OnError;
|
||||
import org.jooq.meta.jaxb.RegexFlag;
|
||||
import org.jooq.meta.jaxb.SchemaMappingType;
|
||||
import org.jooq.meta.jaxb.SyntheticColumnType;
|
||||
import org.jooq.meta.jaxb.SyntheticForeignKeyType;
|
||||
import org.jooq.meta.jaxb.SyntheticIdentityType;
|
||||
import org.jooq.meta.jaxb.SyntheticObjectsType;
|
||||
@ -1155,6 +1156,11 @@ public interface Database extends AutoCloseable {
|
||||
*/
|
||||
void setConfiguredSyntheticObjects(SyntheticObjectsType configuredSyntheticObjects);
|
||||
|
||||
/**
|
||||
* Get the configured synthetic columns.
|
||||
*/
|
||||
List<SyntheticColumnType> getConfiguredSyntheticColumns();
|
||||
|
||||
/**
|
||||
* Get the configured synthetic readonly columns.
|
||||
*/
|
||||
@ -1190,6 +1196,16 @@ public interface Database extends AutoCloseable {
|
||||
*/
|
||||
List<SyntheticViewType> getConfiguredSyntheticViews();
|
||||
|
||||
/**
|
||||
* Mark a synthetic column as used.
|
||||
*/
|
||||
void markUsed(SyntheticColumnType readonlyColumn);
|
||||
|
||||
/**
|
||||
* Retrieve the not-yet used synthetic columns.
|
||||
*/
|
||||
List<SyntheticColumnType> getUnusedSyntheticColumns();
|
||||
|
||||
/**
|
||||
* Mark a synthetic readonly column as used.
|
||||
*/
|
||||
|
||||
@ -189,6 +189,14 @@ public class ObjectFactory {
|
||||
return new SyntheticReadonlyRowidType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link SyntheticColumnType }
|
||||
*
|
||||
*/
|
||||
public SyntheticColumnType createSyntheticColumnType() {
|
||||
return new SyntheticColumnType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link SyntheticIdentityType }
|
||||
*
|
||||
|
||||
@ -0,0 +1,236 @@
|
||||
|
||||
package org.jooq.meta.jaxb;
|
||||
|
||||
import java.io.Serializable;
|
||||
import jakarta.xml.bind.annotation.XmlAccessType;
|
||||
import jakarta.xml.bind.annotation.XmlAccessorType;
|
||||
import jakarta.xml.bind.annotation.XmlElement;
|
||||
import jakarta.xml.bind.annotation.XmlType;
|
||||
import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
import org.jooq.util.jaxb.tools.StringAdapter;
|
||||
import org.jooq.util.jaxb.tools.XMLAppendable;
|
||||
import org.jooq.util.jaxb.tools.XMLBuilder;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Java class for SyntheticColumnType complex type.
|
||||
*
|
||||
* <p>The following schema fragment specifies the expected content contained within this class.
|
||||
*
|
||||
* <pre>
|
||||
* <complexType name="SyntheticColumnType">
|
||||
* <complexContent>
|
||||
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
|
||||
* <all>
|
||||
* <element name="tables" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
|
||||
* <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
|
||||
* <element name="type" type="{http://www.w3.org/2001/XMLSchema}string"/>
|
||||
* <element name="comment" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
|
||||
* </all>
|
||||
* </restriction>
|
||||
* </complexContent>
|
||||
* </complexType>
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
*/
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "SyntheticColumnType", propOrder = {
|
||||
|
||||
})
|
||||
@SuppressWarnings({
|
||||
"all"
|
||||
})
|
||||
public class SyntheticColumnType implements Serializable, XMLAppendable
|
||||
{
|
||||
|
||||
private final static long serialVersionUID = 31700L;
|
||||
@XmlJavaTypeAdapter(StringAdapter.class)
|
||||
protected String tables;
|
||||
@XmlElement(required = true)
|
||||
@XmlJavaTypeAdapter(StringAdapter.class)
|
||||
protected String name;
|
||||
@XmlElement(required = true)
|
||||
@XmlJavaTypeAdapter(StringAdapter.class)
|
||||
protected String type;
|
||||
@XmlJavaTypeAdapter(StringAdapter.class)
|
||||
protected String comment;
|
||||
|
||||
/**
|
||||
* A regular expression matching all tables on which to apply this synthetic readonly column.
|
||||
*
|
||||
*/
|
||||
public String getTables() {
|
||||
return tables;
|
||||
}
|
||||
|
||||
/**
|
||||
* A regular expression matching all tables on which to apply this synthetic readonly column.
|
||||
*
|
||||
*/
|
||||
public void setTables(String value) {
|
||||
this.tables = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* The column name.
|
||||
*
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The column name.
|
||||
*
|
||||
*/
|
||||
public void setName(String value) {
|
||||
this.name = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* The column type.
|
||||
*
|
||||
*/
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* The column type.
|
||||
*
|
||||
*/
|
||||
public void setType(String value) {
|
||||
this.type = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* The column comment.
|
||||
*
|
||||
*/
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* The column comment.
|
||||
*
|
||||
*/
|
||||
public void setComment(String value) {
|
||||
this.comment = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* A regular expression matching all tables on which to apply this synthetic readonly column.
|
||||
*
|
||||
*/
|
||||
public SyntheticColumnType withTables(String value) {
|
||||
setTables(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The column name.
|
||||
*
|
||||
*/
|
||||
public SyntheticColumnType withName(String value) {
|
||||
setName(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The column type.
|
||||
*
|
||||
*/
|
||||
public SyntheticColumnType withType(String value) {
|
||||
setType(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The column comment.
|
||||
*
|
||||
*/
|
||||
public SyntheticColumnType withComment(String value) {
|
||||
setComment(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void appendTo(XMLBuilder builder) {
|
||||
builder.append("tables", tables);
|
||||
builder.append("name", name);
|
||||
builder.append("type", type);
|
||||
builder.append("comment", comment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
XMLBuilder builder = XMLBuilder.nonFormatting();
|
||||
appendTo(builder);
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (this == that) {
|
||||
return true;
|
||||
}
|
||||
if (that == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass()!= that.getClass()) {
|
||||
return false;
|
||||
}
|
||||
SyntheticColumnType other = ((SyntheticColumnType) that);
|
||||
if (tables == null) {
|
||||
if (other.tables!= null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!tables.equals(other.tables)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (name == null) {
|
||||
if (other.name!= null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!name.equals(other.name)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (type == null) {
|
||||
if (other.type!= null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!type.equals(other.type)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (comment == null) {
|
||||
if (other.comment!= null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!comment.equals(other.comment)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = ((prime*result)+((tables == null)? 0 :tables.hashCode()));
|
||||
result = ((prime*result)+((name == null)? 0 :name.hashCode()));
|
||||
result = ((prime*result)+((type == null)? 0 :type.hashCode()));
|
||||
result = ((prime*result)+((comment == null)? 0 :comment.hashCode()));
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -37,6 +37,9 @@ public class SyntheticObjectsType implements Serializable, XMLAppendable
|
||||
@XmlElementWrapper(name = "readonlyRowids")
|
||||
@XmlElement(name = "readonlyRowid")
|
||||
protected List<SyntheticReadonlyRowidType> readonlyRowids;
|
||||
@XmlElementWrapper(name = "columns")
|
||||
@XmlElement(name = "column")
|
||||
protected List<SyntheticColumnType> columns;
|
||||
@XmlElementWrapper(name = "identities")
|
||||
@XmlElement(name = "identity")
|
||||
protected List<SyntheticIdentityType> identities;
|
||||
@ -75,6 +78,17 @@ public class SyntheticObjectsType implements Serializable, XMLAppendable
|
||||
this.readonlyRowids = readonlyRowids;
|
||||
}
|
||||
|
||||
public List<SyntheticColumnType> getColumns() {
|
||||
if (columns == null) {
|
||||
columns = new ArrayList<SyntheticColumnType>();
|
||||
}
|
||||
return columns;
|
||||
}
|
||||
|
||||
public void setColumns(List<SyntheticColumnType> columns) {
|
||||
this.columns = columns;
|
||||
}
|
||||
|
||||
public List<SyntheticIdentityType> getIdentities() {
|
||||
if (identities == null) {
|
||||
identities = new ArrayList<SyntheticIdentityType>();
|
||||
@ -172,6 +186,27 @@ public class SyntheticObjectsType implements Serializable, XMLAppendable
|
||||
return this;
|
||||
}
|
||||
|
||||
public SyntheticObjectsType withColumns(SyntheticColumnType... values) {
|
||||
if (values!= null) {
|
||||
for (SyntheticColumnType value: values) {
|
||||
getColumns().add(value);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SyntheticObjectsType withColumns(Collection<SyntheticColumnType> values) {
|
||||
if (values!= null) {
|
||||
getColumns().addAll(values);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SyntheticObjectsType withColumns(List<SyntheticColumnType> columns) {
|
||||
setColumns(columns);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SyntheticObjectsType withIdentities(SyntheticIdentityType... values) {
|
||||
if (values!= null) {
|
||||
for (SyntheticIdentityType value: values) {
|
||||
@ -281,6 +316,7 @@ public class SyntheticObjectsType implements Serializable, XMLAppendable
|
||||
public final void appendTo(XMLBuilder builder) {
|
||||
builder.append("readonlyColumns", "readonlyColumn", readonlyColumns);
|
||||
builder.append("readonlyRowids", "readonlyRowid", readonlyRowids);
|
||||
builder.append("columns", "column", columns);
|
||||
builder.append("identities", "identity", identities);
|
||||
builder.append("primaryKeys", "primaryKey", primaryKeys);
|
||||
builder.append("uniqueKeys", "uniqueKey", uniqueKeys);
|
||||
@ -325,6 +361,15 @@ public class SyntheticObjectsType implements Serializable, XMLAppendable
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (columns == null) {
|
||||
if (other.columns!= null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!columns.equals(other.columns)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (identities == null) {
|
||||
if (other.identities!= null) {
|
||||
return false;
|
||||
@ -379,6 +424,7 @@ public class SyntheticObjectsType implements Serializable, XMLAppendable
|
||||
int result = 1;
|
||||
result = ((prime*result)+((readonlyColumns == null)? 0 :readonlyColumns.hashCode()));
|
||||
result = ((prime*result)+((readonlyRowids == null)? 0 :readonlyRowids.hashCode()));
|
||||
result = ((prime*result)+((columns == null)? 0 :columns.hashCode()));
|
||||
result = ((prime*result)+((identities == null)? 0 :identities.hashCode()));
|
||||
result = ((prime*result)+((primaryKeys == null)? 0 :primaryKeys.hashCode()));
|
||||
result = ((prime*result)+((uniqueKeys == null)? 0 :uniqueKeys.hashCode()));
|
||||
|
||||
@ -1017,6 +1017,10 @@ This feature is available in the commercial distribution only.]]></jxb:javadoc><
|
||||
<element name="readonlyRowids" type="tns:SyntheticReadonlyRowidsType" minOccurs="0" maxOccurs="1">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Synthetic ROWIDs configuration.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
|
||||
<element name="columns" type="tns:SyntheticColumnsType" minOccurs="0" maxOccurs="1">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Synthetic columns configuration]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
|
||||
<element name="identities" type="tns:SyntheticIdentitiesType" minOccurs="0" maxOccurs="1">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Synthetic identity configuration]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
@ -1084,6 +1088,33 @@ Use this along with the synthetic primary key feature to replace existing primar
|
||||
</all>
|
||||
</complexType>
|
||||
|
||||
<complexType name="SyntheticColumnsType">
|
||||
<sequence>
|
||||
<element name="column" type="tns:SyntheticColumnType" minOccurs="1" maxOccurs="unbounded"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
|
||||
<complexType name="SyntheticColumnType">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Synthetic column configuration]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
<all>
|
||||
<element name="tables" type="string" minOccurs="0" maxOccurs="1">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[A regular expression matching all tables on which to apply this synthetic readonly column.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
|
||||
<element name="name" type="string" minOccurs="1" maxOccurs="1">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[The column name.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
|
||||
<element name="type" type="string" minOccurs="1" maxOccurs="1">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[The column type.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
|
||||
<element name="comment" type="string" minOccurs="0" maxOccurs="1">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[The column comment.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
</all>
|
||||
</complexType>
|
||||
|
||||
<complexType name="SyntheticIdentitiesType">
|
||||
<sequence>
|
||||
<element name="identity" type="tns:SyntheticIdentityType" minOccurs="1" maxOccurs="unbounded"/>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user