Author: max.andersen(a)jboss.com
Date: 2006-11-03 08:19:20 -0500 (Fri, 03 Nov 2006)
New Revision: 10702
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg/Configuration.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/tool/hbm2ddl/DatabaseMetadata.java
Log:
HHH-2208 Table schema use in DatabaseMetadata
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg/Configuration.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg/Configuration.java 2006-11-03
12:20:54 UTC (rev 10701)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg/Configuration.java 2006-11-03
13:19:20 UTC (rev 10702)
@@ -875,11 +875,12 @@
while ( iter.hasNext() ) {
Table table = (Table) iter.next();
if ( table.isPhysicalTable() ) {
-
+ Settings settings = buildSettings();
TableMetadata tableInfo = databaseMetadata.getTableMetadata(
table.getName(),
- table.getSchema(),
- table.getCatalog()
+ ( table.getSchema() == null ) ? settings.getDefaultSchemaName() :
table.getSchema(),
+ ( table.getCatalog() == null ) ? settings.getDefaultCatalogName() :
table.getCatalog()
+
);
if ( tableInfo == null ) {
script.add(
@@ -994,13 +995,12 @@
while ( iter.hasNext() ) {
Table table = (Table) iter.next();
if ( table.isPhysicalTable() ) {
+ Settings settings = buildSettings();
TableMetadata tableInfo = databaseMetadata.getTableMetadata(
table.getName(),
- table.getSchema(),
- table.getCatalog()
- );
-
+ ( table.getSchema() == null ) ? settings.getDefaultSchemaName() :
table.getSchema(),
+ ( table.getCatalog() == null ) ? settings.getDefaultCatalogName() :
table.getCatalog());
if ( tableInfo == null ) {
throw new HibernateException( "Missing table: " + table.getName() );
}
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/tool/hbm2ddl/DatabaseMetadata.java
===================================================================
---
branches/Branch_3_2/Hibernate3/src/org/hibernate/tool/hbm2ddl/DatabaseMetadata.java 2006-11-03
12:20:54 UTC (rev 10701)
+++
branches/Branch_3_2/Hibernate3/src/org/hibernate/tool/hbm2ddl/DatabaseMetadata.java 2006-11-03
13:19:20 UTC (rev 10702)
@@ -16,6 +16,7 @@
import org.hibernate.HibernateException;
import org.hibernate.exception.JDBCExceptionHelper;
import org.hibernate.exception.SQLExceptionConverter;
+import org.hibernate.mapping.Table;
import org.hibernate.dialect.Dialect;
import org.hibernate.util.StringHelper;
@@ -49,7 +50,8 @@
public TableMetadata getTableMetadata(String name, String schema, String catalog) throws
HibernateException {
- TableMetadata table = (TableMetadata) tables.get(name);
+ Object identifier = identifier(catalog, schema, name);
+ TableMetadata table = (TableMetadata) tables.get(identifier);
if (table!=null) {
return table;
}
@@ -83,7 +85,7 @@
String tableName = rs.getString("TABLE_NAME");
if ( name.equalsIgnoreCase(tableName) ) {
table = new TableMetadata(rs, meta, extras);
- tables.put(name, table);
+ tables.put(identifier, table);
return table;
}
}
@@ -107,6 +109,10 @@
}
+ private Object identifier(String catalog, String schema, String name) {
+ return Table.qualify(catalog,schema,name);
+ }
+
private void initSequences(Connection connection, Dialect dialect) throws SQLException
{
if ( dialect.supportsSequences() ) {
String sql = dialect.getQuerySequencesString();
@@ -132,7 +138,11 @@
}
public boolean isSequence(Object key) {
- return key instanceof String && sequences.contains( ( (String) key
).toLowerCase() );
+ if (key instanceof String){
+ String[] strings = StringHelper.split(".", (String) key);
+ return sequences.contains( ( (String) strings[strings.length-1] ).toLowerCase());
+ }
+ return false;
}
public boolean isTable(Object key) throws HibernateException {