- [#2032] Fully qualify all jOOQ-meta Definitions with catalogs - [#4796] Add Setting to turn off rendering catalog at runtime
This commit is contained in:
parent
7037298c0d
commit
314cedcf40
@ -46,7 +46,6 @@ import static org.jooq.util.AbstractDatabase.getDefinition;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -77,7 +76,12 @@ extends AbstractDefinition {
|
||||
|
||||
@Override
|
||||
public final List<Definition> getDefinitionPath() {
|
||||
return Arrays.<Definition>asList(getSchema(), this);
|
||||
List<Definition> result = new ArrayList<Definition>();
|
||||
|
||||
result.addAll(getSchema().getDefinitionPath());
|
||||
result.add(this);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected final List<E> getElements() {
|
||||
|
||||
@ -42,7 +42,6 @@ package org.jooq.util;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.jooq.tools.JooqLogger;
|
||||
@ -63,7 +62,12 @@ public abstract class AbstractPackageDefinition extends AbstractDefinition imple
|
||||
|
||||
@Override
|
||||
public List<Definition> getDefinitionPath() {
|
||||
return Arrays.<Definition>asList(getSchema(), this);
|
||||
List<Definition> result = new ArrayList<Definition>();
|
||||
|
||||
result.addAll(getSchema().getDefinitionPath());
|
||||
result.add(this);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -43,7 +43,6 @@ package org.jooq.util;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -84,12 +83,14 @@ public abstract class AbstractRoutineDefinition extends AbstractDefinition imple
|
||||
|
||||
@Override
|
||||
public List<Definition> getDefinitionPath() {
|
||||
if (pkg != null) {
|
||||
return Arrays.<Definition>asList(getSchema(), pkg, this);
|
||||
}
|
||||
else {
|
||||
return Arrays.<Definition>asList(getSchema(), this);
|
||||
}
|
||||
List<Definition> result = new ArrayList<Definition>();
|
||||
result.addAll(getSchema().getDefinitionPath());
|
||||
|
||||
if (pkg != null)
|
||||
result.add(pkg);
|
||||
|
||||
result.add(this);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void init() {
|
||||
|
||||
@ -40,7 +40,7 @@
|
||||
*/
|
||||
package org.jooq.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DefaultArrayDefinition extends AbstractDefinition implements ArrayDefinition {
|
||||
@ -56,7 +56,12 @@ public class DefaultArrayDefinition extends AbstractDefinition implements ArrayD
|
||||
|
||||
@Override
|
||||
public List<Definition> getDefinitionPath() {
|
||||
return Arrays.<Definition> asList(getSchema(), this);
|
||||
List<Definition> result = new ArrayList<Definition>();
|
||||
|
||||
result.addAll(getSchema().getDefinitionPath());
|
||||
result.add(this);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -40,7 +40,7 @@
|
||||
*/
|
||||
package org.jooq.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DefaultCheckConstraintDefinition extends AbstractDefinition implements CheckConstraintDefinition {
|
||||
@ -57,7 +57,12 @@ public class DefaultCheckConstraintDefinition extends AbstractDefinition impleme
|
||||
|
||||
@Override
|
||||
public List<Definition> getDefinitionPath() {
|
||||
return Arrays.<Definition>asList(getSchema(), this);
|
||||
List<Definition> result = new ArrayList<Definition>();
|
||||
|
||||
result.addAll(getSchema().getDefinitionPath());
|
||||
result.add(this);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -61,7 +61,12 @@ public class DefaultDomainDefinition extends AbstractDefinition implements Domai
|
||||
|
||||
@Override
|
||||
public List<Definition> getDefinitionPath() {
|
||||
return Arrays.<Definition>asList(getSchema(), this);
|
||||
List<Definition> result = new ArrayList<Definition>();
|
||||
|
||||
result.addAll(getSchema().getDefinitionPath());
|
||||
result.add(this);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void addCheckClause(String checkClause) {
|
||||
|
||||
@ -65,7 +65,12 @@ public class DefaultEnumDefinition extends AbstractDefinition implements EnumDef
|
||||
|
||||
@Override
|
||||
public List<Definition> getDefinitionPath() {
|
||||
return Arrays.<Definition>asList(getSchema(), this);
|
||||
List<Definition> result = new ArrayList<Definition>();
|
||||
|
||||
result.addAll(getSchema().getDefinitionPath());
|
||||
result.add(this);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void addLiteral(String literal) {
|
||||
|
||||
@ -41,7 +41,6 @@
|
||||
package org.jooq.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@ -64,7 +63,12 @@ public class DefaultForeignKeyDefinition extends AbstractDefinition implements F
|
||||
|
||||
@Override
|
||||
public List<Definition> getDefinitionPath() {
|
||||
return Arrays.<Definition>asList(getSchema(), this);
|
||||
List<Definition> result = new ArrayList<Definition>();
|
||||
|
||||
result.addAll(getSchema().getDefinitionPath());
|
||||
result.add(this);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -41,7 +41,6 @@
|
||||
package org.jooq.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class DefaultUniqueKeyDefinition extends AbstractDefinition implements UniqueKeyDefinition {
|
||||
@ -67,7 +66,12 @@ public class DefaultUniqueKeyDefinition extends AbstractDefinition implements Un
|
||||
|
||||
@Override
|
||||
public List<Definition> getDefinitionPath() {
|
||||
return Arrays.<Definition>asList(getSchema(), this);
|
||||
List<Definition> result = new ArrayList<Definition>();
|
||||
|
||||
result.addAll(getSchema().getDefinitionPath());
|
||||
result.add(this);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -110,6 +110,10 @@ public class SchemaMapping implements Serializable {
|
||||
return SettingsTools.getRenderMapping(configuration.settings());
|
||||
}
|
||||
|
||||
private final boolean renderCatalog() {
|
||||
return Boolean.TRUE.equals(configuration.settings().isRenderCatalog());
|
||||
}
|
||||
|
||||
private final boolean renderSchema() {
|
||||
return Boolean.TRUE.equals(configuration.settings().isRenderSchema());
|
||||
}
|
||||
@ -262,6 +266,26 @@ public class SchemaMapping implements Serializable {
|
||||
table.setOutput(outputTable);
|
||||
}
|
||||
|
||||
public Catalog map(Catalog catalog) {
|
||||
|
||||
// [#1774] [#4795] The default Settings render schema flag takes
|
||||
// precedence over the DefaultConfiguration's ignoreMapping flag!
|
||||
if (!renderCatalog()) return null;
|
||||
|
||||
Catalog result = catalog;
|
||||
if (result != null) {
|
||||
String catalogName = result.getName();
|
||||
|
||||
// [#2089] DefaultCatalog has an empty schema name
|
||||
if (StringUtils.isEmpty(catalogName))
|
||||
return null;
|
||||
|
||||
// [#4793] TODO implement runtime catalog mapping
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply mapping to a given schema
|
||||
*
|
||||
|
||||
@ -102,11 +102,9 @@ public class SchemaImpl extends AbstractQueryPart implements Schema {
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
Catalog mappedCatalog = getCatalog();
|
||||
// [#4793] TODO: Support this
|
||||
// Utils.getMappedCatalog(ctx.configuration(), getCatalog());
|
||||
Catalog mappedCatalog = Utils.getMappedCatalog(ctx.configuration(), getCatalog());
|
||||
|
||||
if (ctx.qualifyCatalog() && mappedCatalog != null && !StringUtils.isBlank(mappedCatalog.getName())) {
|
||||
if (ctx.qualifyCatalog() && mappedCatalog != null) {
|
||||
ctx.visit(mappedCatalog);
|
||||
ctx.sql('.');
|
||||
}
|
||||
|
||||
@ -101,6 +101,7 @@ import javax.persistence.Id;
|
||||
import org.jooq.Attachable;
|
||||
import org.jooq.AttachableInternal;
|
||||
import org.jooq.BindContext;
|
||||
import org.jooq.Catalog;
|
||||
import org.jooq.Clause;
|
||||
import org.jooq.Condition;
|
||||
import org.jooq.Configuration;
|
||||
@ -1795,6 +1796,21 @@ final class Utils {
|
||||
target.changed.set(targetIndex, source.changed(sourceIndex));
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a {@link Catalog} according to the configured {@link org.jooq.SchemaMapping}
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
static final Catalog getMappedCatalog(Configuration configuration, Catalog catalog) {
|
||||
org.jooq.SchemaMapping mapping = configuration.schemaMapping();
|
||||
|
||||
if (mapping != null) {
|
||||
return mapping.map(catalog);
|
||||
}
|
||||
else {
|
||||
return catalog;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a {@link Schema} according to the configured {@link org.jooq.SchemaMapping}
|
||||
*/
|
||||
|
||||
@ -9,7 +9,15 @@
|
||||
|
||||
<complexType name="Settings">
|
||||
<all>
|
||||
<!-- Whether any catalog name should be rendered at all.
|
||||
Use this for single-catalog environments, or when all objects are made
|
||||
available using synonyms -->
|
||||
<element name="renderCatalog" type="boolean" minOccurs="0" maxOccurs="1" default="true"/>
|
||||
|
||||
<!-- Whether any schema name should be rendered at all.
|
||||
|
||||
Setting this to false also implicitly sets "renderCatalog" to false.
|
||||
|
||||
Use this for single-schema environments, or when all objects are made
|
||||
available using synonyms -->
|
||||
<element name="renderSchema" type="boolean" minOccurs="0" maxOccurs="1" default="true"/>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user