Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@
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;
import org.hibernate.query.sqm.tree.select.SqmSelectStatement;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.sql.ast.SqlAstNodeRenderingMode;
import org.hibernate.sql.ast.SqlAstTranslator;
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
import org.hibernate.sql.ast.spi.SqlAppender;
Expand All @@ -74,7 +76,10 @@
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;
import org.hibernate.type.descriptor.sql.DdlType;
import org.hibernate.type.descriptor.sql.internal.CapacityDependentDdlType;
Expand All @@ -85,6 +90,7 @@
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;
Expand Down Expand Up @@ -303,10 +309,10 @@
super.initializeFunctionRegistry(functionContributions);

CommonFunctionFactory functionFactory = new CommonFunctionFactory(functionContributions);
functionFactory.aggregates( this, SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER );
functionFactory.instr();
functionFactory.substr();
functionFactory.substring_substr();
//also natively supports ANSI-style substring()
functionFactory.substringFromFor();
functionFactory.trunc();
functionFactory.trim2();
functionFactory.space();
Expand All @@ -329,12 +335,30 @@
functionFactory.monthsBetween();
functionFactory.stddev();
functionFactory.variance();
functionFactory.locate_positionSubstring();
functionFactory.bitLength_pattern( "length(?1)*8" );

if ( getVersion().isSameOrAfter( 12 ) ) {
functionFactory.locate_charindex();
}

//coalesce() and nullif() both supported since Informix 12

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();
}
Expand Down Expand Up @@ -704,6 +728,11 @@
return "today";
}

@Override
public String currentTime() {
return currentTimestamp();
}

@Override
public String currentTimestamp() {
return "current";
Expand Down Expand Up @@ -819,14 +848,14 @@
break;
default:
throw new IllegalArgumentException();
}
}

@Override
public String getSelectClauseNullString(int sqlType, TypeConfiguration typeConfiguration) {
DdlType descriptor = typeConfiguration.getDdlTypeRegistry().getDescriptor( sqlType );
if ( descriptor == null ) {
return "null";

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
TypeContributions.contributeType
should be avoided because it has been deprecated.
}
String typeName = descriptor.getTypeName( Size.length( Size.DEFAULT_LENGTH ) );
//trim off the length/precision/scale
Expand All @@ -853,6 +882,17 @@
final JdbcTypeRegistry jdbcTypeRegistry = typeContributions.getTypeConfiguration().getJdbcTypeRegistry();
jdbcTypeRegistry.addDescriptor( Types.NCLOB, ClobJdbcType.DEFAULT );
typeContributions.contributeJdbcType( VarcharUUIDJdbcType.INSTANCE );
typeContributions.contributeJdbcType( ObjectNullAsBinaryTypeJdbcType.INSTANCE );

// Until we remove StandardBasicTypes, we have to keep this
typeContributions.contributeType(
new JavaObjectType(
ObjectNullAsBinaryTypeJdbcType.INSTANCE,
typeContributions.getTypeConfiguration()
.getJavaTypeRegistry()
.getDescriptor( Object.class )
)
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,23 @@
);
}

@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*" )
Comment on lines +189 to +192

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
QueryProducerImplementor.createQuery
should be avoided because it has been deprecated.
.getSingleResult();
assertEquals( "Romania", country );
}
);
}

private Calendar todayCalendar() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.hibernate.ScrollableResults;
import org.hibernate.TypeMismatchException;
import org.hibernate.cfg.Environment;
import org.hibernate.community.dialect.InformixDialect;
import org.hibernate.community.dialect.DerbyDialect;
import org.hibernate.dialect.CockroachDialect;
import org.hibernate.dialect.DB2Dialect;
Expand Down Expand Up @@ -746,6 +747,7 @@ public void testSelectClauseCaseWithSum(SessionFactoryScope scope) {

@Test
@JiraKey(value = "HHH-4150")
@SkipForDialect( dialectClass = InformixDialect.class, majorVersion = 11, minorVersion = 70, reason = "Informix does not support case with count distinct")
public void testSelectClauseCaseWithCountDistinct(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Expand Down Expand Up @@ -3642,17 +3644,21 @@ public void testEJBQLFunctions(SessionFactoryScope scope) {
hql = "select length(a.description) from Animal a";
session.createQuery( hql ).list();

//note: postgres and db2 don't have a 3-arg form, it gets transformed to 2-args
hql = "from Animal a where locate('abc', a.description, 2) = 2";
session.createQuery( hql ).list();
Dialect dialect = session.getDialect();
// Informix before version 12 didn't support finding the index of substrings
if ( !(dialect instanceof InformixDialect && dialect.getVersion().isBefore( 12 )) ) {
//note: postgres and db2 don't have a 3-arg form, it gets transformed to 2-args
hql = "from Animal a where locate('abc', a.description, 2) = 2";
session.createQuery( hql ).list();

hql = "from Animal a where locate('abc', a.description) = 2";
session.createQuery( hql ).list();
hql = "from Animal a where locate('abc', a.description) = 2";
session.createQuery( hql ).list();

hql = "select locate('cat', a.description, 2) from Animal a";
session.createQuery( hql ).list();
hql = "select locate('cat', a.description, 2) from Animal a";
session.createQuery( hql ).list();
}

if ( !(session.getDialect() instanceof DB2Dialect) ) {
if ( !(dialect instanceof DB2Dialect) ) {
hql = "from Animal a where trim(trailing '_' from a.description) = 'cat'";
session.createQuery( hql ).list();

Expand All @@ -3666,7 +3672,7 @@ public void testEJBQLFunctions(SessionFactoryScope scope) {
session.createQuery( hql ).list();
}

if ( !(session.getDialect() instanceof HSQLDialect) ) { //HSQL doesn't like trim() without specification
if ( !(dialect instanceof HSQLDialect) ) { //HSQL doesn't like trim() without specification
hql = "from Animal a where trim(a.description) = 'cat'";
session.createQuery( hql ).list();
}
Expand Down Expand Up @@ -3725,6 +3731,7 @@ public void testOrderByExtraParenthesis(SessionFactoryScope scope) throws Except
}
}

@Test
@RequiresDialectFeature(
feature = DialectFeatureChecks.SupportSubqueryAsLeftHandSideInPredicate.class,
comment = "Database does not support using subquery as singular value expression"
Expand Down
Loading