From b862fd8d445ab013f06e6ad97cde6f754eb43292 Mon Sep 17 00:00:00 2001 From: Denis Bondarenko Date: Tue, 2 Oct 2012 13:24:59 +0300 Subject: [PATCH] fix for ticket 1857 --- .../src/main/java/org/jooq/SchemaMapping.java | 72 +++++++++---------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/SchemaMapping.java b/jOOQ/src/main/java/org/jooq/SchemaMapping.java index 88a6f0e9bb..f87d30ee14 100644 --- a/jOOQ/src/main/java/org/jooq/SchemaMapping.java +++ b/jOOQ/src/main/java/org/jooq/SchemaMapping.java @@ -100,8 +100,8 @@ public class SchemaMapping implements Serializable { private final RenderMapping mapping; private final boolean ignoreMapping; private final boolean renderSchema; - private transient Map schemata; - private transient Map> tables; + private transient Map schemata = new HashMap(); + private transient Map> tables = new HashMap>(); /** * Construct an empty mapping @@ -312,24 +312,28 @@ public class SchemaMapping implements Serializable { // Lazy initialise schema mapping if (!getSchemata().containsKey(schemaName)) { - Schema mapped = schema; + synchronized (this) { + if (!getSchemata().containsKey(schemaName)) { + Schema mapped = schema; - for (MappedSchema s : mapping.getSchemata()) { + for (MappedSchema s : mapping.getSchemata()) { - // A configured mapping was found, add a renamed schema - if (schemaName.equals(s.getInput())) { + // A configured mapping was found, add a renamed schema + if (schemaName.equals(s.getInput())) { - // Ignore self-mappings and void-mappings - if (!isBlank(s.getOutput()) && !s.getOutput().equals(s.getInput())) { - mapped = new RenamedSchema(schema, s.getOutput()); + // Ignore self-mappings and void-mappings + if (!isBlank(s.getOutput()) && !s.getOutput().equals(s.getInput())) { + mapped = new RenamedSchema(schema, s.getOutput()); + } + + break; + } } - break; + // Add mapped schema or self if no mapping was found + getSchemata().put(schemaName, mapped); } } - - // Add mapped schema or self if no mapping was found - getSchemata().put(schemaName, mapped); } result = getSchemata().get(schemaName); @@ -365,29 +369,33 @@ public class SchemaMapping implements Serializable { // Lazy initialise table mapping if (!getTables().containsKey(key)) { - Table mapped = table; + synchronized (this) { + if (!getTables().containsKey(key)) { + Table mapped = table; - schemaLoop: - for (MappedSchema s : mapping.getSchemata()) { - if (schemaName.equals(s.getInput())) { - for (MappedTable t : s.getTables()) { + schemaLoop: + for (MappedSchema s : mapping.getSchemata()) { + if (schemaName.equals(s.getInput())) { + for (MappedTable t : s.getTables()) { - // A configured mapping was found, add a renamed table - if (tableName.equals(t.getInput())) { + // A configured mapping was found, add a renamed table + if (tableName.equals(t.getInput())) { - // Ignore self-mappings and void-mappings - if (!isBlank(t.getOutput()) && !t.getOutput().equals(t.getInput())) { - mapped = new RenamedTable(table, t.getOutput()); + // Ignore self-mappings and void-mappings + if (!isBlank(t.getOutput()) && !t.getOutput().equals(t.getInput())) { + mapped = new RenamedTable(table, t.getOutput()); + } + + break schemaLoop; + } } - - break schemaLoop; } } + + // Add mapped table or self if no mapping was found + getTables().put(key, mapped); } } - - // Add mapped table or self if no mapping was found - getTables().put(key, mapped); } result = getTables().get(key); @@ -416,18 +424,10 @@ public class SchemaMapping implements Serializable { } private final Map getSchemata() { - if (schemata == null) { - schemata = new HashMap(); - } - return schemata; } private final Map> getTables() { - if (tables == null) { - tables = new HashMap>(); - } - return tables; }