Search in sources :

Example 26 with CommonFunctionFactory

use of org.hibernate.dialect.function.CommonFunctionFactory in project hibernate-orm by hibernate.

the class SQLiteDialect method initializeFunctionRegistry.

@Override
public void initializeFunctionRegistry(QueryEngine queryEngine) {
    super.initializeFunctionRegistry(queryEngine);
    final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry();
    final BasicType<String> stringType = basicTypeRegistry.resolve(StandardBasicTypes.STRING);
    final BasicType<Integer> integerType = basicTypeRegistry.resolve(StandardBasicTypes.INTEGER);
    CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine);
    functionFactory.mod_operator();
    functionFactory.leftRight_substr();
    functionFactory.concat_pipeOperator();
    functionFactory.characterLength_length(SqlAstNodeRenderingMode.DEFAULT);
    functionFactory.leastGreatest_minMax();
    functionFactory.radians();
    functionFactory.degrees();
    functionFactory.trunc();
    functionFactory.log();
    functionFactory.trim2();
    functionFactory.substr();
    functionFactory.substring_substr();
    functionFactory.chr_char();
    queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern("locate", integerType, "instr(?2,?1)", "instr(?2,?1,?3)", STRING, STRING, INTEGER, queryEngine.getTypeConfiguration()).setArgumentListSignature("(pattern, string[, start])");
    queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern("lpad", stringType, "(substr(replace(hex(zeroblob(?2)),'00',' '),1,?2-length(?1))||?1)", "(substr(replace(hex(zeroblob(?2)),'00',?3),1,?2-length(?1))||?1)", STRING, INTEGER, STRING, queryEngine.getTypeConfiguration()).setArgumentListSignature("(string, length[, padding])");
    queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern("rpad", stringType, "(?1||substr(replace(hex(zeroblob(?2)),'00',' '),1,?2-length(?1)))", "(?1||substr(replace(hex(zeroblob(?2)),'00',?3),1,?2-length(?1)))", STRING, INTEGER, STRING, queryEngine.getTypeConfiguration()).setArgumentListSignature("(string, length[, padding])");
    queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder("format", "strftime").setInvariantType(stringType).setExactArgumentCount(2).setParameterTypes(TEMPORAL, STRING).setArgumentListSignature("(TEMPORAL datetime as STRING pattern)").register();
    if (!supportsMathFunctions()) {
        queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder("floor", "(cast(?1 as int)-(?1<cast(?1 as int)))").setReturnTypeResolver(StandardFunctionReturnTypeResolvers.useArgType(1)).setExactArgumentCount(1).setParameterTypes(NUMERIC).register();
        queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder("ceiling", "(cast(?1 as int)+(?1>cast(?1 as int)))").setReturnTypeResolver(StandardFunctionReturnTypeResolvers.useArgType(1)).setExactArgumentCount(1).setParameterTypes(NUMERIC).register();
    }
    functionFactory.windowFunctions();
    functionFactory.listagg_groupConcat();
}
Also used : CommonFunctionFactory(org.hibernate.dialect.function.CommonFunctionFactory) BasicTypeRegistry(org.hibernate.type.BasicTypeRegistry)

Example 27 with CommonFunctionFactory

use of org.hibernate.dialect.function.CommonFunctionFactory in project hibernate-orm by hibernate.

the class AbstractTransactSQLDialect method initializeFunctionRegistry.

@Override
public void initializeFunctionRegistry(QueryEngine queryEngine) {
    super.initializeFunctionRegistry(queryEngine);
    CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine);
    functionFactory.cot();
    functionFactory.log();
    functionFactory.ln_log();
    functionFactory.log10();
    functionFactory.atan2_atn2();
    functionFactory.mod_operator();
    functionFactory.square();
    functionFactory.rand();
    functionFactory.radians();
    functionFactory.degrees();
    functionFactory.pi();
    functionFactory.reverse();
    functionFactory.space();
    functionFactory.pad_replicate();
    functionFactory.yearMonthDay();
    functionFactory.ascii();
    functionFactory.chr_char();
    functionFactory.trim1();
    functionFactory.repeat_replicate();
    functionFactory.characterLength_len();
    functionFactory.substring_substringLen();
    functionFactory.datepartDatename();
    functionFactory.lastDay_eomonth();
    queryEngine.getSqmFunctionRegistry().register("least", new CaseLeastGreatestEmulation(true));
    queryEngine.getSqmFunctionRegistry().register("greatest", new CaseLeastGreatestEmulation(false));
    queryEngine.getSqmFunctionRegistry().register("str", new TransactSQLStrFunction(queryEngine.getTypeConfiguration()));
    queryEngine.getSqmFunctionRegistry().register("concat", new CastingConcatFunction(this, "+", false, SqlAstNodeRenderingMode.DEFAULT, queryEngine.getTypeConfiguration()));
}
Also used : CommonFunctionFactory(org.hibernate.dialect.function.CommonFunctionFactory) CaseLeastGreatestEmulation(org.hibernate.dialect.function.CaseLeastGreatestEmulation) TransactSQLStrFunction(org.hibernate.dialect.function.TransactSQLStrFunction) CastingConcatFunction(org.hibernate.dialect.function.CastingConcatFunction)

