[hibernate-commits] Hibernate SVN: r21106 - in core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate: tool/hbm2ddl and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Apr 16 12:21:45 EDT 2013


Author: brmeyer
Date: 2013-04-16 12:21:45 -0400 (Tue, 16 Apr 2013)
New Revision: 21106

Modified:
   core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/cfg/Environment.java
   core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tool/hbm2ddl/DatabaseMetadata.java
   core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdate.java
   core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaValidator.java
Log:
JBPAPP-10709 Hibernate SchemaValidation on synonyms

Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/cfg/Environment.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/cfg/Environment.java	2013-04-15 18:46:57 UTC (rev 21105)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/cfg/Environment.java	2013-04-16 16:21:45 UTC (rev 21106)
@@ -537,6 +537,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/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tool/hbm2ddl/DatabaseMetadata.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tool/hbm2ddl/DatabaseMetadata.java	2013-04-15 18:46:57 UTC (rev 21105)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tool/hbm2ddl/DatabaseMetadata.java	2013-04-16 16:21:45 UTC (rev 21106)
@@ -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/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdate.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdate.java	2013-04-15 18:46:57 UTC (rev 21105)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdate.java	2013-04-16 16:21:45 UTC (rev 21106)
@@ -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/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaValidator.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaValidator.java	2013-04-15 18:46:57 UTC (rev 21105)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaValidator.java	2013-04-16 16:21:45 UTC (rev 21106)
@@ -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 );



More information about the hibernate-commits mailing list