HHH-6201 Handling of o.h.a.Entity and o.h.a.Immutable
This commit is contained in:
parent
a4357757c1
commit
b14a514d73
|
@ -30,6 +30,8 @@ import org.jboss.jandex.AnnotationValue;
|
||||||
|
|
||||||
import org.hibernate.AssertionFailure;
|
import org.hibernate.AssertionFailure;
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
|
import org.hibernate.annotations.OptimisticLockType;
|
||||||
|
import org.hibernate.annotations.PolymorphismType;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.metamodel.binding.EntityBinding;
|
import org.hibernate.metamodel.binding.EntityBinding;
|
||||||
import org.hibernate.metamodel.binding.SimpleAttributeBinding;
|
import org.hibernate.metamodel.binding.SimpleAttributeBinding;
|
||||||
|
@ -42,6 +44,7 @@ import org.hibernate.metamodel.source.annotations.state.relational.AttributeColu
|
||||||
import org.hibernate.metamodel.source.annotations.state.relational.AttributeTupleRelationalState;
|
import org.hibernate.metamodel.source.annotations.state.relational.AttributeTupleRelationalState;
|
||||||
import org.hibernate.metamodel.source.annotations.util.JandexHelper;
|
import org.hibernate.metamodel.source.annotations.util.JandexHelper;
|
||||||
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
||||||
|
import org.hibernate.service.classloading.spi.ClassLoaderService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the domain and relational metamodel for a configured class and binds them together.
|
* Creates the domain and relational metamodel for a configured class and binds them together.
|
||||||
|
@ -204,26 +207,68 @@ public class EntityBinder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindHibernateEntityAnnotation(EntityBinding entityBinding) {
|
private void bindHibernateEntityAnnotation(EntityBinding entityBinding) {
|
||||||
|
// initialize w/ the defaults
|
||||||
|
boolean mutable = true;
|
||||||
|
boolean dynamicInsert = false;
|
||||||
|
boolean dynamicUpdate = false;
|
||||||
|
boolean selectBeforeUpdate = false;
|
||||||
|
PolymorphismType polymorphism = PolymorphismType.IMPLICIT;
|
||||||
|
OptimisticLockType optimisticLock = OptimisticLockType.VERSION;
|
||||||
|
|
||||||
AnnotationInstance hibernateEntityAnnotation = JandexHelper.getSingleAnnotation(
|
AnnotationInstance hibernateEntityAnnotation = JandexHelper.getSingleAnnotation(
|
||||||
configuredClass.getClassInfo(), HibernateDotNames.ENTITY
|
configuredClass.getClassInfo(), HibernateDotNames.ENTITY
|
||||||
);
|
);
|
||||||
// if ( hibAnn != null ) {
|
|
||||||
// dynamicInsert = hibAnn.dynamicInsert();
|
if ( hibernateEntityAnnotation != null ) {
|
||||||
// dynamicUpdate = hibAnn.dynamicUpdate();
|
if ( hibernateEntityAnnotation.value( "mutable" ) != null ) {
|
||||||
// optimisticLockType = hibAnn.optimisticLock();
|
mutable = hibernateEntityAnnotation.value( "mutable" ).asBoolean();
|
||||||
// selectBeforeUpdate = hibAnn.selectBeforeUpdate();
|
}
|
||||||
// polymorphismType = hibAnn.polymorphism();
|
|
||||||
// explicitHibernateEntityAnnotation = true;
|
if ( hibernateEntityAnnotation.value( "dynamicInsert" ) != null ) {
|
||||||
// //persister handled in bind
|
dynamicInsert = hibernateEntityAnnotation.value( "dynamicInsert" ).asBoolean();
|
||||||
// }
|
}
|
||||||
// else {
|
|
||||||
// //default values when the annotation is not there
|
if ( hibernateEntityAnnotation.value( "dynamicUpdate" ) != null ) {
|
||||||
// dynamicInsert = false;
|
dynamicUpdate = hibernateEntityAnnotation.value( "dynamicUpdate" ).asBoolean();
|
||||||
// dynamicUpdate = false;
|
}
|
||||||
// optimisticLockType = OptimisticLockType.VERSION;
|
|
||||||
// polymorphismType = PolymorphismType.IMPLICIT;
|
if ( hibernateEntityAnnotation.value( "selectBeforeUpdate" ) != null ) {
|
||||||
// selectBeforeUpdate = false;
|
selectBeforeUpdate = hibernateEntityAnnotation.value( "selectBeforeUpdate" ).asBoolean();
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
if ( hibernateEntityAnnotation.value( "polymorphism" ) != null ) {
|
||||||
|
polymorphism = PolymorphismType.valueOf( hibernateEntityAnnotation.value( "polymorphism" ).asEnum() );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( hibernateEntityAnnotation.value( "optimisticLock" ) != null ) {
|
||||||
|
optimisticLock = OptimisticLockType.valueOf(
|
||||||
|
hibernateEntityAnnotation.value( "optimisticLock" ).asEnum()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( hibernateEntityAnnotation.value( "persister" ) != null ) {
|
||||||
|
String persister = ( hibernateEntityAnnotation.value( "persister" ).toString() );
|
||||||
|
ClassLoaderService classLoaderService = meta.getServiceRegistry()
|
||||||
|
.getService( ClassLoaderService.class );
|
||||||
|
Class<?> persisterClass = classLoaderService.classForName( persister );
|
||||||
|
entityBinding.setEntityPersisterClass( persisterClass );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// also check for the immutable annotation
|
||||||
|
AnnotationInstance immutableAnnotation = JandexHelper.getSingleAnnotation(
|
||||||
|
configuredClass.getClassInfo(), HibernateDotNames.IMMUTABLE
|
||||||
|
);
|
||||||
|
if ( immutableAnnotation != null ) {
|
||||||
|
mutable = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
entityBinding.setMutable( mutable );
|
||||||
|
entityBinding.setDynamicInsert( dynamicInsert );
|
||||||
|
entityBinding.setDynamicUpdate( dynamicUpdate );
|
||||||
|
entityBinding.setSelectBeforeUpdate( selectBeforeUpdate );
|
||||||
|
entityBinding.setExplicitPolymorphism( PolymorphismType.EXPLICIT.equals( polymorphism ) );
|
||||||
|
entityBinding.setOptimisticLockMode( optimisticLock.ordinal() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private Hierarchical getSuperType() {
|
private Hierarchical getSuperType() {
|
||||||
|
@ -271,7 +316,6 @@ public class EntityBinder {
|
||||||
return IdType.COMPOSED;
|
return IdType.COMPOSED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return IdType.NONE;
|
return IdType.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue