use of org.hibernate.sql.exec.spi.JdbcParameterBinding in project hibernate-orm by hibernate.
the class AbstractJdbcParameter method bindParameterValue.
@Override
public void bindParameterValue(PreparedStatement statement, int startPosition, JdbcParameterBindings jdbcParamBindings, ExecutionContext executionContext) throws SQLException {
final JdbcParameterBinding binding = jdbcParamBindings.getBinding(AbstractJdbcParameter.this);
if (binding == null) {
throw new ExecutionException("JDBC parameter value not bound - " + this);
}
final Object bindValue = binding.getBindValue();
JdbcMapping jdbcMapping = binding.getBindType();
if (jdbcMapping == null) {
jdbcMapping = this.jdbcMapping;
}
// If the parameter type is not known from the context i.e. null or Object, infer it from the bind value
if (jdbcMapping == null || jdbcMapping.getMappedJavaType().getJavaTypeClass() == Object.class) {
jdbcMapping = guessBindType(executionContext, bindValue, jdbcMapping);
}
bindParameterValue(jdbcMapping, statement, bindValue, startPosition, executionContext);
}
use of org.hibernate.sql.exec.spi.JdbcParameterBinding in project hibernate-orm by hibernate.
the class AbstractSqlAstTranslator method getParameterBindValue.
protected Object getParameterBindValue(JdbcParameter parameter) {
final JdbcParameterBinding binding;
if (parameter == getOffsetParameter()) {
binding = new JdbcParameterBindingImpl(getIntegerType(), getLimit().getFirstRow());
} else if (parameter == getLimitParameter()) {
binding = new JdbcParameterBindingImpl(getIntegerType(), getLimit().getMaxRows());
} else {
binding = jdbcParameterBindings.getBinding(parameter);
}
addAppliedParameterBinding(parameter, binding);
return binding.getBindValue();
}
use of org.hibernate.sql.exec.spi.JdbcParameterBinding in project hibernate-orm by hibernate.
the class AbstractSqlAstTranslator method renderFetchPlusOffsetExpressionAsSingleParameter.
protected void renderFetchPlusOffsetExpressionAsSingleParameter(Expression fetchClauseExpression, Expression offsetClauseExpression, int offset) {
if (fetchClauseExpression instanceof Literal) {
final Number fetchCount = (Number) ((Literal) fetchClauseExpression).getLiteralValue();
if (offsetClauseExpression instanceof Literal) {
final Number offsetCount = (Number) ((Literal) offsetClauseExpression).getLiteralValue();
appendSql(fetchCount.intValue() + offsetCount.intValue() + offset);
} else {
appendSql(PARAM_MARKER);
final JdbcParameter offsetParameter = (JdbcParameter) offsetClauseExpression;
final int offsetValue = offset + fetchCount.intValue();
jdbcParameters.addParameter(offsetParameter);
parameterBinders.add((statement, startPosition, jdbcParameterBindings, executionContext) -> {
final JdbcParameterBinding binding = jdbcParameterBindings.getBinding(offsetParameter);
if (binding == null) {
throw new ExecutionException("JDBC parameter value not bound - " + offsetParameter);
}
final Number bindValue = (Number) binding.getBindValue();
offsetParameter.getExpressionType().getJdbcMappings().get(0).getJdbcValueBinder().bind(statement, bindValue.intValue() + offsetValue, startPosition, executionContext.getSession());
});
}
} else {
appendSql(PARAM_MARKER);
final JdbcParameter offsetParameter = (JdbcParameter) offsetClauseExpression;
final JdbcParameter fetchParameter = (JdbcParameter) fetchClauseExpression;
final OffsetReceivingParameterBinder fetchBinder = new OffsetReceivingParameterBinder(offsetParameter, fetchParameter, offset);
// And in this case, we only want to bind a single JDBC parameter
if (!(offsetParameter instanceof OffsetJdbcParameter)) {
jdbcParameters.addParameter(offsetParameter);
parameterBinders.add((statement, startPosition, jdbcParameterBindings, executionContext) -> {
final JdbcParameterBinding binding = jdbcParameterBindings.getBinding(offsetParameter);
if (binding == null) {
throw new ExecutionException("JDBC parameter value not bound - " + offsetParameter);
}
fetchBinder.dynamicOffset = (Number) binding.getBindValue();
});
}
jdbcParameters.addParameter(fetchParameter);
parameterBinders.add(fetchBinder);
}
}
Aggregations