[#7163] Add Settings.parseWithMetaLookups
This commit is contained in:
parent
b5a645a5ff
commit
685a2924e2
47
jOOQ/src/main/java/org/jooq/conf/ParseWithMetaLookups.java
Normal file
47
jOOQ/src/main/java/org/jooq/conf/ParseWithMetaLookups.java
Normal file
@ -0,0 +1,47 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
package org.jooq.conf;
|
||||
|
||||
import javax.xml.bind.annotation.XmlEnum;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Java class for ParseWithMetaLookups.
|
||||
*
|
||||
* <p>The following schema fragment specifies the expected content contained within this class.
|
||||
* <p>
|
||||
* <pre>
|
||||
* <simpleType name="ParseWithMetaLookups">
|
||||
* <restriction base="{http://www.w3.org/2001/XMLSchema}string">
|
||||
* <enumeration value="OFF"/>
|
||||
* <enumeration value="IGNORE_ON_FAILURE"/>
|
||||
* <enumeration value="THROW_ON_FAILURE"/>
|
||||
* </restriction>
|
||||
* </simpleType>
|
||||
* </pre>
|
||||
*
|
||||
*/
|
||||
@XmlType(name = "ParseWithMetaLookups")
|
||||
@XmlEnum
|
||||
public enum ParseWithMetaLookups {
|
||||
|
||||
OFF,
|
||||
IGNORE_ON_FAILURE,
|
||||
THROW_ON_FAILURE;
|
||||
|
||||
public String value() {
|
||||
return name();
|
||||
}
|
||||
|
||||
public static ParseWithMetaLookups fromValue(String v) {
|
||||
return valueOf(v);
|
||||
}
|
||||
|
||||
}
|
||||
@ -112,6 +112,9 @@ public class Settings
|
||||
@XmlElement(defaultValue = "LOG_DEBUG")
|
||||
@XmlSchemaType(name = "string")
|
||||
protected ExecuteWithoutWhere executeDeleteWithoutWhere = ExecuteWithoutWhere.LOG_DEBUG;
|
||||
@XmlElement(defaultValue = "IGNORE_ON_FAILURE")
|
||||
@XmlSchemaType(name = "string")
|
||||
protected ParseWithMetaLookups parseWithMetaLookups = ParseWithMetaLookups.IGNORE_ON_FAILURE;
|
||||
|
||||
/**
|
||||
* Whether any catalog name should be rendered at all.
|
||||
@ -992,6 +995,30 @@ public class Settings
|
||||
this.executeDeleteWithoutWhere = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* [#7163] Whether the parser should perform meta lookups in the Configuration's MetaProvider.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link ParseWithMetaLookups }
|
||||
*
|
||||
*/
|
||||
public ParseWithMetaLookups getParseWithMetaLookups() {
|
||||
return parseWithMetaLookups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the parseWithMetaLookups property.
|
||||
*
|
||||
* @param value
|
||||
* allowed object is
|
||||
* {@link ParseWithMetaLookups }
|
||||
*
|
||||
*/
|
||||
public void setParseWithMetaLookups(ParseWithMetaLookups value) {
|
||||
this.parseWithMetaLookups = value;
|
||||
}
|
||||
|
||||
public Settings withRenderCatalog(Boolean value) {
|
||||
setRenderCatalog(value);
|
||||
return this;
|
||||
@ -1167,4 +1194,9 @@ public class Settings
|
||||
return this;
|
||||
}
|
||||
|
||||
public Settings withParseWithMetaLookups(ParseWithMetaLookups value) {
|
||||
setParseWithMetaLookups(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
116
jOOQ/src/main/java/org/jooq/impl/CatalogMetaImpl.java
Normal file
116
jOOQ/src/main/java/org/jooq/impl/CatalogMetaImpl.java
Normal file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Other licenses:
|
||||
* -----------------------------------------------------------------------------
|
||||
* Commercial licenses for this work are available. These replace the above
|
||||
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
|
||||
* database integrations.
|
||||
*
|
||||
* For more information, please visit: http://www.jooq.org/licenses
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.jooq.Catalog;
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.Meta;
|
||||
import org.jooq.Schema;
|
||||
import org.jooq.Sequence;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.UniqueKey;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
final class CatalogMetaImpl implements Meta {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final Configuration configuration;
|
||||
private final Catalog[] catalogs;
|
||||
|
||||
CatalogMetaImpl(Configuration configuration, Catalog[] catalogs) {
|
||||
this.configuration = configuration;
|
||||
this.catalogs = catalogs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<Catalog> getCatalogs() {
|
||||
return Collections.unmodifiableList(Arrays.asList(catalogs));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<Schema> getSchemas() {
|
||||
List<Schema> result = new ArrayList<Schema>();
|
||||
|
||||
for (Catalog catalog : catalogs)
|
||||
result.addAll(catalog.getSchemas());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<Table<?>> getTables() {
|
||||
List<Table<?>> result = new ArrayList<Table<?>>();
|
||||
|
||||
for (Catalog catalog : catalogs)
|
||||
for (Schema schema : catalog.getSchemas())
|
||||
result.addAll(schema.getTables());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<Sequence<?>> getSequences() {
|
||||
List<Sequence<?>> result = new ArrayList<Sequence<?>>();
|
||||
|
||||
for (Catalog catalog : catalogs)
|
||||
for (Schema schema : catalog.getSchemas())
|
||||
result.addAll(schema.getSequences());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<UniqueKey<?>> getPrimaryKeys() {
|
||||
List<UniqueKey<?>> result = new ArrayList<UniqueKey<?>>();
|
||||
|
||||
for (Catalog catalog : catalogs)
|
||||
for (Schema schema : catalog.getSchemas())
|
||||
for (Table<?> table : schema.getTables())
|
||||
if (table.getPrimaryKey() != null)
|
||||
result.add(table.getPrimaryKey());
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
65
jOOQ/src/main/java/org/jooq/impl/CatalogMetaProvider.java
Normal file
65
jOOQ/src/main/java/org/jooq/impl/CatalogMetaProvider.java
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Other licenses:
|
||||
* -----------------------------------------------------------------------------
|
||||
* Commercial licenses for this work are available. These replace the above
|
||||
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
|
||||
* database integrations.
|
||||
*
|
||||
* For more information, please visit: http://www.jooq.org/licenses
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import org.jooq.Catalog;
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.Meta;
|
||||
import org.jooq.MetaProvider;
|
||||
|
||||
/**
|
||||
* A {@link MetaProvider} that provides its meta data based on (possibly
|
||||
* generated) catalogs.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public class CatalogMetaProvider implements MetaProvider {
|
||||
|
||||
private final Configuration configuration;
|
||||
private final Catalog[] catalogs;
|
||||
|
||||
public CatalogMetaProvider(Configuration configuration, Catalog... catalogs) {
|
||||
this.configuration = configuration;
|
||||
this.catalogs = catalogs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Meta provide() {
|
||||
return new CatalogMetaImpl(configuration, catalogs);
|
||||
}
|
||||
}
|
||||
@ -410,17 +410,17 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
|
||||
|
||||
@Override
|
||||
public Meta meta(Catalog... catalogs) {
|
||||
return null;
|
||||
return new CatalogMetaImpl(configuration(), catalogs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Meta meta(Schema... schemas) {
|
||||
return null;
|
||||
return new SchemaMetaImpl(configuration(), schemas);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Meta meta(Table<?>... tables) {
|
||||
return null;
|
||||
return new TableMetaImpl(configuration(), tables);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Other licenses:
|
||||
* -----------------------------------------------------------------------------
|
||||
* Commercial licenses for this work are available. These replace the above
|
||||
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
|
||||
* database integrations.
|
||||
*
|
||||
* For more information, please visit: http://www.jooq.org/licenses
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.Meta;
|
||||
import org.jooq.MetaProvider;
|
||||
import org.jooq.util.xml.jaxb.InformationSchema;
|
||||
|
||||
/**
|
||||
* A {@link MetaProvider} that provides its meta data based on JAXB-annotated
|
||||
* {@link InformationSchema} meta information.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public class InformationSchemaMetaProvider implements MetaProvider {
|
||||
|
||||
private final Configuration configuration;
|
||||
private final InformationSchema schema;
|
||||
|
||||
public InformationSchemaMetaProvider(Configuration configuration, InformationSchema schema) {
|
||||
this.configuration = configuration;
|
||||
this.schema = schema;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Meta provide() {
|
||||
return new InformationSchemaMetaImpl(configuration, schema);
|
||||
}
|
||||
}
|
||||
@ -39,6 +39,8 @@ package org.jooq.impl;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.jooq.conf.ParseWithMetaLookups.IGNORE_ON_FAILURE;
|
||||
import static org.jooq.conf.ParseWithMetaLookups.THROW_ON_FAILURE;
|
||||
import static org.jooq.impl.DSL.abs;
|
||||
import static org.jooq.impl.DSL.acos;
|
||||
import static org.jooq.impl.DSL.arrayAgg;
|
||||
@ -316,6 +318,7 @@ import org.jooq.MergeFinalStep;
|
||||
import org.jooq.MergeMatchedStep;
|
||||
import org.jooq.MergeNotMatchedStep;
|
||||
import org.jooq.MergeUsingStep;
|
||||
import org.jooq.Meta;
|
||||
import org.jooq.Name;
|
||||
import org.jooq.OrderedAggregateFunction;
|
||||
import org.jooq.OrderedAggregateFunctionOfDeferredType;
|
||||
@ -365,6 +368,7 @@ import org.jooq.WindowSpecification;
|
||||
import org.jooq.WindowSpecificationOrderByStep;
|
||||
import org.jooq.WindowSpecificationRowsAndStep;
|
||||
import org.jooq.WindowSpecificationRowsStep;
|
||||
import org.jooq.conf.ParseWithMetaLookups;
|
||||
import org.jooq.tools.reflect.Reflect;
|
||||
|
||||
/**
|
||||
@ -373,10 +377,14 @@ import org.jooq.tools.reflect.Reflect;
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
final class ParserImpl implements Parser {
|
||||
|
||||
private final DSLContext dsl;
|
||||
private final DSLContext dsl;
|
||||
private final ParseWithMetaLookups metaLookups;
|
||||
private final Meta meta;
|
||||
|
||||
ParserImpl(Configuration configuration) {
|
||||
this.dsl = DSL.using(configuration);
|
||||
this.metaLookups = configuration.settings().getParseWithMetaLookups();
|
||||
this.meta = metaLookups == IGNORE_ON_FAILURE || metaLookups == THROW_ON_FAILURE ? dsl.meta() : null;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
116
jOOQ/src/main/java/org/jooq/impl/SchemaMetaImpl.java
Normal file
116
jOOQ/src/main/java/org/jooq/impl/SchemaMetaImpl.java
Normal file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Other licenses:
|
||||
* -----------------------------------------------------------------------------
|
||||
* Commercial licenses for this work are available. These replace the above
|
||||
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
|
||||
* database integrations.
|
||||
*
|
||||
* For more information, please visit: http://www.jooq.org/licenses
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jooq.Catalog;
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.Meta;
|
||||
import org.jooq.Schema;
|
||||
import org.jooq.Sequence;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.UniqueKey;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
final class SchemaMetaImpl implements Meta {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final Configuration configuration;
|
||||
private final Schema[] schemas;
|
||||
|
||||
SchemaMetaImpl(Configuration configuration, Schema[] schemas) {
|
||||
this.configuration = configuration;
|
||||
this.schemas = schemas;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<Catalog> getCatalogs() {
|
||||
Set<Catalog> result = new LinkedHashSet<Catalog>();
|
||||
|
||||
for (Schema schema : schemas)
|
||||
if (schema.getCatalog() != null)
|
||||
result.add(schema.getCatalog());
|
||||
|
||||
return new ArrayList<Catalog>(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<Schema> getSchemas() {
|
||||
return Collections.unmodifiableList(Arrays.asList(schemas));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<Table<?>> getTables() {
|
||||
List<Table<?>> result = new ArrayList<Table<?>>();
|
||||
|
||||
for (Schema schema : schemas)
|
||||
result.addAll(schema.getTables());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<Sequence<?>> getSequences() {
|
||||
List<Sequence<?>> result = new ArrayList<Sequence<?>>();
|
||||
|
||||
for (Schema schema : schemas)
|
||||
result.addAll(schema.getSequences());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<UniqueKey<?>> getPrimaryKeys() {
|
||||
List<UniqueKey<?>> result = new ArrayList<UniqueKey<?>>();
|
||||
|
||||
for (Schema schema : schemas)
|
||||
for (Table<?> table : schema.getTables())
|
||||
if (table.getPrimaryKey() != null)
|
||||
result.add(table.getPrimaryKey());
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
65
jOOQ/src/main/java/org/jooq/impl/SchemaMetaProvider.java
Normal file
65
jOOQ/src/main/java/org/jooq/impl/SchemaMetaProvider.java
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Other licenses:
|
||||
* -----------------------------------------------------------------------------
|
||||
* Commercial licenses for this work are available. These replace the above
|
||||
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
|
||||
* database integrations.
|
||||
*
|
||||
* For more information, please visit: http://www.jooq.org/licenses
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.Meta;
|
||||
import org.jooq.MetaProvider;
|
||||
import org.jooq.Schema;
|
||||
|
||||
/**
|
||||
* A {@link MetaProvider} that provides its meta data based on (possibly
|
||||
* generated) schemas.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public class SchemaMetaProvider implements MetaProvider {
|
||||
|
||||
private final Configuration configuration;
|
||||
private final Schema[] schemas;
|
||||
|
||||
public SchemaMetaProvider(Configuration configuration, Schema... schemas) {
|
||||
this.configuration = configuration;
|
||||
this.schemas = schemas;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Meta provide() {
|
||||
return new SchemaMetaImpl(configuration, schemas);
|
||||
}
|
||||
}
|
||||
112
jOOQ/src/main/java/org/jooq/impl/TableMetaImpl.java
Normal file
112
jOOQ/src/main/java/org/jooq/impl/TableMetaImpl.java
Normal file
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Other licenses:
|
||||
* -----------------------------------------------------------------------------
|
||||
* Commercial licenses for this work are available. These replace the above
|
||||
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
|
||||
* database integrations.
|
||||
*
|
||||
* For more information, please visit: http://www.jooq.org/licenses
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jooq.Catalog;
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.Meta;
|
||||
import org.jooq.Schema;
|
||||
import org.jooq.Sequence;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.UniqueKey;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
final class TableMetaImpl implements Meta {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final Configuration configuration;
|
||||
private final Table<?>[] tables;
|
||||
|
||||
TableMetaImpl(Configuration configuration, Table<?>[] tables) {
|
||||
this.configuration = configuration;
|
||||
this.tables = tables;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<Catalog> getCatalogs() {
|
||||
Set<Catalog> result = new LinkedHashSet<Catalog>();
|
||||
|
||||
for (Table<?> table : tables)
|
||||
if (table.getSchema() != null)
|
||||
if (table.getSchema().getCatalog() != null)
|
||||
result.add(table.getSchema().getCatalog());
|
||||
|
||||
return new ArrayList<Catalog>(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<Schema> getSchemas() {
|
||||
Set<Schema> result = new LinkedHashSet<Schema>();
|
||||
|
||||
for (Table<?> table : tables)
|
||||
if (table.getSchema() != null)
|
||||
result.add(table.getSchema());
|
||||
|
||||
return new ArrayList<Schema>(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<Table<?>> getTables() {
|
||||
return Collections.unmodifiableList(Arrays.asList(tables));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<Sequence<?>> getSequences() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<UniqueKey<?>> getPrimaryKeys() {
|
||||
List<UniqueKey<?>> result = new ArrayList<UniqueKey<?>>();
|
||||
|
||||
for (Table<?> table : tables)
|
||||
if (table.getPrimaryKey() != null)
|
||||
result.add(table.getPrimaryKey());
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
65
jOOQ/src/main/java/org/jooq/impl/TableMetaProvider.java
Normal file
65
jOOQ/src/main/java/org/jooq/impl/TableMetaProvider.java
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Other licenses:
|
||||
* -----------------------------------------------------------------------------
|
||||
* Commercial licenses for this work are available. These replace the above
|
||||
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
|
||||
* database integrations.
|
||||
*
|
||||
* For more information, please visit: http://www.jooq.org/licenses
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.Meta;
|
||||
import org.jooq.MetaProvider;
|
||||
import org.jooq.Table;
|
||||
|
||||
/**
|
||||
* A {@link MetaProvider} that provides its meta data based on (possibly
|
||||
* generated) schemas.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public class TableMetaProvider implements MetaProvider {
|
||||
|
||||
private final Configuration configuration;
|
||||
private final Table<?>[] tables;
|
||||
|
||||
public TableMetaProvider(Configuration configuration, Table<?>... tables) {
|
||||
this.configuration = configuration;
|
||||
this.tables = tables;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Meta provide() {
|
||||
return new TableMetaImpl(configuration, tables);
|
||||
}
|
||||
}
|
||||
@ -190,6 +190,10 @@ jOOQ queries, for which no specific fetchSize value was specified.]]></jxb:javad
|
||||
<element name="executeDeleteWithoutWhere" type="jooq-runtime:ExecuteWithoutWhere" minOccurs="0" maxOccurs="1" default="LOG_DEBUG">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[[#6771] Specifies whether DELETE statements are allowed to be executed lacking a WHERE clause. This has no effect on rendering the statements SQL string.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
|
||||
<element name="parseWithMetaLookups" type="jooq-runtime:ParseWithMetaLookups" minOccurs="0" maxOccurs="1" default="IGNORE_ON_FAILURE">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[[#7163] Whether the parser should perform meta lookups in the Configuration's MetaProvider.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
</all>
|
||||
</complexType>
|
||||
|
||||
@ -448,4 +452,18 @@ Either <input/> or <inputExpression/> must be provided]]></jxb:javadoc></j
|
||||
<enumeration value="THROW"/>
|
||||
</restriction>
|
||||
</simpleType>
|
||||
|
||||
<simpleType name="ParseWithMetaLookups">
|
||||
<restriction base="string">
|
||||
|
||||
<!-- Meta lookups are deactivated in parser -->
|
||||
<enumeration value="OFF"/>
|
||||
|
||||
<!-- Meta lookups are active in parser, but don't throw exceptions on failure -->
|
||||
<enumeration value="IGNORE_ON_FAILURE"/>
|
||||
|
||||
<!-- Meta lookups are active in parser and throw exceptions on failure -->
|
||||
<enumeration value="THROW_ON_FAILURE"/>
|
||||
</restriction>
|
||||
</simpleType>
|
||||
</schema>
|
||||
Loading…
Reference in New Issue
Block a user