Skip to content

Commit 68b767f

Browse files
committed
HHH-18369 Support Informix matches() function
1 parent 2f95df8 commit 68b767f

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
@@ -50,6 +50,7 @@
5050
import org.hibernate.query.sqm.mutation.internal.temptable.LocalTemporaryTableMutationStrategy;
5151
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableInsertStrategy;
5252
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
53+
import org.hibernate.query.sqm.produce.function.StandardFunctionArgumentTypeResolvers;
5354
import org.hibernate.query.sqm.sql.SqmTranslator;
5455
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
5556
import org.hibernate.query.sqm.sql.StandardSqmTranslatorFactory;
@@ -68,13 +69,15 @@
6869
import org.hibernate.tool.schema.internal.StandardForeignKeyExporter;
6970
import org.hibernate.tool.schema.spi.Exporter;
7071
import org.hibernate.type.JavaObjectType;
72+
import org.hibernate.type.StandardBasicTypes;
7173
import org.hibernate.type.descriptor.jdbc.ObjectNullAsBinaryTypeJdbcType;
7274
import org.hibernate.type.descriptor.sql.DdlType;
7375
import org.hibernate.type.descriptor.sql.internal.CapacityDependentDdlType;
7476
import org.hibernate.type.descriptor.sql.spi.DdlTypeRegistry;
7577
import org.hibernate.type.spi.TypeConfiguration;
7678

7779
import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate;
80+
import static org.hibernate.query.sqm.produce.function.FunctionParameterType.STRING;
7881
import static org.hibernate.type.SqlTypes.BIGINT;
7982
import static org.hibernate.type.SqlTypes.BINARY;
8083
import static org.hibernate.type.SqlTypes.FLOAT;
@@ -294,6 +297,19 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
294297
}
295298
functionContributions.getFunctionRegistry().register( "least", new CaseLeastGreatestEmulation( true ) );
296299
functionContributions.getFunctionRegistry().register( "greatest", new CaseLeastGreatestEmulation( false ) );
300+
functionContributions.getFunctionRegistry().namedDescriptorBuilder( "matches" )
301+
.setInvariantType( functionContributions.getTypeConfiguration()
302+
.getBasicTypeRegistry()
303+
.resolve( StandardBasicTypes.STRING ) )
304+
.setExactArgumentCount( 2 )
305+
.setArgumentTypeResolver(
306+
StandardFunctionArgumentTypeResolvers.impliedOrInvariant(
307+
functionContributions.getTypeConfiguration(),
308+
STRING
309+
)
310+
)
311+
.setArgumentListSignature( "(STRING string, STRING length)" )
312+
.register();
297313
if ( supportsWindowFunctions() ) {
298314
functionFactory.windowFunctions();
299315
}

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)