use of org.hibernate.param.ParameterBinder in project hibernate-orm by hibernate.
the class NativeSQLQueryPlan method performExecuteUpdate.
/**
* Performs the execute query
*
* @param queryParameters The query parameters
* @param session The session
*
* @return The number of affected rows as returned by the JDBC driver
*
* @throws HibernateException Indicates a problem performing the query execution
*/
public int performExecuteUpdate(QueryParameters queryParameters, SharedSessionContractImplementor session) throws HibernateException {
coordinateSharedCacheCleanup(session);
if (queryParameters.isCallable()) {
throw new IllegalArgumentException("callable not yet supported for native queries");
}
int result = 0;
PreparedStatement ps;
RowSelection selection = queryParameters.getRowSelection();
try {
queryParameters.processFilters(this.customQuery.getSQL(), session);
final String sql = session.getJdbcServices().getDialect().addSqlHintOrComment(queryParameters.getFilteredSQL(), queryParameters, session.getFactory().getSessionFactoryOptions().isCommentsEnabled());
ps = session.getJdbcCoordinator().getStatementPreparer().prepareStatement(sql, false);
try {
int col = 1;
for (ParameterBinder binder : this.customQuery.getParameterValueBinders()) {
col += binder.bind(ps, queryParameters, session, col);
}
if (selection != null && selection.getTimeout() != null) {
ps.setQueryTimeout(selection.getTimeout());
}
result = session.getJdbcCoordinator().getResultSetReturn().executeUpdate(ps);
} finally {
if (ps != null) {
session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release(ps);
session.getJdbcCoordinator().afterStatementExecution();
}
}
} catch (SQLException sqle) {
throw session.getFactory().getSQLExceptionHelper().convert(sqle, "could not execute native bulk manipulation query", this.sourceQuery);
}
return result;
}
use of org.hibernate.param.ParameterBinder in project hibernate-orm by hibernate.
the class CustomLoader method bindParameterValues.
@Override
protected int bindParameterValues(PreparedStatement statement, QueryParameters queryParameters, int startIndex, SharedSessionContractImplementor session) throws SQLException {
final Serializable optionalId = queryParameters.getOptionalId();
if (optionalId != null) {
paramValueBinders.get(0).bind(statement, queryParameters, session, startIndex);
return session.getFactory().getMetamodel().entityPersister(queryParameters.getOptionalEntityName()).getIdentifierType().getColumnSpan(session.getFactory());
}
int span = 0;
for (ParameterBinder paramValueBinder : paramValueBinders) {
span += paramValueBinder.bind(statement, queryParameters, session, startIndex + span);
}
return span;
}
use of org.hibernate.param.ParameterBinder in project hibernate-orm by hibernate.
the class OutputsImpl method buildSpecializedCustomLoader.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Hooks into Hibernate's Loader hierarchy for ResultSet -> Object mapping
private static CustomLoaderExtension buildSpecializedCustomLoader(final ResultContext context) {
// might be better to just manually construct the Return(s).. SQLQueryReturnProcessor does a lot of
// work that is really unnecessary here.
final SQLQueryReturnProcessor processor = new SQLQueryReturnProcessor(context.getQueryReturns(), context.getSession().getFactory());
processor.process();
final List<org.hibernate.loader.custom.Return> customReturns = processor.generateCallableReturns();
CustomQuery customQuery = new CustomQuery() {
@Override
public String getSQL() {
return context.getSql();
}
@Override
public Set<String> getQuerySpaces() {
return context.getSynchronizedQuerySpaces();
}
@Override
public List<ParameterBinder> getParameterValueBinders() {
// no parameters in terms of embedded in the SQL string
return Collections.emptyList();
}
@Override
public List<org.hibernate.loader.custom.Return> getCustomQueryReturns() {
return customReturns;
}
};
return new CustomLoaderExtension(customQuery, context.getQueryParameters(), context.getSession());
}
Aggregations