Search in sources :

Example 1 with JdbcMapping

use of org.hibernate.metamodel.mapping.JdbcMapping in project hibernate-orm by hibernate.

the class DynamicResultBuilderEntityStandard method resolveSqlSelection.

private void resolveSqlSelection(String columnAlias, String columnKey, JdbcMapping jdbcMapping, JdbcValuesMetadata jdbcResultsMetadata, DomainResultCreationState domainResultCreationState) {
    final SqlExpressionResolver sqlExpressionResolver = domainResultCreationState.getSqlAstCreationState().getSqlExpressionResolver();
    sqlExpressionResolver.resolveSqlSelection(sqlExpressionResolver.resolveSqlExpression(columnKey, state -> {
        final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition(columnAlias);
        final int valuesArrayPosition = jdbcPosition - 1;
        return new ResultSetMappingSqlSelection(valuesArrayPosition, jdbcMapping);
    }), jdbcMapping.getMappedJavaType(), domainResultCreationState.getSqlAstCreationState().getCreationContext().getSessionFactory().getTypeConfiguration());
}
Also used : DomainResultCreationState(org.hibernate.sql.results.graph.DomainResultCreationState) SingleAttributeIdentifierMapping(org.hibernate.metamodel.mapping.internal.SingleAttributeIdentifierMapping) TableGroupImpl(org.hibernate.query.results.TableGroupImpl) ResultSetMappingSqlSelection(org.hibernate.query.results.ResultSetMappingSqlSelection) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) BiFunction(java.util.function.BiFunction) Function(java.util.function.Function) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) ArrayList(java.util.ArrayList) TableReference(org.hibernate.sql.ast.tree.from.TableReference) ResultsHelper.impl(org.hibernate.query.results.ResultsHelper.impl) NativeQuery(org.hibernate.query.NativeQuery) SqlAliasBaseConstant(org.hibernate.sql.ast.spi.SqlAliasBaseConstant) EntityResult(org.hibernate.sql.results.graph.entity.EntityResult) CollectionPart(org.hibernate.metamodel.mapping.CollectionPart) Fetchable(org.hibernate.sql.results.graph.Fetchable) FetchTiming(org.hibernate.engine.FetchTiming) LockMode(org.hibernate.LockMode) NavigablePath(org.hibernate.query.spi.NavigablePath) DomainResultCreationStateImpl(org.hibernate.query.results.DomainResultCreationStateImpl) Fetch(org.hibernate.sql.results.graph.Fetch) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) Objects(java.util.Objects) EntityIdentifierMapping(org.hibernate.metamodel.mapping.EntityIdentifierMapping) JdbcValuesMetadata(org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata) List(java.util.List) FetchBuilder(org.hibernate.query.results.FetchBuilder) FromClauseAccess(org.hibernate.sql.ast.spi.FromClauseAccess) Collections(java.util.Collections) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) SqlExpressionResolver.createColumnReferenceKey(org.hibernate.sql.ast.spi.SqlExpressionResolver.createColumnReferenceKey) FetchParent(org.hibernate.sql.results.graph.FetchParent) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) ResultSetMappingSqlSelection(org.hibernate.query.results.ResultSetMappingSqlSelection)

Example 2 with JdbcMapping

use of org.hibernate.metamodel.mapping.JdbcMapping in project hibernate-orm by hibernate.

the class FilterDefinitionBinder method processFilterDefinition.

/**
 * Handling for a {@code <filter-def/>} declaration.
 *
 * @param context Access to information relative to the mapping document containing this binding
 * @param jaxbFilterDefinitionMapping The {@code <filter-def/>} JAXB mapping
 */
@SuppressWarnings("unchecked")
static void processFilterDefinition(HbmLocalMetadataBuildingContext context, JaxbHbmFilterDefinitionType jaxbFilterDefinitionMapping) {
    Map<String, JdbcMapping> parameterMap = null;
    String condition = jaxbFilterDefinitionMapping.getCondition();
    for (Serializable content : jaxbFilterDefinitionMapping.getContent()) {
        if (content instanceof String) {
            final String contentString = content.toString().trim();
            if (StringHelper.isNotEmpty(contentString)) {
                if (condition != null && log.isDebugEnabled()) {
                    log.debugf("filter-def [name=%s, origin=%s] defined multiple conditions, accepting arbitrary one", jaxbFilterDefinitionMapping.getName(), context.getOrigin().toString());
                }
            }
        } else {
            final JaxbHbmFilterParameterType jaxbParameterMapping;
            if (content instanceof JaxbHbmFilterParameterType) {
                jaxbParameterMapping = (JaxbHbmFilterParameterType) content;
            } else if (content instanceof JAXBElement) {
                final JAXBElement<JaxbHbmFilterParameterType> jaxbElement = (JAXBElement<JaxbHbmFilterParameterType>) content;
                jaxbParameterMapping = jaxbElement.getValue();
            } else {
                throw new MappingException("Unable to decipher filter-def content type [" + content.getClass().getName() + "]", context.getOrigin());
            }
            if (parameterMap == null) {
                parameterMap = new HashMap<>();
            }
            parameterMap.put(jaxbParameterMapping.getParameterName(), context.getMetadataCollector().getTypeConfiguration().getBasicTypeRegistry().getRegisteredType(jaxbParameterMapping.getParameterValueTypeName()));
        }
    }
    context.getMetadataCollector().addFilterDefinition(new FilterDefinition(jaxbFilterDefinitionMapping.getName(), condition, parameterMap));
    log.debugf("Processed filter definition : %s", jaxbFilterDefinitionMapping.getName());
}
Also used : FilterDefinition(org.hibernate.engine.spi.FilterDefinition) Serializable(java.io.Serializable) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) JaxbHbmFilterParameterType(org.hibernate.boot.jaxb.hbm.spi.JaxbHbmFilterParameterType) JAXBElement(jakarta.xml.bind.JAXBElement) MappingException(org.hibernate.boot.MappingException)

