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

org.hibernate.persister.entity.EntityLoaderLazyCollection 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 .
 */
package org.hibernate.persister.entity;

import java.util.function.Function;

import org.hibernate.LockMode;
import org.hibernate.internal.util.collections.LazyIndexedMap;
import org.hibernate.loader.entity.UniqueEntityLoader;

final class EntityLoaderLazyCollection extends LazyIndexedMap {

	/**
	 * The need here is weird: we need to store an instance of UniqueEntityLoader
	 * for each value of the LockMode enum, but also store two special internal
	 * fetch profiles called "merge" and "refresh".
	 * We assign these two their own ordinal ids such as to be treated as two
	 * additional enum states; but to access these they will have their own
	 * dedicated method implementations.
	 */
	private static final int MERGE_INDEX = LockMode.values().length;
	private static final int REFRESH_INDEX = MERGE_INDEX + 1;
	private static final int TOTAL_STORAGE_SIZE = REFRESH_INDEX + 1;

	public EntityLoaderLazyCollection() {
		super( TOTAL_STORAGE_SIZE );
	}

	UniqueEntityLoader getOrBuildByLockMode(LockMode lockMode, Function builderFunction) {
		return super.computeIfAbsent( lockMode.ordinal(), lockMode, builderFunction );
	}

	UniqueEntityLoader getOrCreateByInternalFetchProfileMerge(Function builderFunction) {
		return super.computeIfAbsent( MERGE_INDEX, null, builderFunction );
	}

	UniqueEntityLoader getOrCreateByInternalFetchProfileRefresh(Function builderFunction) {
		return super.computeIfAbsent( REFRESH_INDEX, null, builderFunction );
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy