com.blazebit.persistence.criteria.impl.path.PluralAttributePath Maven / Gradle / Ivy
/*
* Copyright 2014 - 2022 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.path;
import com.blazebit.persistence.criteria.impl.BlazeCriteriaBuilderImpl;
import javax.persistence.criteria.Selection;
import javax.persistence.metamodel.Attribute;
import javax.persistence.metamodel.Bindable;
import javax.persistence.metamodel.PluralAttribute;
import java.io.Serializable;
/**
* @author Christian Beikov
* @since 1.2.0
*/
public class PluralAttributePath extends AbstractPath implements Serializable {
private final PluralAttribute attribute;
public PluralAttributePath(BlazeCriteriaBuilderImpl criteriaBuilder, AbstractPath source, PluralAttribute attribute) {
super(criteriaBuilder, attribute.getJavaType(), source);
this.attribute = attribute;
}
private PluralAttributePath(PluralAttributePath origin, String alias) {
super(origin.criteriaBuilder, origin.getJavaType(), origin.getBasePath());
this.attribute = origin.attribute;
this.setAlias(alias);
}
@Override
public Selection alias(String alias) {
return new PluralAttributePath(this, alias);
}
public PluralAttribute getAttribute() {
return attribute;
}
@Override
protected boolean isDereferencable() {
// only joined plural attributes can be dereferenced
return false;
}
@Override
public PluralAttributePath treatAs(Class treatAsType) {
throw new UnsupportedOperationException(
"Plural attribute path [" + getBasePath().getPathExpression() + '.'
+ attribute.getName() + "] cannot be dereferenced"
);
}
@Override
protected Attribute findAttribute(String attributeName) {
throw new IllegalArgumentException("Plural attribute paths cannot be dereferenced! Consider joining the path instead!");
}
@Override
public Bindable getModel() {
throw new IllegalArgumentException("Plural attribute paths are not bindable! Consider joining the path instead to get a bindable path!");
}
}