make @IdGeneratorType accept Generator
This commit is contained in:
parent
9389295281
commit
eb6860d9d2
|
@ -10,15 +10,15 @@ import java.lang.annotation.Retention;
|
|||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.hibernate.tuple.InMemoryGenerator;
|
||||
import org.hibernate.tuple.Generator;
|
||||
|
||||
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
/**
|
||||
* Meta-annotation used to mark another annotation as providing configuration
|
||||
* for a custom {@linkplain InMemoryGenerator identifier generator}. This is
|
||||
* the best way to work with customized identifier generation in Hibernate.
|
||||
* for a custom {@linkplain Generator identifier generator}. This is the best
|
||||
* way to work with customized identifier generation in Hibernate.
|
||||
* <p>
|
||||
* For example, if we have a custom identifier generator:
|
||||
* <pre>{@code
|
||||
|
@ -57,21 +57,24 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
|||
* A {@code @IdGeneratorType} annotation must have retention policy
|
||||
* {@link RetentionPolicy#RUNTIME}.
|
||||
*
|
||||
* @see Generator
|
||||
* @see org.hibernate.tuple.AnnotationBasedGenerator
|
||||
*
|
||||
* @since 6.0
|
||||
*/
|
||||
@Target(ANNOTATION_TYPE)
|
||||
@Retention(RUNTIME)
|
||||
public @interface IdGeneratorType {
|
||||
/**
|
||||
* A class that implements {@link InMemoryGenerator} and has a constructor
|
||||
* with the signature:
|
||||
* A class which implements {@link Generator} and has a constructor with
|
||||
* the signature:
|
||||
* <pre>{@code
|
||||
* public GeneratorType(AnnotationType config, Member idMember,
|
||||
* CustomIdGeneratorCreationContext creationContext)
|
||||
* }</pre>
|
||||
* where {@code GeneratorType} is the class that implements
|
||||
* {@code IdentifierGenerator}, and {@code AnnotationType} is the
|
||||
* annotation type to which this annotation was applied.
|
||||
* where {@code GeneratorType} is the class that implements {@code Generator},
|
||||
* and {@code AnnotationType} is the annotation type to which this annotation
|
||||
* was applied.
|
||||
*/
|
||||
Class<? extends InMemoryGenerator> value();
|
||||
Class<? extends Generator> value();
|
||||
}
|
||||
|
|
|
@ -503,7 +503,7 @@ public class PropertyBinder {
|
|||
final IdGeneratorType idGeneratorType = annotationType.getAnnotation( IdGeneratorType.class );
|
||||
assert idGeneratorType != null;
|
||||
return creationContext -> {
|
||||
final InMemoryGenerator generator =
|
||||
final Generator generator =
|
||||
instantiateGenerator(
|
||||
annotation,
|
||||
member,
|
||||
|
@ -577,7 +577,7 @@ public class PropertyBinder {
|
|||
}
|
||||
}
|
||||
|
||||
private static void checkIdGeneratorTiming(Class<? extends Annotation> annotationType, InMemoryGenerator generator) {
|
||||
private static void checkIdGeneratorTiming(Class<? extends Annotation> annotationType, Generator generator) {
|
||||
GenerationTiming timing = generator.getGenerationTiming();
|
||||
if ( timing != INSERT ) {
|
||||
throw new MappingException( "Annotation '" + annotationType
|
||||
|
|
|
@ -266,7 +266,7 @@ public class StandardIdentifierGeneratorFactory
|
|||
if ( !Generator.class.isAssignableFrom( clazz ) ) {
|
||||
// in principle, this shouldn't happen, since @GenericGenerator
|
||||
// constrains the type to subtypes of Generator
|
||||
throw new MappingException( clazz.getName() + " does not implement 'InMemoryGenerator'" );
|
||||
throw new MappingException( clazz.getName() + " does not implement 'Generator'" );
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
package org.hibernate.mapping;
|
||||
|
||||
import org.hibernate.id.factory.spi.CustomIdGeneratorCreationContext;
|
||||
import org.hibernate.tuple.InMemoryGenerator;
|
||||
import org.hibernate.tuple.Generator;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IdentifierGeneratorCreator {
|
||||
InMemoryGenerator createGenerator(CustomIdGeneratorCreationContext context);
|
||||
Generator createGenerator(CustomIdGeneratorCreationContext context);
|
||||
}
|
||||
|
|
|
@ -668,12 +668,11 @@ public abstract class SimpleValue implements KeyValue {
|
|||
* </ul>
|
||||
*
|
||||
* @return The built AttributeConverter -> Type adapter
|
||||
*
|
||||
* @todo : ultimately I want to see attributeConverterJavaType and attributeConverterJdbcTypeCode specify-able separately
|
||||
* then we can "play them against each other" in terms of determining proper typing
|
||||
*
|
||||
* @todo : see if we already have previously built a custom on-the-fly BasicType for this AttributeConverter; see note below about caching
|
||||
*/
|
||||
// @todo : ultimately I want to see attributeConverterJavaType and attributeConverterJdbcTypeCode specifiable separately
|
||||
// then we can "play them against each other" in terms of determining proper typing
|
||||
// @todo : see if we already have previously built a custom on-the-fly BasicType for this AttributeConverter;
|
||||
// see note below about caching
|
||||
private Type buildAttributeConverterTypeAdapter() {
|
||||
// todo : validate the number of columns present here?
|
||||
return buildAttributeConverterTypeAdapter( attributeConverterDescriptor.createJpaAttributeConverter(
|
||||
|
@ -767,7 +766,7 @@ public abstract class SimpleValue implements KeyValue {
|
|||
this.typeParameters = parameterMap;
|
||||
}
|
||||
|
||||
public void setTypeParameters(Map<String, ? extends Object> parameters) {
|
||||
public void setTypeParameters(Map<String, ?> parameters) {
|
||||
if ( parameters != null ) {
|
||||
Properties properties = new Properties();
|
||||
properties.putAll( parameters );
|
||||
|
|
|
@ -14,11 +14,12 @@ import org.hibernate.resource.beans.spi.BeanInstanceProducer;
|
|||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* BeanInstanceProducer implementation based on direct instantiation
|
||||
*
|
||||
* In normal Hibernate use this is used when either:
|
||||
* * there is no configured back-end container
|
||||
* * the back-end container did not define a bean for this class
|
||||
* {@link BeanInstanceProducer} implementation based on direct instantiation.
|
||||
* Usually, this is used when either:
|
||||
* <ul>
|
||||
* <li>there is no configured back-end container, or
|
||||
* <li>the back-end container did not define a bean for this class.
|
||||
* </ul>
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue