org.hibernate.tuple.VmValueGeneration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of beangle-hibernate-core Show documentation
Show all versions of beangle-hibernate-core Show documentation
Hibernate Orm Core Shade,Support Scala Collection
/*
* 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 extends ValueGenerator>> 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