Search in sources :

Example 1 with SqmFunctionRegistry

use of org.hibernate.query.sqm.function.SqmFunctionRegistry in project hibernate-orm by hibernate.

the class FirebirdDialect method initializeFunctionRegistry.

@Override
public void initializeFunctionRegistry(QueryEngine queryEngine) {
    super.initializeFunctionRegistry(queryEngine);
    final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry();
    final BasicType<byte[]> byteArrayType = basicTypeRegistry.resolve(StandardBasicTypes.BINARY);
    final BasicType<Integer> integerType = basicTypeRegistry.resolve(StandardBasicTypes.INTEGER);
    final BasicType<Short> shortType = basicTypeRegistry.resolve(StandardBasicTypes.SHORT);
    final BasicType<Double> doubleType = basicTypeRegistry.resolve(StandardBasicTypes.DOUBLE);
    final BasicType<Character> characterType = basicTypeRegistry.resolve(StandardBasicTypes.CHARACTER);
    CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine);
    functionFactory.concat_pipeOperator();
    functionFactory.cot();
    functionFactory.cosh();
    functionFactory.sinh();
    functionFactory.tanh();
    if (getVersion().isSameOrAfter(3, 0)) {
        functionFactory.moreHyperbolic();
        functionFactory.stddevPopSamp();
        functionFactory.varPopSamp();
        functionFactory.covarPopSamp();
        functionFactory.corr();
        functionFactory.regrLinearRegressionAggregates();
    }
    functionFactory.log();
    functionFactory.log10();
    functionFactory.pi();
    functionFactory.rand();
    functionFactory.sinh();
    functionFactory.tanh();
    functionFactory.cosh();
    functionFactory.trunc();
    functionFactory.octetLength();
    functionFactory.bitLength();
    functionFactory.substringFromFor();
    functionFactory.overlay();
    functionFactory.position();
    functionFactory.reverse();
    functionFactory.bitandorxornot_binAndOrXorNot();
    functionFactory.leastGreatest_minMaxValue();
    SqmFunctionRegistry functionRegistry = queryEngine.getSqmFunctionRegistry();
    functionRegistry.registerBinaryTernaryPattern("locate", integerType, "position(?1 in ?2)", "position(?1,?2,?3)", STRING, STRING, INTEGER, queryEngine.getTypeConfiguration()).setArgumentListSignature("(pattern, string[, start])");
    functionRegistry.namedDescriptorBuilder("ascii_val").setExactArgumentCount(1).setInvariantType(shortType).register();
    functionRegistry.registerAlternateKey("ascii", "ascii_val");
    functionRegistry.namedDescriptorBuilder("ascii_char").setExactArgumentCount(1).setInvariantType(characterType).register();
    functionRegistry.registerAlternateKey("chr", "ascii_char");
    functionRegistry.registerAlternateKey("char", "ascii_char");
    functionRegistry.registerPattern("radians", "((?1)*pi()/180e0)", doubleType);
    functionRegistry.registerPattern("degrees", "((?1)*180e0/pi())", doubleType);
    if (getVersion().isSameOrAfter(3)) {
        functionFactory.windowFunctions();
        if (getVersion().isSameOrAfter(4, 0)) {
            Arrays.asList("md5", "sha1", "sha256", "sha512").forEach(hash -> functionRegistry.registerPattern(hash, "crypt_hash(?1 using " + hash + ")", byteArrayType));
            functionRegistry.registerAlternateKey("sha", "sha1");
            functionRegistry.registerPattern("crc32", "hash(?1 using crc32)", integerType);
        }
    }
    functionFactory.listagg_list("varchar");
}
Also used : CommonFunctionFactory(org.hibernate.dialect.function.CommonFunctionFactory) BasicTypeRegistry(org.hibernate.type.BasicTypeRegistry) SqmFunctionRegistry(org.hibernate.query.sqm.function.SqmFunctionRegistry)

Example 2 with SqmFunctionRegistry

