Skip to content

Commit 75fba65

Browse files
VladoKurucbeikov
authored andcommitted
HHH-18369 Support Informix matches() function
1 parent df5e02a commit 75fba65

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.hibernate.query.sqm.mutation.internal.temptable.LocalTemporaryTableMutationStrategy;
5656
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableInsertStrategy;
5757
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
58+
import org.hibernate.query.sqm.produce.function.StandardFunctionArgumentTypeResolvers;
5859
import org.hibernate.query.sqm.sql.SqmTranslator;
5960
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
6061
import org.hibernate.query.sqm.sql.StandardSqmTranslatorFactory;
@@ -73,6 +74,7 @@
7374
import org.hibernate.tool.schema.internal.StandardForeignKeyExporter;
7475
import org.hibernate.tool.schema.spi.Exporter;
7576
import org.hibernate.type.JavaObjectType;
77+
import org.hibernate.type.StandardBasicTypes;
7678
import org.hibernate.type.descriptor.jdbc.ClobJdbcType;
7779
import org.hibernate.type.descriptor.jdbc.ObjectNullAsBinaryTypeJdbcType;
7880
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
@@ -85,6 +87,7 @@
8587
import jakarta.persistence.TemporalType;
8688

8789
import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate;
90+
import static org.hibernate.query.sqm.produce.function.FunctionParameterType.STRING;
8891
import static org.hibernate.type.SqlTypes.BIGINT;
8992
import static org.hibernate.type.SqlTypes.BINARY;
9093
import static org.hibernate.type.SqlTypes.FLOAT;
@@ -315,6 +318,20 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
315318

316319
functionContributions.getFunctionRegistry().register( "least", new CaseLeastGreatestEmulation( true ) );
317320
functionContributions.getFunctionRegistry().register( "greatest", new CaseLeastGreatestEmulation( false ) );
321+
functionContributions.getFunctionRegistry().namedDescriptorBuilder( "matches" )
322+
.setInvariantType( functionContributions.getTypeConfiguration()
323+
.getBasicTypeRegistry()
324+
.resolve( StandardBasicTypes.STRING )
325+
)
326+
.setExactArgumentCount( 2 )
327+
.setArgumentTypeResolver(
328+
StandardFunctionArgumentTypeResolvers.impliedOrInvariant(
329+
functionContributions.getTypeConfiguration(),
330+
STRING
331+
)
332+
)
333+
.setArgumentListSignature( "(STRING string, STRING pattern)" )
334+
.register();
318335
if ( supportsWindowFunctions() ) {
319336
functionFactory.windowFunctions();
320337
}

hibernate-community-dialects/src/test/java/org/hibernate/community/dialect/InformixFunctionTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,23 @@ public void testCurrentTimestamp(SessionFactoryScope scope) {
181181
);
182182
}
183183

184+
@Test
185+
@TestForIssue(jiraKey = "HHH-18369")
186+
public void testMatches(SessionFactoryScope scope) {
187+
scope.inTransaction(
188+
(session) -> {
189+
String country = (String) session.createQuery(
190+
"select e.country " +
191+
"from Event e " +
192+
"where e.id = :id and matches(e.country, :country) = 'T'" )
193+
.setParameter( "id", event.id )
194+
.setParameter( "country", "R*" )
195+
.getSingleResult();
196+
assertEquals( "Romania", country );
197+
}
198+
);
199+
}
200+
184201
private Calendar todayCalendar() {
185202
Calendar calendar = Calendar.getInstance();
186203
calendar.set(Calendar.HOUR_OF_DAY, 0);

0 commit comments

Comments
 (0)