Author: steve.ebersole(a)jboss.com
Date: 2007-01-19 09:45:38 -0500 (Fri, 19 Jan 2007)
New Revision: 11063
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg/SettingsFactory.java
Log:
HHH-2372 : building settings w/o db connection
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg/SettingsFactory.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg/SettingsFactory.java 2007-01-19
14:45:23 UTC (rev 11062)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg/SettingsFactory.java 2007-01-19
14:45:38 UTC (rev 11063)
@@ -72,45 +72,54 @@
boolean metaReportsDDLCausesTxnCommit = false;
boolean metaReportsDDLInTxnSupported = true;
- try {
- Connection conn = connections.getConnection();
+ // 'hibernate.temp.use_jdbc_metadata_defaults' is a temporary magic value.
+ // The need for it is intended to be alleviated with 3.3 developement, thus it is
+ // not defined as an Environment constant...
+ // it is used to control whether we should consult the JDBC metadata to determine
+ // certain Settings default values; it is useful to *not* do this when the database
+ // may not be available (mainly in tools usage).
+ boolean useJdbcMetadata = PropertiesHelper.getBoolean(
"hibernate.temp.use_jdbc_metadata_defaults", props, true );
+ if ( useJdbcMetadata ) {
try {
- DatabaseMetaData meta = conn.getMetaData();
- databaseName = meta.getDatabaseProductName();
- databaseMajorVersion = getDatabaseMajorVersion(meta);
- log.info("RDBMS: " + databaseName + ", version: " +
meta.getDatabaseProductVersion() );
- log.info("JDBC driver: " + meta.getDriverName() + ", version: " +
meta.getDriverVersion() );
-
- metaSupportsScrollable =
meta.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE);
- metaSupportsBatchUpdates = meta.supportsBatchUpdates();
- metaReportsDDLCausesTxnCommit = meta.dataDefinitionCausesTransactionCommit();
- metaReportsDDLInTxnSupported = !meta.dataDefinitionIgnoredInTransactions();
-
- if ( Environment.jvmSupportsGetGeneratedKeys() ) {
- try {
- Boolean result = (Boolean)
DatabaseMetaData.class.getMethod("supportsGetGeneratedKeys", null)
- .invoke(meta, null);
- metaSupportsGetGeneratedKeys = result.booleanValue();
+ Connection conn = connections.getConnection();
+ try {
+ DatabaseMetaData meta = conn.getMetaData();
+ databaseName = meta.getDatabaseProductName();
+ databaseMajorVersion = getDatabaseMajorVersion(meta);
+ log.info("RDBMS: " + databaseName + ", version: " +
meta.getDatabaseProductVersion() );
+ log.info("JDBC driver: " + meta.getDriverName() + ", version: "
+ meta.getDriverVersion() );
+
+ metaSupportsScrollable =
meta.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE);
+ metaSupportsBatchUpdates = meta.supportsBatchUpdates();
+ metaReportsDDLCausesTxnCommit = meta.dataDefinitionCausesTransactionCommit();
+ metaReportsDDLInTxnSupported = !meta.dataDefinitionIgnoredInTransactions();
+
+ if ( Environment.jvmSupportsGetGeneratedKeys() ) {
+ try {
+ Boolean result = (Boolean)
DatabaseMetaData.class.getMethod("supportsGetGeneratedKeys", null)
+ .invoke(meta, null);
+ metaSupportsGetGeneratedKeys = result.booleanValue();
+ }
+ catch (AbstractMethodError ame) {
+ metaSupportsGetGeneratedKeys = false;
+ }
+ catch (Exception e) {
+ metaSupportsGetGeneratedKeys = false;
+ }
}
- catch (AbstractMethodError ame) {
- metaSupportsGetGeneratedKeys = false;
- }
- catch (Exception e) {
- metaSupportsGetGeneratedKeys = false;
- }
+
}
-
+ finally {
+ connections.closeConnection(conn);
+ }
}
- finally {
- connections.closeConnection(conn);
+ catch (SQLException sqle) {
+ log.warn("Could not obtain connection metadata", sqle);
}
+ catch (UnsupportedOperationException uoe) {
+ // user supplied JDBC connections
+ }
}
- catch (SQLException sqle) {
- log.warn("Could not obtain connection metadata", sqle);
- }
- catch (UnsupportedOperationException uoe) {
- // user supplied JDBC connections
- }
settings.setDataDefinitionImplicitCommit( metaReportsDDLCausesTxnCommit );
settings.setDataDefinitionInTransactionSupported( metaReportsDDLInTxnSupported );