HHH-18369 Support Informix matches() function

This commit is contained in:
Vladimír Kuruc 2024-07-10 11:56:16 +02:00 committed by Christian Beikov
parent d341240b1a
commit a23096484f
2 changed files with 35 additions and 1 deletions

View File

@ -57,6 +57,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;
@ -76,6 +77,7 @@ import org.hibernate.tool.schema.internal.StandardForeignKeyExporter;
import org.hibernate.tool.schema.internal.StandardTableExporter;
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;
@ -88,6 +90,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;
@ -342,6 +345,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 pattern)" )
.register();
if ( supportsWindowFunctions() ) {
functionFactory.windowFunctions();
}

View File

@ -179,6 +179,23 @@ public class InformixFunctionTest {
);
}
@Test
@JiraKey( value = "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);