Search in sources :

Example 1 with H2Dialect

use of org.hibernate.dialect.H2Dialect in project hibernate-orm by hibernate.

the class ServiceBootstrappingTest method testBuildWithLogging.

@Test
public void testBuildWithLogging() {
    Properties props = ConnectionProviderBuilder.getConnectionProviderProperties();
    props.put(Environment.SHOW_SQL, "true");
    StandardServiceRegistryImpl serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings(props).build();
    try {
        JdbcServices jdbcServices = serviceRegistry.getService(JdbcServices.class);
        assertTrue(jdbcServices.getDialect() instanceof H2Dialect);
        final ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping(ConnectionProviderJdbcConnectionAccess.class, jdbcServices.getBootstrapJdbcConnectionAccess());
        assertTrue(connectionAccess.getConnectionProvider().isUnwrappableAs(DriverManagerConnectionProviderImpl.class));
        assertTrue(jdbcServices.getSqlStatementLogger().isLogToStdout());
    } finally {
        serviceRegistry.destroy();
    }
}
Also used : DriverManagerConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) H2Dialect(org.hibernate.dialect.H2Dialect) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) Properties(java.util.Properties) StandardServiceRegistryImpl(org.hibernate.boot.registry.internal.StandardServiceRegistryImpl) ConnectionProviderJdbcConnectionAccess(org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess) Test(org.junit.Test)

Example 2 with H2Dialect

use of org.hibernate.dialect.H2Dialect in project hibernate-orm by hibernate.

the class ServiceBootstrappingTest method testBasicBuild.

@Test
public void testBasicBuild() {
    // this test requires that SHOW_SQL property isn't passed from the outside (eg. via Gradle)
    final String showSqlPropertyFromOutside = System.getProperty(Environment.SHOW_SQL);
    Assume.assumeFalse("true".equals(showSqlPropertyFromOutside));
    final StandardServiceRegistryImpl serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings(ConnectionProviderBuilder.getConnectionProviderProperties()).build();
    try {
        final JdbcServices jdbcServices = serviceRegistry.getService(JdbcServices.class);
        assertTrue(jdbcServices.getDialect() instanceof H2Dialect);
        final ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping(ConnectionProviderJdbcConnectionAccess.class, jdbcServices.getBootstrapJdbcConnectionAccess());
        assertTrue(connectionAccess.getConnectionProvider().isUnwrappableAs(DriverManagerConnectionProviderImpl.class));
        assertFalse(jdbcServices.getSqlStatementLogger().isLogToStdout());
    } finally {
        serviceRegistry.destroy();
    }
}
Also used : DriverManagerConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) H2Dialect(org.hibernate.dialect.H2Dialect) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) StandardServiceRegistryImpl(org.hibernate.boot.registry.internal.StandardServiceRegistryImpl) ConnectionProviderJdbcConnectionAccess(org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess) Test(org.junit.Test)

Example 3 with H2Dialect

use of org.hibernate.dialect.H2Dialect in project hibernate-orm by hibernate.

the class StandardDialectResolver method resolveDialect.

