From b4ed7a1813fbf8b97da2c90a0c0383174615739e Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Wed, 2 Oct 2024 14:30:31 +0200 Subject: [PATCH] [jOOQ/jOOQ#15335] Support synonym export/import in InformationSchema XML --- .../java/org/jooq/codegen/XMLGenerator.java | 16 ++++ .../main/kotlin/org/jooq/kotlin/Extensions.kt | 11 +++ .../java/org/jooq/meta/xml/XMLDatabase.java | 32 +++++++ .../main/java/org/jooq/impl/AbstractMeta.java | 2 +- .../jooq/impl/InformationSchemaExport.java | 56 +++++++++++- .../jooq/impl/InformationSchemaMetaImpl.java | 87 +++++++++++++++++++ .../jooq/util/xml/jaxb/InformationSchema.java | 47 ++++++++++ .../org/jooq/util/xml/jaxb/ObjectFactory.java | 8 ++ .../org/jooq/xsd/jooq-meta-3.20.0.xsd | 20 +++++ 9 files changed, 277 insertions(+), 2 deletions(-) diff --git a/jOOQ-codegen/src/main/java/org/jooq/codegen/XMLGenerator.java b/jOOQ-codegen/src/main/java/org/jooq/codegen/XMLGenerator.java index 5940c7fa77..b892f6002a 100644 --- a/jOOQ-codegen/src/main/java/org/jooq/codegen/XMLGenerator.java +++ b/jOOQ-codegen/src/main/java/org/jooq/codegen/XMLGenerator.java @@ -65,6 +65,7 @@ import org.jooq.meta.ParameterDefinition; import org.jooq.meta.RoutineDefinition; import org.jooq.meta.SchemaDefinition; import org.jooq.meta.SequenceDefinition; +// ... import org.jooq.meta.TableDefinition; // ... import org.jooq.meta.UniqueKeyDefinition; @@ -86,6 +87,7 @@ import org.jooq.util.xml.jaxb.Routine; import org.jooq.util.xml.jaxb.RoutineType; import org.jooq.util.xml.jaxb.Schema; import org.jooq.util.xml.jaxb.Sequence; +import org.jooq.util.xml.jaxb.Synonym; import org.jooq.util.xml.jaxb.Table; import org.jooq.util.xml.jaxb.TableConstraint; import org.jooq.util.xml.jaxb.TableType; @@ -428,6 +430,20 @@ public class XMLGenerator extends AbstractGenerator { + + + + + + + + + + + + + + diff --git a/jOOQ-kotlin/src/main/kotlin/org/jooq/kotlin/Extensions.kt b/jOOQ-kotlin/src/main/kotlin/org/jooq/kotlin/Extensions.kt index c267af9ce1..8a7ee15c74 100644 --- a/jOOQ-kotlin/src/main/kotlin/org/jooq/kotlin/Extensions.kt +++ b/jOOQ-kotlin/src/main/kotlin/org/jooq/kotlin/Extensions.kt @@ -805,6 +805,17 @@ fun MutableList.trigger(block: org.jooq.util.xml add(e) } +fun InformationSchema.synonyms(block: MutableList.() -> Unit) { + block(synonyms) +} + +@JvmName("mutableListSynonym") +fun MutableList.synonym(block: org.jooq.util.xml.jaxb.Synonym.() -> Unit) { + val e = org.jooq.util.xml.jaxb.Synonym() + block(e) + add(e) +} + // [jooq-tools] END [information-schema] // ---------------------------------------------------------------------------- diff --git a/jOOQ-meta/src/main/java/org/jooq/meta/xml/XMLDatabase.java b/jOOQ-meta/src/main/java/org/jooq/meta/xml/XMLDatabase.java index a4db5b85dd..afaa48273a 100644 --- a/jOOQ-meta/src/main/java/org/jooq/meta/xml/XMLDatabase.java +++ b/jOOQ-meta/src/main/java/org/jooq/meta/xml/XMLDatabase.java @@ -100,6 +100,7 @@ import org.jooq.meta.DefaultIndexColumnDefinition; import org.jooq.meta.DefaultRelations; import org.jooq.meta.DefaultSequenceDefinition; // ... +// ... import org.jooq.meta.DomainDefinition; import org.jooq.meta.EnumDefinition; import org.jooq.meta.IndexColumnDefinition; @@ -108,6 +109,7 @@ import org.jooq.meta.PackageDefinition; import org.jooq.meta.RoutineDefinition; import org.jooq.meta.SchemaDefinition; import org.jooq.meta.SequenceDefinition; +// ... import org.jooq.meta.TableDefinition; // ... import org.jooq.meta.UDTDefinition; @@ -125,6 +127,7 @@ import org.jooq.util.xml.jaxb.ReferentialConstraint; import org.jooq.util.xml.jaxb.Routine; import org.jooq.util.xml.jaxb.Schema; import org.jooq.util.xml.jaxb.Sequence; +import org.jooq.util.xml.jaxb.Synonym; import org.jooq.util.xml.jaxb.Table; import org.jooq.util.xml.jaxb.TableConstraint; import org.jooq.util.xml.jaxb.TableConstraintType; @@ -625,6 +628,35 @@ public class XMLDatabase extends AbstractDatabase { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractMeta.java b/jOOQ/src/main/java/org/jooq/impl/AbstractMeta.java index 7ad0aa5f22..fef08793dc 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractMeta.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractMeta.java @@ -828,7 +828,7 @@ abstract class AbstractMeta extends AbstractScope implements Meta, Serializable // correct results @Override public /* non-final */ InformationSchema informationSchema() { - return InformationSchemaExport.exportCatalogs(configuration(), getCatalogs()); + return InformationSchemaExport.export(configuration(), this); } final Table lookupTable(Table table) { diff --git a/jOOQ/src/main/java/org/jooq/impl/InformationSchemaExport.java b/jOOQ/src/main/java/org/jooq/impl/InformationSchemaExport.java index d51e7209bd..d54d2b86e3 100644 --- a/jOOQ/src/main/java/org/jooq/impl/InformationSchemaExport.java +++ b/jOOQ/src/main/java/org/jooq/impl/InformationSchemaExport.java @@ -59,15 +59,16 @@ import org.jooq.Field; import org.jooq.ForeignKey; import org.jooq.Index; import org.jooq.Key; +import org.jooq.Meta; import org.jooq.Param; import org.jooq.Qualified; import org.jooq.Schema; import org.jooq.Sequence; import org.jooq.SortField; import org.jooq.SortOrder; +// ... import org.jooq.Table; import org.jooq.UniqueKey; -import org.jooq.impl.QOM.GenerationOption; import org.jooq.util.xml.jaxb.CheckConstraint; import org.jooq.util.xml.jaxb.Column; import org.jooq.util.xml.jaxb.IndexColumnUsage; @@ -139,6 +140,17 @@ final class InformationSchemaExport { exportSequence0(configuration, result, q); } + return result; + } + + static final InformationSchema export(Configuration configuration, Meta meta) { + InformationSchema result = exportCatalogs(configuration, meta.getCatalogs()); + + + + + + return result; } @@ -165,6 +177,11 @@ final class InformationSchemaExport { for (Sequence q : s.getSequences()) exportSequence0(configuration, result, q); + + + + + } } @@ -265,6 +282,43 @@ final class InformationSchemaExport { result.getSequences().add(iq); } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + private static final void exportCatalog0(InformationSchema result, Catalog c) { org.jooq.util.xml.jaxb.Catalog ic = new org.jooq.util.xml.jaxb.Catalog(); diff --git a/jOOQ/src/main/java/org/jooq/impl/InformationSchemaMetaImpl.java b/jOOQ/src/main/java/org/jooq/impl/InformationSchemaMetaImpl.java index 5a7de1e725..6a897532d5 100644 --- a/jOOQ/src/main/java/org/jooq/impl/InformationSchemaMetaImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/InformationSchemaMetaImpl.java @@ -80,6 +80,7 @@ import org.jooq.Schema; import org.jooq.Sequence; import org.jooq.SortField; import org.jooq.Statement; +// ... import org.jooq.Table; import org.jooq.TableField; import org.jooq.TableOptions; @@ -129,6 +130,11 @@ final class InformationSchemaMetaImpl extends AbstractMeta { + + + + + InformationSchemaMetaImpl(Configuration configuration, InformationSchema source) { super(configuration); @@ -155,6 +161,11 @@ final class InformationSchemaMetaImpl extends AbstractMeta { + + + + + init(source); } @@ -599,6 +610,48 @@ final class InformationSchemaMetaImpl extends AbstractMeta { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -639,6 +692,9 @@ final class InformationSchemaMetaImpl extends AbstractMeta { + + + if (!errors.isEmpty()) throw new IllegalArgumentException(errors.toString()); } @@ -713,6 +769,18 @@ final class InformationSchemaMetaImpl extends AbstractMeta { + + + + + + + + + + + + @@ -763,6 +831,11 @@ final class InformationSchemaMetaImpl extends AbstractMeta { + + + + + } private static final class InformationSchemaTable extends TableImpl { @@ -827,6 +900,20 @@ final class InformationSchemaMetaImpl extends AbstractMeta { + + + + + + + + + + + + + + diff --git a/jOOQ/src/main/java/org/jooq/util/xml/jaxb/InformationSchema.java b/jOOQ/src/main/java/org/jooq/util/xml/jaxb/InformationSchema.java index f83f5cf369..b68145d09e 100644 --- a/jOOQ/src/main/java/org/jooq/util/xml/jaxb/InformationSchema.java +++ b/jOOQ/src/main/java/org/jooq/util/xml/jaxb/InformationSchema.java @@ -43,6 +43,7 @@ import org.jooq.util.jaxb.tools.XMLBuilder; * <element name="parameters" type="{http://www.jooq.org/xsd/jooq-meta-3.20.0.xsd}Parameters" minOccurs="0"/> * <element name="element_types" type="{http://www.jooq.org/xsd/jooq-meta-3.20.0.xsd}ElementTypes" minOccurs="0"/> * <element name="triggers" type="{http://www.jooq.org/xsd/jooq-meta-3.20.0.xsd}Triggers" minOccurs="0"/> + * <element name="synonyms" type="{http://www.jooq.org/xsd/jooq-meta-3.20.0.xsd}Synonyms" minOccurs="0"/> * </all> * </restriction> * </complexContent> @@ -117,6 +118,9 @@ public class InformationSchema implements Serializable, XMLAppendable @XmlElementWrapper(name = "triggers") @XmlElement(name = "trigger") protected List triggers; + @XmlElementWrapper(name = "synonyms") + @XmlElement(name = "synonym") + protected List synonyms; public List getCatalogs() { if (catalogs == null) { @@ -316,6 +320,17 @@ public class InformationSchema implements Serializable, XMLAppendable this.triggers = triggers; } + public List getSynonyms() { + if (synonyms == null) { + synonyms = new ArrayList(); + } + return synonyms; + } + + public void setSynonyms(List synonyms) { + this.synonyms = synonyms; + } + public InformationSchema withCatalogs(Catalog... values) { if (values!= null) { for (Catalog value: values) { @@ -694,6 +709,27 @@ public class InformationSchema implements Serializable, XMLAppendable return this; } + public InformationSchema withSynonyms(Synonym... values) { + if (values!= null) { + for (Synonym value: values) { + getSynonyms().add(value); + } + } + return this; + } + + public InformationSchema withSynonyms(Collection values) { + if (values!= null) { + getSynonyms().addAll(values); + } + return this; + } + + public InformationSchema withSynonyms(List synonyms) { + setSynonyms(synonyms); + return this; + } + @Override public final void appendTo(XMLBuilder builder) { builder.append("catalogs", "catalog", catalogs); @@ -714,6 +750,7 @@ public class InformationSchema implements Serializable, XMLAppendable builder.append("parameters", "parameter", parameters); builder.append("element_types", "element_type", elementTypes); builder.append("triggers", "trigger", triggers); + builder.append("synonyms", "synonym", synonyms); } @Override @@ -897,6 +934,15 @@ public class InformationSchema implements Serializable, XMLAppendable return false; } } + if (synonyms == null) { + if (other.synonyms!= null) { + return false; + } + } else { + if (!synonyms.equals(other.synonyms)) { + return false; + } + } return true; } @@ -922,6 +968,7 @@ public class InformationSchema implements Serializable, XMLAppendable result = ((prime*result)+((parameters == null)? 0 :parameters.hashCode())); result = ((prime*result)+((elementTypes == null)? 0 :elementTypes.hashCode())); result = ((prime*result)+((triggers == null)? 0 :triggers.hashCode())); + result = ((prime*result)+((synonyms == null)? 0 :synonyms.hashCode())); return result; } diff --git a/jOOQ/src/main/java/org/jooq/util/xml/jaxb/ObjectFactory.java b/jOOQ/src/main/java/org/jooq/util/xml/jaxb/ObjectFactory.java index fc37ff6079..47735f4faa 100644 --- a/jOOQ/src/main/java/org/jooq/util/xml/jaxb/ObjectFactory.java +++ b/jOOQ/src/main/java/org/jooq/util/xml/jaxb/ObjectFactory.java @@ -181,4 +181,12 @@ public class ObjectFactory { return new Trigger(); } + /** + * Create an instance of {@link Synonym } + * + */ + public Synonym createSynonym() { + return new Synonym(); + } + } diff --git a/jOOQ/src/main/resources/org/jooq/xsd/jooq-meta-3.20.0.xsd b/jOOQ/src/main/resources/org/jooq/xsd/jooq-meta-3.20.0.xsd index ff731d9c59..6f4fc8f200 100644 --- a/jOOQ/src/main/resources/org/jooq/xsd/jooq-meta-3.20.0.xsd +++ b/jOOQ/src/main/resources/org/jooq/xsd/jooq-meta-3.20.0.xsd @@ -25,6 +25,7 @@ + @@ -400,6 +401,25 @@ + + + + + + + + + + + + + + + + + + +