use of org.jooq.conf.MappedCatalog in project jOOQ by jOOQ.
the class SchemaMapping method map.
/**
* Apply mapping to a given table
*
* @param table The generated table to be mapped
* @return The configured table
*/
@SuppressWarnings("unchecked")
@Nullable
public <R extends Record> Table<R> map(Table<R> table) {
Table<R> result = table;
// [#4652] Don't initialise table mapping if not necessary
if (result != null && (!mapping().getSchemata().isEmpty() || !mapping().getCatalogs().isEmpty())) {
Catalog catalog = result.getCatalog();
Schema schema = result.getSchema();
// [#1186] TODO: replace this by calling table.getQualifiedName()
if (catalog == null)
catalog = DSL.catalog(name(""));
if (schema == null)
schema = schema(name(""));
String catalogName = catalog.getName();
String schemaName = schema.getName();
String tableName = result.getName();
String key = StringUtils.isEmpty(catalogName) ? (StringUtils.isEmpty(schemaName) ? tableName : (schemaName + "." + tableName)) : (catalogName + '.' + schemaName + '.' + tableName);
// Lazy initialise table mapping
if (!getTables().containsKey(key)) {
// want to use Configuration and dependent objects in a "thread-safe" manner
synchronized (this) {
if (!getTables().containsKey(key)) {
catalogLoop: for (MappedCatalog c : mapping().getCatalogs()) {
if (matches(c, catalogName)) {
for (MappedSchema s : c.getSchemata()) {
if (matches(s, schemaName)) {
for (MappedTable t : s.getTables()) {
// A configured mapping was found, add a renamed table
if (matches(t, tableName)) {
// Ignore self-mappings and void-mappings
if (!isBlank(t.getOutput()))
if (t.getInput() != null && !t.getOutput().equals(tableName))
result = new RenamedTable<>(map(schema), result, t.getOutput());
else if (t.getInputExpression() != null)
result = new RenamedTable<>(map(schema), result, t.getInputExpression().matcher(tableName).replaceAll(t.getOutput()));
break catalogLoop;
}
}
}
}
// [#7498] Even without table mapping configuration, we may still need to map the schema
result = new RenamedTable<>(map(schema), result, tableName);
break catalogLoop;
}
}
if (!(result instanceof RenamedTable))
schemaLoop: for (MappedSchema s : mapping().getSchemata()) {
if (matches(s, schemaName)) {
for (MappedTable t : s.getTables()) {
// A configured mapping was found, add a renamed table
if (matches(t, tableName)) {
// Ignore self-mappings and void-mappings
if (!isBlank(t.getOutput()))
if (t.getInput() != null && !t.getOutput().equals(tableName))
result = new RenamedTable<>(map(schema), result, t.getOutput());
else if (t.getInputExpression() != null)
result = new RenamedTable<>(map(schema), result, t.getInputExpression().matcher(tableName).replaceAll(t.getOutput()));
break schemaLoop;
}
}
// [#7498] Even without table mapping configuration, we may still need to map the schema
result = new RenamedTable<>(map(schema), result, tableName);
break schemaLoop;
}
}
// Add mapped table or self if no mapping was found
getTables().put(key, result);
}
}
}
result = (Table<R>) getTables().get(key);
}
return result;
}
use of org.jooq.conf.MappedCatalog in project jOOQ by jOOQ.
the class SchemaMapping method map.
/**
* Apply mapping to a given schema
*
* @param schema The schema to be mapped
* @return The configured schema
*/
@Nullable
public Schema map(Schema schema) {
// The DefaultConfiguration's ignoreMapping flag!
if (!renderSchema())
return null;
else // [#9708] Don't map an already mapped schema again
if (schema instanceof RenamedSchema)
return schema;
Schema result = schema;
RenderMapping m = mapping();
// [#4642] Don't initialise schema mapping if not necessary
if (!m.getSchemata().isEmpty() || !m.getCatalogs().isEmpty() || !isEmpty(m.getDefaultSchema()) || !isEmpty(m.getDefaultCatalog())) {
if (result == null)
result = schema(name(""));
Catalog catalog = result.getCatalog();
if (catalog == null)
catalog = DSL.catalog(name(""));
// [#2089] DefaultSchema has an empty schema name
// [#7498] But we're mapping those names as well
String catalogName = catalog.getName();
String schemaName = result.getName();
String key = StringUtils.isEmpty(catalogName) ? schemaName : catalogName + '.' + schemaName;
// Lazy initialise schema mapping
if (!getSchemata().containsKey(key)) {
// want to use a Configuration and dependent objects in a "thread-safe" manner
synchronized (this) {
if (!getSchemata().containsKey(key)) {
catalogLoop: for (MappedCatalog c : m.getCatalogs()) {
if (matches(c, catalogName)) {
for (MappedSchema s : c.getSchemata()) {
if (matches(s, schemaName)) {
// Ignore self-mappings and void-mappings
if (!isBlank(s.getOutput()))
if (s.getInput() != null && !s.getOutput().equals(schemaName))
result = new RenamedSchema(map(catalog), result, s.getOutput());
else if (s.getInputExpression() != null)
result = new RenamedSchema(map(catalog), result, s.getInputExpression().matcher(schemaName).replaceAll(s.getOutput()));
break catalogLoop;
}
}
// [#7498] Even without schema mapping configuration, we may still need to map the catalog
result = new RenamedSchema(map(catalog), result, schemaName);
break catalogLoop;
}
}
if (!(result instanceof RenamedSchema)) {
for (MappedSchema s : m.getSchemata()) {
// A configured mapping was found, add a renamed schema
if (matches(s, schemaName)) {
// Ignore self-mappings and void-mappings
if (!isBlank(s.getOutput()))
if (s.getInput() != null && !s.getOutput().equals(schemaName))
result = new RenamedSchema(map(catalog), result, s.getOutput());
else if (s.getInputExpression() != null)
result = new RenamedSchema(map(catalog), result, s.getInputExpression().matcher(schemaName).replaceAll(s.getOutput()));
break;
}
}
}
// [#13034] Apply defaultCatalog irrespective of defaultSchema and the above mappings
if (result.getCatalog() != null && map(result.getCatalog()) == null)
result = new RenamedSchema(null, result, result.getName());
// [#13035] Cache the application of the defaultSchema
if ("".equals(result.getName()))
result = null;
else if (result.getName().equals(m.getDefaultSchema()) && (result.getCatalog() == null || "".equals(result.getCatalog().getName()) || result.getCatalog().getName().equals(m.getDefaultCatalog())))
result = null;
// Add mapped schema or self if no mapping was found
getSchemata().put(key, result);
}
}
}
result = getSchemata().get(key);
}
return result;
}
use of org.jooq.conf.MappedCatalog in project jOOQ by jOOQ.
the class SchemaMapping method map.
@Nullable
public Catalog map(Catalog catalog) {
// precedence over the DefaultConfiguration's ignoreMapping flag!
if (!renderCatalog())
return null;
else // Don't map an already mapped catalog again
if (catalog instanceof RenamedCatalog)
return catalog;
Catalog result = catalog;
if (result == null)
result = DSL.catalog(name(""));
// [#2089] DefaultCatalog has an empty schema name
// But we're mapping those names as well
String catalogName = result.getName();
// [#4642] Don't initialise catalog mapping if not necessary
RenderMapping m = mapping();
if (!m.getCatalogs().isEmpty() || !isEmpty(m.getDefaultCatalog())) {
// Lazy initialise catalog mapping
if (!getCatalogs().containsKey(catalogName)) {
// want to use a Configuration and dependent objects in a "thread-safe" manner
synchronized (this) {
if (!getCatalogs().containsKey(catalogName)) {
for (MappedCatalog c : m.getCatalogs()) {
// A configured mapping was found, add a renamed catalog
if (matches(c, catalogName)) {
// Ignore self-mappings and void-mappings
if (!isBlank(c.getOutput()))
if (c.getInput() != null && !c.getOutput().equals(catalogName))
result = new RenamedCatalog(result, c.getOutput());
else if (c.getInputExpression() != null)
result = new RenamedCatalog(result, c.getInputExpression().matcher(catalogName).replaceAll(c.getOutput()));
break;
}
}
// [#13035] Cache the application of the defaultCatalog
if ("".equals(result.getName()) || result.getName().equals(m.getDefaultCatalog()))
result = null;
// Add mapped catalog or self if no mapping was found
getCatalogs().put(catalogName, result);
}
}
}
result = getCatalogs().get(catalogName);
}
return result;
}
Aggregations