@Override
public Dialect resolveDialect(DialectResolutionInfo info) {
    final String databaseName = info.getDatabaseName();
    if ("CUBRID".equalsIgnoreCase(databaseName)) {
        return new CUBRIDDialect();
    }
    if ("HSQL Database Engine".equals(databaseName)) {
        return new HSQLDialect();
    }
    if ("H2".equals(databaseName)) {
        return new H2Dialect();
    }
    if ("MySQL".equals(databaseName)) {
        final int majorVersion = info.getDatabaseMajorVersion();
        if (majorVersion >= 5) {
            return new MySQL5Dialect();
        }
        return new MySQLDialect();
    }
    if ("PostgreSQL".equals(databaseName)) {
        final int majorVersion = info.getDatabaseMajorVersion();
        final int minorVersion = info.getDatabaseMinorVersion();
        if (majorVersion == 9) {
            if (minorVersion >= 4) {
                return new PostgreSQL94Dialect();
            } else if (minorVersion >= 2) {
                return new PostgreSQL92Dialect();
            }
            return new PostgreSQL9Dialect();
        }
        if (majorVersion == 8 && minorVersion >= 2) {
            return new PostgreSQL82Dialect();
        }
        return new PostgreSQL81Dialect();
    }
    if ("EnterpriseDB".equals(databaseName)) {
        return new PostgresPlusDialect();
    }
    if ("Apache Derby".equals(databaseName)) {
        final int majorVersion = info.getDatabaseMajorVersion();
        final int minorVersion = info.getDatabaseMinorVersion();
        if (majorVersion > 10 || (majorVersion == 10 && minorVersion >= 7)) {
            return new DerbyTenSevenDialect();
        } else if (majorVersion == 10 && minorVersion == 6) {
            return new DerbyTenSixDialect();
        } else if (majorVersion == 10 && minorVersion == 5) {
            return new DerbyTenFiveDialect();
        } else {
            return new DerbyDialect();
        }
    }
    if ("ingres".equalsIgnoreCase(databaseName)) {
        final int majorVersion = info.getDatabaseMajorVersion();
        final int minorVersion = info.getDatabaseMinorVersion();
        switch(majorVersion) {
            case 9:
                if (minorVersion > 2) {
                    return new Ingres9Dialect();
                }
                return new IngresDialect();
            case 10:
                return new Ingres10Dialect();
            default:
                LOG.unknownIngresVersion(majorVersion);
        }
        return new IngresDialect();
    }
    if (databaseName.startsWith("Microsoft SQL Server")) {
        final int majorVersion = info.getDatabaseMajorVersion();
        switch(majorVersion) {
            case 8:
                {
                    return new SQLServerDialect();
                }
            case 9:
                {
                    return new SQLServer2005Dialect();
                }
            case 10:
                {
                    return new SQLServer2008Dialect();
                }
            case 11:
            case 12:
            case 13:
                {
                    return new SQLServer2012Dialect();
                }
            default:
                {
                    if (majorVersion < 8) {
                        LOG.unknownSqlServerVersion(majorVersion, SQLServerDialect.class);
                        return new SQLServerDialect();
                    } else {
                        // assume `majorVersion > 13`
                        LOG.unknownSqlServerVersion(majorVersion, SQLServer2012Dialect.class);
                        return new SQLServer2012Dialect();
                    }
                }
        }
    }
    if ("Sybase SQL Server".equals(databaseName) || "Adaptive Server Enterprise".equals(databaseName)) {
        return new SybaseASE15Dialect();
    }
    if (databaseName.startsWith("Adaptive Server Anywhere")) {
        return new SybaseAnywhereDialect();
    }
    if ("Informix Dynamic Server".equals(databaseName)) {
        return new InformixDialect();
    }
    if ("DB2 UDB for AS/400".equals(databaseName)) {
        return new DB2400Dialect();
    }
    if (databaseName.startsWith("DB2/")) {
        return new DB2Dialect();
    }
    if ("Oracle".equals(databaseName)) {
        final int majorVersion = info.getDatabaseMajorVersion();
        switch(majorVersion) {
            case 12:
                return new Oracle12cDialect();
            case 11:
            // fall through
            case 10:
                return new Oracle10gDialect();
            case 9:
                return new Oracle9iDialect();
            case 8:
                return new Oracle8iDialect();
            default:
                LOG.unknownOracleVersion(majorVersion);
        }
        return new Oracle8iDialect();
    }
    if ("HDB".equals(databaseName)) {
        // SAP recommends defaulting to column store.
        return new HANAColumnStoreDialect();
    }
    if (databaseName.startsWith("Firebird")) {
        return new FirebirdDialect();
    }
    return null;
}
Also used : MySQL5Dialect(org.hibernate.dialect.MySQL5Dialect) SybaseASE15Dialect(org.hibernate.dialect.SybaseASE15Dialect) H2Dialect(org.hibernate.dialect.H2Dialect) PostgreSQL92Dialect(org.hibernate.dialect.PostgreSQL92Dialect) IngresDialect(org.hibernate.dialect.IngresDialect) DerbyTenSixDialect(org.hibernate.dialect.DerbyTenSixDialect) Oracle10gDialect(org.hibernate.dialect.Oracle10gDialect) PostgreSQL94Dialect(org.hibernate.dialect.PostgreSQL94Dialect) FirebirdDialect(org.hibernate.dialect.FirebirdDialect) PostgreSQL82Dialect(org.hibernate.dialect.PostgreSQL82Dialect) PostgreSQL81Dialect(org.hibernate.dialect.PostgreSQL81Dialect) MySQLDialect(org.hibernate.dialect.MySQLDialect) PostgreSQL9Dialect(org.hibernate.dialect.PostgreSQL9Dialect) SybaseAnywhereDialect(org.hibernate.dialect.SybaseAnywhereDialect) DerbyTenSevenDialect(org.hibernate.dialect.DerbyTenSevenDialect) DB2400Dialect(org.hibernate.dialect.DB2400Dialect) Ingres9Dialect(org.hibernate.dialect.Ingres9Dialect) HSQLDialect(org.hibernate.dialect.HSQLDialect) HANAColumnStoreDialect(org.hibernate.dialect.HANAColumnStoreDialect) PostgresPlusDialect(org.hibernate.dialect.PostgresPlusDialect) DerbyDialect(org.hibernate.dialect.DerbyDialect) SQLServerDialect(org.hibernate.dialect.SQLServerDialect) Oracle9iDialect(org.hibernate.dialect.Oracle9iDialect) DerbyTenFiveDialect(org.hibernate.dialect.DerbyTenFiveDialect) DB2Dialect(org.hibernate.dialect.DB2Dialect) Oracle8iDialect(org.hibernate.dialect.Oracle8iDialect) Ingres10Dialect(org.hibernate.dialect.Ingres10Dialect) SQLServer2012Dialect(org.hibernate.dialect.SQLServer2012Dialect) Oracle12cDialect(org.hibernate.dialect.Oracle12cDialect) SQLServer2005Dialect(org.hibernate.dialect.SQLServer2005Dialect) InformixDialect(org.hibernate.dialect.InformixDialect) CUBRIDDialect(org.hibernate.dialect.CUBRIDDialect) SQLServer2008Dialect(org.hibernate.dialect.SQLServer2008Dialect)

