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

org.hibernate.graph.internal.RootGraphImpl Maven / Gradle / Ivy

There is a newer version: 7.0.0.Alpha1
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.internal;

import javax.persistence.EntityGraph;

import org.hibernate.cfg.NotYetImplementedException;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.graph.SubGraph;
import org.hibernate.graph.spi.GraphImplementor;
import org.hibernate.graph.spi.RootGraphImplementor;
import org.hibernate.graph.spi.SubGraphImplementor;
import org.hibernate.metamodel.model.domain.spi.EntityTypeDescriptor;
import org.hibernate.metamodel.model.domain.spi.IdentifiableTypeDescriptor;

/**
 * The Hibernate implementation of the JPA EntityGraph contract.
 *
 * @author Steve Ebersole
 */
public class RootGraphImpl extends AbstractGraph implements EntityGraph, RootGraphImplementor {
	private final String name;

	public RootGraphImpl(
			String name,
			EntityTypeDescriptor entityType,
			boolean mutable,
			SessionFactoryImplementor sessionFactory) {
		super( entityType, mutable, sessionFactory );
		this.name = name;
	}

	public RootGraphImpl(String name, EntityTypeDescriptor entityType, SessionFactoryImplementor sessionFactory) {
		this(
				name,
				entityType,
				true,
				sessionFactory
		);
	}

	public RootGraphImpl(String name, boolean mutable, GraphImplementor original) {
		super( mutable, original );
		this.name = name;
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public RootGraphImplementor makeCopy(boolean mutable) {
		return new RootGraphImpl<>( null, mutable, this );
	}

	@Override
	public SubGraphImplementor makeSubGraph(boolean mutable) {
		return new SubGraphImpl<>( mutable, this );
	}

	@Override
	public RootGraphImplementor makeRootGraph(String name, boolean mutable) {
		if ( ! mutable && ! isMutable() ) {
			return this;
		}

		return super.makeRootGraph( name, mutable );
	}

	@Override
	public  SubGraph addSubclassSubgraph(Class type) {
		throw new NotYetImplementedException(  );
	}

	@Override
	public boolean appliesTo(EntityTypeDescriptor entityType) {
		if ( this.getGraphedType().equals( entityType ) ) {
			return true;
		}

		IdentifiableTypeDescriptor superType = entityType.getSupertype();
		while ( superType != null ) {
			if ( superType.equals( entityType ) ) {
				return true;
			}
			superType = superType.getSupertype();
		}

		return false;
	}

	@Override
	public boolean appliesTo(String entityName) {
		return appliesTo( sessionFactory().getMetamodel().entity( entityName ) );
	}

	@Override
	public boolean appliesTo(Class entityType) {
		return appliesTo( sessionFactory().getMetamodel().entity( entityType ) );
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy