boolean metaSupportsScrollable = false;
boolean metaSupportsGetGeneratedKeys = false;
boolean metaSupportsBatchUpdates = false;
boolean metaReportsDDLCausesTxnCommit = false;
boolean metaReportsDDLInTxnSupported = true;
Dialect dialect = null;
JdbcSupport jdbcSupport = null;
// 'hibernate.temp.use_jdbc_metadata_defaults' is a temporary magic value.
// The need for it is intended to be alleviated with future 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 {
Connection conn = connections.getConnection();
try {
DatabaseMetaData meta = conn.getMetaData();
log.info( "RDBMS: " + meta.getDatabaseProductName() + ", version: " + meta.getDatabaseProductVersion() );
log.info( "JDBC driver: " + meta.getDriverName() + ", version: " + meta.getDriverVersion() );
dialect = DialectFactory.buildDialect( props, conn );
jdbcSupport = JdbcSupportLoader.loadJdbcSupport( conn );
metaSupportsScrollable = meta.supportsResultSetType( ResultSet.TYPE_SCROLL_INSENSITIVE );
metaSupportsBatchUpdates = meta.supportsBatchUpdates();
metaReportsDDLCausesTxnCommit = meta.dataDefinitionCausesTransactionCommit();
metaReportsDDLInTxnSupported = !meta.dataDefinitionIgnoredInTransactions();
metaSupportsGetGeneratedKeys = meta.supportsGetGeneratedKeys();
}
catch ( SQLException sqle ) {
log.warn( "Could not obtain connection metadata", sqle );
}
finally {
connections.closeConnection( conn );
}
}
catch ( SQLException sqle ) {
log.warn( "Could not obtain connection to query metadata", sqle );
dialect = DialectFactory.buildDialect( props );
}
catch ( UnsupportedOperationException uoe ) {
// user supplied JDBC connections
dialect = DialectFactory.buildDialect( props );
}
}
else {
dialect = DialectFactory.buildDialect( props );
}
settings.setDataDefinitionImplicitCommit( metaReportsDDLCausesTxnCommit );
settings.setDataDefinitionInTransactionSupported( metaReportsDDLInTxnSupported );
settings.setDialect( dialect );
if ( jdbcSupport == null ) {
jdbcSupport = JdbcSupportLoader.loadJdbcSupport( null );
}
settings.setJdbcSupport( jdbcSupport );
//use dialect default properties
final Properties properties = new Properties();
properties.putAll( dialect.getDefaultProperties() );
properties.putAll( props );
// Transaction settings:
TransactionFactory transactionFactory = createTransactionFactory(properties);