use of org.hibernate.dialect.function.SQLServerFormatEmulation in project hibernate-orm by hibernate.
the class SQLServerDialect method initializeFunctionRegistry.
@Override
public void initializeFunctionRegistry(QueryEngine queryEngine) {
super.initializeFunctionRegistry(queryEngine);
final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry();
BasicType<Date> dateType = basicTypeRegistry.resolve(StandardBasicTypes.DATE);
BasicType<Date> timeType = basicTypeRegistry.resolve(StandardBasicTypes.TIME);
BasicType<Date> timestampType = basicTypeRegistry.resolve(StandardBasicTypes.TIMESTAMP);
CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine);
// For SQL-Server we need to cast certain arguments to varchar(max) to be able to concat them
queryEngine.getSqmFunctionRegistry().register("count", new CountFunction(this, queryEngine.getTypeConfiguration(), SqlAstNodeRenderingMode.DEFAULT, "+", "varchar(max)", false));
// AVG by default uses the input type, so we possibly need to cast the argument type, hence a special function
functionFactory.avg_castingNonDoubleArguments(this, SqlAstNodeRenderingMode.DEFAULT);
functionFactory.truncate_round();
functionFactory.everyAny_minMaxIif();
functionFactory.bitLength_pattern("datalength(?1) * 8");
if (getVersion().isSameOrAfter(10)) {
functionFactory.locate_charindex();
functionFactory.stddevPopSamp_stdevp();
functionFactory.varPopSamp_varp();
}
if (getVersion().isSameOrAfter(11)) {
queryEngine.getSqmFunctionRegistry().register("format", new SQLServerFormatEmulation(this, queryEngine.getTypeConfiguration()));
// actually translate() was added in 2017 but
// it's not worth adding a new dialect for that!
functionFactory.translate();
functionFactory.median_percentileCont(true);
queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder("datefromparts").setInvariantType(dateType).setExactArgumentCount(3).setParameterTypes(INTEGER).register();
queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder("timefromparts").setInvariantType(timeType).setExactArgumentCount(5).setParameterTypes(INTEGER).register();
queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder("smalldatetimefromparts").setInvariantType(timestampType).setExactArgumentCount(5).setParameterTypes(INTEGER).register();
queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder("datetimefromparts").setInvariantType(timestampType).setExactArgumentCount(7).setParameterTypes(INTEGER).register();
queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder("datetime2fromparts").setInvariantType(timestampType).setExactArgumentCount(8).setParameterTypes(INTEGER).register();
queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder("datetimeoffsetfromparts").setInvariantType(timestampType).setExactArgumentCount(10).setParameterTypes(INTEGER).register();
}
functionFactory.windowFunctions();
functionFactory.inverseDistributionOrderedSetAggregates_windowEmulation();
functionFactory.hypotheticalOrderedSetAggregates_windowEmulation();
if (getVersion().isSameOrAfter(14)) {
functionFactory.listagg_stringAggWithinGroup("varchar(max)");
}
}
Aggregations