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());
}
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());
}
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));
}
}
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());
}
}
}
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());
}
}
Aggregations