org.hibernate.graph.spi.GraphImplementor 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.graph.spi;
import java.util.List;
import java.util.function.Consumer;
import org.hibernate.graph.AttributeNode;
import org.hibernate.graph.CannotBecomeEntityGraphException;
import org.hibernate.graph.CannotContainSubGraphException;
import org.hibernate.graph.Graph;
import org.hibernate.metamodel.model.domain.JpaMetamodel;
import org.hibernate.metamodel.model.domain.ManagedDomainType;
import org.hibernate.metamodel.model.domain.PersistentAttribute;
/**
* Integration version of the Graph contract
*
* @author Strong Liu
* @author Steve Ebersole
* @author Andrea Boriero
*/
public interface GraphImplementor extends Graph, GraphNodeImplementor {
boolean appliesTo(ManagedDomainType managedType);
boolean appliesTo(Class javaType);
@SuppressWarnings("unchecked")
void merge(GraphImplementor... others);
JpaMetamodel jpaMetamodel();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Co-variant returns
@Override
RootGraphImplementor makeRootGraph(String name, boolean mutable) throws CannotBecomeEntityGraphException;
@Override
SubGraphImplementor makeSubGraph(boolean mutable);
@Override
GraphImplementor makeCopy(boolean mutable);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// AttributeNode access
default void visitAttributeNodes(Consumer> consumer) {
getAttributeNodeImplementors().forEach( consumer );
}
AttributeNodeImplementor addAttributeNode(AttributeNodeImplementor makeCopy);
List> getAttributeNodeImplementors();
@Override
@SuppressWarnings("unchecked")
default List> getAttributeNodeList() {
return (List) getAttributeNodeImplementors();
}
@Override
AttributeNodeImplementor findAttributeNode(String attributeName);
@Override
AttributeNodeImplementor findAttributeNode(PersistentAttribute attribute);
@Override
AttributeNodeImplementor addAttributeNode(String attributeName) throws CannotContainSubGraphException;
@Override
AttributeNodeImplementor addAttributeNode(PersistentAttribute attribute)
throws CannotContainSubGraphException;
@SuppressWarnings("unchecked")
default AttributeNodeImplementor findOrCreateAttributeNode(String name) {
return findOrCreateAttributeNode( (PersistentAttribute) getGraphedType().getAttribute( name ) );
}
AttributeNodeImplementor findOrCreateAttributeNode(PersistentAttribute attribute);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// sub graph nodes
@Override
@SuppressWarnings("unchecked")
default SubGraphImplementor addSubGraph(String attributeName) throws CannotContainSubGraphException {
return (SubGraphImplementor) findOrCreateAttributeNode( attributeName ).makeSubGraph();
}
@Override
default SubGraphImplementor addSubGraph(String attributeName, Class subType)
throws CannotContainSubGraphException {
return findOrCreateAttributeNode( attributeName ).makeSubGraph( subType );
}
@Override
default SubGraphImplementor addSubGraph(PersistentAttribute attribute)
throws CannotContainSubGraphException {
return findOrCreateAttributeNode( attribute ).makeSubGraph();
}
@Override
default SubGraphImplementor addSubGraph(
PersistentAttribute attribute,
Class subType) throws CannotContainSubGraphException {
return findOrCreateAttributeNode( attribute ).makeSubGraph( subType );
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// key sub graph nodes
@Override
@SuppressWarnings("unchecked")
default SubGraphImplementor addKeySubGraph(String attributeName) {
return (SubGraphImplementor) findOrCreateAttributeNode( attributeName ).makeKeySubGraph();
}
@Override
default SubGraphImplementor addKeySubGraph(String attributeName, Class subtype) {
return findOrCreateAttributeNode( attributeName ).makeKeySubGraph( subtype );
}
@Override
default SubGraphImplementor addKeySubGraph(PersistentAttribute attribute) {
return findOrCreateAttributeNode( attribute ).makeKeySubGraph();
}
@Override
default SubGraphImplementor addKeySubGraph(
PersistentAttribute attribute,
Class subType) throws CannotContainSubGraphException {
return findOrCreateAttributeNode( attribute ).makeKeySubGraph( subType );
}
}