Example 3 with JdbcMapping

use of org.hibernate.metamodel.mapping.JdbcMapping in project hibernate-orm by hibernate.

the class AbstractSqlAstTranslator method addAppliedParameterBinding.

protected void addAppliedParameterBinding(JdbcParameter parameter, JdbcParameterBinding binding) {
    if (appliedParameterBindings.isEmpty()) {
        appliedParameterBindings = new IdentityHashMap<>();
    }
    if (binding == null) {
        appliedParameterBindings.put(parameter, null);
    } else {
        final JdbcMapping bindType = binding.getBindType();
        final Object value = bindType.getJavaTypeDescriptor().getMutabilityPlan().deepCopy(binding.getBindValue());
        appliedParameterBindings.put(parameter, new JdbcParameterBindingImpl(bindType, value));
    }
}
Also used : JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) JdbcParameterBindingImpl(org.hibernate.sql.exec.internal.JdbcParameterBindingImpl)

Example 4 with JdbcMapping

use of org.hibernate.metamodel.mapping.JdbcMapping in project hibernate-orm by hibernate.

the class AbstractSqlAstTranslator method renderAsLiteral.

protected void renderAsLiteral(JdbcParameter jdbcParameter, Object literalValue) {
    if (literalValue == null) {
        appendSql(SqlAppender.NULL_KEYWORD);
    } else {
        assert jdbcParameter.getExpressionType().getJdbcTypeCount() == 1;
        final JdbcMapping jdbcMapping = jdbcParameter.getExpressionType().getJdbcMappings().get(0);
        final JdbcLiteralFormatter literalFormatter = jdbcMapping.getJdbcType().getJdbcLiteralFormatter(jdbcMapping.getJavaTypeDescriptor());
        if (literalFormatter == null) {
            throw new IllegalArgumentException("Can't render parameter as literal, no literal formatter found");
        } else {
            literalFormatter.appendJdbcLiteral(this, literalValue, dialect, getWrapperOptions());
        }
    }
}
Also used : JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) JdbcLiteralFormatter(org.hibernate.type.descriptor.jdbc.JdbcLiteralFormatter)

Example 5 with JdbcMapping

use of org.hibernate.metamodel.mapping.JdbcMapping in project hibernate-orm by hibernate.

the class AbstractSqlAstTranslator method renderLiteral.

@SuppressWarnings("unchecked")
protected void renderLiteral(Literal literal, boolean castParameter) {
    assert literal.getExpressionType().getJdbcTypeCount() == 1;
    final JdbcMapping jdbcMapping = literal.getJdbcMapping();
    final JdbcLiteralFormatter literalFormatter = jdbcMapping.getJdbcType().getJdbcLiteralFormatter(jdbcMapping.getJavaTypeDescriptor());
    // If we encounter a plain literal in the select clause which has no literal formatter, we must render it as parameter
    if (literalFormatter == null) {
        parameterBinders.add(literal);
        final LiteralAsParameter<Object> jdbcParameter = new LiteralAsParameter<>(literal);
        if (castParameter) {
            renderCasted(jdbcParameter);
        } else {
            appendSql(PARAM_MARKER);
        }
    } else {
        literalFormatter.appendJdbcLiteral(this, literal.getLiteralValue(), dialect, getWrapperOptions());
    }
}
Also used : JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) LiteralAsParameter(org.hibernate.sql.ast.tree.expression.LiteralAsParameter) JdbcLiteralFormatter(org.hibernate.type.descriptor.jdbc.JdbcLiteralFormatter)

Aggregations

JdbcMapping (org.hibernate.metamodel.mapping.JdbcMapping)61 EntityPersister (org.hibernate.persister.entity.EntityPersister)34 Test (org.junit.jupiter.api.Test)31 BasicAttributeMapping (org.hibernate.metamodel.mapping.internal.BasicAttributeMapping)29 MappingMetamodelImplementor (org.hibernate.metamodel.spi.MappingMetamodelImplementor)29 JdbcTypeRegistry (org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry)14 ArrayList (java.util.ArrayList)11 List (java.util.List)8 Expression (org.hibernate.sql.ast.tree.expression.Expression)6 JdbcParameter (org.hibernate.sql.ast.tree.expression.JdbcParameter)6 Collections (java.util.Collections)5 IdentityHashMap (java.util.IdentityHashMap)5 Map (java.util.Map)5 PluralAttributeMapping (org.hibernate.metamodel.mapping.PluralAttributeMapping)5 NavigablePath (org.hibernate.query.spi.NavigablePath)5 JdbcType (org.hibernate.type.descriptor.jdbc.JdbcType)5 HashMap (java.util.HashMap)4 EntityIdentifierMapping (org.hibernate.metamodel.mapping.EntityIdentifierMapping)4 PatternRenderer (org.hibernate.query.sqm.produce.function.internal.PatternRenderer)4 TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)4