Example 4 with H2Dialect

use of org.hibernate.dialect.H2Dialect in project hibernate-orm by hibernate.

the class BaseCoreFunctionalTestCase method constructConfiguration.

protected Configuration constructConfiguration() {
    Configuration configuration = new Configuration();
    configuration.setProperty(AvailableSettings.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName());
    configuration.setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
    if (createSchema()) {
        configuration.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
        final String secondSchemaName = createSecondSchema();
        if (StringHelper.isNotEmpty(secondSchemaName)) {
            if (!(getDialect() instanceof H2Dialect)) {
                throw new UnsupportedOperationException("Only H2 dialect supports creation of second schema.");
            }
            Helper.createH2Schema(secondSchemaName, configuration);
        }
    }
    configuration.setImplicitNamingStrategy(ImplicitNamingStrategyLegacyJpaImpl.INSTANCE);
    configuration.setProperty(Environment.DIALECT, getDialect().getClass().getName());
    return configuration;
}
Also used : Configuration(org.hibernate.cfg.Configuration) H2Dialect(org.hibernate.dialect.H2Dialect) CachingRegionFactory(org.hibernate.testing.cache.CachingRegionFactory)

Example 5 with H2Dialect

use of org.hibernate.dialect.H2Dialect in project hibernate-orm by hibernate.

the class ServiceBootstrappingTest method testBuildWithServiceOverride.

@Test
public void testBuildWithServiceOverride() {
    StandardServiceRegistryImpl serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings(ConnectionProviderBuilder.getConnectionProviderProperties()).build();
    Properties props = ConnectionProviderBuilder.getConnectionProviderProperties();
    props.setProperty(Environment.DIALECT, H2Dialect.class.getName());
    try {
        JdbcServices jdbcServices = serviceRegistry.getService(JdbcServices.class);
        assertTrue(jdbcServices.getDialect() instanceof H2Dialect);
        ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping(ConnectionProviderJdbcConnectionAccess.class, jdbcServices.getBootstrapJdbcConnectionAccess());
        assertTrue(connectionAccess.getConnectionProvider().isUnwrappableAs(DriverManagerConnectionProviderImpl.class));
    } finally {
        serviceRegistry.destroy();
    }
    try {
        serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings(props).addService(ConnectionProvider.class, new UserSuppliedConnectionProviderImpl()).build();
        JdbcServices jdbcServices = serviceRegistry.getService(JdbcServices.class);
        assertTrue(jdbcServices.getDialect() instanceof H2Dialect);
        ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping(ConnectionProviderJdbcConnectionAccess.class, jdbcServices.getBootstrapJdbcConnectionAccess());
        assertTrue(connectionAccess.getConnectionProvider().isUnwrappableAs(UserSuppliedConnectionProviderImpl.class));
    } finally {
        serviceRegistry.destroy();
    }
}
Also used : DriverManagerConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl) UserSuppliedConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) H2Dialect(org.hibernate.dialect.H2Dialect) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) Properties(java.util.Properties) StandardServiceRegistryImpl(org.hibernate.boot.registry.internal.StandardServiceRegistryImpl) ConnectionProviderJdbcConnectionAccess(org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess) ConnectionProvider(org.hibernate.engine.jdbc.connections.spi.ConnectionProvider) Test(org.junit.Test)

Aggregations

H2Dialect (org.hibernate.dialect.H2Dialect)6 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)3 StandardServiceRegistryImpl (org.hibernate.boot.registry.internal.StandardServiceRegistryImpl)3 DriverManagerConnectionProviderImpl (org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl)3 ConnectionProviderJdbcConnectionAccess (org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess)3 JdbcServices (org.hibernate.engine.jdbc.spi.JdbcServices)3 Test (org.junit.Test)3 Properties (java.util.Properties)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Configuration (org.hibernate.cfg.Configuration)1 CUBRIDDialect (org.hibernate.dialect.CUBRIDDialect)1 DB2400Dialect (org.hibernate.dialect.DB2400Dialect)1 DB2Dialect (org.hibernate.dialect.DB2Dialect)1 DerbyDialect (org.hibernate.dialect.DerbyDialect)1 DerbyTenFiveDialect (org.hibernate.dialect.DerbyTenFiveDialect)1 DerbyTenSevenDialect (org.hibernate.dialect.DerbyTenSevenDialect)1 DerbyTenSixDialect (org.hibernate.dialect.DerbyTenSixDialect)1 FirebirdDialect (org.hibernate.dialect.FirebirdDialect)1 HANAColumnStoreDialect (org.hibernate.dialect.HANAColumnStoreDialect)1