All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.graph.Graph Maven / Gradle / Ivy

There is a newer version: 6.6.2.Final
Show newest version
/*
 * 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;

import java.util.List;

import jakarta.persistence.metamodel.PluralAttribute;
import org.hibernate.metamodel.model.domain.ManagedDomainType;
import org.hibernate.metamodel.model.domain.PersistentAttribute;

/**
 * A container for {@link AttributeNode} references.
 *
 * @apiNote Acts as an abstraction over the JPA-defined interfaces
 *          {@link jakarta.persistence.EntityGraph} and
 *          {@link jakarta.persistence.Subgraph}, which have no
 *          common supertype.
 *
 * @author Strong Liu
 * @author Steve Ebersole
 * @author Andrea Boriero
 *
 * @see RootGraph
 * @see SubGraph
 * @see jakarta.persistence.EntityGraph
 * @see jakarta.persistence.Subgraph
 */
public interface Graph extends GraphNode {

	/**
	 * Add a subgraph rooted at a plural attribute, allowing further
	 * nodes to be added to the subgraph.
	 *
	 * @apiNote This method is missing in JPA, and nodes cannot be
	 *          added in a typesafe way to subgraphs representing
	 *          fetched collections
	 *
	 * @since 6.3
	 */
	default  SubGraph addPluralSubgraph(PluralAttribute attribute) {
		return addSubGraph( attribute.getName() );
	}

	/**
	 * Graphs apply only to {@link jakarta.persistence.metamodel.ManagedType}s.
	 *
	 * @return the {@code ManagedType} being graphed here.
	 */
	ManagedDomainType getGraphedType();

	/**
	 * Create a named root {@link Graph} if the given name is not null.
	 *
	 * @param mutable controls whether the resulting {@code Graph} is mutable
	 *
	 * @throws CannotBecomeEntityGraphException If the named attribute is not entity-valued
	 */
	RootGraph makeRootGraph(String name, boolean mutable)
			throws CannotBecomeEntityGraphException;

	/**
	 * Create a new (mutable or immutable) {@link SubGraph} rooted at
	 * this {@link Graph}.
	 */
	SubGraph makeSubGraph(boolean mutable);

	@Override
	Graph makeCopy(boolean mutable);


	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// AttributeNode handling

	/**
	 * Ultimately only needed for implementing
	 * {@link jakarta.persistence.EntityGraph#getAttributeNodes()}
	 * and {@link jakarta.persistence.Subgraph#getAttributeNodes()}
	 */
	List> getGraphAttributeNodes();

	/**
	 * Find an already existing AttributeNode by attributeName within
	 * this container
	 */
	 AttributeNode findAttributeNode(String attributeName);

	/**
	 * Find an already existing AttributeNode by corresponding attribute
	 * reference, within this container.
	 */
	 AttributeNode findAttributeNode(PersistentAttribute attribute);

	/**
	 * Get a list of all existing AttributeNodes within this container.
	 */
	List> getAttributeNodeList();

	/**
	 * Add an {@link AttributeNode} (with no associated {@link SubGraph})
	 * to this container by attribute name.
	 */
	 AttributeNode addAttributeNode(String attributeName);

	/**
	 * Add an {@link AttributeNode} (with no associated {@link SubGraph})
	 * to this container by attribute reference.
	 */
	 AttributeNode addAttributeNode(PersistentAttribute attribute);



	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// sub graph nodes

	/**
	 * Create and return a new (mutable) {@link SubGraph} associated with
	 * the named {@link AttributeNode}.
	 *
	 * @apiNote If no such AttributeNode exists yet, it is created.
	 */
	 SubGraph addSubGraph(String attributeName)
			throws CannotContainSubGraphException;

	 SubGraph addSubGraph(String attributeName, Class type)
			throws CannotContainSubGraphException;

	/**
	 * Create and return a new (mutable) {@link SubGraph} associated with
	 * the {@link AttributeNode} for the given attribute.
	 *
	 * @apiNote If no such AttributeNode exists yet, it is created.
	 */
	 SubGraph addSubGraph(PersistentAttribute attribute)
			throws CannotContainSubGraphException;

	 SubGraph addSubGraph(PersistentAttribute attribute, Class type)
			throws CannotContainSubGraphException;

	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// key sub graph nodes

	 SubGraph addKeySubGraph(String attributeName)
			throws CannotContainSubGraphException;
	 SubGraph addKeySubGraph(String attributeName, Class type)
			throws CannotContainSubGraphException;

	 SubGraph addKeySubGraph(PersistentAttribute attribute)
			throws CannotContainSubGraphException;
	 SubGraph addKeySubGraph(PersistentAttribute attribute, Class type)
			throws CannotContainSubGraphException;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy