Tests with current_timestamp requires Dialect UsesStandardCurrentTimestampFunction feature

This commit is contained in:
Vladimír Kuruc 2024-08-15 14:21:02 +02:00 committed by Steve Ebersole
parent d90807f9e4
commit 5975d02e39
9 changed files with 49 additions and 57 deletions

View File

@ -661,6 +661,11 @@ public class InformixDialect extends Dialect {
appender.appendSql( datetimeFormat( format ).result() );
}
@Override
public boolean supportsStandardCurrentTimestampFunction() {
return false;
}
public static Replacer datetimeFormat(String format) {
return new Replacer( format, "'", "" )
.replace("%", "%%")

View File

@ -25,15 +25,14 @@ import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.UpdateTimestamp;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.SybaseDialect;
import org.hibernate.dialect.TiDBDialect;
import org.hibernate.generator.EventType;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
@ -47,9 +46,9 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Steve Ebersole
*/
@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true, reason = "CURRENT_TIMESTAMP not supported as default value in Sybase")
@SkipForDialect(dialectClass = MySQLDialect.class, reason = "See HHH-10196")
@SkipForDialect(dialectClass = TiDBDialect.class, reason = "See HHH-10196")
@RequiresDialectFeature( feature = DialectFeatureChecks.CurrentTimestampHasMicrosecondPrecision.class )
@RequiresDialectFeature( feature = DialectFeatureChecks.UsesStandardCurrentTimestampFunction.class )
@DomainModel( annotatedClasses = ComplexValueGenerationTests.AuditedEntity.class )
@SessionFactory
@SuppressWarnings("JUnitMalformedDeclaration")

View File

