use of org.hibernate.hql.internal.ast.tree.AssignmentSpecification in project hibernate-orm by hibernate.
the class HqlSqlWalker method evaluateAssignment.
private void evaluateAssignment(AST eq, Queryable persister, int targetIndex) {
if (persister.isMultiTable()) {
// no need to even collect this information if the persister is considered multi-table
AssignmentSpecification specification = new AssignmentSpecification(eq, persister);
if (targetIndex >= 0) {
assignmentSpecifications.add(targetIndex, specification);
} else {
assignmentSpecifications.add(specification);
}
numberOfParametersInSetClause += specification.getParameters().length;
}
}
use of org.hibernate.hql.internal.ast.tree.AssignmentSpecification in project hibernate-orm by hibernate.
the class AbstractInlineIdsUpdateHandlerImpl method execute.
@Override
public int execute(SharedSessionContractImplementor session, QueryParameters queryParameters) {
IdsClauseBuilder values = prepareInlineStatement(session, queryParameters);
if (!values.getIds().isEmpty()) {
String[] tableNames = getTargetedQueryable().getConstraintOrderedTableNameClosure();
String[][] columnNames = getTargetedQueryable().getContraintOrderedTableKeyColumnClosure();
String idSubselect = values.toStatement();
assignmentParameterSpecifications = new ParameterSpecification[tableNames.length][];
for (int tableIndex = 0; tableIndex < tableNames.length; tableIndex++) {
boolean affected = false;
final List<ParameterSpecification> parameterList = new ArrayList<>();
Update update = generateUpdate(tableNames[tableIndex], columnNames[tableIndex], idSubselect, "bulk update");
final List<AssignmentSpecification> assignmentSpecifications = walker().getAssignmentSpecifications();
for (AssignmentSpecification assignmentSpecification : assignmentSpecifications) {
if (assignmentSpecification.affectsTable(tableNames[tableIndex])) {
affected = true;
update.appendAssignmentFragment(assignmentSpecification.getSqlAssignmentFragment());
if (assignmentSpecification.getParameters() != null) {
Collections.addAll(parameterList, assignmentSpecification.getParameters());
}
}
}
if (affected) {
updates.put(tableIndex, update.toStatementString());
assignmentParameterSpecifications[tableIndex] = parameterList.toArray(new ParameterSpecification[parameterList.size()]);
}
}
// Start performing the updates
for (Map.Entry<Integer, String> updateEntry : updates.entrySet()) {
int i = updateEntry.getKey();
String update = updateEntry.getValue();
if (update == null) {
continue;
}
try {
try (PreparedStatement ps = session.getJdbcCoordinator().getStatementPreparer().prepareStatement(update, false)) {
// jdbc params are 1-based
int position = 1;
if (assignmentParameterSpecifications[i] != null) {
for (int x = 0; x < assignmentParameterSpecifications[i].length; x++) {
position += assignmentParameterSpecifications[i][x].bind(ps, queryParameters, session, position);
}
}
session.getJdbcCoordinator().getResultSetReturn().executeUpdate(ps);
}
} catch (SQLException e) {
throw convert(e, "error performing bulk update", update);
}
}
}
return values.getIds().size();
}
Aggregations