Example 28 with CommonFunctionFactory

use of org.hibernate.dialect.function.CommonFunctionFactory in project hibernate-orm by hibernate.

the class CockroachDialect method initializeFunctionRegistry.

@Override
public void initializeFunctionRegistry(QueryEngine queryEngine) {
    super.initializeFunctionRegistry(queryEngine);
    final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry();
    final BasicType<String> stringType = basicTypeRegistry.resolve(StandardBasicTypes.STRING);
    CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine);
    functionFactory.ascii();
    functionFactory.char_chr();
    functionFactory.overlay();
    functionFactory.position();
    functionFactory.substringFromFor();
    functionFactory.locate_positionSubstring();
    functionFactory.trim2();
    functionFactory.substr();
    functionFactory.reverse();
    functionFactory.repeat();
    functionFactory.md5();
    functionFactory.sha1();
    functionFactory.octetLength();
    functionFactory.bitLength();
    functionFactory.cbrt();
    functionFactory.cot();
    functionFactory.degrees();
    functionFactory.radians();
    functionFactory.pi();
    // TODO: emulate second arg
    functionFactory.trunc();
    queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder("format", "experimental_strftime").setInvariantType(stringType).setArgumentsValidator(CommonFunctionFactory.formatValidator()).setArgumentListSignature("(TEMPORAL datetime as STRING pattern)").register();
    functionFactory.windowFunctions();
    functionFactory.listagg_stringAgg("string");
    functionFactory.inverseDistributionOrderedSetAggregates();
    functionFactory.hypotheticalOrderedSetAggregates();
}
Also used : CommonFunctionFactory(org.hibernate.dialect.function.CommonFunctionFactory) BasicTypeRegistry(org.hibernate.type.BasicTypeRegistry)

Example 29 with CommonFunctionFactory

use of org.hibernate.dialect.function.CommonFunctionFactory in project hibernate-orm by hibernate.

the class DB2Dialect method initializeFunctionRegistry.

@Override
public void initializeFunctionRegistry(QueryEngine queryEngine) {
    super.initializeFunctionRegistry(queryEngine);
    CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine);
    // 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.cot();
    functionFactory.degrees();
    functionFactory.log();
    functionFactory.log10();
    functionFactory.radians();
    functionFactory.rand();
    functionFactory.soundex();
    functionFactory.trim2();
    functionFactory.space();
    functionFactory.repeat();
    queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder("substr").setInvariantType(queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve(StandardBasicTypes.STRING)).setArgumentCountBetween(2, 4).setParameterTypes(FunctionParameterType.STRING, FunctionParameterType.INTEGER, FunctionParameterType.INTEGER, FunctionParameterType.ANY).setArgumentListSignature("(STRING string, INTEGER start[, INTEGER length[, units]])").register();
    queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder("substring").setInvariantType(queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve(StandardBasicTypes.STRING)).setArgumentCountBetween(2, 4).setParameterTypes(FunctionParameterType.STRING, FunctionParameterType.INTEGER, FunctionParameterType.INTEGER, FunctionParameterType.ANY).setArgumentListSignature("(STRING string{ INTEGER from|,} start[{ INTEGER for|,} length[, units]])").register();
    functionFactory.translate();
    functionFactory.bitand();
    functionFactory.bitor();
    functionFactory.bitxor();
    functionFactory.bitnot();
    functionFactory.yearMonthDay();
    functionFactory.hourMinuteSecond();
    functionFactory.dayofweekmonthyear();
    functionFactory.weekQuarter();
    functionFactory.daynameMonthname();
    functionFactory.lastDay();
    functionFactory.toCharNumberDateTimestamp();
    functionFactory.dateTimeTimestamp();
    functionFactory.concat_pipeOperator();
    functionFactory.octetLength();
    functionFactory.ascii();
    functionFactory.char_chr();
    functionFactory.position();
    functionFactory.trunc();
    functionFactory.truncate();
    functionFactory.insert();
    functionFactory.overlayCharacterLength_overlay();
    functionFactory.median();
    functionFactory.stddev();
    functionFactory.stddevPopSamp();
    functionFactory.regrLinearRegressionAggregates();
    functionFactory.variance();
    functionFactory.stdevVarianceSamp();
    functionFactory.addYearsMonthsDaysHoursMinutesSeconds();
    functionFactory.yearsMonthsDaysHoursMinutesSecondsBetween();
    functionFactory.dateTrunc();
    functionFactory.bitLength_pattern("length(?1)*8");
    // DB2 wants parameter operands to be casted to allow lengths bigger than 255
    queryEngine.getSqmFunctionRegistry().register("concat", new CastingConcatFunction(this, "||", true, SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER, queryEngine.getTypeConfiguration()));
    // For the count distinct emulation distinct
    queryEngine.getSqmFunctionRegistry().register("count", new CountFunction(this, queryEngine.getTypeConfiguration(), SqlAstNodeRenderingMode.DEFAULT, "||", getCastTypeName(queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve(StandardBasicTypes.STRING), null, null, null), true));
    queryEngine.getSqmFunctionRegistry().register("format", new DB2FormatEmulation(queryEngine.getTypeConfiguration()));
    queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder("posstr").setInvariantType(queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve(StandardBasicTypes.INTEGER)).setExactArgumentCount(2).setParameterTypes(FunctionParameterType.STRING, FunctionParameterType.STRING).setArgumentListSignature("(STRING string, STRING pattern)").register();
    functionFactory.windowFunctions();
    if (getDB2Version().isSameOrAfter(9, 5)) {
        functionFactory.listagg(null);
        if (getDB2Version().isSameOrAfter(11, 1)) {
            functionFactory.inverseDistributionOrderedSetAggregates();
            functionFactory.hypotheticalOrderedSetAggregates_windowEmulation();
        }
    }
}
Also used : CountFunction(org.hibernate.dialect.function.CountFunction) CommonFunctionFactory(org.hibernate.dialect.function.CommonFunctionFactory) DB2FormatEmulation(org.hibernate.dialect.function.DB2FormatEmulation) CastingConcatFunction(org.hibernate.dialect.function.CastingConcatFunction)

Example 30 with CommonFunctionFactory

use of org.hibernate.dialect.function.CommonFunctionFactory in project hibernate-orm by hibernate.

the class SybaseDialect method initializeFunctionRegistry.

@Override
public void initializeFunctionRegistry(QueryEngine queryEngine) {
    super.initializeFunctionRegistry(queryEngine);
    CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine);
    // For SQL-Server we need to cast certain arguments to varchar(16384) to be able to concat them
    queryEngine.getSqmFunctionRegistry().register("count", new CountFunction(this, queryEngine.getTypeConfiguration(), SqlAstNodeRenderingMode.DEFAULT, "+", "varchar(16384)", 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);
    // this doesn't work 100% on earlier versions of Sybase
    // which were missing the third parameter in charindex()
    // TODO: we could emulate it with substring() like in Postgres
    functionFactory.locate_charindex();
    functionFactory.replace_strReplace();
    functionFactory.everyAny_minMaxCase();
    functionFactory.bitLength_pattern("datalength(?1) * 8");
    queryEngine.getSqmFunctionRegistry().register("timestampadd", new IntegralTimestampaddFunction(this, queryEngine.getTypeConfiguration()));
}
Also used : IntegralTimestampaddFunction(org.hibernate.dialect.function.IntegralTimestampaddFunction) CountFunction(org.hibernate.dialect.function.CountFunction) CommonFunctionFactory(org.hibernate.dialect.function.CommonFunctionFactory)

Aggregations

CommonFunctionFactory (org.hibernate.dialect.function.CommonFunctionFactory)30 BasicTypeRegistry (org.hibernate.type.BasicTypeRegistry)9 CountFunction (org.hibernate.dialect.function.CountFunction)4 Date (java.util.Date)3 CaseLeastGreatestEmulation (org.hibernate.dialect.function.CaseLeastGreatestEmulation)3 CastingConcatFunction (org.hibernate.dialect.function.CastingConcatFunction)3 TypeConfiguration (org.hibernate.type.spi.TypeConfiguration)3 InsertSubstringOverlayEmulation (org.hibernate.dialect.function.InsertSubstringOverlayEmulation)2 IntegralTimestampaddFunction (org.hibernate.dialect.function.IntegralTimestampaddFunction)2 DateTimeUtils.appendAsDate (org.hibernate.type.descriptor.DateTimeUtils.appendAsDate)2 Instant (java.time.Instant)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 LocalTime (java.time.LocalTime)1 OffsetDateTime (java.time.OffsetDateTime)1 CastFunction (org.hibernate.dialect.function.CastFunction)1 CastStrEmulation (org.hibernate.dialect.function.CastStrEmulation)1 CoalesceIfnullEmulation (org.hibernate.dialect.function.CoalesceIfnullEmulation)1 CurrentFunction (org.hibernate.dialect.function.CurrentFunction)1 DB2FormatEmulation (org.hibernate.dialect.function.DB2FormatEmulation)1