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

org.hibernate.graph.internal.SubGraphImpl 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.metamodel.Attribute;

import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.graph.spi.AttributeNodeImplementor;
import org.hibernate.graph.spi.SubGraphImplementor;
import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
import org.hibernate.metamodel.model.domain.spi.PersistentAttributeDescriptor;

/**
 * @author Steve Ebersole
 */
public class SubGraphImpl extends AbstractGraph implements SubGraphImplementor {
	public SubGraphImpl(
			ManagedTypeDescriptor managedType,
			boolean mutable,
			SessionFactoryImplementor sessionFactory) {
		super( managedType, mutable, sessionFactory );
	}

	public SubGraphImpl(boolean mutable, AbstractGraph original) {
		super( mutable, original );
	}

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

	@Override
	public SubGraphImplementor makeSubGraph(boolean mutable) {
		if ( ! mutable && ! isMutable() ) {
			return this;
		}

		return makeCopy( true );
	}

	@Override
	public  SubGraphImplementor addKeySubGraph(String attributeName) {
		return super.addKeySubGraph( attributeName );
	}

	@Override
	@SuppressWarnings("unchecked")
	public  AttributeNodeImplementor addAttributeNode(Attribute attribute) {
		return addAttributeNode( (PersistentAttributeDescriptor) attribute );
	}

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

		ManagedTypeDescriptor superType = managedType.getSuperType();
		while ( superType != null ) {
			if ( superType.equals( managedType ) ) {
				return true;
			}
			superType = superType.getSuperType();
		}

		return false;
	}

	@Override
	public boolean appliesTo(Class javaType) {
		return appliesTo( sessionFactory().getMetamodel().managedType( javaType ) );
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy