Search in sources :

Example 1 with MariaDBDialect

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

the class MySQLSkipAutoCommitTest method dataSource.

@Override
protected DataSource dataSource() {
    DataSource dataSource = null;
    if (getDialect() instanceof MariaDBDialect) {
        dataSource = ReflectionUtil.newInstance("org.mariadb.jdbc.MariaDbDataSource");
    } else if (getDialect() instanceof MySQLDialect) {
        try {
            // ConnectorJ 8
            dataSource = ReflectionUtil.newInstance("com.mysql.cj.jdbc.MysqlDataSource");
        } catch (IllegalArgumentException e) {
            try {
                // ConnectorJ 5
                dataSource = ReflectionUtil.newInstance("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
            } catch (Exception e2) {
                e2.addSuppressed(e);
                throw e;
            }
        }
    }
    ReflectionUtil.setProperty(dataSource, "url", Environment.getProperties().getProperty(AvailableSettings.URL));
    ReflectionUtil.setProperty(dataSource, "user", Environment.getProperties().getProperty(AvailableSettings.USER));
    ReflectionUtil.setProperty(dataSource, "password", Environment.getProperties().getProperty(AvailableSettings.PASS));
    return dataSource;
}
Also used : MySQLDialect(org.hibernate.dialect.MySQLDialect) MariaDBDialect(org.hibernate.dialect.MariaDBDialect) DataSource(javax.sql.DataSource)

Example 2 with MariaDBDialect

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

the class MySQLSkipAutoCommitTest method dataSource.

@Override
protected DataSource dataSource() {
    DataSource dataSource = ReflectionUtil.newInstance("com.mysql.cj.jdbc.MysqlDataSource");
    if (getDialect() instanceof MariaDBDialect) {
        dataSource = ReflectionUtil.newInstance("org.mariadb.jdbc.MariaDbDataSource");
    }
    ReflectionUtil.setProperty(dataSource, "url", Environment.getProperties().getProperty(AvailableSettings.URL));
    ReflectionUtil.setProperty(dataSource, "user", Environment.getProperties().getProperty(AvailableSettings.USER));
    ReflectionUtil.setProperty(dataSource, "password", Environment.getProperties().getProperty(AvailableSettings.PASS));
    return dataSource;
}
Also used : MariaDBDialect(org.hibernate.dialect.MariaDBDialect) DataSource(javax.sql.DataSource)

Example 3 with MariaDBDialect

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

the class MySQLDropConstraintThrowsExceptionTest method testEnumTypeInterpretation.

@Test
public void testEnumTypeInterpretation() {
    final PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider(false, false);
    final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().enableAutoClose().applySetting(AvailableSettings.HBM2DDL_AUTO, "update").applySetting(AvailableSettings.CONNECTION_PROVIDER, connectionProvider).build();
    SessionFactory sessionFactory = null;
    try {
        final Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(Customer.class).buildMetadata();
        sessionFactory = metadata.buildSessionFactory();
        List<String> alterStatements = connectionProvider.getExecuteStatements().stream().filter(sql -> sql.toLowerCase().contains("alter ")).map(String::trim).collect(Collectors.toList());
        if (metadata.getDatabase().getDialect() instanceof MariaDBDialect) {
            assertTrue(alterStatements.get(0).matches("alter table if exists CUSTOMER\\s+drop index .*?"));
            assertTrue(alterStatements.get(1).matches("alter table if exists CUSTOMER\\s+add constraint .*? unique \\(CUSTOMER_ID\\)"));
        } else {
            assertTrue(alterStatements.get(0).matches("alter table CUSTOMER\\s+drop index .*?"));
            assertTrue(alterStatements.get(1).matches("alter table CUSTOMER\\s+add constraint .*? unique \\(CUSTOMER_ID\\)"));
        }
    } finally {
        if (sessionFactory != null) {
            sessionFactory.close();
        }
        StandardServiceRegistryBuilder.destroy(serviceRegistry);
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) MariaDBDialect(org.hibernate.dialect.MariaDBDialect) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) PreparedStatementSpyConnectionProvider(org.hibernate.testing.orm.jdbc.PreparedStatementSpyConnectionProvider) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) BaseUnitTest(org.hibernate.testing.orm.junit.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 4 with MariaDBDialect

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

the class ValidityAuditStrategyRevEndTsTest method verifyRevEndTimeStamps.

private void verifyRevEndTimeStamps(String debugInfo, List<Map<String, Object>> revisionEntities) {
    for (Map<String, Object> revisionEntity : revisionEntities) {
        Date revendTimestamp = (Date) revisionEntity.get(revendTimestampColumName);
        SequenceIdRevisionEntity revEnd = (SequenceIdRevisionEntity) revisionEntity.get("REVEND");
        if (revendTimestamp == null) {
            Assert.assertNull(revEnd);
        } else {
            final Dialect dialect = getDialect();
            if (dialect instanceof MySQLDialect && dialect.getVersion().isBefore(5, 7) && !(dialect instanceof MariaDBDialect)) {
                // MySQL5 DATETIME column type does not contain milliseconds.
                // MySQL 5.7 supports milliseconds and when MySQL57InnoDBDialect is used, it is assumed that
                // the column is defined as DATETIME(6).
                Assert.assertEquals(revendTimestamp.getTime(), (revEnd.getTimestamp() - (revEnd.getTimestamp() % 1000)));
            } else if (dialect instanceof SybaseASEDialect) {
                // Sybase "DATETIME values are accurate to 1/300 second on platforms that support this level of granularity".
                Assert.assertEquals(revendTimestamp.getTime() / 1000.0, revEnd.getTimestamp() / 1000.0, 1.0 / 300.0);
            } else {
                Assert.assertEquals(revendTimestamp.getTime(), revEnd.getTimestamp());
            }
        }
    }
}
Also used : MySQLDialect(org.hibernate.dialect.MySQLDialect) MariaDBDialect(org.hibernate.dialect.MariaDBDialect) SybaseASEDialect(org.hibernate.dialect.SybaseASEDialect) SequenceIdRevisionEntity(org.hibernate.envers.enhanced.SequenceIdRevisionEntity) MySQLDialect(org.hibernate.dialect.MySQLDialect) MariaDBDialect(org.hibernate.dialect.MariaDBDialect) SybaseASEDialect(org.hibernate.dialect.SybaseASEDialect) Dialect(org.hibernate.dialect.Dialect) Date(java.util.Date)

Aggregations

MariaDBDialect (org.hibernate.dialect.MariaDBDialect)4 DataSource (javax.sql.DataSource)2 MySQLDialect (org.hibernate.dialect.MySQLDialect)2 Date (java.util.Date)1 SessionFactory (org.hibernate.SessionFactory)1 Metadata (org.hibernate.boot.Metadata)1 MetadataSources (org.hibernate.boot.MetadataSources)1 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)1 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)1 Dialect (org.hibernate.dialect.Dialect)1 SybaseASEDialect (org.hibernate.dialect.SybaseASEDialect)1 SequenceIdRevisionEntity (org.hibernate.envers.enhanced.SequenceIdRevisionEntity)1 PreparedStatementSpyConnectionProvider (org.hibernate.testing.orm.jdbc.PreparedStatementSpyConnectionProvider)1 BaseUnitTest (org.hibernate.testing.orm.junit.BaseUnitTest)1 Test (org.junit.jupiter.api.Test)1