HHH-18369 Support Informix matches() function

This commit is contained in:
Vladimír Kuruc 2024-07-10 11:56:16 +02:00
parent 772d576491
commit 14d4232755
2 changed files with 34 additions and 0 deletions

View File

@ -55,6 +55,7 @@ import org.hibernate.query.sqm.mutation.internal.temptable.LocalTemporaryTableIn
import org.hibernate.query.sqm.mutation.internal.temptable.LocalTemporaryTableMutationStrategy;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableInsertStrategy;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
import org.hibernate.query.sqm.produce.function.StandardFunctionArgumentTypeResolvers;
import org.hibernate.query.sqm.sql.SqmTranslator;
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
import org.hibernate.query.sqm.sql.StandardSqmTranslatorFactory;
@ -73,6 +74,7 @@ import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
import org.hibernate.tool.schema.internal.StandardForeignKeyExporter;
import org.hibernate.tool.schema.spi.Exporter;
import org.hibernate.type.JavaObjectType;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.descriptor.jdbc.ClobJdbcType;
import org.hibernate.type.descriptor.jdbc.ObjectNullAsBinaryTypeJdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
@ -85,6 +87,7 @@ import org.hibernate.type.spi.TypeConfiguration;
import jakarta.persistence.TemporalType;
import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate;
import static org.hibernate.query.sqm.produce.function.FunctionParameterType.STRING;
import static org.hibernate.type.SqlTypes.BIGINT;
import static org.hibernate.type.SqlTypes.BINARY;
import static org.hibernate.type.SqlTypes.FLOAT;
@ -315,6 +318,20 @@ public class InformixDialect extends Dialect {
functionContributions.getFunctionRegistry().register( "least", new CaseLeastGreatestEmulation( true ) );
functionContributions.getFunctionRegistry().register( "greatest", new CaseLeastGreatestEmulation( false ) );
functionContributions.getFunctionRegistry().namedDescriptorBuilder( "matches" )
.setInvariantType( functionContributions.getTypeConfiguration()
.getBasicTypeRegistry()
.resolve( StandardBasicTypes.STRING )
)
.setExactArgumentCount( 2 )
.setArgumentTypeResolver(
StandardFunctionArgumentTypeResolvers.impliedOrInvariant(
functionContributions.getTypeConfiguration(),
STRING
)
)
.setArgumentListSignature( "(STRING string, STRING length)" )
.register();
if ( supportsWindowFunctions() ) {
functionFactory.windowFunctions();
}

View File

@ -181,6 +181,23 @@ public class InformixFunctionTest {
);
}
@Test
@TestForIssue(jiraKey = "HHH-18369")
public void testMatches(SessionFactoryScope scope) {
scope.inTransaction(
(session) -> {
String country = (String) session.createQuery(
"select e.country " +
"from Event e " +
"where e.id = :id and matches(e.country, :country) = 'T'" )
.setParameter( "id", event.id )
.setParameter( "country", "R*" )
.getSingleResult();
assertEquals( "Romania", country );
}
);
}
private Calendar todayCalendar() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 0);