@ -13,13 +13,11 @@ import java.util.EnumSet;
import org.hibernate.annotations.ValueGenerationType;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.SybaseDialect;
import org.hibernate.generator.EventType;
import org.hibernate.generator.EventTypeSets;
import org.hibernate.generator.OnExecutionGenerator;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.SkipForDialect;
import org.junit.Test;
import jakarta.persistence.Column;
@ -32,7 +30,6 @@ import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
/**
* @author Vlad Mihalcea
*/
@SkipForDialect(value = SybaseDialect.class, comment = "Sybase doesn't seem to support current_timestamp")
public class DatabaseValueGenerationTest extends BaseEntityManagerFunctionalTestCase {
@Override

View File

@ -8,7 +8,6 @@ package org.hibernate.orm.test.mapping.generated;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Member;
import java.sql.Time;
import java.sql.Timestamp;
import java.time.Instant;
@ -31,19 +30,17 @@ import org.hibernate.annotations.Generated;
import org.hibernate.annotations.UpdateTimestamp;
import org.hibernate.annotations.ValueGenerationType;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.SybaseDialect;
import org.hibernate.generator.AnnotationBasedGenerator;
import org.hibernate.generator.EventType;
import org.hibernate.generator.GeneratorCreationContext;
import org.hibernate.generator.OnExecutionGenerator;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
@ -51,32 +48,24 @@ import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@SkipForDialect(value = SybaseDialect.class, comment = "CURRENT_TIMESTAMP not supported as default value in Sybase")
@SkipForDialect(value = MySQLDialect.class, comment = "See HHH-10196")
@RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class)
public class DefaultGeneratedValueIdentityTest extends BaseCoreFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] { TheEntity.class };
}
@Override
protected boolean isCleanupTestDataUsingBulkDelete() {
return true;
}
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsIdentityColumns.class)
@RequiresDialectFeature( feature = DialectFeatureChecks.CurrentTimestampHasMicrosecondPrecision.class )
@RequiresDialectFeature( feature = DialectFeatureChecks.UsesStandardCurrentTimestampFunction.class )
@DomainModel( annotatedClasses = DefaultGeneratedValueIdentityTest.TheEntity.class )
@SessionFactory
@SuppressWarnings("JUnitMalformedDeclaration")
public class DefaultGeneratedValueIdentityTest {
@Test
@TestForIssue( jiraKey = "HHH-12671" )
public void testGenerationWithIdentityInsert() {
@JiraKey( "HHH-12671" )
public void testGenerationWithIdentityInsert(SessionFactoryScope scope) {
final TheEntity theEntity = new TheEntity();
doInHibernate( this::sessionFactory, session -> {
scope.inTransaction( (session) -> {
assertNull( theEntity.createdDate );
assertNull( theEntity.alwaysDate );
assertNull( theEntity.vmCreatedDate );
@ -121,7 +110,7 @@ public class DefaultGeneratedValueIdentityTest extends BaseCoreFunctionalTestCas
assertNotNull( theEntity.alwaysDate );
assertEquals( "Bob", theEntity.name );
doInHibernate( this::sessionFactory, session -> {
scope.inTransaction( (session) -> {
TheEntity _theEntity = session.get( TheEntity.class, theEntity.id );
assertNotNull( _theEntity.createdDate );
assertNotNull( _theEntity.alwaysDate );
@ -145,8 +134,13 @@ public class DefaultGeneratedValueIdentityTest extends BaseCoreFunctionalTestCas
} );
}
@AfterEach
public void dropTestData(SessionFactoryScope scope) {
scope.inTransaction( (s) -> s.createQuery( "delete TheEntity" ).executeUpdate() );
}
@Entity( name = "TheEntity" )
private static class TheEntity {
public static class TheEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

View File

@ -25,21 +25,20 @@ import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.UpdateTimestamp;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.SybaseDialect;
import org.hibernate.dialect.TiDBDialect;
import org.hibernate.generator.EventType;
import org.hibernate.generator.internal.CurrentTimestampGeneration;
import org.hibernate.orm.test.annotations.MutableClock;
import org.hibernate.orm.test.annotations.MutableClockSettingProvider;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.SettingProvider;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -60,9 +59,8 @@ import static org.junit.Assert.assertTrue;
* @author Steve Ebersole
* @author Gunnar Morling
*/
@SkipForDialect( dialectClass = SybaseDialect.class, matchSubTypes = true, reason = "CURRENT_TIMESTAMP not supported as default value in Sybase" )
@SkipForDialect( dialectClass = MySQLDialect.class, reason = "See HHH-10196" )
@SkipForDialect( dialectClass = TiDBDialect.class, reason = "See HHH-10196" )
@RequiresDialectFeature( feature = DialectFeatureChecks.CurrentTimestampHasMicrosecondPrecision.class )
@RequiresDialectFeature( feature = DialectFeatureChecks.UsesStandardCurrentTimestampFunction.class )
@ServiceRegistry(settingProviders = @SettingProvider(settingName = CurrentTimestampGeneration.CLOCK_SETTING_NAME, provider = MutableClockSettingProvider.class))
@DomainModel( annotatedClasses = DefaultGeneratedValueTest.TheEntity.class )
@SessionFactory

View File

@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@DomainModel( annotatedClasses = MultipleGeneratedValuesTests.GeneratedInstantEntity.class )
@SessionFactory
@RequiresDialectFeature(feature = DialectFeatureChecks.CurrentTimestampHasMicrosecondPrecision.class, comment = "Without this, we might not see an update to the timestamp")
@SkipForDialect( dialectClass = SybaseASEDialect.class, matchSubTypes = true, reason = "CURRENT_TIMESTAMP not supported in insert/update in Sybase ASE. Also see https://groups.google.com/g/comp.databases.sybase/c/j-RxPnF3img" )
@RequiresDialectFeature( feature = DialectFeatureChecks.UsesStandardCurrentTimestampFunction.class )
@SkipForDialect( dialectClass = SQLServerDialect.class, matchSubTypes = true, reason = "CURRENT_TIMESTAMP has millisecond precision" )
public class MultipleGeneratedValuesTests {
@Test

View File

@ -9,7 +9,6 @@ package org.hibernate.orm.test.mapping.generated.temporals;
import java.time.Instant;
import org.hibernate.HibernateError;
import org.hibernate.dialect.SybaseASEDialect;
import org.hibernate.generator.EventType;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
@ -17,7 +16,6 @@ import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity;
@ -34,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@DomainModel( annotatedClasses = ProposedGeneratedTests.GeneratedInstantEntity.class )
@SessionFactory
@RequiresDialectFeature(feature = DialectFeatureChecks.CurrentTimestampHasMicrosecondPrecision.class, comment = "Without this, we might not see an update to the timestamp")
@SkipForDialect( dialectClass = SybaseASEDialect.class, matchSubTypes = true, reason = "CURRENT_TIMESTAMP not supported in insert/update in Sybase ASE. Also see https://groups.google.com/g/comp.databases.sybase/c/j-RxPnF3img" )
@RequiresDialectFeature( feature = DialectFeatureChecks.UsesStandardCurrentTimestampFunction.class )
public class ProposedGeneratedTests {
@Test
public void test(SessionFactoryScope scope) throws InterruptedException {

View File

@ -9,6 +9,7 @@ package org.hibernate.orm.test.query.hql;
import org.hamcrest.Matchers;
import org.hibernate.QueryException;
import org.hibernate.community.dialect.AltibaseDialect;
import org.hibernate.community.dialect.InformixDialect;
import org.hibernate.dialect.CockroachDialect;
import org.hibernate.dialect.DB2Dialect;
import org.hibernate.community.dialect.DerbyDialect;
@ -568,6 +569,7 @@ public class FunctionTests {
@Test
@SkipForDialect(dialectClass = DerbyDialect.class, reason = "Derby doesn't support any form of date truncation")
@SkipForDialect(dialectClass = InformixDialect.class, reason = "Informix doesn't support any form of date truncation")
public void testDateTruncFunction(SessionFactoryScope scope) {
scope.inTransaction(
session -> {

View File

@ -12,15 +12,14 @@ import java.util.Date;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.Generated;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.SybaseDialect;
import org.hibernate.query.Query;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.Test;
import jakarta.persistence.GeneratedValue;
@ -43,8 +42,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
* @author Gail Badner
*/
@SuppressWarnings("JUnitMalformedDeclaration")
@SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true, reason = "CURRENT_TIMESTAMP not supported as default value in MySQL")
@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true, reason = "CURRENT_TIMESTAMP not supported as default value in Sybase")
@RequiresDialectFeature(feature = DialectFeatureChecks.CurrentTimestampHasMicrosecondPrecision.class, comment = "Without this, we might not see an update to the timestamp")
@RequiresDialectFeature( feature = DialectFeatureChecks.UsesStandardCurrentTimestampFunction.class )
@DomainModel(
annotatedClasses = TimestampPropertyTest.Entity.class
)