Example usage for org.hibernate.dialect SybaseASE15Dialect SybaseASE15Dialect

List of usage examples for org.hibernate.dialect SybaseASE15Dialect SybaseASE15Dialect

Introduction

In this page you can find the example usage for org.hibernate.dialect SybaseASE15Dialect SybaseASE15Dialect.

Prototype

public SybaseASE15Dialect() 

Source Link

Document

Constructs a SybaseASE15Dialect

Usage

From source file:com.liferay.portal.spring.hibernate.DialectDetector.java

License:Open Source License

public static Dialect getDialect(DataSource dataSource) {
    String dialectKey = null;/*from   www . j  av a 2 s.c  o  m*/
    Dialect dialect = null;

    Connection connection = null;

    try {
        connection = dataSource.getConnection();

        DatabaseMetaData databaseMetaData = connection.getMetaData();

        String dbName = databaseMetaData.getDatabaseProductName();
        int dbMajorVersion = databaseMetaData.getDatabaseMajorVersion();

        dialectKey = dbName.concat(StringPool.COLON).concat(String.valueOf(dbMajorVersion));

        dialect = _dialects.get(dialectKey);

        if (dialect != null) {
            return dialect;
        }

        if (_log.isInfoEnabled()) {
            _log.info("Determine dialect for " + dbName + " " + dbMajorVersion);
        }

        if (dbName.startsWith("HSQL")) {
            if (_log.isWarnEnabled()) {
                StringBundler sb = new StringBundler(6);

                sb.append("Liferay is configured to use Hypersonic as ");
                sb.append("its database. Do NOT use Hypersonic in ");
                sb.append("production. Hypersonic is an embedded ");
                sb.append("database useful for development and demo'ing ");
                sb.append("purposes. The database settings can be ");
                sb.append("changed in portal-ext.properties.");

                _log.warn(sb.toString());
            }
        }

        if (dbName.equals("ASE") && (dbMajorVersion == 15)) {
            dialect = new SybaseASE15Dialect();
        } else if (dbName.startsWith("DB2") && (dbMajorVersion == 9)) {
            dialect = new DB2Dialect();
        } else if (dbName.startsWith("Microsoft") && (dbMajorVersion == 9)) {
            dialect = new SQLServer2005Dialect();
        } else if (dbName.startsWith("Microsoft") && (dbMajorVersion == 10)) {
            dialect = new SQLServer2008Dialect();
        } else if (dbName.startsWith("Oracle") && (dbMajorVersion >= 10)) {
            dialect = new Oracle10gDialect();
        } else {
            dialect = DialectFactory.buildDialect(new Properties(), connection);
        }
    } catch (Exception e) {
        String msg = GetterUtil.getString(e.getMessage());

        if (msg.indexOf("explicitly set for database: DB2") != -1) {
            dialect = new DB2400Dialect();

            if (_log.isWarnEnabled()) {
                _log.warn("DB2400Dialect was dynamically chosen as the "
                        + "Hibernate dialect for DB2. This can be " + "overriden in portal.properties");
            }
        } else {
            _log.error(e, e);
        }
    } finally {
        DataAccess.cleanUp(connection);
    }

    if (dialect == null) {
        throw new RuntimeException("No dialect found");
    } else if (dialectKey != null) {
        if (_log.isInfoEnabled()) {
            _log.info("Found dialect " + dialect.getClass().getName());
        }

        _dialects.put(dialectKey, dialect);
    }

    return dialect;
}