Search in sources :

Example 16 with SqlFunction

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

the class SqlGenerator method beginFunctionTemplate.

@Override
protected void beginFunctionTemplate(AST node, AST nameNode) {
    // NOTE for AGGREGATE both nodes are the same; for METHOD the first is the METHOD, the second is the
    // 		METHOD_NAME
    FunctionNode functionNode = (FunctionNode) node;
    SQLFunction sqlFunction = functionNode.getSQLFunction();
    if (sqlFunction == null) {
        // if SQLFunction is null we just write the function out as it appears in the hql statement
        super.beginFunctionTemplate(node, nameNode);
    } else {
        // this function has a registered SQLFunction -> redirect output and catch the arguments
        outputStack.addFirst(writer);
        if (node.getType() == CAST) {
            writer = new CastFunctionArguments();
        } else {
            writer = new StandardFunctionArguments();
        }
    }
}
Also used : FunctionNode(org.hibernate.hql.internal.ast.tree.FunctionNode) SQLFunction(org.hibernate.dialect.function.SQLFunction)

Example 17 with SqlFunction

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

the class SQLFunctionsTest method locateAppropriateDialectFunctionNameForAliasTest.

private String locateAppropriateDialectFunctionNameForAliasTest() {
    for (Iterator itr = getDialect().getFunctions().entrySet().iterator(); itr.hasNext(); ) {
        final Map.Entry entry = (Map.Entry) itr.next();
        final SQLFunction function = (SQLFunction) entry.getValue();
        if (!function.hasArguments() && !function.hasParenthesesIfNoArguments()) {
            return (String) entry.getKey();
        }
    }
    return null;
}
Also used : Iterator(java.util.Iterator) SQLFunction(org.hibernate.dialect.function.SQLFunction) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with SqlFunction

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

the class Configuration method buildSessionFactory.

/**
	 * Create a {@link SessionFactory} using the properties and mappings in this configuration. The
	 * SessionFactory will be immutable, so changes made to this Configuration afterQuery building the
	 * SessionFactory will not affect it.
	 *
	 * @param serviceRegistry The registry of services to be used in creating this session factory.
	 *
	 * @return The built {@link SessionFactory}
	 *
	 * @throws HibernateException usually indicates an invalid configuration or invalid mapping information
	 */
public SessionFactory buildSessionFactory(ServiceRegistry serviceRegistry) throws HibernateException {
    log.debug("Building session factory using provided StandardServiceRegistry");
    final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder((StandardServiceRegistry) serviceRegistry);
    if (implicitNamingStrategy != null) {
        metadataBuilder.applyImplicitNamingStrategy(implicitNamingStrategy);
    }
    if (physicalNamingStrategy != null) {
        metadataBuilder.applyPhysicalNamingStrategy(physicalNamingStrategy);
    }
    if (sharedCacheMode != null) {
        metadataBuilder.applySharedCacheMode(sharedCacheMode);
    }
    if (!typeContributorRegistrations.isEmpty()) {
        for (TypeContributor typeContributor : typeContributorRegistrations) {
            metadataBuilder.applyTypes(typeContributor);
        }
    }
    if (!basicTypes.isEmpty()) {
        for (BasicType basicType : basicTypes) {
            metadataBuilder.applyBasicType(basicType);
        }
    }
    if (sqlFunctions != null) {
        for (Map.Entry<String, SQLFunction> entry : sqlFunctions.entrySet()) {
            metadataBuilder.applySqlFunction(entry.getKey(), entry.getValue());
        }
    }
    if (auxiliaryDatabaseObjectList != null) {
        for (AuxiliaryDatabaseObject auxiliaryDatabaseObject : auxiliaryDatabaseObjectList) {
            metadataBuilder.applyAuxiliaryDatabaseObject(auxiliaryDatabaseObject);
        }
    }
    if (attributeConverterDefinitionsByClass != null) {
        for (AttributeConverterDefinition attributeConverterDefinition : attributeConverterDefinitionsByClass.values()) {
            metadataBuilder.applyAttributeConverter(attributeConverterDefinition);
        }
    }
    final Metadata metadata = metadataBuilder.build();
    final SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
    if (interceptor != null && interceptor != EmptyInterceptor.INSTANCE) {
        sessionFactoryBuilder.applyInterceptor(interceptor);
    }
    if (getSessionFactoryObserver() != null) {
        sessionFactoryBuilder.addSessionFactoryObservers(getSessionFactoryObserver());
    }
    if (getEntityNotFoundDelegate() != null) {
        sessionFactoryBuilder.applyEntityNotFoundDelegate(getEntityNotFoundDelegate());
    }
    if (getEntityTuplizerFactory() != null) {
        sessionFactoryBuilder.applyEntityTuplizerFactory(getEntityTuplizerFactory());
    }
    if (getCurrentTenantIdentifierResolver() != null) {
        sessionFactoryBuilder.applyCurrentTenantIdentifierResolver(getCurrentTenantIdentifierResolver());
    }
    return sessionFactoryBuilder.build();
}
Also used : BasicType(org.hibernate.type.BasicType) MetadataBuilder(org.hibernate.boot.MetadataBuilder) SessionFactoryBuilder(org.hibernate.boot.SessionFactoryBuilder) Metadata(org.hibernate.boot.Metadata) SQLFunction(org.hibernate.dialect.function.SQLFunction) AuxiliaryDatabaseObject(org.hibernate.boot.model.relational.AuxiliaryDatabaseObject) Map(java.util.Map) HashMap(java.util.HashMap) TypeContributor(org.hibernate.boot.model.TypeContributor)

Aggregations

SQLFunction (org.hibernate.dialect.function.SQLFunction)18 Test (org.junit.Test)7 List (java.util.List)5 ArrayList (java.util.ArrayList)4 Session (org.hibernate.Session)4 Type (org.hibernate.type.Type)4 Map (java.util.Map)3 Transaction (org.hibernate.Transaction)3 CommonAST (antlr.CommonAST)2 AST (antlr.collections.AST)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Mapping (org.hibernate.engine.spi.Mapping)2 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)2 FunctionNode (org.hibernate.hql.internal.ast.tree.FunctionNode)2 Component (org.hibernate.mapping.Component)2 Formula (org.hibernate.mapping.Formula)2 TestForIssue (org.hibernate.testing.TestForIssue)2 HibernateException (org.hibernate.HibernateException)1 SQLQuery (org.hibernate.SQLQuery)1