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

org.hibernate.tuple.VmValueGeneration 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.tuple;

import java.lang.reflect.Constructor;
import java.util.EnumSet;

import org.hibernate.HibernateException;
import org.hibernate.Internal;
import org.hibernate.annotations.GeneratorType;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.generator.EventType;
import org.hibernate.generator.BeforeExecutionGenerator;

import static org.hibernate.internal.util.ReflectHelper.getDefaultConstructor;

/**
 * A {@link BeforeExecutionGenerator} which delegates to a {@link ValueGenerator}.
 * Underlies the {@link GeneratorType} annotation.
 *
 * @author Gunnar Morling
 *
 * @deprecated since {@link GeneratorType} is deprecated
 */
@Internal
@Deprecated(since = "6.2")
public class VmValueGeneration implements BeforeExecutionGenerator {

	private final EnumSet eventTypes;
	private final ValueGenerator generator;

	public VmValueGeneration(GeneratorType annotation) {
		Constructor> constructor = getDefaultConstructor( annotation.type() );
		try {
			generator = constructor.newInstance();
		}
		catch (Exception e) {
			throw new HibernateException( "Couldn't instantiate value generator", e );
		}
		eventTypes = annotation.when().eventTypes();
	}

	@Override
	public EnumSet getEventTypes() {
		return eventTypes;
	}

	@Override
	public Object generate(SharedSessionContractImplementor session, Object owner, Object currentValue, EventType eventType) {
		return generator.generateValue( session.asSessionImplementor(), owner, currentValue );
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy