From 5068b8e808bccf170293b5b9b9ebefc9d6821c74 Mon Sep 17 00:00:00 2001 From: Strong Liu Date: Mon, 9 Apr 2012 19:27:09 +0800 Subject: [PATCH] HHH-7195 Table does not handle quoted catalog --- .../java/org/hibernate/cfg/Configuration.java | 6 ++--- .../java/org/hibernate/mapping/Table.java | 26 +++++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java b/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java index 8a2cda8050..6891b495dc 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java @@ -2804,7 +2804,7 @@ public class Configuration implements Serializable { } public String getLogicalTableName(Table table) throws MappingException { - return getLogicalTableName( table.getQuotedSchema(), table.getCatalog(), table.getQuotedName() ); + return getLogicalTableName( table.getQuotedSchema(), table.getQuotedCatalog(), table.getQuotedName() ); } private String getLogicalTableName(String schema, String catalog, String physicalName) throws MappingException { @@ -2919,7 +2919,7 @@ public class Configuration implements Serializable { finalName = ( String ) binding.logicalToPhysical.get( logicalName ); } String key = buildTableNameKey( - currentTable.getQuotedSchema(), currentTable.getCatalog(), currentTable.getQuotedName() + currentTable.getQuotedSchema(), currentTable.getQuotedCatalog(), currentTable.getQuotedName() ); TableDescription description = ( TableDescription ) tableNameBinding.get( key ); if ( description != null ) { @@ -2948,7 +2948,7 @@ public class Configuration implements Serializable { logical = ( String ) binding.physicalToLogical.get( physicalName ); } String key = buildTableNameKey( - currentTable.getQuotedSchema(), currentTable.getCatalog(), currentTable.getQuotedName() + currentTable.getQuotedSchema(), currentTable.getQuotedCatalog(), currentTable.getQuotedName() ); description = ( TableDescription ) tableNameBinding.get( key ); if ( description != null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Table.java b/hibernate-core/src/main/java/org/hibernate/mapping/Table.java index 8d643060f8..f12e9745c3 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Table.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Table.java @@ -60,6 +60,7 @@ public class Table implements RelationalModel, Serializable { private final int uniqueInteger; private boolean quoted; private boolean schemaQuoted; + private boolean catalogQuoted; private static int tableCounter = 0; private List checkConstraints = new ArrayList(); private String rowId; @@ -117,7 +118,7 @@ public class Table implements RelationalModel, Serializable { getQuotedSchema( dialect ); String usedCatalog = catalog == null ? defaultCatalog : - catalog; + getQuotedCatalog( dialect ); return qualify( usedCatalog, usedSchema, quotedName ); } @@ -166,6 +167,18 @@ public class Table implements RelationalModel, Serializable { schema; } + public String getQuotedCatalog() { + return catalogQuoted ? + "`" + catalog + "`" : + catalog; + } + + public String getQuotedCatalog(Dialect dialect) { + return catalogQuoted ? + dialect.openQuote() + catalog + dialect.closeQuote() : + catalog; + } + public void setName(String name) { if ( name.charAt( 0 ) == '`' ) { quoted = true; @@ -651,7 +664,13 @@ public class Table implements RelationalModel, Serializable { } public void setCatalog(String catalog) { - this.catalog = catalog; + if ( catalog != null && catalog.charAt( 0 ) == '`' ) { + catalogQuoted = true; + this.catalog = catalog.substring( 1, catalog.length() - 1 ); + } + else { + this.catalog = catalog; + } } public int getUniqueInteger() { @@ -669,6 +688,9 @@ public class Table implements RelationalModel, Serializable { public boolean isSchemaQuoted() { return schemaQuoted; } + public boolean isCatalogQuoted() { + return catalogQuoted; + } public boolean isQuoted() { return quoted;