org.hibernate.metamodel.model.domain.internal.AbstractPluralAttribute Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-core Show documentation
Show all versions of hibernate-core Show documentation
Hibernate's core ORM functionality
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.metamodel.model.domain.internal;
import java.io.Serializable;
import java.util.Collection;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.metamodel.internal.MetadataContext;
import org.hibernate.metamodel.model.domain.PluralPersistentAttribute;
import org.hibernate.metamodel.model.domain.SimpleDomainType;
import org.hibernate.query.NavigablePath;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.hql.spi.SqmCreationState;
import org.hibernate.query.sqm.internal.SqmMappingModelHelper;
import org.hibernate.query.sqm.tree.domain.SqmPath;
import org.hibernate.query.sqm.tree.domain.SqmPluralValuedSimplePath;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
/**
* @param The (D)eclaring type
* @param The {@link Collection} type
* @param The type of the Collection's elements
*
* @author Emmanuel Bernard
* @author Steve Ebersole
*/
public abstract class AbstractPluralAttribute
extends AbstractAttribute
implements PluralPersistentAttribute, Serializable {
private final CollectionClassification classification;
private final SqmPathSource elementPathSource;
@SuppressWarnings("WeakerAccess")
protected AbstractPluralAttribute(
PluralAttributeBuilder builder,
MetadataContext metadataContext) {
super(
builder.getDeclaringType(),
builder.getProperty().getName(),
builder.getCollectionJavaTypeDescriptor(),
builder.getAttributeClassification(),
builder.getValueType(),
builder.getMember(),
metadataContext
);
this.classification = builder.getCollectionClassification();
this.elementPathSource = SqmMappingModelHelper.resolveSqmPathSource(
getName(),
builder.getValueType(),
BindableType.PLURAL_ATTRIBUTE
);
}
@Override
public String getPathName() {
return getName();
}
@Override
public CollectionClassification getCollectionClassification() {
return classification;
}
@Override
public SqmPathSource getElementPathSource() {
return elementPathSource;
}
@Override
public SqmPathSource findSubPathSource(String name) {
return elementPathSource.findSubPathSource( name );
}
@Override
public CollectionType getCollectionType() {
return getCollectionClassification().toJpaClassification();
}
@Override
public JavaTypeDescriptor getExpressableJavaTypeDescriptor() {
return getElementType().getExpressableJavaTypeDescriptor();
}
@Override
public SimpleDomainType getElementType() {
return getValueGraphType();
}
@Override
@SuppressWarnings("unchecked")
public SimpleDomainType getValueGraphType() {
return (SimpleDomainType) super.getValueGraphType();
}
@Override
public SimpleDomainType getKeyGraphType() {
return null;
}
@Override
public boolean isAssociation() {
return getPersistentAttributeType() == PersistentAttributeType.ONE_TO_MANY
|| getPersistentAttributeType() == PersistentAttributeType.MANY_TO_MANY;
}
@Override
public boolean isCollection() {
return true;
}
@Override
public BindableType getBindableType() {
return BindableType.PLURAL_ATTRIBUTE;
}
@Override
public Class getBindableJavaType() {
return getElementType().getJavaType();
}
@Override
public SqmPath createSqmPath(SqmPath lhs, SqmCreationState creationState) {
final NavigablePath navigablePath = lhs.getNavigablePath().append( getPathName() );
//noinspection unchecked
return new SqmPluralValuedSimplePath(
navigablePath,
this,
lhs,
creationState.getCreationContext().getNodeBuilder()
);
}
}