[jOOQ/jOOQ#17474] Add support for synthetic synonyms

This commit is contained in:
Lukas Eder 2024-10-22 16:10:51 +02:00
parent 61f5c1d020
commit cd27f7e3fd
8 changed files with 491 additions and 8 deletions

View File

@ -801,6 +801,12 @@ public class MetaExtensions {
setForeignKeys(l);
}
public void synonyms(Action<SyntheticSynonymTypeListExtension> action) {
SyntheticSynonymTypeListExtension l = objects.newInstance(SyntheticSynonymTypeListExtension.class, objects);
action.execute(l);
setSynonyms(l);
}
public void views(Action<SyntheticViewTypeListExtension> action) {
SyntheticViewTypeListExtension l = objects.newInstance(SyntheticViewTypeListExtension.class, objects);
action.execute(l);
@ -904,6 +910,16 @@ public class MetaExtensions {
}
}
public static class SyntheticSynonymTypeExtension extends SyntheticSynonymType {
final ObjectFactory objects;
@Inject
public SyntheticSynonymTypeExtension(ObjectFactory objects) {
this.objects = objects;
}
}
public static class SyntheticViewTypeExtension extends SyntheticViewType {
final ObjectFactory objects;
@ -1570,6 +1586,22 @@ public class MetaExtensions {
}
}
public static class SyntheticSynonymTypeListExtension extends ArrayList<SyntheticSynonymType> {
final ObjectFactory objects;
@Inject
public SyntheticSynonymTypeListExtension(ObjectFactory objects) {
this.objects = objects;
}
public void synonym(Action<SyntheticSynonymTypeExtension> action) {
SyntheticSynonymTypeExtension o = objects.newInstance(SyntheticSynonymTypeExtension.class, objects);
action.execute(o);
add(o);
}
}
public static class SyntheticViewTypeListExtension extends ArrayList<SyntheticViewType> {
final ObjectFactory objects;

View File

@ -629,6 +629,17 @@ fun MutableList<SyntheticForeignKeyType>.foreignKey(block: SyntheticForeignKeyTy
add(e)
}
fun SyntheticObjectsType.synonyms(block: MutableList<SyntheticSynonymType>.() -> Unit) {
block(synonyms)
}
@JvmName("mutableListSyntheticSynonymType")
fun MutableList<SyntheticSynonymType>.synonym(block: SyntheticSynonymType.() -> Unit) {
val e = SyntheticSynonymType()
block(e)
add(e)
}
fun SyntheticObjectsType.views(block: MutableList<SyntheticViewType>.() -> Unit) {
block(views)
}

View File

@ -157,6 +157,7 @@ import org.jooq.meta.jaxb.SyntheticObjectsType;
import org.jooq.meta.jaxb.SyntheticPrimaryKeyType;
import org.jooq.meta.jaxb.SyntheticReadonlyColumnType;
import org.jooq.meta.jaxb.SyntheticReadonlyRowidType;
import org.jooq.meta.jaxb.SyntheticSynonymType;
import org.jooq.meta.jaxb.SyntheticUniqueKeyType;
import org.jooq.meta.jaxb.SyntheticViewType;
// ...
@ -271,6 +272,8 @@ public abstract class AbstractDatabase implements Database {
private Set<SyntheticUniqueKeyType> unusedSyntheticUniqueKeys = new HashSet<>();
private List<SyntheticForeignKeyType> configuredSyntheticForeignKeys = new ArrayList<>();
private Set<SyntheticForeignKeyType> unusedSyntheticForeignKeys = new HashSet<>();
private List<SyntheticSynonymType> configuredSyntheticSynonyms = new ArrayList<>();
private Set<SyntheticSynonymType> unusedSyntheticSynonyms = new HashSet<>();
private List<SyntheticViewType> configuredSyntheticViews = new ArrayList<>();
private Set<SyntheticViewType> unusedSyntheticViews = new HashSet<>();
private List<SyntheticDaoType> configuredSyntheticDaos = new ArrayList<>();
@ -3070,21 +3073,45 @@ public abstract class AbstractDatabase implements Database {
log.info("Synonyms fetched", fetchedSize(e, synonyms));
});
}
else
log.info("Synonyms excluded");
}
return synonyms;
}
@Override
public final List<SynonymDefinition> getSynonyms(SchemaDefinition schema) {
if (synonymsBySchema == null)
synonymsBySchema = new LinkedHashMap<>();
return filterSchema(getSynonyms(), schema, synonymsBySchema);
}
@Override
public final SynonymDefinition getSynonym(SchemaDefinition schema, String name) {
return getSynonym(schema, name, false);
}
@Override
public final SynonymDefinition getSynonym(SchemaDefinition schema, String name, boolean ignoreCase) {
return getDefinition(getSynonyms(schema), name, ignoreCase);
}
@Override
public final SynonymDefinition getSynonym(SchemaDefinition schema, Name name) {
return getSynonym(schema, name, false);
}
@Override
public final SynonymDefinition getSynonym(SchemaDefinition schema, Name name, boolean ignoreCase) {
return getDefinition(getSynonyms(schema), name, ignoreCase);
}
/* [/pro] */
@Override
public final List<ArrayDefinition> getArrays(SchemaDefinition schema) {
@ -3690,6 +3717,7 @@ public abstract class AbstractDatabase implements Database {
getConfiguredSyntheticPrimaryKeys().addAll(configuredSyntheticObjects.getPrimaryKeys());
getConfiguredSyntheticUniqueKeys().addAll(configuredSyntheticObjects.getUniqueKeys());
getConfiguredSyntheticForeignKeys().addAll(configuredSyntheticObjects.getForeignKeys());
getConfiguredSyntheticSynonyms().addAll(configuredSyntheticObjects.getSynonyms());
getConfiguredSyntheticViews().addAll(configuredSyntheticObjects.getViews());
getConfiguredSyntheticDaos().addAll(configuredSyntheticObjects.getDaos());
@ -3702,6 +3730,7 @@ public abstract class AbstractDatabase implements Database {
unusedSyntheticPrimaryKeys.addAll(configuredSyntheticObjects.getPrimaryKeys());
unusedSyntheticUniqueKeys.addAll(configuredSyntheticObjects.getUniqueKeys());
unusedSyntheticForeignKeys.addAll(configuredSyntheticObjects.getForeignKeys());
unusedSyntheticSynonyms.addAll(configuredSyntheticObjects.getSynonyms());
unusedSyntheticViews.addAll(configuredSyntheticObjects.getViews());
@ -3723,6 +3752,8 @@ public abstract class AbstractDatabase implements Database {
log.info("Commercial feature", "Synthetic unique keys are a commercial only feature. Please upgrade to the jOOQ Professional Edition");
if (!configuredSyntheticObjects.getForeignKeys().isEmpty())
log.info("Commercial feature", "Synthetic foreign keys are a commercial only feature. Please upgrade to the jOOQ Professional Edition");
if (!configuredSyntheticObjects.getSynonyms().isEmpty())
log.info("Commercial feature", "Synthetic synonyms are a commercial only feature. Please upgrade to the jOOQ Professional Edition");
}
}
@ -3798,6 +3829,14 @@ public abstract class AbstractDatabase implements Database {
return configuredSyntheticForeignKeys;
}
@Override
public List<SyntheticSynonymType> getConfiguredSyntheticSynonyms() {
if (configuredSyntheticSynonyms == null)
configuredSyntheticSynonyms = new ArrayList<>();
return configuredSyntheticSynonyms;
}
@Override
public List<SyntheticViewType> getConfiguredSyntheticViews() {
if (configuredSyntheticViews == null)
@ -3859,6 +3898,11 @@ public abstract class AbstractDatabase implements Database {
unusedSyntheticForeignKeys.remove(foreignKey);
}
@Override
public void markUsed(SyntheticSynonymType synonym) {
unusedSyntheticSynonyms.remove(synonym);
}
@Override
public void markUsed(SyntheticViewType view) {
unusedSyntheticViews.remove(view);
@ -3909,6 +3953,11 @@ public abstract class AbstractDatabase implements Database {
return new ArrayList<>(unusedSyntheticForeignKeys);
}
@Override
public List<SyntheticSynonymType> getUnusedSyntheticSynonyms() {
return new ArrayList<>(unusedSyntheticSynonyms);
}
@Override
public List<SyntheticViewType> getUnusedSyntheticViews() {
return new ArrayList<>(unusedSyntheticViews);

View File

@ -70,6 +70,7 @@ import org.jooq.meta.jaxb.SyntheticObjectsType;
import org.jooq.meta.jaxb.SyntheticPrimaryKeyType;
import org.jooq.meta.jaxb.SyntheticReadonlyColumnType;
import org.jooq.meta.jaxb.SyntheticReadonlyRowidType;
import org.jooq.meta.jaxb.SyntheticSynonymType;
import org.jooq.meta.jaxb.SyntheticUniqueKeyType;
import org.jooq.meta.jaxb.SyntheticViewType;
@ -1454,6 +1455,11 @@ public interface Database extends AutoCloseable {
*/
List<SyntheticForeignKeyType> getConfiguredSyntheticForeignKeys();
/**
* Get the configured synthetic synonyms.
*/
List<SyntheticSynonymType> getConfiguredSyntheticSynonyms();
/**
* Get the configured synthetic views.
*/
@ -1554,6 +1560,16 @@ public interface Database extends AutoCloseable {
*/
List<SyntheticForeignKeyType> getUnusedSyntheticForeignKeys();
/**
* Mark a synthetic synonym as used.
*/
void markUsed(SyntheticSynonymType synonym);
/**
* Retrieve the not-yet used synthetic synonyms.
*/
List<SyntheticSynonymType> getUnusedSyntheticSynonyms();
/**
* Mark a synthetic view as used.
*/

View File

@ -293,6 +293,14 @@ public class ObjectFactory {
return new SyntheticForeignKeyType();
}
/**
* Create an instance of {@link SyntheticSynonymType }
*
*/
public SyntheticSynonymType createSyntheticSynonymType() {
return new SyntheticSynonymType();
}
/**
* Create an instance of {@link SyntheticViewType }
*

View File

@ -58,6 +58,9 @@ public class SyntheticObjectsType implements Serializable, XMLAppendable
@XmlElementWrapper(name = "foreignKeys")
@XmlElement(name = "foreignKey")
protected List<SyntheticForeignKeyType> foreignKeys;
@XmlElementWrapper(name = "synonyms")
@XmlElement(name = "synonym")
protected List<SyntheticSynonymType> synonyms;
@XmlElementWrapper(name = "views")
@XmlElement(name = "view")
protected List<SyntheticViewType> views;
@ -164,6 +167,17 @@ public class SyntheticObjectsType implements Serializable, XMLAppendable
this.foreignKeys = foreignKeys;
}
public List<SyntheticSynonymType> getSynonyms() {
if (synonyms == null) {
synonyms = new ArrayList<SyntheticSynonymType>();
}
return synonyms;
}
public void setSynonyms(List<SyntheticSynonymType> synonyms) {
this.synonyms = synonyms;
}
public List<SyntheticViewType> getViews() {
if (views == null) {
views = new ArrayList<SyntheticViewType>();
@ -375,6 +389,27 @@ public class SyntheticObjectsType implements Serializable, XMLAppendable
return this;
}
public SyntheticObjectsType withSynonyms(SyntheticSynonymType... values) {
if (values!= null) {
for (SyntheticSynonymType value: values) {
getSynonyms().add(value);
}
}
return this;
}
public SyntheticObjectsType withSynonyms(Collection<SyntheticSynonymType> values) {
if (values!= null) {
getSynonyms().addAll(values);
}
return this;
}
public SyntheticObjectsType withSynonyms(List<SyntheticSynonymType> synonyms) {
setSynonyms(synonyms);
return this;
}
public SyntheticObjectsType withViews(SyntheticViewType... values) {
if (values!= null) {
for (SyntheticViewType value: values) {
@ -428,6 +463,7 @@ public class SyntheticObjectsType implements Serializable, XMLAppendable
builder.append("primaryKeys", "primaryKey", primaryKeys);
builder.append("uniqueKeys", "uniqueKey", uniqueKeys);
builder.append("foreignKeys", "foreignKey", foreignKeys);
builder.append("synonyms", "synonym", synonyms);
builder.append("views", "view", views);
builder.append("daos", "view", daos);
}
@ -532,6 +568,15 @@ public class SyntheticObjectsType implements Serializable, XMLAppendable
return false;
}
}
if (synonyms == null) {
if (other.synonyms!= null) {
return false;
}
} else {
if (!synonyms.equals(other.synonyms)) {
return false;
}
}
if (views == null) {
if (other.views!= null) {
return false;
@ -566,6 +611,7 @@ public class SyntheticObjectsType implements Serializable, XMLAppendable
result = ((prime*result)+((primaryKeys == null)? 0 :primaryKeys.hashCode()));
result = ((prime*result)+((uniqueKeys == null)? 0 :uniqueKeys.hashCode()));
result = ((prime*result)+((foreignKeys == null)? 0 :foreignKeys.hashCode()));
result = ((prime*result)+((synonyms == null)? 0 :synonyms.hashCode()));
result = ((prime*result)+((views == null)? 0 :views.hashCode()));
result = ((prime*result)+((daos == null)? 0 :daos.hashCode()));
return result;

View File

@ -0,0 +1,282 @@
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 SyntheticSynonymType complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="SyntheticSynonymType"&gt;
* &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;all&gt;
* &lt;element name="catalog" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
* &lt;element name="schema" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
* &lt;element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/&gt;
* &lt;element name="table" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
* &lt;element name="ignoreUnused" type="{http://www.w3.org/2001/XMLSchema}boolean" minOccurs="0"/&gt;
* &lt;/all&gt;
* &lt;/restriction&gt;
* &lt;/complexContent&gt;
* &lt;/complexType&gt;
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SyntheticSynonymType", propOrder = {
})
@SuppressWarnings({
"all"
})
public class SyntheticSynonymType implements Serializable, XMLAppendable
{
private final static long serialVersionUID = 32000L;
@XmlJavaTypeAdapter(StringAdapter.class)
protected String catalog;
@XmlJavaTypeAdapter(StringAdapter.class)
protected String schema;
@XmlElement(required = true)
@XmlJavaTypeAdapter(StringAdapter.class)
protected String name;
@XmlJavaTypeAdapter(StringAdapter.class)
protected String table;
@XmlElement(defaultValue = "false")
protected Boolean ignoreUnused = false;
/**
* The defining catalog of the synonym.
*
*/
public String getCatalog() {
return catalog;
}
/**
* The defining catalog of the synonym.
*
*/
public void setCatalog(String value) {
this.catalog = value;
}
/**
* The defining schema of the synonym.
*
*/
public String getSchema() {
return schema;
}
/**
* The defining schema of the synonym.
*
*/
public void setSchema(String value) {
this.schema = value;
}
/**
* The synonym name.
*
*/
public String getName() {
return name;
}
/**
* The synonym name.
*
*/
public void setName(String value) {
this.name = value;
}
/**
* A regular expression matching a table to which to apply this synthetic synonym.
*
*/
public String getTable() {
return table;
}
/**
* A regular expression matching a table to which to apply this synthetic synonym.
*
*/
public void setTable(String value) {
this.table = value;
}
/**
* Set this flag to true if no warning should be logged if this object was not used by a code generation run.
*
* @return
* possible object is
* {@link Boolean }
*
*/
public Boolean isIgnoreUnused() {
return ignoreUnused;
}
/**
* Set this flag to true if no warning should be logged if this object was not used by a code generation run.
*
* @param value
* allowed object is
* {@link Boolean }
*
*/
public void setIgnoreUnused(Boolean value) {
this.ignoreUnused = value;
}
/**
* The defining catalog of the synonym.
*
*/
public SyntheticSynonymType withCatalog(String value) {
setCatalog(value);
return this;
}
/**
* The defining schema of the synonym.
*
*/
public SyntheticSynonymType withSchema(String value) {
setSchema(value);
return this;
}
/**
* The synonym name.
*
*/
public SyntheticSynonymType withName(String value) {
setName(value);
return this;
}
/**
* A regular expression matching a table to which to apply this synthetic synonym.
*
*/
public SyntheticSynonymType withTable(String value) {
setTable(value);
return this;
}
/**
* Set this flag to true if no warning should be logged if this object was not used by a code generation run.
*
*/
public SyntheticSynonymType withIgnoreUnused(Boolean value) {
setIgnoreUnused(value);
return this;
}
@Override
public final void appendTo(XMLBuilder builder) {
builder.append("catalog", catalog);
builder.append("schema", schema);
builder.append("name", name);
builder.append("table", table);
builder.append("ignoreUnused", ignoreUnused);
}
@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;
}
SyntheticSynonymType other = ((SyntheticSynonymType) that);
if (catalog == null) {
if (other.catalog!= null) {
return false;
}
} else {
if (!catalog.equals(other.catalog)) {
return false;
}
}
if (schema == null) {
if (other.schema!= null) {
return false;
}
} else {
if (!schema.equals(other.schema)) {
return false;
}
}
if (name == null) {
if (other.name!= null) {
return false;
}
} else {
if (!name.equals(other.name)) {
return false;
}
}
if (table == null) {
if (other.table!= null) {
return false;
}
} else {
if (!table.equals(other.table)) {
return false;
}
}
if (ignoreUnused == null) {
if (other.ignoreUnused!= null) {
return false;
}
} else {
if (!ignoreUnused.equals(other.ignoreUnused)) {
return false;
}
}
return true;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = ((prime*result)+((catalog == null)? 0 :catalog.hashCode()));
result = ((prime*result)+((schema == null)? 0 :schema.hashCode()));
result = ((prime*result)+((name == null)? 0 :name.hashCode()));
result = ((prime*result)+((table == null)? 0 :table.hashCode()));
result = ((prime*result)+((ignoreUnused == null)? 0 :ignoreUnused.hashCode()));
return result;
}
}

View File

@ -1525,7 +1525,13 @@ This feature is available in the commercial distribution only.]]></jxb:javadoc><
<p>
This feature is available in the commercial distribution only.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="synonyms" type="tns:SyntheticSynonymsType" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Synthetic synonym configuration.
<p>
This feature is available in the commercial distribution only.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="views" type="tns:SyntheticViewsType" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Synthetic view configuration]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
@ -1827,6 +1833,39 @@ This feature is available in the commercial distribution only.]]></jxb:javadoc><
</sequence>
</complexType>
<complexType name="SyntheticSynonymsType">
<sequence>
<element name="synonym" type="tns:SyntheticSynonymType" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
<complexType name="SyntheticSynonymType">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Synthetic synonym configuration.
<p>
This feature is available in the commercial distribution only.]]></jxb:javadoc></jxb:property></appinfo></annotation>
<all>
<element name="catalog" type="string" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[The defining catalog of the synonym.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="schema" type="string" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[The defining schema of the synonym.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="name" type="string" minOccurs="1" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[The synonym name.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="table" type="string" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[A regular expression matching a table to which to apply this synthetic synonym.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="ignoreUnused" type="boolean" default="false" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Set this flag to true if no warning should be logged if this object was not used by a code generation run.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
</all>
</complexType>
<complexType name="SyntheticViewsType">
<sequence>
<element name="view" type="tns:SyntheticViewType" minOccurs="0" maxOccurs="unbounded"/>