Example usage for org.hibernate.engine.jdbc.dialect.spi DialectFactory buildDialect

List of usage examples for org.hibernate.engine.jdbc.dialect.spi DialectFactory buildDialect

Introduction

In this page you can find the example usage for org.hibernate.engine.jdbc.dialect.spi DialectFactory buildDialect.

Prototype

public Dialect buildDialect(Map configValues, DialectResolutionInfoSource resolutionInfoSource)
        throws HibernateException;

Source Link

Document

Builds an appropriate Dialect instance.

Usage

From source file:org.grails.orm.hibernate.support.HibernateDialectDetectorFactoryBean.java

License:Apache License

public void afterPropertiesSet() throws MetaDataAccessException {
    Assert.notNull(dataSource, "Data source is not set!");
    Assert.notNull(vendorNameDialectMappings, "Vendor name/dialect mappings are not set!");

    Connection connection = null;

    String dbName = (String) JdbcUtils.extractDatabaseMetaData(dataSource, "getDatabaseProductName");

    try {//www . j  av  a2s  .com
        connection = DataSourceUtils.getConnection(dataSource);

        try {
            final DialectFactory dialectFactory = createDialectFactory();
            final Connection finalConnection = connection;
            DialectResolutionInfoSource infoSource = new DialectResolutionInfoSource() {
                @Override
                public DialectResolutionInfo getDialectResolutionInfo() {
                    try {
                        return new DatabaseMetaDataDialectResolutionInfoAdapter(finalConnection.getMetaData());
                    } catch (SQLException e) {
                        throw new CouldNotDetermineHibernateDialectException(
                                "Could not determine Hibernate dialect", e);
                    }
                }
            };
            hibernateDialect = dialectFactory.buildDialect(hibernateProperties, infoSource);
            hibernateDialectClassName = hibernateDialect.getClass().getName();
        } catch (HibernateException e) {
            hibernateDialectClassName = vendorNameDialectMappings.getProperty(dbName);
        }

        if (!StringUtils.hasText(hibernateDialectClassName)) {
            throw new CouldNotDetermineHibernateDialectException(
                    "Could not determine Hibernate dialect for database name [" + dbName + "]!");
        }
    } finally {
        DataSourceUtils.releaseConnection(connection, dataSource);
    }
}