Interface JpaProvider


  • public interface JpaProvider
    A JPA provider implementation provides information about which features are supported by a JPA implementation.
    Since:
    1.2.0
    Author:
    Christian Beikov
    • Method Detail

      • supportsJpa21

        boolean supportsJpa21()
        Whether JPA 2.1 specification is supported.
        Returns:
        True if JPA 2.1 is supported, false otherwise
      • supportsEntityJoin

        boolean supportsEntityJoin()
        Whether Entity Joins are supported.
        Returns:
        True if Entity Joins are supported, false otherwise
      • supportsInsertStatement

        boolean supportsInsertStatement()
        Whether Insert statements are supported.
        Returns:
        True if Insert statements are supported, false otherwise
      • needsBracketsForListParameter

        boolean needsBracketsForListParameter()
        Whether brackets are needed around a list parameter.
        Returns:
        True if brackets are needed, false otherwise
      • needsJoinSubqueryRewrite

        boolean needsJoinSubqueryRewrite()
        Returns whether key restricted left joins should be rewritten to subquery joins. This is part of the workaround for https://hibernate.atlassian.net/browse/HHH-9329 which makes key restricted left joins wrong.
        Returns:
        true if joins should be rewritten to subquery joins, false otherwise
      • getBooleanExpression

        String getBooleanExpression​(boolean value)
        The JPQL expression to use for the given literal boolean value. This expression is used in contexts where an expression is assumed.
        Parameters:
        value - The boolean value
        Returns:
        The JPQL expression to use to reflect the boolean value
      • getBooleanConditionalExpression

        String getBooleanConditionalExpression​(boolean value)
        The JPQL conditional expression to use for the given literal boolean value. This expression is used in contexts where a predicate is assumed.
        Parameters:
        value - The boolean value
        Returns:
        The JPQL conditional expression to use to reflect the boolean value
      • getNullExpression

        String getNullExpression()
        The JPQL expression to use for the NULL literal.
        Returns:
        The JPQL expression to use to reflect the NULL value
      • getOnClause

        String getOnClause()
        The name of the clause that has the same semantics as the ON clause which was introduced in JPA 2.1.
        Returns:
        The name of the ON clause
      • getCollectionValueFunction

        String getCollectionValueFunction()
        Normally returns VALUE, but since Hibernate does weird things when using that, it returns null. Returning null results in omitting VALUE in the final query that is passed to the JPA provider.
        Returns:
        The value function
      • supportsCollectionValueDereference

        boolean supportsCollectionValueDereference()
        Whether dereferencing a VALUE function expression is supported by the JPA provider.
        Returns:
        True if dereferencing is supported, false otherwise
      • getDefaultQueryResultType

        Class<?> getDefaultQueryResultType()
        The default result type of a scalar query.
        Returns:
        The default result type
      • getCustomFunctionInvocation

        String getCustomFunctionInvocation​(String functionName,
                                           int argumentCount)
        Returns the start of a JPQL representation of a function invocation for the given function name and argument count. Normally this returns FUNCTION('functionName', but implementations may also allow to render the function name directly.
        Parameters:
        functionName - The function name
        argumentCount - The number of the arguments that the function is invoked with
        Returns:
        The start of the JPQL represenation for the function invocation
      • escapeCharacter

        String escapeCharacter​(char character)
        The given escape character for a LIKE predicate as string.
        Parameters:
        character - The escape character
        Returns:
        The string representation
      • supportsNullPrecedenceExpression

        boolean supportsNullPrecedenceExpression()
        Whether the query language supports the null precedence clause.
        Returns:
        True if the null precedence clause is supported, false otherwise
      • renderNullPrecedence

        void renderNullPrecedence​(StringBuilder sb,
                                  String expression,
                                  String resolvedExpression,
                                  String order,
                                  String nulls)
        Renders the null precedence into the given string builder.
        Parameters:
        sb - The builder to which the null precedence should be appended to
        expression - The order by expression which might be a select alias
        resolvedExpression - The resolved expression for a possible select alias or the expression
        order - The order as string (ASC or DESC)
        nulls - The null precedence as string (NULLS FIRST or NULLS LAST)
      • supportsRootTreat

        boolean supportsRootTreat()
        Whether treating a from/root alias is supported. For example SELECT TREAT(alias AS Subtype).property FROM ..
        Returns:
        True if treating a from alias is supported, false otherwise
      • supportsTreatJoin

        boolean supportsTreatJoin()
        Whether a treat join is supported. For example SELECT ... FROM .. JOIN TREAT(alias.relation AS Subtype)
        Returns:
        True if a treat join is supported, false otherwise
      • supportsTreatCorrelation

        boolean supportsTreatCorrelation()
        Whether a correlation path with a treat expression is supported. For example SELECT (SELECT .. FROM TREAT(parent AS Subtype).relation) FROM ..
        Returns:
        True if a treat in correlation expressions is supported, false otherwise
      • supportsRootTreatJoin

        boolean supportsRootTreatJoin()
        Whether a root treat in a join is supported. For example SELECT ... FROM .. JOIN TREAT(alias AS Subtype).relation
        Returns:
        True if a root treat in a join is supported, false otherwise
      • supportsRootTreatTreatJoin

        boolean supportsRootTreatTreatJoin()
        Whether a root treat in a treat join is supported. For example SELECT ... FROM .. JOIN TREAT(TREAT(alias AS Subtype).relation AS Subtype)
        Returns:
        True if a root treat in a treat join is supported, false otherwise
      • supportsSubtypePropertyResolving

        boolean supportsSubtypePropertyResolving()
        Whether properties accessed of a from node are implicitly resolved to properties of a subtype of the from node.
        Returns:
        True if subtype property resolving is supported, false otherwise
      • supportsSubtypeRelationResolving

        boolean supportsSubtypeRelationResolving()
        Whether relations of a from node in joins are implicitly resolved to the relations of a subtype of the from node.
        Returns:
        True if subtype relation resolving is supported, false otherwise
      • supportsCountStar

        boolean supportsCountStar()
        Whether the COUNT(*) syntax is supported.
        Returns:
        True if COUNT(*) syntax is supported, false otherwise
      • supportsCustomFunctions

        boolean supportsCustomFunctions()
        Whether the custom functions are supported.
        Returns:
        True if custom functions are supported, false otherwise
        Since:
        1.4.0
      • supportsNonScalarSubquery

        boolean supportsNonScalarSubquery()
        Whether the non scalar subqueries are supported.
        Returns:
        True if non scalar subqueries are supported, false otherwise
        Since:
        1.4.1
      • supportsSubqueryInFunction

        boolean supportsSubqueryInFunction()
        Whether the subqueries in functions are supported.
        Returns:
        True if subqueries in functions are supported, false otherwise
        Since:
        1.4.1
      • supportsSubqueryAliasShadowing

        boolean supportsSubqueryAliasShadowing()
        Whether the subqueries alias shadowing is supported.
        Returns:
        True if subqueries alias shadowing is supported, false otherwise
        Since:
        1.4.1
      • getDiscriminatorColumnCheck

        String[] getDiscriminatorColumnCheck​(javax.persistence.metamodel.EntityType<?> entityType)
        Returns an array with the column name of the discriminator of the given entity type and the discriminator value, or null.
        Parameters:
        entityType - The entity type
        Returns:
        The column name of the discriminator and the discriminator value, or null
        Since:
        1.3.0
      • isForeignJoinColumn

        boolean isForeignJoinColumn​(javax.persistence.metamodel.EntityType<?> ownerType,
                                    String attributeName)
        Whether the join columns for the given attribute are in a foreign table.
        Parameters:
        ownerType - The owner of the attribute
        attributeName - The attribute name to check
        Returns:
        True if join columns are in a foreign table, false otherwise
      • isColumnShared

        boolean isColumnShared​(javax.persistence.metamodel.EntityType<?> ownerType,
                               String attributeName)
        Whether columns for the given attribute are shared between multiple subtypes or shared by occupying the same slot in the resulting SQL.
        Parameters:
        ownerType - The owner of the attribute
        attributeName - The attribute name to check
        Returns:
        True if columns of the attribute are shared, false otherwise
      • getColumnNames

        String[] getColumnNames​(javax.persistence.metamodel.EntityType<?> ownerType,
                                String attributeName)
        Returns the column names of the attribute of the given entity type.
        Parameters:
        ownerType - The owner of the attribute
        attributeName - The attribute name
        Returns:
        The column names of the attribute
      • getColumnNames

        String[] getColumnNames​(javax.persistence.metamodel.EntityType<?> ownerType,
                                String elementCollectionPath,
                                String attributeName)
        Returns the column names of the attribute of the given entity type within the element collection.
        Parameters:
        ownerType - The owner of the attribute
        elementCollectionPath - The path to the element collection within which the attribute is contained
        attributeName - The attribute name
        Returns:
        The column names of the attribute
        Since:
        1.3.0
      • getColumnTypes

        String[] getColumnTypes​(javax.persistence.metamodel.EntityType<?> ownerType,
                                String attributeName)
        Returns the SQL column type names of the given attribute of the given entity type.
        Parameters:
        ownerType - The owner of the attribute
        attributeName - The attribute name
        Returns:
        The SQL column type names for the attribute
      • getColumnTypes

        String[] getColumnTypes​(javax.persistence.metamodel.EntityType<?> ownerType,
                                String elementCollectionPath,
                                String attributeName)
        Returns the SQL column type names of the given attribute of the given entity type within the element collection.
        Parameters:
        ownerType - The owner of the attribute
        elementCollectionPath - The path to the element collection within which the attribute is contained
        attributeName - The attribute name
        Returns:
        The SQL column type names for the attribute
        Since:
        1.3.0
      • requiresTreatFilter

        JpaProvider.ConstraintType requiresTreatFilter​(javax.persistence.metamodel.EntityType<?> ownerType,
                                                       String attributeName,
                                                       JoinType joinType)
        Returns where to put treat filters for a treat joined association of this attribute. This is for JPA providers that don't correctly filter the types. Hibernate for example does not automatically add the type constraint to treat joins of a type that uses the table per class inheritance strategy.
        Parameters:
        ownerType - The declaring type of the attribute to check
        attributeName - The attribute name for which to check the treat filter requirement or null
        joinType - The join type used for the treat join
        Returns:
        The constraint type for the treat filter
      • getMappedBy

        String getMappedBy​(javax.persistence.metamodel.EntityType<?> ownerType,
                           String attributeName)
        If the given attribute is an inverse collection, the mapped by attribute name is returned. Otherwise returns null.
        Parameters:
        ownerType - The declaring type of the attribute to check
        attributeName - The name of the inverse attribute for which to retrieve the mapped by value
        Returns:
        The mapped by attribute name if the given attribute is an inverse collection, null otherwise
      • getWritableMappedByMappings

        Map<String,​String> getWritableMappedByMappings​(javax.persistence.metamodel.EntityType<?> inverseType,
                                                             javax.persistence.metamodel.EntityType<?> ownerType,
                                                             String attributeName,
                                                             String inverseAttribute)
        If the given attribute is insertable = false and updatable = false it returns the writable mappings for the inverse type. Otherwise returns null.
        Parameters:
        inverseType - The type containing the inverse relation
        ownerType - The declaring type of the attribute to check
        attributeName - The name of the attribute for which to retrieve the writable mapped by mapping
        inverseAttribute - The name of the inverse attribute for which to retrieve the writable mapped by mapping
        Returns:
        The writable mappings for the inverse type if the attribute is not insertable or updatable, null otherwise
      • getJoinTable

        JoinTable getJoinTable​(javax.persistence.metamodel.EntityType<?> ownerType,
                               String attributeName)
        If the given attribute is a collection that uses a join table, returns it's descriptor. Otherwise returns null.
        Parameters:
        ownerType - The declaring type of the attribute to check
        attributeName - The name of the attribute for which to retrieve the join table name
        Returns:
        The join table information if the attribute has one, null otherwise
      • isBag

        boolean isBag​(javax.persistence.metamodel.EntityType<?> ownerType,
                      String attributeName)
        Whether the given attribute is a non-indexed and non-ordered collection a.k.a. a bag.
        Parameters:
        ownerType - The declaring type of the attribute to check
        attributeName - The name of the attribute to check
        Returns:
        True if it is a bag, false otherwise
      • isOrphanRemoval

        boolean isOrphanRemoval​(javax.persistence.metamodel.ManagedType<?> ownerType,
                                String attributeName)
        Whether orphan removal is activated for the given attribute.
        Parameters:
        ownerType - The declaring type of the attribute to check
        attributeName - The name of the attribute to check
        Returns:
        True if orphan removal is activated, else false
      • isOrphanRemoval

        boolean isOrphanRemoval​(javax.persistence.metamodel.ManagedType<?> ownerType,
                                String elementCollectionPath,
                                String attributeName)
        Whether orphan removal is activated for the given attribute within the element collection.
        Parameters:
        ownerType - The declaring type of the attribute to check
        elementCollectionPath - The path to the element collection within which the attribute is contained
        attributeName - The name of the attribute to check
        Returns:
        True if orphan removal is activated, else false
        Since:
        1.3.0
      • isDeleteCascaded

        boolean isDeleteCascaded​(javax.persistence.metamodel.ManagedType<?> ownerType,
                                 String attributeName)
        Whether delete cascading is activated for the given attribute.
        Parameters:
        ownerType - The declaring type of the attribute to check
        attributeName - The name of the attribute to check
        Returns:
        True if delete cascading is activated, else false
      • isDeleteCascaded

        boolean isDeleteCascaded​(javax.persistence.metamodel.ManagedType<?> ownerType,
                                 String elementCollectionPath,
                                 String attributeName)
        Whether delete cascading is activated for the given attribute within the element collection.
        Parameters:
        ownerType - The declaring type of the attribute to check
        elementCollectionPath - The path to the element collection within which the attribute is contained
        attributeName - The name of the attribute to check
        Returns:
        True if delete cascading is activated, else false
        Since:
        1.3.0
      • hasJoinCondition

        boolean hasJoinCondition​(javax.persistence.metamodel.ManagedType<?> ownerType,
                                 String elementCollectionPath,
                                 String attributeName)
        Whether the given attribute has a join condition.
        Parameters:
        ownerType - The declaring type of the attribute to check
        elementCollectionPath - The nullable path to the element collection within which the attribute is contained
        attributeName - The name of the attribute to check
        Returns:
        True if it has a join condition, else false
      • containsEntity

        boolean containsEntity​(javax.persistence.EntityManager em,
                               Class<?> entityClass,
                               Object id)
        Returns whether the entity with the id is contained in the entity managers persistence context.
        Parameters:
        em - The entity manager
        entityClass - The entity class
        id - The entity id
        Returns:
        True if it is contained, false otherwise
      • supportsSingleValuedAssociationIdExpressions

        boolean supportsSingleValuedAssociationIdExpressions()
        Indicates if the provider supports expressions like doc.owner.id without generating an extra join.
        Returns:
        true if supported, else false
      • supportsForeignAssociationInOnClause

        boolean supportsForeignAssociationInOnClause()
        Indicates if the provider supports the use of foreign associations in the ON clause. This is the case when implicit joins in the ON clause are specially treated regarding SQL rendering. If an expression like alias.association.property results in a subquery or table group join when used in the ON clause, the JPA provider supports this feature. Normally this silently fails with invalid SQL. By returning false, subqueries will be generated for such associations instead. The value is not yet used but will be in a future version. Also see: https://github.com/Blazebit/blaze-persistence/issues/402
        Returns:
        true if supported, else false
      • supportsUpdateSetEmbeddable

        boolean supportsUpdateSetEmbeddable()
        Indicates whether an embeddable can be set via an update queries SET clause. Although the JPA spec mandates this, it doesn't seem to be asserted so some providers don't support it.
        Returns:
        true if supported, else false
      • supportsUpdateSetAssociationId

        boolean supportsUpdateSetAssociationId()
        Indicates whether an association id can be set via an update queries SET clause or if the association has to be set as a whole.
        Returns:
        true if supported, else false
        Since:
        1.5.0
      • supportsTransientEntityAsParameter

        boolean supportsTransientEntityAsParameter()
        Indicates if the provider supports the use of transient entity objects as parameters.
        Returns:
        true if supported, else false
      • needsAssociationToIdRewriteInOnClause

        boolean needsAssociationToIdRewriteInOnClause()
        Indicates if the provider needs associations in the ON clause to use their id. If needed, an expression like alias.association in the ON clause is rewritten to alias.association.id.
        Returns:
        true if required, else false
      • needsBrokenAssociationToIdRewriteInOnClause

        boolean needsBrokenAssociationToIdRewriteInOnClause()
        Indicates if the provider needs associations in the ON clause to use their id. If needed, an expression like alias.association in the ON clause is rewritten to alias.association.id which relies on a broken type check in older Hibernate versions.
        Returns:
        true if required, else false
      • needsTypeConstraintForColumnSharing

        boolean needsTypeConstraintForColumnSharing()
        Indicates if the provider does column sharing for same named columns in inheritance mappings and thus requires the use of a CASE WHEN expression for restricting casted accesses like e.g. TREAT(alias AS Subtype).property to retain cast semantics.
        Returns:
        true if required, else false
      • supportsCollectionTableCleanupOnDelete

        boolean supportsCollectionTableCleanupOnDelete()
        Indicates whether the provider clears collection table entries on bulk delete operations.
        Returns:
        true if supported, else false
      • supportsJoinTableCleanupOnDelete

        boolean supportsJoinTableCleanupOnDelete()
        Indicates whether the provider clears join table entries on bulk delete operations.
        Returns:
        true if supported, else false
      • needsCorrelationPredicateWhenCorrelatingWithWhereClause

        boolean needsCorrelationPredicateWhenCorrelatingWithWhereClause()
        Indicates whether the provider supports correlating inverse associations.
        Returns:
        true if needed, else false
        Since:
        1.3.0
      • supportsSingleValuedAssociationNaturalIdExpressions

        boolean supportsSingleValuedAssociationNaturalIdExpressions()
        Indicates whether the provider supports optimized natural id access.
        Returns:
        true if supported, else false
        Since:
        1.3.0
      • supportsGroupByEntityAlias

        boolean supportsGroupByEntityAlias()
        Indicates whether the provider supports group by entity alias properly.
        Returns:
        true if supported, else false
        Since:
        1.3.0
      • needsElementCollectionIdCutoff

        boolean needsElementCollectionIdCutoff()
        Indicates whether the provider needs to cutoff id properties when used as subpath of element collections. This is to be able to workaround https://hibernate.atlassian.net/browse/HHH-13045 .
        Returns:
        true if needed, else false
        Since:
        1.3.0
      • needsUnproxyForFieldAccess

        boolean needsUnproxyForFieldAccess()
        Indicates whether the provider requires an unproxied entity for field access to work.
        Returns:
        true if needed, else false
        Since:
        1.4.1
      • setCacheable

        void setCacheable​(javax.persistence.Query query)
        Enables query result caching for the given query.
        Parameters:
        query - Enables query result caching for the query
        Since:
        1.2.0
      • getIdentifierOrUniqueKeyEmbeddedPropertyNames

        List<String> getIdentifierOrUniqueKeyEmbeddedPropertyNames​(javax.persistence.metamodel.EntityType<?> owner,
                                                                   String attributeName)
        Get the identifier or unique key inverse properties of an association attribute.
        Parameters:
        owner - The owning entity type
        attributeName - The association attribute
        Returns:
        the identifier or unique key inverse properties of the association attribute
        Since:
        1.2.1
      • getIdentifierOrUniqueKeyEmbeddedPropertyNames

        List<String> getIdentifierOrUniqueKeyEmbeddedPropertyNames​(javax.persistence.metamodel.EntityType<?> owner,
                                                                   String elementCollectionPath,
                                                                   String attributeName)
        Get the identifier or unique key inverse properties of an association attribute within an element collection.
        Parameters:
        owner - The owning entity type
        elementCollectionPath - The path to the element collection within which the attribute is contained
        attributeName - The association attribute
        Returns:
        the identifier or unique key inverse properties of the association attribute
        Since:
        1.3.0
      • getJoinMappingPropertyNames

        Map<String,​String> getJoinMappingPropertyNames​(javax.persistence.metamodel.EntityType<?> owner,
                                                             String elementCollectionPath,
                                                             String attributeName)
        Returns the join mapping property names of an association attribute. This is a mapping from target to source property names.
        Parameters:
        owner - The owning entity type
        elementCollectionPath - The nullable path to the element collection within which the attribute is contained
        attributeName - The association attribute
        Returns:
        the property names from target type to the source type
        Since:
        1.4.0
      • supportsEnumLiteral

        boolean supportsEnumLiteral​(javax.persistence.metamodel.ManagedType<?> ownerType,
                                    String attributeName,
                                    boolean key)
        Whether the enum type of the given attribute supports being used as literal by it's FQN.
        Parameters:
        ownerType - The declaring type of the attribute to check
        attributeName - The name of the attribute to check
        key - Whether the key part of a map attribute should be checked or the attribute element type
        Returns:
        true if supported, false otherwise
        Since:
        1.5.0
      • supportsTemporalLiteral

        boolean supportsTemporalLiteral()
        Whether the JPA provider supports the temporal literal.
        Returns:
        true if supported, false otherwise
        Since:
        1.5.0
      • getIdentifier

        Object getIdentifier​(Object entity)
        Returns the identifier of the entity object.
        Parameters:
        entity - The entity
        Returns:
        the primary identifier of the entity
        Since:
        1.3.0
      • unproxy

        <T> T unproxy​(T entity)
        Returns the unproxied i.e. the real entity object.
        Type Parameters:
        T - The entity type
        Parameters:
        entity - The entity, maybe a proxy
        Returns:
        the real entity object
        Since:
        1.3.0
      • getJpaMetamodelAccessor

        JpaMetamodelAccessor getJpaMetamodelAccessor()
        Returns the JpaMetamodelAccessor for this JPA vendor.
        Returns:
        the JpaMetamodelAccessor for this JPA vendor
        Since:
        1.3.0