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

org.hibernate.proxy.HibernateProxy 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 .
 */
package org.hibernate.proxy;
import java.io.Serializable;

import org.hibernate.Internal;
import org.hibernate.engine.spi.PrimeAmongSecondarySupertypes;

/**
 * Interface implemented directly by entity proxies, exposing
 * access to the associated {@link LazyInitializer}.
 *
 * @author Gavin King
 */
public interface HibernateProxy extends Serializable, PrimeAmongSecondarySupertypes {

	/**
	 * Extract the {@link LazyInitializer} from the given object,
	 * if and only if the object is actually a proxy. Otherwise,
	 * return a null value.
	 *
	 * @param object any reference to an entity
	 * @return the associated {@link LazyInitializer} if the given
	 *         object is a proxy, or {@code null} otherwise.
	 */
	static LazyInitializer extractLazyInitializer(final Object object) {
		if ( object instanceof PrimeAmongSecondarySupertypes ) {
			PrimeAmongSecondarySupertypes t = (PrimeAmongSecondarySupertypes) object;
			final HibernateProxy hibernateProxy = t.asHibernateProxy();
			if ( hibernateProxy != null ) {
				return hibernateProxy.getHibernateLazyInitializer();
			}
		}
		return null;
	}

	/**
	 * Perform serialization-time write-replacement of this proxy.
	 *
	 * @return The serializable proxy replacement.
	 */
	Object writeReplace();

	/**
	 * Get the {@linkplain LazyInitializer lazy initialization handler}
	 * for this object.
	 *
	 * @return The associated {@link LazyInitializer}.
	 */
	LazyInitializer getHibernateLazyInitializer();

	/**
	 * Special internal contract to optimize type checking.
	 *
	 * @see PrimeAmongSecondarySupertypes
	 *
	 * @return this instance
	 */
	@Internal
	@Override
	default HibernateProxy asHibernateProxy() {
		return this;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy