Author: brmeyer
Date: 2013-05-29 10:36:36 -0400 (Wed, 29 May 2013)
New Revision: 21124
Modified:
core/patches/hibernate-3.3.2.GA_CP04_JBPAPP-10707/core/src/main/java/org/hibernate/cfg/Environment.java
core/patches/hibernate-3.3.2.GA_CP04_JBPAPP-10707/core/src/main/java/org/hibernate/tool/hbm2ddl/DatabaseMetadata.java
core/patches/hibernate-3.3.2.GA_CP04_JBPAPP-10707/core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdate.java
core/patches/hibernate-3.3.2.GA_CP04_JBPAPP-10707/core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaValidator.java
Log:
HHH-8183 Also support synonyms for schema validation
Modified:
core/patches/hibernate-3.3.2.GA_CP04_JBPAPP-10707/core/src/main/java/org/hibernate/cfg/Environment.java
===================================================================
---
core/patches/hibernate-3.3.2.GA_CP04_JBPAPP-10707/core/src/main/java/org/hibernate/cfg/Environment.java 2013-05-29
14:18:30 UTC (rev 21123)
+++
core/patches/hibernate-3.3.2.GA_CP04_JBPAPP-10707/core/src/main/java/org/hibernate/cfg/Environment.java 2013-05-29
14:36:36 UTC (rev 21124)
@@ -523,6 +523,14 @@
public static final String BYTECODE_PROVIDER = "hibernate.bytecode.provider";
public static final String JPAQL_STRICT_COMPLIANCE=
"hibernate.query.jpaql_strict_compliance";
+
+ /**
+ * If enabled, allows {@link org.hibernate.tool.hbm2ddl.DatabaseMetadata} to
+ * support synonyms during schema update and validations. Due to the
+ * possibility that this would return duplicate tables (especially in
+ * Oracle), this is disabled by default.
+ */
+ public static final String ENABLE_SYNONYMS = "hibernate.synonyms";
private static final BytecodeProvider BYTECODE_PROVIDER_INSTANCE;
private static final boolean ENABLE_BINARY_STREAMS;
Modified:
core/patches/hibernate-3.3.2.GA_CP04_JBPAPP-10707/core/src/main/java/org/hibernate/tool/hbm2ddl/DatabaseMetadata.java
===================================================================
---
core/patches/hibernate-3.3.2.GA_CP04_JBPAPP-10707/core/src/main/java/org/hibernate/tool/hbm2ddl/DatabaseMetadata.java 2013-05-29
14:18:30 UTC (rev 21123)
+++
core/patches/hibernate-3.3.2.GA_CP04_JBPAPP-10707/core/src/main/java/org/hibernate/tool/hbm2ddl/DatabaseMetadata.java 2013-05-29
14:36:36 UTC (rev 21124)
@@ -35,10 +35,13 @@
import java.util.Set;
import org.hibernate.HibernateException;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
import org.hibernate.dialect.Dialect;
import org.hibernate.exception.JDBCExceptionHelper;
import org.hibernate.exception.SQLExceptionConverter;
import org.hibernate.mapping.Table;
+import org.hibernate.util.PropertiesHelper;
import org.hibernate.util.StringHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -57,20 +60,52 @@
private DatabaseMetaData meta;
private SQLExceptionConverter sqlExceptionConverter;
+
+ private final String[] types;
- public DatabaseMetadata(Connection connection, Dialect dialect) throws SQLException {
- this(connection, dialect, true);
+ /**
+ * @deprecated Use
+ * {@link #DatabaseMetadata(Connection, Dialect, Configuration)}
+ * instead
+ */
+ @Deprecated
+ public DatabaseMetadata(Connection connection, Dialect dialect)
+ throws SQLException {
+ this(connection, dialect, null, true);
}
- public DatabaseMetadata(Connection connection, Dialect dialect, boolean extras) throws
SQLException {
+ /**
+ * @deprecated Use
+ * {@link #DatabaseMetadata(Connection, Dialect, Configuration, boolean)}
+ * instead
+ */
+ @Deprecated
+ public DatabaseMetadata(Connection connection, Dialect dialect,
+ boolean extras) throws SQLException {
+ this(connection, dialect, null, extras);
+ }
+
+ public DatabaseMetadata(Connection connection, Dialect dialect,
+ Configuration config) throws SQLException {
+ this(connection, dialect, config, true);
+ }
+
+ public DatabaseMetadata(Connection connection, Dialect dialect,
+ Configuration config, boolean extras) throws SQLException {
sqlExceptionConverter = dialect.buildSQLExceptionConverter();
meta = connection.getMetaData();
this.extras = extras;
initSequences(connection, dialect);
+ if (config != null
+ && PropertiesHelper.getBoolean(
+ Environment.ENABLE_SYNONYMS,
+ config.getProperties(), false)) {
+ types = new String[] { "TABLE", "VIEW", "SYNONYM" };
+ } else {
+ types = new String[] { "TABLE", "VIEW" };
+ }
}
- private static final String[] TYPES = {"TABLE", "VIEW"};
-
public TableMetadata getTableMetadata(String name, String schema, String catalog,
boolean isQuoted) throws HibernateException {
Object identifier = identifier(catalog, schema, name);
@@ -84,14 +119,14 @@
ResultSet rs = null;
try {
if ( (isQuoted && meta.storesMixedCaseQuotedIdentifiers())) {
- rs = meta.getTables(catalog, schema, name, TYPES);
+ rs = meta.getTables(catalog, schema, name, types);
} else if ( (isQuoted && meta.storesUpperCaseQuotedIdentifiers())
|| (!isQuoted && meta.storesUpperCaseIdentifiers() )) {
rs = meta.getTables(
StringHelper.toUpperCase(catalog),
StringHelper.toUpperCase(schema),
StringHelper.toUpperCase(name),
- TYPES
+ types
);
}
else if ( (isQuoted && meta.storesLowerCaseQuotedIdentifiers())
@@ -100,11 +135,11 @@
StringHelper.toLowerCase(catalog),
StringHelper.toLowerCase(schema),
StringHelper.toLowerCase(name),
- TYPES
+ types
);
}
else {
- rs = meta.getTables(catalog, schema, name, TYPES);
+ rs = meta.getTables(catalog, schema, name, types);
}
while ( rs.next() ) {
Modified:
core/patches/hibernate-3.3.2.GA_CP04_JBPAPP-10707/core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdate.java
===================================================================
---
core/patches/hibernate-3.3.2.GA_CP04_JBPAPP-10707/core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdate.java 2013-05-29
14:18:30 UTC (rev 21123)
+++
core/patches/hibernate-3.3.2.GA_CP04_JBPAPP-10707/core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdate.java 2013-05-29
14:36:36 UTC (rev 21124)
@@ -167,7 +167,7 @@
log.info( "fetching database metadata" );
connectionHelper.prepare( true );
connection = connectionHelper.getConnection();
- meta = new DatabaseMetadata( connection, dialect );
+ meta = new DatabaseMetadata( connection, dialect, configuration );
stmt = connection.createStatement();
}
catch ( SQLException sqle ) {
Modified:
core/patches/hibernate-3.3.2.GA_CP04_JBPAPP-10707/core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaValidator.java
===================================================================
---
core/patches/hibernate-3.3.2.GA_CP04_JBPAPP-10707/core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaValidator.java 2013-05-29
14:18:30 UTC (rev 21123)
+++
core/patches/hibernate-3.3.2.GA_CP04_JBPAPP-10707/core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaValidator.java 2013-05-29
14:36:36 UTC (rev 21124)
@@ -129,7 +129,7 @@
log.info( "fetching database metadata" );
connectionHelper.prepare( false );
connection = connectionHelper.getConnection();
- meta = new DatabaseMetadata( connection, dialect, false );
+ meta = new DatabaseMetadata( connection, dialect, configuration, false );
}
catch ( SQLException sqle ) {
log.error( "could not get database metadata", sqle );