diff --git a/jOOQ/src/main/java/org/jooq/RenamedTable.java b/jOOQ/src/main/java/org/jooq/RenamedTable.java index 8cd90138d8..acb53a6839 100644 --- a/jOOQ/src/main/java/org/jooq/RenamedTable.java +++ b/jOOQ/src/main/java/org/jooq/RenamedTable.java @@ -42,14 +42,14 @@ import org.jooq.impl.TableImpl; * * @author Lukas Eder */ -class RenamedTable extends TableImpl { +class RenamedTable extends TableImpl { /** * Generated UID */ private static final long serialVersionUID = -309012919785933903L; - RenamedTable(Table delegate, String rename) { + RenamedTable(Table delegate, String rename) { super(rename, delegate.getSchema()); for (Field field : delegate.fields()) { diff --git a/jOOQ/src/main/java/org/jooq/SchemaMapping.java b/jOOQ/src/main/java/org/jooq/SchemaMapping.java index 11496ef433..f89c8a2f65 100644 --- a/jOOQ/src/main/java/org/jooq/SchemaMapping.java +++ b/jOOQ/src/main/java/org/jooq/SchemaMapping.java @@ -362,9 +362,10 @@ public class SchemaMapping implements Serializable { * @param table The generated table to be mapped * @return The configured table */ - public Table map(Table table) { + @SuppressWarnings("unchecked") + public Table map(Table table) { if (ignoreMapping) return table; - Table result = null; + Table result = null; if (table != null) { Schema schema = table.getSchema(); @@ -383,7 +384,7 @@ public class SchemaMapping implements Serializable { // want to use Factory and dependent objects in a "thread-safe" manner synchronized (this) { if (!getTables().containsKey(key)) { - Table mapped = table; + Table mapped = table; schemaLoop: for (MappedSchema s : mapping.getSchemata()) { @@ -395,7 +396,7 @@ public class SchemaMapping implements Serializable { // Ignore self-mappings and void-mappings if (!isBlank(t.getOutput()) && !t.getOutput().equals(t.getInput())) { - mapped = new RenamedTable(table, t.getOutput()); + mapped = new RenamedTable(table, t.getOutput()); } break schemaLoop; @@ -410,7 +411,7 @@ public class SchemaMapping implements Serializable { } } - result = getTables().get(key); + result = (Table) getTables().get(key); } return result; diff --git a/jOOQ/src/main/java/org/jooq/impl/Executor.java b/jOOQ/src/main/java/org/jooq/impl/Executor.java index 9f102ca2ce..181dd86653 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Executor.java +++ b/jOOQ/src/main/java/org/jooq/impl/Executor.java @@ -437,6 +437,34 @@ public class Executor implements Configuration { configuration.setExecuteListeners(listeners); } + /** + * Map a schema to another one. + *

+ * This will map a schema onto another one, depending on configured schema + * mapping in this Executor. If no applicable schema mapping + * can be found, the schema itself is returned. + * + * @param schema A schema + * @return The mapped schema + */ + public final Schema map(Schema schema) { + return Utils.getMappedSchema(this, schema); + } + + /** + * Map a table to another one. + *

+ * This will map a table onto another one, depending on configured table + * mapping in this Executor. If no applicable table mapping + * can be found, the table itself is returned. + * + * @param table A table + * @return The mapped table + */ + public final Table map(Table table) { + return Utils.getMappedTable(this, table); + } + // ------------------------------------------------------------------------- // XXX Convenience methods accessing the underlying Connection // ------------------------------------------------------------------------- diff --git a/jOOQ/src/main/java/org/jooq/impl/Utils.java b/jOOQ/src/main/java/org/jooq/impl/Utils.java index dad9c9111e..10390063ce 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Utils.java +++ b/jOOQ/src/main/java/org/jooq/impl/Utils.java @@ -993,7 +993,7 @@ final class Utils { * Map a {@link Table} according to the configured {@link org.jooq.SchemaMapping} */ @SuppressWarnings("deprecation") - static final Table getMappedTable(Configuration configuration, Table table) { + static final Table getMappedTable(Configuration configuration, Table table) { org.jooq.SchemaMapping mapping = configuration.getSchemaMapping(); if (mapping != null) {