Skip to content

Commit 73348b8

Browse files
committed
HHH-18369 Support Informix matches() function
1 parent 9616d45 commit 73348b8

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.hibernate.query.sqm.mutation.internal.temptable.LocalTemporaryTableMutationStrategy;
5353
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableInsertStrategy;
5454
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
55+
import org.hibernate.query.sqm.produce.function.StandardFunctionArgumentTypeResolvers;
5556
import org.hibernate.query.sqm.sql.SqmTranslator;
5657
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
5758
import org.hibernate.query.sqm.sql.StandardSqmTranslatorFactory;
@@ -70,6 +71,7 @@
7071
import org.hibernate.tool.schema.internal.StandardForeignKeyExporter;
7172
import org.hibernate.tool.schema.spi.Exporter;
7273
import org.hibernate.type.JavaObjectType;
74+
import org.hibernate.type.StandardBasicTypes;
7375
import org.hibernate.type.descriptor.jdbc.ClobJdbcType;
7476
import org.hibernate.type.descriptor.jdbc.ObjectNullAsBinaryTypeJdbcType;
7577
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
@@ -79,6 +81,7 @@
7981
import org.hibernate.type.spi.TypeConfiguration;
8082

8183
import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate;
84+
import static org.hibernate.query.sqm.produce.function.FunctionParameterType.STRING;
8285
import static org.hibernate.type.SqlTypes.BIGINT;
8386
import static org.hibernate.type.SqlTypes.BINARY;
8487
import static org.hibernate.type.SqlTypes.FLOAT;
@@ -298,6 +301,19 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
298301
}
299302
functionContributions.getFunctionRegistry().register( "least", new CaseLeastGreatestEmulation( true ) );
300303
functionContributions.getFunctionRegistry().register( "greatest", new CaseLeastGreatestEmulation( false ) );
304+
functionContributions.getFunctionRegistry().namedDescriptorBuilder( "matches" )
305+
.setInvariantType( functionContributions.getTypeConfiguration()
306+
.getBasicTypeRegistry()
307+
.resolve( StandardBasicTypes.STRING ) )
308+
.setExactArgumentCount( 2 )
309+
.setArgumentTypeResolver(
310+
StandardFunctionArgumentTypeResolvers.impliedOrInvariant(
311+
functionContributions.getTypeConfiguration(),
312+
STRING
313+
)
314+
)
315+
.setArgumentListSignature( "(STRING string, STRING length)" )
316+
.register();
301317
if ( supportsWindowFunctions() ) {
302318
functionFactory.windowFunctions();
303319
}

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)