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.model.domain.spi.PluralPersistentAttribute;
import org.hibernate.metamodel.model.domain.spi.SimpleTypeDescriptor;
/**
* @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 Class collectionClass;
protected AbstractPluralAttribute(PluralAttributeBuilder builder) {
super(
builder.getDeclaringType(),
builder.getProperty().getName(),
builder.getAttributeNature(),
builder.getValueType(),
builder.getMember()
);
this.collectionClass = builder.getCollectionClass();
}
public static PluralAttributeBuilder create(
AbstractManagedType ownerType,
SimpleTypeDescriptor attrType,
Class collectionClass,
SimpleTypeDescriptor keyType) {
return new PluralAttributeBuilder<>( ownerType, attrType, collectionClass, keyType );
}
@Override
public SimpleTypeDescriptor getElementType() {
return getValueGraphType();
}
@Override
@SuppressWarnings("unchecked")
public SimpleTypeDescriptor getValueGraphType() {
return (SimpleTypeDescriptor) super.getValueGraphType();
}
@Override
public SimpleTypeDescriptor 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 Class getJavaType() {
return collectionClass;
}
}