Search in sources :

Example 1 with RequiresDialect

use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.

the class JoinTableWithDefaultSchemaTest method testGetTableDataForJoinTableWithDefaultSchema.

@Test
@TestForIssue(jiraKey = "HHH-10978")
@RequiresDialect(SQLServerDialect.class)
public void testGetTableDataForJoinTableWithDefaultSchema() {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DEFAULT_CATALOG, "hibernate_orm_test").applySetting(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "false").build();
    try {
        final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Task.class).addAnnotatedClass(Project.class).buildMetadata();
        metadata.validate();
        // first create the schema...
        new SchemaExport().create(EnumSet.of(TargetType.DATABASE), metadata);
        try {
            // validate the schema
            new SchemaValidator().validate(metadata);
        } finally {
            // cleanup
            new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata);
        }
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) SchemaValidator(org.hibernate.tool.hbm2ddl.SchemaValidator) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue) RequiresDialect(org.hibernate.testing.RequiresDialect)

Example 2 with RequiresDialect

use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.

the class NativeSQLQueriesTest method testEscapeColonInSQL.

@Test
@RequiresDialect(MySQL5Dialect.class)
public void testEscapeColonInSQL() throws QueryException {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    SQLQuery query = s.createSQLQuery("SELECT @row \\:= 1");
    List list = query.list();
    assertTrue(list.get(0).toString().equals("1"));
    t.commit();
    s.close();
}
Also used : Transaction(org.hibernate.Transaction) List(java.util.List) SQLQuery(org.hibernate.SQLQuery) Session(org.hibernate.Session) Test(org.junit.Test) RequiresDialect(org.hibernate.testing.RequiresDialect)

Example 3 with RequiresDialect

use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.

the class CustomRunner method convertSkipToIgnore.

protected Ignore convertSkipToIgnore(FrameworkMethod frameworkMethod) {
    // @Skip
    Skip skip = Helper.locateAnnotation(Skip.class, frameworkMethod, getTestClass());
    if (skip != null) {
        if (isMatch(skip.condition())) {
            return buildIgnore(skip);
        }
    }
    // @SkipForDialects & @SkipForDialect
    for (SkipForDialect skipForDialectAnn : Helper.collectAnnotations(SkipForDialect.class, SkipForDialects.class, frameworkMethod, getTestClass())) {
        for (Class<? extends Dialect> dialectClass : skipForDialectAnn.value()) {
            if (skipForDialectAnn.strictMatching()) {
                if (dialectClass.equals(dialect.getClass())) {
                    return buildIgnore(skipForDialectAnn);
                }
            } else {
                if (dialectClass.isInstance(dialect)) {
                    return buildIgnore(skipForDialectAnn);
                }
            }
        }
    }
    // @RequiresDialects & @RequiresDialect
    final List<RequiresDialect> requiresDialects = Helper.collectAnnotations(RequiresDialect.class, RequiresDialects.class, frameworkMethod, getTestClass());
    if (!requiresDialects.isEmpty() && !isDialectMatchingRequired(requiresDialects)) {
        return buildIgnore(requiresDialects);
    }
    // @RequiresDialectFeature
    RequiresDialectFeature requiresDialectFeatureAnn = Helper.locateAnnotation(RequiresDialectFeature.class, frameworkMethod, getTestClass());
    if (requiresDialectFeatureAnn != null) {
        try {
            for (Class<? extends DialectCheck> checkClass : requiresDialectFeatureAnn.value()) {
                if (!checkClass.newInstance().isMatch(dialect)) {
                    return buildIgnore(requiresDialectFeatureAnn);
                }
            }
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new RuntimeException("Unable to instantiate DialectCheck", e);
        }
    }
    return null;
}
Also used : SkipForDialect(org.hibernate.testing.SkipForDialect) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature) Skip(org.hibernate.testing.Skip) RequiresDialect(org.hibernate.testing.RequiresDialect) NoTestsRemainException(org.junit.runner.manipulation.NoTestsRemainException)

Example 4 with RequiresDialect

use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.

the class CustomRunner method buildIgnore.

private Ignore buildIgnore(List<RequiresDialect> requiresDialects) {
    String ignoreMessage = "";
    for (RequiresDialect requiresDialect : requiresDialects) {
        ignoreMessage += getIgnoreMessage("@RequiresDialect non-match", requiresDialect.comment(), requiresDialect.jiraKey());
        ignoreMessage += System.lineSeparator();
    }
    return new IgnoreImpl(ignoreMessage);
}
Also used : RequiresDialect(org.hibernate.testing.RequiresDialect)

Example 5 with RequiresDialect

use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.

the class HQLTest method test_hql_group_by_example_4.

@Test
@RequiresDialect(H2Dialect.class)
@RequiresDialect(PostgreSQL81Dialect.class)
@RequiresDialect(MySQL5Dialect.class)
public void test_hql_group_by_example_4() {
    doInJPA(this::entityManagerFactory, entityManager -> {
        Call call11 = new Call();
        call11.setDuration(10);
        call11.setTimestamp(Timestamp.from(LocalDateTime.of(2000, 1, 1, 0, 0, 0).toInstant(ZoneOffset.UTC)));
        Phone phone = entityManager.createQuery("select p from Phone p where p.calls is empty ", Phone.class).getResultList().get(0);
        phone.addCall(call11);
        entityManager.flush();
        entityManager.clear();
        List<Object[]> personTotalCallDurations = entityManager.createQuery("select p, sum( c.duration ) " + "from Call c " + "join c.phone p " + "group by p", Object[].class).getResultList();
        assertEquals(2, personTotalCallDurations.size());
    });
}
Also used : Call(org.hibernate.userguide.model.Call) Phone(org.hibernate.userguide.model.Phone) Test(org.junit.Test) RequiresDialect(org.hibernate.testing.RequiresDialect)

Aggregations

RequiresDialect (org.hibernate.testing.RequiresDialect)41 Test (org.junit.Test)39 Session (org.hibernate.Session)18 TestForIssue (org.hibernate.testing.TestForIssue)13 RequiresDialectFeature (org.hibernate.testing.RequiresDialectFeature)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 ExecutionException (java.util.concurrent.ExecutionException)6 FutureTask (java.util.concurrent.FutureTask)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Transaction (org.hibernate.Transaction)6 HashMap (java.util.HashMap)5 Query (javax.persistence.Query)5 Phone (org.hibernate.userguide.model.Phone)5 LockTimeoutException (javax.persistence.LockTimeoutException)4 List (java.util.List)3 EntityManager (javax.persistence.EntityManager)3 TypedQuery (javax.persistence.TypedQuery)3 LockOptions (org.hibernate.LockOptions)3 NamedNativeQuery (org.hibernate.annotations.NamedNativeQuery)3 NamedQuery (org.hibernate.annotations.NamedQuery)3