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