use of org.hibernate.query.sqm.function.SqmFunctionRegistry in project hibernate-orm by hibernate.

the class QueryEngine method from.

public static QueryEngine from(SessionFactoryImplementor sessionFactory, MetadataImplementor metadata) {
    final QueryEngineOptions queryEngineOptions = sessionFactory.getSessionFactoryOptions();
    final SqmCreationOptions sqmCreationOptions = new SqmCreationOptionsStandard(sessionFactory);
    final Dialect dialect = sessionFactory.getJdbcServices().getDialect();
    final HqlTranslator hqlTranslator = resolveHqlTranslator(queryEngineOptions, dialect, sessionFactory, sqmCreationOptions);
    final SqmTranslatorFactory sqmTranslatorFactory = resolveSqmTranslatorFactory(queryEngineOptions, dialect);
    final SqmFunctionRegistry customSqmFunctionRegistry;
    if (queryEngineOptions.getCustomSqmFunctionRegistry() == null) {
        final Map<String, SqmFunctionDescriptor> customSqlFunctionMap = queryEngineOptions.getCustomSqlFunctionMap();
        if (customSqlFunctionMap == null || customSqlFunctionMap.isEmpty()) {
            customSqmFunctionRegistry = null;
        } else {
            customSqmFunctionRegistry = new SqmFunctionRegistry();
            customSqlFunctionMap.forEach(customSqmFunctionRegistry::register);
        }
    } else {
        customSqmFunctionRegistry = queryEngineOptions.getCustomSqmFunctionRegistry();
    }
    return new QueryEngine(sessionFactory.getUuid(), sessionFactory.getName(), sessionFactory.getSessionFactoryOptions().getJpaCompliance(), () -> sessionFactory.getRuntimeMetamodels().getJpaMetamodel(), sessionFactory.getSessionFactoryOptions().getCriteriaValueHandlingMode(), sessionFactory.getSessionFactoryOptions().getPreferredSqlTypeCodeForBoolean(), metadata.buildNamedQueryRepository(sessionFactory), hqlTranslator, sqmTranslatorFactory, sessionFactory.getServiceRegistry().getService(NativeQueryInterpreter.class), buildInterpretationCache(sessionFactory::getStatistics, sessionFactory.getProperties()), metadata.getTypeConfiguration(), dialect, customSqmFunctionRegistry, sessionFactory.getServiceRegistry());
}
Also used : SqmCreationOptionsStandard(org.hibernate.query.sqm.internal.SqmCreationOptionsStandard) SqmFunctionDescriptor(org.hibernate.query.sqm.function.SqmFunctionDescriptor) NativeQueryInterpreter(org.hibernate.engine.query.spi.NativeQueryInterpreter) SqmCreationOptions(org.hibernate.query.hql.spi.SqmCreationOptions) HqlTranslator(org.hibernate.query.hql.HqlTranslator) StandardHqlTranslator(org.hibernate.query.hql.internal.StandardHqlTranslator) Dialect(org.hibernate.dialect.Dialect) StandardSqmTranslatorFactory(org.hibernate.query.sqm.sql.StandardSqmTranslatorFactory) SqmTranslatorFactory(org.hibernate.query.sqm.sql.SqmTranslatorFactory) SqmFunctionRegistry(org.hibernate.query.sqm.function.SqmFunctionRegistry)

Example 3 with SqmFunctionRegistry

use of org.hibernate.query.sqm.function.SqmFunctionRegistry in project hibernate-orm by hibernate.

the class SqlServerDialectContributor method contributeFunctions.

@Override
public void contributeFunctions(FunctionContributions functionContributions) {
    HSMessageLogger.LOGGER.functionContributions(this.getClass().getCanonicalName());
    final SqlServerSqmFunctionDescriptors functions = new SqlServerSqmFunctionDescriptors(functionContributions);
    final SqmFunctionRegistry functionRegistry = functionContributions.getFunctionRegistry();
    functions.asMap().forEach((key, desc) -> {
        functionRegistry.register(key.getName(), desc);
        key.getAltName().ifPresent(altName -> functionRegistry.registerAlternateKey(altName, key.getName()));
    });
}
Also used : SqmFunctionRegistry(org.hibernate.query.sqm.function.SqmFunctionRegistry)

