org.hibernate.jpa.graph.internal.SubgraphImpl Maven / Gradle / Ivy
/*
* 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 .
*/
package org.hibernate.jpa.graph.internal;
import java.util.List;
import javax.persistence.AttributeNode;
import javax.persistence.Subgraph;
import javax.persistence.metamodel.Attribute;
import javax.persistence.metamodel.ManagedType;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.graph.spi.GraphNodeImplementor;
/**
* @author Steve Ebersole
*/
public class SubgraphImpl extends AbstractGraphNode implements Subgraph, GraphNodeImplementor {
private final ManagedType managedType;
private final Class subclass;
@SuppressWarnings("WeakerAccess")
public SubgraphImpl(
SessionFactoryImplementor entityManagerFactory,
ManagedType managedType,
Class subclass) {
super( entityManagerFactory, true );
this.managedType = managedType;
this.subclass = subclass;
}
private SubgraphImpl(SubgraphImpl original) {
super( original, false );
this.managedType = original.managedType;
this.subclass = original.subclass;
}
@SuppressWarnings("WeakerAccess")
public SubgraphImpl makeImmutableCopy() {
return new SubgraphImpl<>( this );
}
@Override
public void addAttributeNodes(String... attributeNames) {
super.addAttributeNodes( attributeNames );
}
@Override
@SafeVarargs
public final void addAttributeNodes(Attribute... attributes) {
super.addAttributeNodes( attributes );
}
@Override
public SubgraphImpl addSubgraph(Attribute attribute) {
return super.addSubgraph( attribute );
}
@Override
public SubgraphImpl addSubgraph(Attribute attribute, Class type) {
return super.addSubgraph( attribute, type );
}
@Override
public SubgraphImpl addSubgraph(String attributeName) {
return super.addSubgraph( attributeName );
}
@Override
public SubgraphImpl addSubgraph(String attributeName, Class type) {
return super.addSubgraph( attributeName, type );
}
@Override
public SubgraphImpl addKeySubgraph(Attribute attribute) {
return super.addKeySubgraph( attribute );
}
@Override
public SubgraphImpl addKeySubgraph(Attribute attribute, Class type) {
return super.addKeySubgraph( attribute, type );
}
@Override
public SubgraphImpl addKeySubgraph(String attributeName) {
return super.addKeySubgraph( attributeName );
}
@Override
public SubgraphImpl addKeySubgraph(String attributeName, Class type) {
return super.addKeySubgraph( attributeName, type );
}
@Override
@SuppressWarnings("unchecked")
public Class getClassType() {
return managedType.getJavaType();
}
@Override
public List> getAttributeNodes() {
return super.attributeNodes();
}
@Override
@SuppressWarnings("unchecked")
protected Attribute resolveAttribute(String attributeName) {
final Attribute attribute = managedType.getAttribute( attributeName );
if ( attribute == null ) {
throw new IllegalArgumentException(
String.format(
"Given attribute name [%s] is not an attribute on this class [%s]",
attributeName,
managedType.getClass().getName()
)
);
}
return attribute;
}
@Override
ManagedType getManagedType() {
return managedType;
}
}