com.blazebit.persistence.criteria.impl.BlazeCriteriaDeleteImpl Maven / Gradle / Ivy
/*
* Copyright 2014 - 2021 Blazebit.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.blazebit.persistence.criteria.impl;
import com.blazebit.persistence.DeleteCriteriaBuilder;
import com.blazebit.persistence.criteria.BlazeCriteriaDelete;
import javax.persistence.EntityManager;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.ParameterExpression;
import javax.persistence.criteria.Predicate;
import java.util.Map;
/**
* @author Christian Beikov
* @since 1.2.0
*/
public class BlazeCriteriaDeleteImpl extends AbstractModificationCriteriaQuery implements BlazeCriteriaDelete {
public BlazeCriteriaDeleteImpl(BlazeCriteriaBuilderImpl criteriaBuilder, Class targetEntity, String alias) {
super(criteriaBuilder);
from(targetEntity, alias);
}
@Override
public BlazeCriteriaDelete where(Expression restriction) {
setRestriction(restriction);
return this;
}
@Override
public BlazeCriteriaDelete where(Predicate... restrictions) {
setRestriction(restrictions);
return this;
}
@Override
public DeleteCriteriaBuilder createCriteriaBuilder(EntityManager entityManager) {
RenderContextImpl context = new RenderContextImpl();
@SuppressWarnings("unchecked")
DeleteCriteriaBuilder deleteCriteriaBuilder = criteriaBuilder.getCriteriaBuilderFactory()
.delete(entityManager, (Class) getRoot().getJavaType(), getRoot().getAlias());
renderWhere(deleteCriteriaBuilder, context);
for (ImplicitParameterBinding b : context.getImplicitParameterBindings()) {
b.bind(deleteCriteriaBuilder);
}
for (Map.Entry> entry : context.getExplicitParameterNameMapping().entrySet()) {
deleteCriteriaBuilder.setParameterType(entry.getKey(), entry.getValue().getParameterType());
}
return deleteCriteriaBuilder;
}
}