Example 4 with SqmFunctionRegistry

use of org.hibernate.query.sqm.function.SqmFunctionRegistry in project hibernate-orm by hibernate.

the class CockroachDbContributor method contributeFunctions.

@Override
public void contributeFunctions(FunctionContributions functionContributions) {
    HSMessageLogger.LOGGER.functionContributions(this.getClass().getCanonicalName());
    final PostgisSqmFunctionDescriptors postgisFunctions = new PostgisSqmFunctionDescriptors(functionContributions);
    final SqmFunctionRegistry functionRegistry = functionContributions.getFunctionRegistry();
    postgisFunctions.asMap().forEach((key, desc) -> {
        if (isUnsupported(key)) {
            return;
        }
        functionRegistry.register(key.getName(), desc);
        key.getAltName().ifPresent(altName -> functionRegistry.registerAlternateKey(altName, key.getName()));
    });
}
Also used : SqmFunctionRegistry(org.hibernate.query.sqm.function.SqmFunctionRegistry) PostgisSqmFunctionDescriptors(org.hibernate.spatial.dialect.postgis.PostgisSqmFunctionDescriptors)

Example 5 with SqmFunctionRegistry

use of org.hibernate.query.sqm.function.SqmFunctionRegistry in project hibernate-orm by hibernate.

the class H2GisDialectContributor method contributeFunctions.

@Override
public void contributeFunctions(FunctionContributions functionContributions) {
    HSMessageLogger.LOGGER.functionContributions(this.getClass().getCanonicalName());
    final KeyedSqmFunctionDescriptors functions = new H2SqmFunctionDescriptors(functionContributions);
    final SqmFunctionRegistry functionRegistry = functionContributions.getFunctionRegistry();
    functions.asMap().forEach((key, desc) -> {
        functionRegistry.register(key.getName(), desc);
        key.getAltName().ifPresent(altName -> functionRegistry.registerAlternateKey(altName, key.getName()));
    });
}
Also used : KeyedSqmFunctionDescriptors(org.hibernate.spatial.KeyedSqmFunctionDescriptors) SqmFunctionRegistry(org.hibernate.query.sqm.function.SqmFunctionRegistry)

Aggregations

SqmFunctionRegistry (org.hibernate.query.sqm.function.SqmFunctionRegistry)10 KeyedSqmFunctionDescriptors (org.hibernate.spatial.KeyedSqmFunctionDescriptors)4 Dialect (org.hibernate.dialect.Dialect)1 CommonFunctionFactory (org.hibernate.dialect.function.CommonFunctionFactory)1 NativeQueryInterpreter (org.hibernate.engine.query.spi.NativeQueryInterpreter)1 HqlTranslator (org.hibernate.query.hql.HqlTranslator)1 StandardHqlTranslator (org.hibernate.query.hql.internal.StandardHqlTranslator)1 SqmCreationOptions (org.hibernate.query.hql.spi.SqmCreationOptions)1 SqmFunctionDescriptor (org.hibernate.query.sqm.function.SqmFunctionDescriptor)1 SqmCreationOptionsStandard (org.hibernate.query.sqm.internal.SqmCreationOptionsStandard)1 SqmTranslatorFactory (org.hibernate.query.sqm.sql.SqmTranslatorFactory)1 StandardSqmTranslatorFactory (org.hibernate.query.sqm.sql.StandardSqmTranslatorFactory)1 PostgisSqmFunctionDescriptors (org.hibernate.spatial.dialect.postgis.PostgisSqmFunctionDescriptors)1 SessionFactoryScope (org.hibernate.testing.orm.junit.SessionFactoryScope)1 BasicTypeRegistry (org.hibernate.type.BasicTypeRegistry)1 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)1