HHH-9077 - org.hibernate.metamodel.source.spi TLC
This commit is contained in:
parent
c7a07a170a
commit
bab7fc6a47
|
@ -55,7 +55,7 @@ import org.hibernate.metamodel.spi.binding.AbstractSingularAssociationAttributeB
|
||||||
import org.hibernate.metamodel.spi.binding.AbstractSingularAttributeBinding;
|
import org.hibernate.metamodel.spi.binding.AbstractSingularAttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.BasicAttributeBinding;
|
import org.hibernate.metamodel.spi.binding.BasicAttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding;
|
import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.InheritanceType;
|
import org.hibernate.metamodel.spi.binding.InheritanceType;
|
||||||
import org.hibernate.metamodel.spi.binding.RelationalValueBinding;
|
import org.hibernate.metamodel.spi.binding.RelationalValueBinding;
|
||||||
|
@ -424,8 +424,8 @@ class TypeSafeActivator {
|
||||||
if ( !isComposite( attributeBinding ) ) {
|
if ( !isComposite( attributeBinding ) ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
CompositeAttributeBinding compositeAttributeBinding = (CompositeAttributeBinding) attributeBinding;
|
EmbeddedAttributeBinding embeddedAttributeBinding = (EmbeddedAttributeBinding) attributeBinding;
|
||||||
attributeBinding = compositeAttributeBinding.locateAttributeBinding( element );
|
attributeBinding = embeddedAttributeBinding.getEmbeddableBinding().locateAttributeBinding( element );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return attributeBinding;
|
return attributeBinding;
|
||||||
|
|
|
@ -873,7 +873,7 @@ public final class SessionFactoryImpl
|
||||||
&& model.getCaching().getRequested() == TruthValue.TRUE ) {
|
&& model.getCaching().getRequested() == TruthValue.TRUE ) {
|
||||||
String baseRegionName = model.getCaching().getRegion();
|
String baseRegionName = model.getCaching().getRegion();
|
||||||
if ( baseRegionName == null ) {
|
if ( baseRegionName == null ) {
|
||||||
baseRegionName = model.getAttributePath();
|
baseRegionName = model.getAttributePath().getFullPath();
|
||||||
}
|
}
|
||||||
final String cacheRegionName = StringHelper.makePath(
|
final String cacheRegionName = StringHelper.makePath(
|
||||||
settings.getCacheRegionPrefix(),
|
settings.getCacheRegionPrefix(),
|
||||||
|
|
|
@ -84,6 +84,7 @@ import org.hibernate.metamodel.spi.InFlightMetadataCollector;
|
||||||
import org.hibernate.metamodel.spi.MetadataBuildingOptions;
|
import org.hibernate.metamodel.spi.MetadataBuildingOptions;
|
||||||
import org.hibernate.metamodel.spi.MetadataContributor;
|
import org.hibernate.metamodel.spi.MetadataContributor;
|
||||||
import org.hibernate.metamodel.spi.MetadataSourceProcessor;
|
import org.hibernate.metamodel.spi.MetadataSourceProcessor;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeElementNature;
|
||||||
import org.hibernate.metamodel.spi.TypeContributions;
|
import org.hibernate.metamodel.spi.TypeContributions;
|
||||||
import org.hibernate.metamodel.spi.TypeContributor;
|
import org.hibernate.metamodel.spi.TypeContributor;
|
||||||
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
||||||
|
@ -94,7 +95,6 @@ import org.hibernate.metamodel.spi.binding.IdentifierGeneratorDefinition;
|
||||||
import org.hibernate.metamodel.spi.binding.IndexedPluralAttributeBinding;
|
import org.hibernate.metamodel.spi.binding.IndexedPluralAttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding;
|
import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
|
import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding;
|
|
||||||
import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
|
import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.PluralAttributeKeyBinding;
|
import org.hibernate.metamodel.spi.binding.PluralAttributeKeyBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.RelationalValueBinding;
|
import org.hibernate.metamodel.spi.binding.RelationalValueBinding;
|
||||||
|
@ -385,7 +385,7 @@ public class MetadataBuildingProcess {
|
||||||
PluralAttributeKeyBinding keyBinding = pluralAttributeBinding.getPluralAttributeKeyBinding();
|
PluralAttributeKeyBinding keyBinding = pluralAttributeBinding.getPluralAttributeKeyBinding();
|
||||||
if ( keyBinding.isInverse() || keyBinding.isNullable() ||
|
if ( keyBinding.isInverse() || keyBinding.isNullable() ||
|
||||||
pluralAttributeBinding.getPluralAttributeElementBinding().getNature() !=
|
pluralAttributeBinding.getPluralAttributeElementBinding().getNature() !=
|
||||||
PluralAttributeElementBinding.Nature.ONE_TO_MANY ) {
|
PluralAttributeElementNature.ONE_TO_MANY ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Ensure this isn't a bidirectional association by ensuring FK columns don't match relational columns of any
|
// Ensure this isn't a bidirectional association by ensuring FK columns don't match relational columns of any
|
||||||
|
@ -498,8 +498,15 @@ public class MetadataBuildingProcess {
|
||||||
|
|
||||||
}
|
}
|
||||||
else if ( override.getRegionType() == CacheRegionDefinition.CacheRegionType.COLLECTION ) {
|
else if ( override.getRegionType() == CacheRegionDefinition.CacheRegionType.COLLECTION ) {
|
||||||
|
String collectionRole = role;
|
||||||
|
if ( !role.contains( "#" ) ) {
|
||||||
|
final int pivotPosition = role.lastIndexOf( '.' );
|
||||||
|
if ( pivotPosition > 0 ) {
|
||||||
|
collectionRole = role.substring( 0, pivotPosition ) + '#' + role.substring( pivotPosition + 1 );
|
||||||
|
}
|
||||||
|
}
|
||||||
final PluralAttributeBinding pluralAttributeBinding = bindingContext.getMetadataCollector().getCollection(
|
final PluralAttributeBinding pluralAttributeBinding = bindingContext.getMetadataCollector().getCollection(
|
||||||
role
|
collectionRole
|
||||||
);
|
);
|
||||||
if ( pluralAttributeBinding != null ) {
|
if ( pluralAttributeBinding != null ) {
|
||||||
pluralAttributeBinding.getCaching().overlay( override );
|
pluralAttributeBinding.getCaching().overlay( override );
|
||||||
|
@ -1119,20 +1126,11 @@ public class MetadataBuildingProcess {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addCollection(PluralAttributeBinding pluralAttributeBinding) {
|
public void addCollection(PluralAttributeBinding pluralAttributeBinding) {
|
||||||
final String owningEntityName = pluralAttributeBinding.getContainer().seekEntityBinding().getEntityName();
|
final String collectionRole = pluralAttributeBinding.getAttributeRole().getFullPath();
|
||||||
final String containerPathBase = pluralAttributeBinding.getContainer().getPathBase();
|
|
||||||
final String attributeName = pluralAttributeBinding.getAttribute().getName();
|
|
||||||
final String collectionRole;
|
|
||||||
if ( StringHelper.isEmpty( containerPathBase ) ) {
|
|
||||||
collectionRole = owningEntityName + '.' + attributeName;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
collectionRole = owningEntityName + '.' + containerPathBase + '.' + attributeName;
|
|
||||||
}
|
|
||||||
if ( collectionBindingMap.containsKey( collectionRole ) ) {
|
if ( collectionBindingMap.containsKey( collectionRole ) ) {
|
||||||
throw new DuplicateMappingException( DuplicateMappingException.Type.ENTITY, collectionRole );
|
throw new DuplicateMappingException( DuplicateMappingException.Type.ENTITY, collectionRole );
|
||||||
}
|
}
|
||||||
collectionBindingMap.put( collectionRole, pluralAttributeBinding );
|
collectionBindingMap.put( pluralAttributeBinding.getAttributeRole().getFullPath(), pluralAttributeBinding );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -35,7 +35,7 @@ public class CollectionTableNamingStrategyHelper extends TableNamingStrategyHelp
|
||||||
|
|
||||||
public CollectionTableNamingStrategyHelper(final AbstractPluralAttributeBinding pluralAttributeBinding) {
|
public CollectionTableNamingStrategyHelper(final AbstractPluralAttributeBinding pluralAttributeBinding) {
|
||||||
super( pluralAttributeBinding.getContainer().seekEntityBinding() );
|
super( pluralAttributeBinding.getContainer().seekEntityBinding() );
|
||||||
this.propertyName = Binder.createAttributePath( pluralAttributeBinding );
|
this.propertyName = pluralAttributeBinding.getAttribute().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -44,25 +44,26 @@ import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
||||||
import org.hibernate.metamodel.reflite.spi.MethodDescriptor;
|
import org.hibernate.metamodel.reflite.spi.MethodDescriptor;
|
||||||
import org.hibernate.metamodel.reflite.spi.PrimitiveTypeDescriptor;
|
import org.hibernate.metamodel.reflite.spi.PrimitiveTypeDescriptor;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSource;
|
import org.hibernate.metamodel.source.spi.AttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.BasicPluralAttributeElementSource;
|
import org.hibernate.metamodel.source.spi.EmbeddedAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.ComponentAttributeSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.HibernateTypeSource;
|
import org.hibernate.metamodel.source.spi.HibernateTypeSource;
|
||||||
import org.hibernate.metamodel.source.spi.IdentifiableTypeSource;
|
import org.hibernate.metamodel.source.spi.IdentifiableTypeSource;
|
||||||
import org.hibernate.metamodel.source.spi.ManyToManyPluralAttributeElementSource;
|
import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceBasic;
|
||||||
|
import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceManyToMany;
|
||||||
import org.hibernate.metamodel.source.spi.PluralAttributeSource;
|
import org.hibernate.metamodel.source.spi.PluralAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
||||||
import org.hibernate.metamodel.spi.InFlightMetadataCollector;
|
import org.hibernate.metamodel.spi.InFlightMetadataCollector;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeElementNature;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeNature;
|
||||||
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.BasicAttributeBinding;
|
import org.hibernate.metamodel.spi.binding.BasicAttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.BasicPluralAttributeElementBinding;
|
import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding;
|
|
||||||
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.EntityDiscriminator;
|
import org.hibernate.metamodel.spi.binding.EntityDiscriminator;
|
||||||
import org.hibernate.metamodel.spi.binding.EntityIdentifier;
|
import org.hibernate.metamodel.spi.binding.EntityIdentifier;
|
||||||
import org.hibernate.metamodel.spi.binding.HibernateTypeDescriptor;
|
import org.hibernate.metamodel.spi.binding.HibernateTypeDescriptor;
|
||||||
import org.hibernate.metamodel.spi.binding.ManyToManyPluralAttributeElementBinding;
|
|
||||||
import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
|
import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding;
|
import org.hibernate.metamodel.spi.binding.PluralAttributeElementBindingBasic;
|
||||||
|
import org.hibernate.metamodel.spi.binding.PluralAttributeElementBindingManyToMany;
|
||||||
import org.hibernate.metamodel.spi.binding.RelationalValueBinding;
|
import org.hibernate.metamodel.spi.binding.RelationalValueBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.TypeDefinition;
|
import org.hibernate.metamodel.spi.binding.TypeDefinition;
|
||||||
|
@ -381,11 +382,11 @@ class HibernateTypeHelper {
|
||||||
final boolean isAttributeIdentifier,
|
final boolean isAttributeIdentifier,
|
||||||
final Aggregate composite,
|
final Aggregate composite,
|
||||||
final JavaTypeDescriptor defaultTypeDescriptor,
|
final JavaTypeDescriptor defaultTypeDescriptor,
|
||||||
final CompositeAttributeBinding attributeBinding) {
|
final EmbeddedAttributeBinding attributeBinding) {
|
||||||
Type resolvedType = typeFactory().component(
|
Type resolvedType = typeFactory().component(
|
||||||
new ComponentMetamodel(
|
new ComponentMetamodel(
|
||||||
serviceRegistry,
|
serviceRegistry,
|
||||||
attributeBinding,
|
attributeBinding.getEmbeddableBinding(),
|
||||||
isAttributeIdentifier,
|
isAttributeIdentifier,
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
|
@ -400,8 +401,8 @@ class HibernateTypeHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
void bindBasicCollectionElementType(
|
void bindBasicCollectionElementType(
|
||||||
final BasicPluralAttributeElementBinding elementBinding,
|
final PluralAttributeElementBindingBasic elementBinding,
|
||||||
final BasicPluralAttributeElementSource elementSource,
|
final PluralAttributeElementSourceBasic elementSource,
|
||||||
final JavaTypeDescriptor defaultElementTypeDescriptor) {
|
final JavaTypeDescriptor defaultElementTypeDescriptor) {
|
||||||
bindHibernateTypeDescriptor(
|
bindHibernateTypeDescriptor(
|
||||||
elementBinding.getHibernateTypeDescriptor(),
|
elementBinding.getHibernateTypeDescriptor(),
|
||||||
|
@ -415,10 +416,10 @@ class HibernateTypeHelper {
|
||||||
}
|
}
|
||||||
void bindNonAggregatedCompositeIdentifierType(
|
void bindNonAggregatedCompositeIdentifierType(
|
||||||
final ServiceRegistry serviceRegistry,
|
final ServiceRegistry serviceRegistry,
|
||||||
final CompositeAttributeBinding syntheticAttributeBinding,
|
final EmbeddedAttributeBinding syntheticAttributeBinding,
|
||||||
final SingularAttribute syntheticAttribute) {
|
final SingularAttribute syntheticAttribute) {
|
||||||
final Type resolvedType = typeFactory().embeddedComponent(
|
final Type resolvedType = typeFactory().embeddedComponent(
|
||||||
new ComponentMetamodel( serviceRegistry, syntheticAttributeBinding, true, false )
|
new ComponentMetamodel( serviceRegistry, syntheticAttributeBinding.getEmbeddableBinding(), true, false )
|
||||||
);
|
);
|
||||||
final HibernateTypeDescriptor typeDescriptor = syntheticAttributeBinding.getHibernateTypeDescriptor();
|
final HibernateTypeDescriptor typeDescriptor = syntheticAttributeBinding.getHibernateTypeDescriptor();
|
||||||
final String className = syntheticAttribute.getSingularAttributeType().getDescriptor() == null ?
|
final String className = syntheticAttribute.getSingularAttributeType().getDescriptor() == null ?
|
||||||
|
@ -433,8 +434,8 @@ class HibernateTypeHelper {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
void bindManyToManyAttributeType(
|
void bindManyToManyAttributeType(
|
||||||
final ManyToManyPluralAttributeElementBinding elementBinding,
|
final PluralAttributeElementBindingManyToMany elementBinding,
|
||||||
final ManyToManyPluralAttributeElementSource elementSource,
|
final PluralAttributeElementSourceManyToMany elementSource,
|
||||||
final EntityBinding referencedEntityBinding,
|
final EntityBinding referencedEntityBinding,
|
||||||
final JavaTypeDescriptor defaultElementTypeDescriptor) {
|
final JavaTypeDescriptor defaultElementTypeDescriptor) {
|
||||||
final Type resolvedElementType = typeFactory().manyToOne(
|
final Type resolvedElementType = typeFactory().manyToOne(
|
||||||
|
@ -455,7 +456,7 @@ class HibernateTypeHelper {
|
||||||
);
|
);
|
||||||
bindJdbcDataType(
|
bindJdbcDataType(
|
||||||
resolvedElementType,
|
resolvedElementType,
|
||||||
elementBinding.getRelationalValueBindings()
|
elementBinding.getRelationalValueContainer().relationalValueBindings()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -508,7 +509,7 @@ class HibernateTypeHelper {
|
||||||
ClassLoaderService classLoaderService,
|
ClassLoaderService classLoaderService,
|
||||||
final PluralAttributeBinding pluralAttributeBinding,
|
final PluralAttributeBinding pluralAttributeBinding,
|
||||||
final PluralAttributeSource pluralAttributeSource,
|
final PluralAttributeSource pluralAttributeSource,
|
||||||
final PluralAttributeSource.Nature nature) {
|
final PluralAttributeNature nature) {
|
||||||
if ( pluralAttributeBinding.getHibernateTypeDescriptor().getExplicitTypeName() != null ) {
|
if ( pluralAttributeBinding.getHibernateTypeDescriptor().getExplicitTypeName() != null ) {
|
||||||
return resolveCustomCollectionType( pluralAttributeBinding );
|
return resolveCustomCollectionType( pluralAttributeBinding );
|
||||||
}
|
}
|
||||||
|
@ -562,8 +563,8 @@ class HibernateTypeHelper {
|
||||||
else if ( pluralAttributeBinding.getOrderBy() != null ) {
|
else if ( pluralAttributeBinding.getOrderBy() != null ) {
|
||||||
return typeFactory().orderedSet( role, propertyRef );
|
return typeFactory().orderedSet( role, propertyRef );
|
||||||
}
|
}
|
||||||
else if ( pluralAttributeBinding.getPluralAttributeElementBinding().getNature() == PluralAttributeElementBinding.Nature.MANY_TO_MANY &&
|
else if ( pluralAttributeBinding.getPluralAttributeElementBinding().getNature() == PluralAttributeElementNature.MANY_TO_MANY &&
|
||||||
( (ManyToManyPluralAttributeElementBinding) pluralAttributeBinding.getPluralAttributeElementBinding() ).getManyToManyOrderBy() != null ) {
|
( (PluralAttributeElementBindingManyToMany) pluralAttributeBinding.getPluralAttributeElementBinding() ).getManyToManyOrderBy() != null ) {
|
||||||
return typeFactory().orderedSet( role, propertyRef );
|
return typeFactory().orderedSet( role, propertyRef );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -736,10 +737,10 @@ class HibernateTypeHelper {
|
||||||
resolvedHibernateType
|
resolvedHibernateType
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else if ( CompositeAttributeBinding.class.isInstance( attributeBinding ) ) {
|
else if ( EmbeddedAttributeBinding.class.isInstance( attributeBinding ) ) {
|
||||||
pushHibernateTypeInformationDown(
|
pushHibernateTypeInformationDown(
|
||||||
(ComponentAttributeSource) attributeSource,
|
(EmbeddedAttributeSource) attributeSource,
|
||||||
(CompositeAttributeBinding) attributeBinding,
|
(EmbeddedAttributeBinding) attributeBinding,
|
||||||
resolvedHibernateType
|
resolvedHibernateType
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -763,8 +764,8 @@ class HibernateTypeHelper {
|
||||||
|
|
||||||
@SuppressWarnings({ "UnusedParameters" })
|
@SuppressWarnings({ "UnusedParameters" })
|
||||||
private void pushHibernateTypeInformationDown(
|
private void pushHibernateTypeInformationDown(
|
||||||
final ComponentAttributeSource attributeSource,
|
final EmbeddedAttributeSource attributeSource,
|
||||||
final CompositeAttributeBinding attributeBinding,
|
final EmbeddedAttributeBinding attributeBinding,
|
||||||
final Type resolvedHibernateType) {
|
final Type resolvedHibernateType) {
|
||||||
final HibernateTypeDescriptor hibernateTypeDescriptor = attributeBinding.getHibernateTypeDescriptor();
|
final HibernateTypeDescriptor hibernateTypeDescriptor = attributeBinding.getHibernateTypeDescriptor();
|
||||||
|
|
||||||
|
@ -773,8 +774,8 @@ class HibernateTypeHelper {
|
||||||
singularAttribute.resolveType( makeDomainType( hibernateTypeDescriptor.getJavaTypeDescriptor().getName() ) );
|
singularAttribute.resolveType( makeDomainType( hibernateTypeDescriptor.getJavaTypeDescriptor().getName() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<AttributeSource> subAttributeSourceIterator = attributeSource.attributeSources().iterator();
|
Iterator<AttributeSource> subAttributeSourceIterator = attributeSource.getEmbeddableSource().attributeSources().iterator();
|
||||||
for ( AttributeBinding subAttributeBinding : attributeBinding.attributeBindings() ) {
|
for ( AttributeBinding subAttributeBinding : attributeBinding.getEmbeddableBinding().attributeBindings() ) {
|
||||||
AttributeSource subAttributeSource = subAttributeSourceIterator.next();
|
AttributeSource subAttributeSource = subAttributeSourceIterator.next();
|
||||||
if ( SingularAttributeBinding.class.isInstance( subAttributeBinding ) ) {
|
if ( SingularAttributeBinding.class.isInstance( subAttributeBinding ) ) {
|
||||||
processSingularAttributeTypeInformation(
|
processSingularAttributeTypeInformation(
|
||||||
|
@ -834,11 +835,11 @@ class HibernateTypeHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public JavaTypeDescriptor determineJavaType(
|
public JavaTypeDescriptor determineJavaType(
|
||||||
final ComponentAttributeSource attributeSource,
|
final EmbeddedAttributeSource attributeSource,
|
||||||
final AttributeContainer attributeContainer,
|
final AttributeContainer attributeContainer,
|
||||||
final EntityMode entityMode) {
|
final EntityMode entityMode) {
|
||||||
if ( attributeSource.getTypeDescriptor() != null ) {
|
if ( attributeSource.getEmbeddableSource().getTypeDescriptor() != null ) {
|
||||||
return attributeSource.getTypeDescriptor();
|
return attributeSource.getEmbeddableSource().getTypeDescriptor();
|
||||||
}
|
}
|
||||||
else if ( entityMode == EntityMode.MAP ) {
|
else if ( entityMode == EntityMode.MAP ) {
|
||||||
return bindingContext().typeDescriptor( Map.class.getName() );
|
return bindingContext().typeDescriptor( Map.class.getName() );
|
||||||
|
|
|
@ -35,9 +35,9 @@ import org.hibernate.metamodel.source.spi.DerivedValueSource;
|
||||||
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
||||||
import org.hibernate.metamodel.source.spi.RelationalValueSourceContainer;
|
import org.hibernate.metamodel.source.spi.RelationalValueSourceContainer;
|
||||||
import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
||||||
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
import org.hibernate.metamodel.spi.binding.AttributeBindingContainer;
|
import org.hibernate.metamodel.spi.binding.AttributeBindingContainer;
|
||||||
import org.hibernate.metamodel.spi.binding.RelationalValueBinding;
|
import org.hibernate.metamodel.spi.binding.RelationalValueBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
|
||||||
import org.hibernate.metamodel.spi.domain.Attribute;
|
import org.hibernate.metamodel.spi.domain.Attribute;
|
||||||
import org.hibernate.metamodel.spi.relational.Column;
|
import org.hibernate.metamodel.spi.relational.Column;
|
||||||
import org.hibernate.metamodel.spi.relational.DerivedValue;
|
import org.hibernate.metamodel.spi.relational.DerivedValue;
|
||||||
|
@ -92,15 +92,15 @@ public class RelationalValueBindingHelper {
|
||||||
final List<Binder.DefaultNamingStrategy> defaultNameStrategies,
|
final List<Binder.DefaultNamingStrategy> defaultNameStrategies,
|
||||||
final boolean forceNonNullable) {
|
final boolean forceNonNullable) {
|
||||||
final List<RelationalValueBinding> valueBindings = new ArrayList<RelationalValueBinding>();
|
final List<RelationalValueBinding> valueBindings = new ArrayList<RelationalValueBinding>();
|
||||||
final SingularAttributeBinding.NaturalIdMutability naturalIdMutability;
|
final NaturalIdMutability naturalIdMutability;
|
||||||
if ( SingularAttributeSource.class.isInstance( valueSourceContainer ) ) {
|
if ( SingularAttributeSource.class.isInstance( valueSourceContainer ) ) {
|
||||||
naturalIdMutability = SingularAttributeSource.class.cast( valueSourceContainer ).getNaturalIdMutability();
|
naturalIdMutability = SingularAttributeSource.class.cast( valueSourceContainer ).getNaturalIdMutability();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
naturalIdMutability = SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID;
|
naturalIdMutability = NaturalIdMutability.NOT_NATURAL_ID;
|
||||||
}
|
}
|
||||||
final boolean isNaturalId = naturalIdMutability != SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID;
|
final boolean isNaturalId = naturalIdMutability != NaturalIdMutability.NOT_NATURAL_ID;
|
||||||
final boolean isImmutableNaturalId = isNaturalId && ( naturalIdMutability == SingularAttributeBinding.NaturalIdMutability.IMMUTABLE );
|
final boolean isImmutableNaturalId = isNaturalId && ( naturalIdMutability == NaturalIdMutability.IMMUTABLE );
|
||||||
final boolean reallyForceNonNullable = forceNonNullable ; //|| isNaturalId; todo is a natural id column should be not nullable?
|
final boolean reallyForceNonNullable = forceNonNullable ; //|| isNaturalId; todo is a natural id column should be not nullable?
|
||||||
|
|
||||||
if ( valueSourceContainer.relationalValueSources().isEmpty() ) {
|
if ( valueSourceContainer.relationalValueSources().isEmpty() ) {
|
||||||
|
|
|
@ -26,28 +26,30 @@ package org.hibernate.metamodel.internal.binder;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.AssertionFailure;
|
import org.hibernate.AssertionFailure;
|
||||||
import org.hibernate.internal.CoreLogging;
|
import org.hibernate.internal.CoreLogging;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
|
||||||
import org.hibernate.metamodel.source.spi.AggregatedCompositeIdentifierSource;
|
import org.hibernate.metamodel.source.spi.AggregatedCompositeIdentifierSource;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSource;
|
import org.hibernate.metamodel.source.spi.AttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSourceResolutionContext;
|
import org.hibernate.metamodel.source.spi.AttributeSourceResolutionContext;
|
||||||
import org.hibernate.metamodel.source.spi.ComponentAttributeSource;
|
import org.hibernate.metamodel.source.spi.EmbeddedAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.EntityHierarchySource;
|
import org.hibernate.metamodel.source.spi.EntityHierarchySource;
|
||||||
import org.hibernate.metamodel.source.spi.EntitySource;
|
import org.hibernate.metamodel.source.spi.EntitySource;
|
||||||
import org.hibernate.metamodel.source.spi.IdentifiableTypeSource;
|
import org.hibernate.metamodel.source.spi.IdentifiableTypeSource;
|
||||||
import org.hibernate.metamodel.source.spi.IdentifierSource;
|
import org.hibernate.metamodel.source.spi.IdentifierSource;
|
||||||
import org.hibernate.metamodel.source.spi.IndexedPluralAttributeSource;
|
import org.hibernate.metamodel.source.spi.IndexedPluralAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.NonAggregatedCompositeIdentifierSource;
|
import org.hibernate.metamodel.source.spi.NonAggregatedCompositeIdentifierSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.PluralAttributeIndexSourceResolver;
|
||||||
import org.hibernate.metamodel.source.spi.PluralAttributeSource;
|
import org.hibernate.metamodel.source.spi.PluralAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.SimpleIdentifierSource;
|
import org.hibernate.metamodel.source.spi.SimpleIdentifierSource;
|
||||||
import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.ToOneAttributeSource;
|
import org.hibernate.metamodel.source.spi.ToOneAttributeSource;
|
||||||
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
|
import org.hibernate.metamodel.spi.SingularAttributeNature;
|
||||||
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
||||||
import org.hibernate.metamodel.spi.relational.Column;
|
import org.hibernate.metamodel.spi.relational.Column;
|
||||||
|
@ -64,12 +66,11 @@ import org.jboss.logging.Logger;
|
||||||
public class SourceIndex {
|
public class SourceIndex {
|
||||||
private static final Logger log = CoreLogging.logger( SourceIndex.class );
|
private static final Logger log = CoreLogging.logger( SourceIndex.class );
|
||||||
|
|
||||||
private static final String EMPTY_STRING = "";
|
|
||||||
|
|
||||||
private final Map<String, EntitySourceIndex> entitySourceIndexByEntityName = new HashMap<String, EntitySourceIndex>();
|
private final Map<String, EntitySourceIndex> entitySourceIndexByEntityName = new HashMap<String, EntitySourceIndex>();
|
||||||
private final Map<AttributeSourceKey, AttributeSource> attributeSourcesByKey = new HashMap<AttributeSourceKey, AttributeSource>();
|
private final Map<AttributeRole, AttributeSource> attributeSourcesByKey = new HashMap<AttributeRole, AttributeSource>();
|
||||||
private final Map<AttributeSourceKey, AttributeSourceKey> mappedByAttributeKeysByOwnerAttributeKeys =
|
|
||||||
new HashMap<AttributeSourceKey, AttributeSourceKey>();
|
private final Map<AttributeRole, AttributeRole> mappedByAttributeKeysByOwnerAttributeKeys =
|
||||||
|
new HashMap<AttributeRole, AttributeRole>();
|
||||||
|
|
||||||
|
|
||||||
public void indexHierarchy(EntityHierarchySource hierarchy) {
|
public void indexHierarchy(EntityHierarchySource hierarchy) {
|
||||||
|
@ -105,21 +106,21 @@ public class SourceIndex {
|
||||||
case SIMPLE: {
|
case SIMPLE: {
|
||||||
final AttributeSource identifierAttributeSource =
|
final AttributeSource identifierAttributeSource =
|
||||||
( (SimpleIdentifierSource) identifierSource ).getIdentifierAttributeSource();
|
( (SimpleIdentifierSource) identifierSource ).getIdentifierAttributeSource();
|
||||||
indexAttributeSources( hierarchyInfo, EMPTY_STRING, identifierAttributeSource, true );
|
indexAttributeSources( hierarchyInfo, identifierAttributeSource, true );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NON_AGGREGATED_COMPOSITE: {
|
case NON_AGGREGATED_COMPOSITE: {
|
||||||
final List<SingularAttributeSource> nonAggregatedAttributeSources =
|
final List<SingularAttributeSource> nonAggregatedAttributeSources =
|
||||||
( (NonAggregatedCompositeIdentifierSource) identifierSource ).getAttributeSourcesMakingUpIdentifier();
|
( (NonAggregatedCompositeIdentifierSource) identifierSource ).getAttributeSourcesMakingUpIdentifier();
|
||||||
for ( SingularAttributeSource nonAggregatedAttributeSource : nonAggregatedAttributeSources ) {
|
for ( SingularAttributeSource nonAggregatedAttributeSource : nonAggregatedAttributeSources ) {
|
||||||
indexAttributeSources( hierarchyInfo, EMPTY_STRING, nonAggregatedAttributeSource, true );
|
indexAttributeSources( hierarchyInfo, nonAggregatedAttributeSource, true );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AGGREGATED_COMPOSITE: {
|
case AGGREGATED_COMPOSITE: {
|
||||||
final ComponentAttributeSource aggregatedAttributeSource =
|
final EmbeddedAttributeSource aggregatedAttributeSource =
|
||||||
( (AggregatedCompositeIdentifierSource) identifierSource ).getIdentifierAttributeSource();
|
( (AggregatedCompositeIdentifierSource) identifierSource ).getIdentifierAttributeSource();
|
||||||
indexAttributeSources( hierarchyInfo, EMPTY_STRING, aggregatedAttributeSource, true );
|
indexAttributeSources( hierarchyInfo, aggregatedAttributeSource, true );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
@ -132,29 +133,22 @@ public class SourceIndex {
|
||||||
|
|
||||||
private void indexAttributeSources(
|
private void indexAttributeSources(
|
||||||
AttributeIndexingTarget attributeIndexingTarget,
|
AttributeIndexingTarget attributeIndexingTarget,
|
||||||
String pathBase,
|
|
||||||
AttributeSource attributeSource,
|
AttributeSource attributeSource,
|
||||||
boolean isInIdentifier) {
|
boolean isInIdentifier) {
|
||||||
final AttributeSourceKey key = new AttributeSourceKey(
|
log.debugf( "Indexing attribute source [%s]", attributeSource.getAttributeRole() );
|
||||||
attributeIndexingTarget.getAttributeSourceKeyBase(),
|
attributeSourcesByKey.put( attributeSource.getAttributeRole(), attributeSource );
|
||||||
pathBase,
|
|
||||||
attributeSource.getName()
|
|
||||||
);
|
|
||||||
attributeSourcesByKey.put( key, attributeSource );
|
|
||||||
log.debugf( "Indexing attribute source [%s]", key );
|
|
||||||
|
|
||||||
if ( attributeSource.isSingular() ) {
|
if ( attributeSource.isSingular() ) {
|
||||||
attributeIndexingTarget.indexSingularAttributeSource( pathBase, (SingularAttributeSource) attributeSource, isInIdentifier );
|
attributeIndexingTarget.indexSingularAttributeSource( (SingularAttributeSource) attributeSource, isInIdentifier );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
attributeIndexingTarget.indexPluralAttributeSource( pathBase, (PluralAttributeSource) attributeSource );
|
attributeIndexingTarget.indexPluralAttributeSource( (PluralAttributeSource) attributeSource );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( attributeSource instanceof ComponentAttributeSource ) {
|
if ( attributeSource instanceof EmbeddedAttributeSource ) {
|
||||||
for ( AttributeSource subAttributeSource : ( (ComponentAttributeSource) attributeSource ).attributeSources() ) {
|
for ( AttributeSource subAttributeSource : ( (EmbeddedAttributeSource) attributeSource ).getEmbeddableSource().attributeSources() ) {
|
||||||
indexAttributeSources(
|
indexAttributeSources(
|
||||||
attributeIndexingTarget,
|
attributeIndexingTarget,
|
||||||
key.attributePath(),
|
|
||||||
subAttributeSource,
|
subAttributeSource,
|
||||||
isInIdentifier
|
isInIdentifier
|
||||||
);
|
);
|
||||||
|
@ -163,9 +157,8 @@ public class SourceIndex {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void indexAttributes(EntitySourceIndex entitySourceIndex) {
|
private void indexAttributes(EntitySourceIndex entitySourceIndex) {
|
||||||
final String emptyString = "";
|
|
||||||
for ( final AttributeSource attributeSource : entitySourceIndex.entitySource.attributeSources() ) {
|
for ( final AttributeSource attributeSource : entitySourceIndex.entitySource.attributeSources() ) {
|
||||||
indexAttributeSources(entitySourceIndex, emptyString, attributeSource, false );
|
indexAttributeSources( entitySourceIndex, attributeSource, false );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,181 +176,77 @@ public class SourceIndex {
|
||||||
entitySourceIndexByEntityName.get( binding.getEntityName() ).resolveAttributeSources( context );
|
entitySourceIndexByEntityName.get( binding.getEntityName() ).resolveAttributeSources( context );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<AttributeSourceKey, SingularAttributeSource> getSingularAttributeSources(
|
public Map<AttributeRole, SingularAttributeSource> getSingularAttributeSources(
|
||||||
String entityName,
|
String entityName,
|
||||||
boolean isMappedBy,
|
boolean isMappedBy,
|
||||||
SingularAttributeSource.Nature nature) {
|
SingularAttributeNature singularAttributeNature) {
|
||||||
final EntitySourceIndex entitySourceIndex = entitySourceIndexByEntityName.get( entityName );
|
final EntitySourceIndex entitySourceIndex = entitySourceIndexByEntityName.get( entityName );
|
||||||
return entitySourceIndex.getSingularAttributeSources( isMappedBy, nature );
|
return entitySourceIndex.getSingularAttributeSources( isMappedBy, singularAttributeNature );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<AttributeSourceKey, PluralAttributeSource> getPluralAttributeSources(
|
public Map<AttributeRole, PluralAttributeSource> getPluralAttributeSources(
|
||||||
String entityName,
|
String entityName,
|
||||||
boolean isInverse) {
|
boolean isInverse) {
|
||||||
final EntitySourceIndex entitySourceIndex = entitySourceIndexByEntityName.get( entityName );
|
final EntitySourceIndex entitySourceIndex = entitySourceIndexByEntityName.get( entityName );
|
||||||
return entitySourceIndex.getPluralAttributeSources( isInverse );
|
return entitySourceIndex.getPluralAttributeSources( isInverse );
|
||||||
}
|
}
|
||||||
|
|
||||||
public AttributeSource attributeSource(final String entityName, final String attributePath) {
|
public AttributeSource attributeSource(final AttributeRole attributeRole) {
|
||||||
return attributeSourcesByKey.get( new AttributeSourceKey( entityName, attributePath ) );
|
return attributeSourcesByKey.get( attributeRole );
|
||||||
|
}
|
||||||
|
|
||||||
|
public AttributeSource attributeSource(String entityName, String attributePath) {
|
||||||
|
final AttributeRole base = new AttributeRole( entityName );
|
||||||
|
|
||||||
|
AttributeRole role;
|
||||||
|
if ( attributePath.contains( "." ) ) {
|
||||||
|
role = base;
|
||||||
|
for ( String part : attributePath.split( "\\." ) ) {
|
||||||
|
role = role.append( part );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
role = base.append( attributePath );
|
||||||
|
}
|
||||||
|
return attributeSourcesByKey.get( role );
|
||||||
}
|
}
|
||||||
|
|
||||||
public AttributeSource attributeSource(EntityBinding entityBinding, AttributeBinding attributeBinding) {
|
public AttributeSource attributeSource(EntityBinding entityBinding, AttributeBinding attributeBinding) {
|
||||||
return attributeSourcesByKey.get(
|
return attributeSourcesByKey.get( attributeBinding.getAttributeRole() );
|
||||||
new AttributeSourceKey(
|
|
||||||
entityBinding.getEntityName(),
|
|
||||||
attributeBinding.getAttributePath()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public AttributeSource locateAttributeSourceOwnedBy(final String entityName, final String attributePath) {
|
|
||||||
AttributeSourceKey ownerKey = new AttributeSourceKey( entityName, attributePath );
|
|
||||||
AttributeSourceKey mappedByKey = mappedByAttributeKeysByOwnerAttributeKeys.get( ownerKey );
|
|
||||||
return mappedByKey == null ? null : attributeSourcesByKey.get( mappedByKey );
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntitySource entitySource(final String entityName) {
|
|
||||||
return entitySourceIndexByEntityName.get( entityName ).entitySource;
|
|
||||||
}
|
|
||||||
|
|
||||||
private EntitySourceIndex entitySourceIndex(String entityName) {
|
|
||||||
return entitySourceIndexByEntityName.get( entityName );
|
|
||||||
}
|
|
||||||
|
|
||||||
void addMappedByAssociationByOwnerAssociation(AttributeSourceKey ownerKey, AttributeSourceKey ownedKey) {
|
|
||||||
mappedByAttributeKeysByOwnerAttributeKeys.put(
|
|
||||||
ownerKey,
|
|
||||||
ownedKey
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper class for indexing attribute look ups.
|
|
||||||
*/
|
|
||||||
public static class AttributeSourceKey {
|
|
||||||
private final String entityName;
|
|
||||||
private final String containerPath;
|
|
||||||
private final String attributeName;
|
|
||||||
|
|
||||||
private AttributeSourceKey(final String entityName, final String containerPath, final String attributeName) {
|
|
||||||
this.entityName = entityName;
|
|
||||||
this.containerPath = containerPath;
|
|
||||||
this.attributeName = attributeName;
|
|
||||||
}
|
|
||||||
|
|
||||||
private AttributeSourceKey(final String entityName, final String attributePath) {
|
|
||||||
this.entityName = entityName;
|
|
||||||
int indexLastDot = attributePath.lastIndexOf( '.' );
|
|
||||||
if ( indexLastDot == -1 ) {
|
|
||||||
this.containerPath = EMPTY_STRING;
|
|
||||||
this.attributeName = attributePath;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.containerPath = attributePath.substring( 0, indexLastDot );
|
|
||||||
this.attributeName = attributePath.substring( indexLastDot + 1 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String entityName() {
|
|
||||||
return entityName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String containerPath() {
|
|
||||||
return containerPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String attributeName() {
|
|
||||||
return attributeName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String attributePath() {
|
|
||||||
return StringHelper.isEmpty( containerPath )
|
|
||||||
? attributeName
|
|
||||||
: containerPath + '.' + attributeName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAttributePathQualifiedByEntityName() {
|
|
||||||
return entityName + '.' + attributePath();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return getAttributePathQualifiedByEntityName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if ( this == o ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if ( o == null || getClass() != o.getClass() ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
final AttributeSourceKey that = (AttributeSourceKey) o;
|
|
||||||
return attributeName.equals( that.attributeName )
|
|
||||||
&& containerPath.equals( that.containerPath )
|
|
||||||
&& entityName.equals( that.entityName );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
int result = entityName.hashCode();
|
|
||||||
result = 31 * result + containerPath.hashCode();
|
|
||||||
result = 31 * result + attributeName.hashCode();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static interface AttributeIndexingTarget {
|
private static interface AttributeIndexingTarget {
|
||||||
public String getAttributeSourceKeyBase();
|
public void indexSingularAttributeSource(SingularAttributeSource attributeSource, boolean isInIdentifier);
|
||||||
|
public void indexPluralAttributeSource(PluralAttributeSource attributeSource);
|
||||||
public void indexSingularAttributeSource(
|
|
||||||
String pathBase,
|
|
||||||
SingularAttributeSource attributeSource,
|
|
||||||
boolean isInIdentifier);
|
|
||||||
|
|
||||||
public void indexPluralAttributeSource(String pathBase, PluralAttributeSource attributeSource);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static abstract class AbstractAttributeIndexingTarget implements AttributeIndexingTarget {
|
private static abstract class AbstractAttributeIndexingTarget implements AttributeIndexingTarget {
|
||||||
private final Map<AttributeSourceKey, SingularAttributeSource> unresolvedSingularAttributeSourcesByKey
|
private final Map<AttributeRole, SingularAttributeSource> unresolvedSingularAttributeSourcesByKey
|
||||||
= new HashMap<AttributeSourceKey, SingularAttributeSource>();
|
= new HashMap<AttributeRole, SingularAttributeSource>();
|
||||||
|
|
||||||
private final Map<SingularAttributeSource.Nature, Map<AttributeSourceKey, SingularAttributeSource>> identifierAttributeSourcesByNature
|
private final Map<SingularAttributeNature, Map<AttributeRole, SingularAttributeSource>> identifierAttributeSourcesByNature
|
||||||
= new EnumMap<SingularAttributeSource.Nature, Map<AttributeSourceKey, SingularAttributeSource>>( SingularAttributeSource.Nature.class );
|
= new EnumMap<SingularAttributeNature, Map<AttributeRole, SingularAttributeSource>>( SingularAttributeNature.class );
|
||||||
private final Map<SingularAttributeSource.Nature, Map<AttributeSourceKey, SingularAttributeSource>> nonMappedBySingularAttributeSourcesByNature
|
private final Map<SingularAttributeNature, Map<AttributeRole, SingularAttributeSource>> nonMappedBySingularAttributeSourcesByNature
|
||||||
= new EnumMap<SingularAttributeSource.Nature, Map<AttributeSourceKey, SingularAttributeSource>>( SingularAttributeSource.Nature.class );
|
= new EnumMap<SingularAttributeNature, Map<AttributeRole, SingularAttributeSource>>( SingularAttributeNature.class );
|
||||||
private final Map<SingularAttributeSource.Nature, Map<AttributeSourceKey, SingularAttributeSource>> mappedBySingularAttributeSourcesByNature
|
private final Map<SingularAttributeNature, Map<AttributeRole, SingularAttributeSource>> mappedBySingularAttributeSourcesByNature
|
||||||
= new EnumMap<SingularAttributeSource.Nature, Map<AttributeSourceKey, SingularAttributeSource>>( SingularAttributeSource.Nature.class );
|
= new EnumMap<SingularAttributeNature, Map<AttributeRole, SingularAttributeSource>>( SingularAttributeNature.class );
|
||||||
|
|
||||||
// TODO: the following should not need to be LinkedHashMap, but it appears that some unit tests
|
// TODO: the following should not need to be LinkedHashMap, but it appears that some unit tests
|
||||||
// depend on the ordering
|
// depend on the ordering
|
||||||
// TODO: rework nonInversePluralAttributeSourcesByKey and inversePluralAttributeSourcesByKey
|
// TODO: rework nonInversePluralAttributeSourcesByKey and inversePluralAttributeSourcesByKey
|
||||||
private final Map<AttributeSourceKey, PluralAttributeSource> nonInversePluralAttributeSourcesByKey =
|
private final Map<AttributeRole, PluralAttributeSource> nonInversePluralAttributeSourcesByKey =
|
||||||
new LinkedHashMap<AttributeSourceKey, PluralAttributeSource>();
|
new LinkedHashMap<AttributeRole, PluralAttributeSource>();
|
||||||
private final Map<AttributeSourceKey, PluralAttributeSource> inversePluralAttributeSourcesByKey =
|
private final Map<AttributeRole, PluralAttributeSource> inversePluralAttributeSourcesByKey =
|
||||||
new LinkedHashMap<AttributeSourceKey, PluralAttributeSource>();
|
new LinkedHashMap<AttributeRole, PluralAttributeSource>();
|
||||||
|
|
||||||
protected AttributeSourceKey makeKey(String pathBase, AttributeSource attributeSource) {
|
|
||||||
return new AttributeSourceKey( getAttributeSourceKeyBase(), pathBase, attributeSource.getName() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void indexSingularAttributeSource(
|
public void indexSingularAttributeSource(SingularAttributeSource attributeSource, boolean isInIdentifier) {
|
||||||
String pathBase,
|
if ( attributeSource.getSingularAttributeNature() == null ) {
|
||||||
SingularAttributeSource attributeSource,
|
unresolvedSingularAttributeSourcesByKey.put( attributeSource.getAttributeRole(), attributeSource );
|
||||||
boolean isInIdentifier) {
|
|
||||||
final AttributeSourceKey attributeSourceKey = makeKey( pathBase, attributeSource );
|
|
||||||
if ( attributeSource.getNature() == null ) {
|
|
||||||
unresolvedSingularAttributeSourcesByKey.put( attributeSourceKey, attributeSource );
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Map<SingularAttributeSource.Nature, Map<AttributeSourceKey, SingularAttributeSource>> map;
|
final Map<SingularAttributeNature, Map<AttributeRole, SingularAttributeSource>> map;
|
||||||
if ( isInIdentifier ) {
|
if ( isInIdentifier ) {
|
||||||
map = identifierAttributeSourcesByNature;
|
map = identifierAttributeSourcesByNature;
|
||||||
}
|
}
|
||||||
|
@ -369,54 +258,65 @@ public class SourceIndex {
|
||||||
map = nonMappedBySingularAttributeSourcesByNature;
|
map = nonMappedBySingularAttributeSourcesByNature;
|
||||||
}
|
}
|
||||||
|
|
||||||
indexSingularAttributeSource( attributeSourceKey, attributeSource, map );
|
indexSingularAttributeSource( attributeSource, map );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void indexSingularAttributeSource(
|
private static void indexSingularAttributeSource(
|
||||||
AttributeSourceKey attributeSourceKey,
|
|
||||||
SingularAttributeSource attributeSource,
|
SingularAttributeSource attributeSource,
|
||||||
Map<SingularAttributeSource.Nature, Map<AttributeSourceKey, SingularAttributeSource>> map) {
|
Map<SingularAttributeNature, Map<AttributeRole, SingularAttributeSource>> map) {
|
||||||
final Map<AttributeSourceKey, SingularAttributeSource> singularAttributeSources;
|
final Map<AttributeRole, SingularAttributeSource> singularAttributeSources;
|
||||||
if ( map.containsKey( attributeSource.getNature() ) ) {
|
if ( map.containsKey( attributeSource.getSingularAttributeNature() ) ) {
|
||||||
singularAttributeSources = map.get( attributeSource.getNature() );
|
singularAttributeSources = map.get( attributeSource.getSingularAttributeNature() );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
singularAttributeSources = new LinkedHashMap<AttributeSourceKey,SingularAttributeSource>();
|
singularAttributeSources = new LinkedHashMap<AttributeRole,SingularAttributeSource>();
|
||||||
map.put( attributeSource.getNature(), singularAttributeSources );
|
map.put( attributeSource.getSingularAttributeNature(), singularAttributeSources );
|
||||||
}
|
}
|
||||||
if ( singularAttributeSources.put( attributeSourceKey, attributeSource ) != null ) {
|
if ( singularAttributeSources.put( attributeSource.getAttributeRole(), attributeSource ) != null ) {
|
||||||
throw new AssertionFailure(
|
throw new AssertionFailure(
|
||||||
String.format( "Attempt to reindex attribute source for: [%s]", attributeSourceKey )
|
String.format(
|
||||||
|
Locale.ENGLISH,
|
||||||
|
"Attempt to reindex attribute source for: [%s]",
|
||||||
|
attributeSource.getAttributeRole()
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void indexPluralAttributeSource(
|
public void indexPluralAttributeSource(PluralAttributeSource attributeSource) {
|
||||||
String pathBase,
|
final Map<AttributeRole,PluralAttributeSource> map = attributeSource.isInverse()
|
||||||
PluralAttributeSource attributeSource) {
|
|
||||||
final AttributeSourceKey key = makeKey( pathBase, attributeSource );
|
|
||||||
final Map<AttributeSourceKey,PluralAttributeSource> map = attributeSource.isInverse()
|
|
||||||
? inversePluralAttributeSourcesByKey
|
? inversePluralAttributeSourcesByKey
|
||||||
: nonInversePluralAttributeSourcesByKey;
|
: nonInversePluralAttributeSourcesByKey;
|
||||||
if ( map.put( key, attributeSource ) != null ) {
|
if ( map.put( attributeSource.getAttributeRole(), attributeSource ) != null ) {
|
||||||
throw new AssertionFailure(
|
throw new AssertionFailure(
|
||||||
String.format( "Attempt to reindex attribute source for: [%s]", key )
|
String.format(
|
||||||
|
Locale.ENGLISH,
|
||||||
|
"Attempt to reindex attribute source for: [%s]",
|
||||||
|
attributeSource.getAttributeRole() )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Map<AttributeSourceKey, SingularAttributeSource> getSingularAttributeSources(
|
public Map<AttributeRole, SingularAttributeSource> getSingularAttributeSources(
|
||||||
boolean isMappedBy,
|
boolean isMappedBy,
|
||||||
SingularAttributeSource.Nature nature) {
|
SingularAttributeNature singularAttributeNature) {
|
||||||
final Map<AttributeSourceKey, SingularAttributeSource> entries;
|
final Map<AttributeRole, SingularAttributeSource> entries;
|
||||||
if ( isMappedBy && mappedBySingularAttributeSourcesByNature.containsKey( nature ) ) {
|
if ( isMappedBy && mappedBySingularAttributeSourcesByNature.containsKey( singularAttributeNature ) ) {
|
||||||
entries = Collections.unmodifiableMap( mappedBySingularAttributeSourcesByNature.get( nature ) );
|
entries = Collections.unmodifiableMap(
|
||||||
|
mappedBySingularAttributeSourcesByNature.get(
|
||||||
|
singularAttributeNature
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
else if ( !isMappedBy && nonMappedBySingularAttributeSourcesByNature.containsKey( nature ) ) {
|
else if ( !isMappedBy && nonMappedBySingularAttributeSourcesByNature.containsKey( singularAttributeNature ) ) {
|
||||||
entries = Collections.unmodifiableMap( nonMappedBySingularAttributeSourcesByNature.get( nature ) );
|
entries = Collections.unmodifiableMap(
|
||||||
|
nonMappedBySingularAttributeSourcesByNature.get(
|
||||||
|
singularAttributeNature
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
entries = Collections.emptyMap();
|
entries = Collections.emptyMap();
|
||||||
|
@ -424,8 +324,8 @@ public class SourceIndex {
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<AttributeSourceKey, PluralAttributeSource> getPluralAttributeSources(boolean isInverse) {
|
public Map<AttributeRole, PluralAttributeSource> getPluralAttributeSources(boolean isInverse) {
|
||||||
final Map<AttributeSourceKey,PluralAttributeSource> map = isInverse
|
final Map<AttributeRole,PluralAttributeSource> map = isInverse
|
||||||
? inversePluralAttributeSourcesByKey
|
? inversePluralAttributeSourcesByKey
|
||||||
: nonInversePluralAttributeSourcesByKey;
|
: nonInversePluralAttributeSourcesByKey;
|
||||||
return Collections.unmodifiableMap( map );
|
return Collections.unmodifiableMap( map );
|
||||||
|
@ -442,41 +342,52 @@ public class SourceIndex {
|
||||||
// so it needs to be resolved.
|
// so it needs to be resolved.
|
||||||
pluralAttributeSource.resolvePluralAttributeElementSource( sourceResolutionContext );
|
pluralAttributeSource.resolvePluralAttributeElementSource( sourceResolutionContext );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( IndexedPluralAttributeSource.class.isInstance( pluralAttributeSource ) ) {
|
if ( IndexedPluralAttributeSource.class.isInstance( pluralAttributeSource ) ) {
|
||||||
IndexedPluralAttributeSource indexedPluralAttributeSource =
|
final IndexedPluralAttributeSource indexedPluralAttributeSource = (IndexedPluralAttributeSource) pluralAttributeSource;
|
||||||
(IndexedPluralAttributeSource) pluralAttributeSource;
|
if ( PluralAttributeIndexSourceResolver.class.isInstance( indexedPluralAttributeSource.getIndexSource() ) ) {
|
||||||
indexedPluralAttributeSource.resolvePluralAttributeIndexSource( sourceResolutionContext );
|
( (PluralAttributeIndexSourceResolver) indexedPluralAttributeSource.getIndexSource() ).resolvePluralAttributeIndexSource(
|
||||||
|
sourceResolutionContext
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( PluralAttributeSource pluralAttributeSource : nonInversePluralAttributeSourcesByKey.values() ) {
|
for ( PluralAttributeSource pluralAttributeSource : nonInversePluralAttributeSourcesByKey.values() ) {
|
||||||
if ( IndexedPluralAttributeSource.class.isInstance( pluralAttributeSource ) ) {
|
if ( IndexedPluralAttributeSource.class.isInstance( pluralAttributeSource ) ) {
|
||||||
IndexedPluralAttributeSource indexedPluralAttributeSource =
|
final IndexedPluralAttributeSource indexedPluralAttributeSource = (IndexedPluralAttributeSource) pluralAttributeSource;
|
||||||
(IndexedPluralAttributeSource) pluralAttributeSource;
|
if ( PluralAttributeIndexSourceResolver.class.isInstance( indexedPluralAttributeSource.getIndexSource() ) ) {
|
||||||
indexedPluralAttributeSource.resolvePluralAttributeIndexSource( sourceResolutionContext );
|
( (PluralAttributeIndexSourceResolver) indexedPluralAttributeSource.getIndexSource() ).resolvePluralAttributeIndexSource(
|
||||||
|
sourceResolutionContext
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// cycle through unresolved SingularAttributeSource.
|
// cycle through unresolved SingularAttributeSource.
|
||||||
// TODO: rework so approach is similar to one-to-many/many-to-many resolution.
|
// TODO: rework so approach is similar to one-to-many/many-to-many resolution.
|
||||||
for ( Iterator<Map.Entry<AttributeSourceKey,SingularAttributeSource>> it = unresolvedSingularAttributeSourcesByKey.entrySet().iterator(); it.hasNext(); ) {
|
for ( final SingularAttributeSource attributeSource : unresolvedSingularAttributeSourcesByKey.values() ) {
|
||||||
final Map.Entry<AttributeSourceKey,SingularAttributeSource> entry = it.next();
|
|
||||||
final AttributeSourceKey attributeSourceKey = entry.getKey();
|
|
||||||
final SingularAttributeSource attributeSource = entry.getValue();
|
|
||||||
if ( !ToOneAttributeSource.class.isInstance( attributeSource ) ) {
|
if ( !ToOneAttributeSource.class.isInstance( attributeSource ) ) {
|
||||||
throw new AssertionFailure(
|
throw new AssertionFailure(
|
||||||
String.format( "Only a ToOneAttributeSource is expected to have a null nature; attribute: %s ", attributeSourceKey )
|
String.format(
|
||||||
|
Locale.ENGLISH,
|
||||||
|
"Only a ToOneAttributeSource is expected to have a null nature; attribute: %s ",
|
||||||
|
attributeSource.getAttributeRole()
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
ToOneAttributeSource toOneAttributeSource = (ToOneAttributeSource) attributeSource;
|
ToOneAttributeSource toOneAttributeSource = (ToOneAttributeSource) attributeSource;
|
||||||
toOneAttributeSource.resolveToOneAttributeSource( sourceResolutionContext );
|
toOneAttributeSource.resolveToOneAttributeSource( sourceResolutionContext );
|
||||||
if ( toOneAttributeSource.getNature() == null ) {
|
if ( toOneAttributeSource.getSingularAttributeNature() == null ) {
|
||||||
throw new AssertionFailure(
|
throw new AssertionFailure(
|
||||||
String.format( "Null nature should have been resolved: %s ", attributeSourceKey )
|
String.format(
|
||||||
|
Locale.ENGLISH,
|
||||||
|
"Null nature should have been resolved: %s ",
|
||||||
|
attributeSource.getAttributeRole()
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
indexSingularAttributeSource(
|
indexSingularAttributeSource(
|
||||||
attributeSourceKey,
|
|
||||||
attributeSource,
|
attributeSource,
|
||||||
toOneAttributeSource.isMappedBy()
|
toOneAttributeSource.isMappedBy()
|
||||||
? mappedBySingularAttributeSourcesByNature
|
? mappedBySingularAttributeSourcesByNature
|
||||||
|
@ -498,22 +409,17 @@ public class SourceIndex {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAttributeSourceKeyBase() {
|
public void indexPluralAttributeSource(PluralAttributeSource attributeSource) {
|
||||||
return hierarchyKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void indexPluralAttributeSource(String pathBase, PluralAttributeSource attributeSource) {
|
|
||||||
throw new AssertionFailure(
|
throw new AssertionFailure(
|
||||||
String.format(
|
String.format(
|
||||||
"Identifiers should not contain plural attributes: [%s]",
|
"Identifiers should not contain plural attributes: [%s]",
|
||||||
makeKey( pathBase, attributeSource )
|
attributeSource.getAttributeRole().getFullPath()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<AttributeSourceKey, PluralAttributeSource> getPluralAttributeSources(boolean isInverse) {
|
public Map<AttributeRole, PluralAttributeSource> getPluralAttributeSources(boolean isInverse) {
|
||||||
return Collections.emptyMap();
|
return Collections.emptyMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -553,17 +459,15 @@ public class SourceIndex {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAttributeSourceKeyBase() {
|
public Map<AttributeRole, SingularAttributeSource> getSingularAttributeSources(
|
||||||
return entitySource.getEntityName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<AttributeSourceKey, SingularAttributeSource> getSingularAttributeSources(
|
|
||||||
boolean isMappedBy,
|
boolean isMappedBy,
|
||||||
SingularAttributeSource.Nature nature) {
|
SingularAttributeNature singularAttributeNature) {
|
||||||
Map<AttributeSourceKey, SingularAttributeSource> values = hierarchyInfo.getSingularAttributeSources( isMappedBy, nature );
|
Map<AttributeRole, SingularAttributeSource> values = hierarchyInfo.getSingularAttributeSources(
|
||||||
|
isMappedBy,
|
||||||
|
singularAttributeNature
|
||||||
|
);
|
||||||
if ( values == null || values.isEmpty() ) {
|
if ( values == null || values.isEmpty() ) {
|
||||||
values = super.getSingularAttributeSources( isMappedBy, nature );
|
values = super.getSingularAttributeSources( isMappedBy, singularAttributeNature );
|
||||||
}
|
}
|
||||||
|
|
||||||
return values;
|
return values;
|
||||||
|
@ -591,9 +495,4 @@ public class SourceIndex {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class DependencyTreeNode {
|
|
||||||
private String dependedOnHierarchyKey;
|
|
||||||
private List<String> dependantHierarchyKeys;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ package org.hibernate.metamodel.internal.resolver;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.metamodel.source.spi.ManyToManyPluralAttributeElementSource;
|
import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceManyToMany;
|
||||||
import org.hibernate.metamodel.source.spi.PluralAttributeSource;
|
import org.hibernate.metamodel.source.spi.PluralAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.ToOneAttributeSource;
|
import org.hibernate.metamodel.source.spi.ToOneAttributeSource;
|
||||||
import org.hibernate.metamodel.spi.binding.AttributeBindingContainer;
|
import org.hibernate.metamodel.spi.binding.AttributeBindingContainer;
|
||||||
|
@ -77,13 +77,13 @@ public interface AssociationRelationalBindingResolver {
|
||||||
|
|
||||||
List<RelationalValueBinding> resolveManyToManyElementRelationalValueBindings(
|
List<RelationalValueBinding> resolveManyToManyElementRelationalValueBindings(
|
||||||
final EntityBinding entityBinding,
|
final EntityBinding entityBinding,
|
||||||
final ManyToManyPluralAttributeElementSource elementSource,
|
final PluralAttributeElementSourceManyToMany elementSource,
|
||||||
final TableSpecification collectionTable,
|
final TableSpecification collectionTable,
|
||||||
final EntityBinding referencedEntityBinding);
|
final EntityBinding referencedEntityBinding);
|
||||||
|
|
||||||
ForeignKey resolveManyToManyElementForeignKey(
|
ForeignKey resolveManyToManyElementForeignKey(
|
||||||
final EntityBinding entityBinding,
|
final EntityBinding entityBinding,
|
||||||
final ManyToManyPluralAttributeElementSource elementSource,
|
final PluralAttributeElementSourceManyToMany elementSource,
|
||||||
final TableSpecification collectionTable,
|
final TableSpecification collectionTable,
|
||||||
final List<RelationalValueBinding> relationalValueBindings,
|
final List<RelationalValueBinding> relationalValueBindings,
|
||||||
final EntityBinding referencedEntityBinding);
|
final EntityBinding referencedEntityBinding);
|
||||||
|
|
|
@ -32,17 +32,17 @@ import org.hibernate.metamodel.internal.binder.BinderRootContext;
|
||||||
import org.hibernate.metamodel.internal.binder.ForeignKeyHelper;
|
import org.hibernate.metamodel.internal.binder.ForeignKeyHelper;
|
||||||
import org.hibernate.metamodel.internal.binder.RelationalValueBindingHelper;
|
import org.hibernate.metamodel.internal.binder.RelationalValueBindingHelper;
|
||||||
import org.hibernate.metamodel.source.spi.AssociationSource;
|
import org.hibernate.metamodel.source.spi.AssociationSource;
|
||||||
import org.hibernate.metamodel.source.spi.ManyToManyPluralAttributeElementSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.MappedByAssociationSource;
|
import org.hibernate.metamodel.source.spi.MappedByAssociationSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceManyToMany;
|
||||||
import org.hibernate.metamodel.source.spi.PluralAttributeSource;
|
import org.hibernate.metamodel.source.spi.PluralAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.ToOneAttributeSource;
|
import org.hibernate.metamodel.source.spi.ToOneAttributeSource;
|
||||||
import org.hibernate.metamodel.spi.LocalBindingContext;
|
import org.hibernate.metamodel.spi.LocalBindingContext;
|
||||||
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.AttributeBindingContainer;
|
import org.hibernate.metamodel.spi.binding.AttributeBindingContainer;
|
||||||
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.ManyToManyPluralAttributeElementBinding;
|
|
||||||
import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding;
|
import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
|
import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
|
||||||
|
import org.hibernate.metamodel.spi.binding.PluralAttributeElementBindingManyToMany;
|
||||||
import org.hibernate.metamodel.spi.binding.RelationalValueBinding;
|
import org.hibernate.metamodel.spi.binding.RelationalValueBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.SecondaryTable;
|
import org.hibernate.metamodel.spi.binding.SecondaryTable;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAssociationAttributeBinding;
|
import org.hibernate.metamodel.spi.binding.SingularAssociationAttributeBinding;
|
||||||
|
@ -166,7 +166,7 @@ public class MappedByAssociationRelationalBindingResolverImpl implements Associa
|
||||||
@Override
|
@Override
|
||||||
public List<RelationalValueBinding> resolveManyToManyElementRelationalValueBindings(
|
public List<RelationalValueBinding> resolveManyToManyElementRelationalValueBindings(
|
||||||
final EntityBinding entityBinding,
|
final EntityBinding entityBinding,
|
||||||
final ManyToManyPluralAttributeElementSource elementSource,
|
final PluralAttributeElementSourceManyToMany elementSource,
|
||||||
final TableSpecification collectionTable,
|
final TableSpecification collectionTable,
|
||||||
final EntityBinding referencedEntityBinding) {
|
final EntityBinding referencedEntityBinding) {
|
||||||
{
|
{
|
||||||
|
@ -198,7 +198,7 @@ public class MappedByAssociationRelationalBindingResolverImpl implements Associa
|
||||||
@Override
|
@Override
|
||||||
public ForeignKey resolveManyToManyElementForeignKey(
|
public ForeignKey resolveManyToManyElementForeignKey(
|
||||||
final EntityBinding entityBinding,
|
final EntityBinding entityBinding,
|
||||||
final ManyToManyPluralAttributeElementSource elementSource,
|
final PluralAttributeElementSourceManyToMany elementSource,
|
||||||
final TableSpecification collectionTable,
|
final TableSpecification collectionTable,
|
||||||
final List<RelationalValueBinding> relationalValueBindings,
|
final List<RelationalValueBinding> relationalValueBindings,
|
||||||
final EntityBinding referencedEntityBinding) {
|
final EntityBinding referencedEntityBinding) {
|
||||||
|
@ -246,9 +246,9 @@ public class MappedByAssociationRelationalBindingResolverImpl implements Associa
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final PluralAttributeBinding pluralOwnerAttributeBinding = (PluralAttributeBinding) ownerAttributeBinding;
|
final PluralAttributeBinding pluralOwnerAttributeBinding = (PluralAttributeBinding) ownerAttributeBinding;
|
||||||
final ManyToManyPluralAttributeElementBinding ownerElementBinding =
|
final PluralAttributeElementBindingManyToMany ownerElementBinding =
|
||||||
(ManyToManyPluralAttributeElementBinding) pluralOwnerAttributeBinding.getPluralAttributeElementBinding();
|
(PluralAttributeElementBindingManyToMany) pluralOwnerAttributeBinding.getPluralAttributeElementBinding();
|
||||||
return ownerElementBinding.getRelationalValueBindings();
|
return ownerElementBinding.getRelationalValueContainer().relationalValueBindings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,8 +268,8 @@ public class MappedByAssociationRelationalBindingResolverImpl implements Associa
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final PluralAttributeBinding pluralOwnerAttributeBinding = (PluralAttributeBinding) ownerAttributeBinding;
|
final PluralAttributeBinding pluralOwnerAttributeBinding = (PluralAttributeBinding) ownerAttributeBinding;
|
||||||
final ManyToManyPluralAttributeElementBinding ownerElementBinding =
|
final PluralAttributeElementBindingManyToMany ownerElementBinding =
|
||||||
(ManyToManyPluralAttributeElementBinding) pluralOwnerAttributeBinding.getPluralAttributeElementBinding();
|
(PluralAttributeElementBindingManyToMany) pluralOwnerAttributeBinding.getPluralAttributeElementBinding();
|
||||||
foreignKey = ownerElementBinding.getForeignKey();
|
foreignKey = ownerElementBinding.getForeignKey();
|
||||||
}
|
}
|
||||||
if ( attributeSource.getKeySource().isCascadeDeleteEnabled() ) {
|
if ( attributeSource.getKeySource().isCascadeDeleteEnabled() ) {
|
||||||
|
@ -293,8 +293,8 @@ public class MappedByAssociationRelationalBindingResolverImpl implements Associa
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final PluralAttributeBinding ownerPluralAttributeBinding = (PluralAttributeBinding) ownerAttributeBinding;
|
final PluralAttributeBinding ownerPluralAttributeBinding = (PluralAttributeBinding) ownerAttributeBinding;
|
||||||
final ManyToManyPluralAttributeElementBinding ownerElementBinding =
|
final PluralAttributeElementBindingManyToMany ownerElementBinding =
|
||||||
(ManyToManyPluralAttributeElementBinding) ownerPluralAttributeBinding
|
(PluralAttributeElementBindingManyToMany) ownerPluralAttributeBinding
|
||||||
.getPluralAttributeElementBinding();
|
.getPluralAttributeElementBinding();
|
||||||
referencedAttributeBinding = attributeBindingContainer.seekEntityBinding().locateAttributeBinding(
|
referencedAttributeBinding = attributeBindingContainer.seekEntityBinding().locateAttributeBinding(
|
||||||
ownerElementBinding.getForeignKey().getTargetTable(),
|
ownerElementBinding.getForeignKey().getTargetTable(),
|
||||||
|
|
|
@ -38,14 +38,14 @@ import org.hibernate.metamodel.internal.binder.RelationalValueBindingHelper;
|
||||||
import org.hibernate.metamodel.internal.binder.TableHelper;
|
import org.hibernate.metamodel.internal.binder.TableHelper;
|
||||||
import org.hibernate.metamodel.source.spi.AssociationSource;
|
import org.hibernate.metamodel.source.spi.AssociationSource;
|
||||||
import org.hibernate.metamodel.source.spi.ForeignKeyContributingSource;
|
import org.hibernate.metamodel.source.spi.ForeignKeyContributingSource;
|
||||||
import org.hibernate.metamodel.source.spi.ManyToManyPluralAttributeElementSource;
|
import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceManyToMany;
|
||||||
import org.hibernate.metamodel.source.spi.PluralAttributeElementSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.PluralAttributeKeySource;
|
import org.hibernate.metamodel.source.spi.PluralAttributeKeySource;
|
||||||
import org.hibernate.metamodel.source.spi.PluralAttributeSource;
|
import org.hibernate.metamodel.source.spi.PluralAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.RelationalValueSourceContainer;
|
import org.hibernate.metamodel.source.spi.RelationalValueSourceContainer;
|
||||||
import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.TableSpecificationSource;
|
import org.hibernate.metamodel.source.spi.TableSpecificationSource;
|
||||||
import org.hibernate.metamodel.source.spi.ToOneAttributeSource;
|
import org.hibernate.metamodel.source.spi.ToOneAttributeSource;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeElementNature;
|
||||||
import org.hibernate.metamodel.spi.binding.AttributeBindingContainer;
|
import org.hibernate.metamodel.spi.binding.AttributeBindingContainer;
|
||||||
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.RelationalValueBinding;
|
import org.hibernate.metamodel.spi.binding.RelationalValueBinding;
|
||||||
|
@ -194,7 +194,7 @@ public class StandardAssociationRelationalBindingResolverImpl implements Associa
|
||||||
@Override
|
@Override
|
||||||
public List<RelationalValueBinding> resolveManyToManyElementRelationalValueBindings(
|
public List<RelationalValueBinding> resolveManyToManyElementRelationalValueBindings(
|
||||||
final EntityBinding entityBinding,
|
final EntityBinding entityBinding,
|
||||||
final ManyToManyPluralAttributeElementSource elementSource,
|
final PluralAttributeElementSourceManyToMany elementSource,
|
||||||
final TableSpecification collectionTable,
|
final TableSpecification collectionTable,
|
||||||
final EntityBinding referencedEntityBinding) {
|
final EntityBinding referencedEntityBinding) {
|
||||||
final List<Column> targetColumns =
|
final List<Column> targetColumns =
|
||||||
|
@ -230,7 +230,7 @@ public class StandardAssociationRelationalBindingResolverImpl implements Associa
|
||||||
@Override
|
@Override
|
||||||
public ForeignKey resolveManyToManyElementForeignKey(
|
public ForeignKey resolveManyToManyElementForeignKey(
|
||||||
final EntityBinding entityBinding,
|
final EntityBinding entityBinding,
|
||||||
final ManyToManyPluralAttributeElementSource elementSource,
|
final PluralAttributeElementSourceManyToMany elementSource,
|
||||||
final TableSpecification collectionTable,
|
final TableSpecification collectionTable,
|
||||||
final List<RelationalValueBinding> relationalValueBindings,
|
final List<RelationalValueBinding> relationalValueBindings,
|
||||||
final EntityBinding referencedEntityBinding) {
|
final EntityBinding referencedEntityBinding) {
|
||||||
|
@ -318,7 +318,7 @@ public class StandardAssociationRelationalBindingResolverImpl implements Associa
|
||||||
keySource,
|
keySource,
|
||||||
entityBinding,
|
entityBinding,
|
||||||
collectionTable,
|
collectionTable,
|
||||||
attributeSource.getElementSource().getNature() != PluralAttributeElementSource.Nature.ONE_TO_MANY,
|
attributeSource.getElementSource().getNature() != PluralAttributeElementNature.ONE_TO_MANY,
|
||||||
namingStrategies
|
namingStrategies
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,18 @@ public class Primitives {
|
||||||
this.primitiveType
|
this.primitiveType
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PrimitiveTypeDescriptor getPrimitiveType() {
|
||||||
|
return primitiveType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrimitiveWrapperTypeDescriptor getPrimitiveWrapperType() {
|
||||||
|
return primitiveWrapperType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayDescriptor getPrimitiveArrayType() {
|
||||||
|
return primitiveArrayType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final PrimitiveGroup CHAR = new PrimitiveGroup( char.class, char[].class, Character.class );
|
public static final PrimitiveGroup CHAR = new PrimitiveGroup( char.class, char[].class, Character.class );
|
||||||
|
|
|
@ -1,78 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.metamodel.source.internal;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.AbstractPersistentAttribute;
|
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Common contract for source of all persistent attributes.
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
|
||||||
* @author Hardy Ferentschik
|
|
||||||
*/
|
|
||||||
public abstract class AbstractAttributeSource implements AttributeSource {
|
|
||||||
private final AbstractManagedTypeSource container;
|
|
||||||
private final AbstractPersistentAttribute attribute;
|
|
||||||
|
|
||||||
protected AbstractAttributeSource(
|
|
||||||
AbstractManagedTypeSource container,
|
|
||||||
AbstractPersistentAttribute attribute) {
|
|
||||||
this.container = container;
|
|
||||||
this.attribute = attribute;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AbstractManagedTypeSource getContainer() {
|
|
||||||
return container;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AbstractPersistentAttribute getPersistentAttribute() {
|
|
||||||
return attribute;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return attribute.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPropertyAccessorName() {
|
|
||||||
return attribute.getAccessorStrategy();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isIncludedInOptimisticLocking() {
|
|
||||||
return getPersistentAttribute().isIncludeInOptimisticLocking();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<? extends ToolingHintSource> getToolingHintSources() {
|
|
||||||
// todo : when hooking in unified (Hibernate-specific) xml elements need to account for this
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,56 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.metamodel.source.internal;
|
|
||||||
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.AssociationOverride;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.AttributeOverride;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.entity.ManagedTypeMetadata;
|
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSourceContainer;
|
|
||||||
import org.hibernate.metamodel.spi.LocalBindingContext;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base class for sources of "managed type" (entity, mapped-superclass,
|
|
||||||
* embeddable) information.
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
|
||||||
* @author Hardy Ferentschik
|
|
||||||
*/
|
|
||||||
public abstract class AbstractManagedTypeSource implements AttributeSourceContainer {
|
|
||||||
private final ManagedTypeMetadata metadata;
|
|
||||||
|
|
||||||
protected AbstractManagedTypeSource(ManagedTypeMetadata metadata) {
|
|
||||||
this.metadata = metadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LocalBindingContext getLocalBindingContext() {
|
|
||||||
return metadata.getLocalBindingContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract AttributeOverride locateAttributeOverride(String path);
|
|
||||||
|
|
||||||
abstract AssociationOverride locateAssociationOverride(String path);
|
|
||||||
|
|
||||||
abstract AttributeConversionInfo locateConversionInfo(String path);
|
|
||||||
}
|
|
|
@ -1,178 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.metamodel.source.internal;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.hibernate.engine.FetchStyle;
|
|
||||||
import org.hibernate.engine.FetchTiming;
|
|
||||||
import org.hibernate.engine.spi.CascadeStyle;
|
|
||||||
import org.hibernate.engine.spi.CascadeStyles;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.SingularAssociationAttribute;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.EnumConversionHelper;
|
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.MappedByAssociationSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.ToOneAttributeSource;
|
|
||||||
import org.hibernate.type.ForeignKeyDirection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Common support for singular association (*-to-one) persistent attributes.
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
|
||||||
* @author Gail Badner
|
|
||||||
*/
|
|
||||||
public abstract class AbstractSingularAssociationAttributeSource
|
|
||||||
extends AbstractSingularAttributeSource
|
|
||||||
implements ToOneAttributeSource {
|
|
||||||
|
|
||||||
private final Set<CascadeStyle> cascadeStyles;
|
|
||||||
private final Set<MappedByAssociationSource> ownedAssociationSources = new HashSet<MappedByAssociationSource>();
|
|
||||||
|
|
||||||
private Nature nature;
|
|
||||||
|
|
||||||
public AbstractSingularAssociationAttributeSource(
|
|
||||||
AbstractManagedTypeSource container,
|
|
||||||
SingularAssociationAttribute attribute) {
|
|
||||||
super( container, attribute );
|
|
||||||
this.cascadeStyles = determineCascadeStyles( attribute );
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Set<CascadeStyle> determineCascadeStyles(SingularAssociationAttribute associationAttribute) {
|
|
||||||
final Set<CascadeStyle> cascadeStyles = EnumConversionHelper.cascadeTypeToCascadeStyleSet(
|
|
||||||
associationAttribute.getJpaCascadeTypes(),
|
|
||||||
associationAttribute.getHibernateCascadeTypes(),
|
|
||||||
associationAttribute.getContext()
|
|
||||||
);
|
|
||||||
if ( associationAttribute.isOrphanRemoval() ) {
|
|
||||||
cascadeStyles.add( CascadeStyles.DELETE_ORPHAN );
|
|
||||||
}
|
|
||||||
return cascadeStyles;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void validateConversionInfo(AttributeConversionInfo conversionInfo) {
|
|
||||||
throw getContainer().getLocalBindingContext().makeMappingException(
|
|
||||||
"Illegal attempt to apply AttributeConverter to non-basic attribute : "
|
|
||||||
+ getPersistentAttribute().getBackingMember().toString()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setNature(Nature nature) {
|
|
||||||
assert this.nature == null;
|
|
||||||
this.nature = nature;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SingularAssociationAttribute getPersistentAttribute() {
|
|
||||||
return (SingularAssociationAttribute) super.getPersistentAttribute();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SingularAttributeSource.Nature getNature() {
|
|
||||||
return nature;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AttributeSource getAttributeSource() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getReferencedEntityName() {
|
|
||||||
return getPersistentAttribute().getTargetTypeName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isUnique() {
|
|
||||||
return nature == Nature.ONE_TO_ONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isIgnoreNotFound() {
|
|
||||||
return getPersistentAttribute().isIgnoreNotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<MappedByAssociationSource> getOwnedAssociationSources() {
|
|
||||||
return ownedAssociationSources;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addMappedByAssociationSource(MappedByAssociationSource attributeSource) {
|
|
||||||
if ( attributeSource == null ) {
|
|
||||||
throw new IllegalArgumentException( "attributeSource must be non-null." );
|
|
||||||
}
|
|
||||||
ownedAssociationSources.add( attributeSource );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isMappedBy() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<CascadeStyle> getCascadeStyles() {
|
|
||||||
return cascadeStyles;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FetchTiming getFetchTiming() {
|
|
||||||
return getPersistentAttribute().isLazy()
|
|
||||||
? FetchTiming.DELAYED
|
|
||||||
: FetchTiming.IMMEDIATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FetchStyle getFetchStyle() {
|
|
||||||
if ( getPersistentAttribute().getFetchStyle() != null ) {
|
|
||||||
return getPersistentAttribute().getFetchStyle();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return getPersistentAttribute().isLazy()
|
|
||||||
? FetchStyle.SELECT
|
|
||||||
: FetchStyle.JOIN;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isUnWrapProxy() {
|
|
||||||
return getPersistentAttribute().isUnWrapProxy();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ToOneAttributeSourceImpl{attribute=" + getPersistentAttribute()
|
|
||||||
+ ", cascadeStyles=" + cascadeStyles + '}';
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ForeignKeyDirection getForeignKeyDirection() {
|
|
||||||
return nature == Nature.ONE_TO_ONE && !getPersistentAttribute().isOptional()
|
|
||||||
? ForeignKeyDirection.FROM_PARENT
|
|
||||||
: ForeignKeyDirection.TO_PARENT;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,97 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.metamodel.source.internal;
|
|
||||||
|
|
||||||
import org.hibernate.mapping.PropertyGeneration;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.AbstractPersistentAttribute;
|
|
||||||
import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
|
||||||
|
|
||||||
import static org.hibernate.metamodel.spi.binding.SingularAttributeBinding.NaturalIdMutability;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Common support for singular, non-composite persistent attributes.
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
|
||||||
* @author Hardy Ferentschik
|
|
||||||
*/
|
|
||||||
public abstract class AbstractSingularAttributeSource
|
|
||||||
extends AbstractAttributeSource
|
|
||||||
implements SingularAttributeSource {
|
|
||||||
private final AttributeConversionInfo conversionInfo;
|
|
||||||
|
|
||||||
protected AbstractSingularAttributeSource(
|
|
||||||
AbstractManagedTypeSource container,
|
|
||||||
AbstractPersistentAttribute attribute) {
|
|
||||||
super( container, attribute );
|
|
||||||
|
|
||||||
this.conversionInfo = container.locateConversionInfo( attribute.getName() );
|
|
||||||
validateConversionInfo( conversionInfo );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void validateConversionInfo(AttributeConversionInfo conversionInfo);
|
|
||||||
|
|
||||||
public AttributeConversionInfo getConversionInfo() {
|
|
||||||
return conversionInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSingular() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isVirtualAttribute() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PropertyGeneration getGeneration() {
|
|
||||||
return getPersistentAttribute().getPropertyGeneration();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isLazy() {
|
|
||||||
return getPersistentAttribute().isLazy();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NaturalIdMutability getNaturalIdMutability() {
|
|
||||||
return getPersistentAttribute().getNaturalIdMutability();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areValuesIncludedInInsertByDefault() {
|
|
||||||
return getPersistentAttribute().isInsertable();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areValuesIncludedInUpdateByDefault() {
|
|
||||||
return !getPersistentAttribute().isId() && getPersistentAttribute().isUpdatable();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areValuesNullableByDefault() {
|
|
||||||
return !getPersistentAttribute().isId() && getPersistentAttribute().isOptional();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,140 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.metamodel.source.internal;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.ColumnSourceImpl;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.DerivedValueSourceImpl;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.AttributeOverride;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.BasicAttribute;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.Column;
|
|
||||||
import org.hibernate.metamodel.source.spi.HibernateTypeSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents source of a basic singular attribute information for binding
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
|
||||||
*/
|
|
||||||
public class BasicAttributeSourceImpl extends AbstractSingularAttributeSource {
|
|
||||||
private final List<RelationalValueSource> relationalValueSources;
|
|
||||||
|
|
||||||
protected BasicAttributeSourceImpl(AbstractManagedTypeSource container, BasicAttribute attribute) {
|
|
||||||
super( container, attribute );
|
|
||||||
|
|
||||||
if ( container.locateAttributeOverride( attribute.getName() ) != null ) {
|
|
||||||
throw container.getLocalBindingContext().makeMappingException(
|
|
||||||
"Association-override not valid on basic attributes : "
|
|
||||||
+ attribute.getBackingMember().toString()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
this.relationalValueSources = new ArrayList<RelationalValueSource>();
|
|
||||||
if ( attribute.getFormulaValue() != null ) {
|
|
||||||
relationalValueSources.add( new DerivedValueSourceImpl( attribute.getFormulaValue() ) );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
final AttributeOverride attributeOverride = container.locateAttributeOverride( attribute.getName() );
|
|
||||||
final int explicitColumnCount = attribute.getColumnValues().size();
|
|
||||||
|
|
||||||
if ( explicitColumnCount == 0 ) {
|
|
||||||
Column overrideColumn = attributeOverride.getImpliedColumn();
|
|
||||||
if ( overrideColumn != null
|
|
||||||
|| attribute.getCustomReadFragment() != null
|
|
||||||
|| attribute.getCustomWriteFragment() != null
|
|
||||||
|| attribute.getCheckCondition() != null ) {
|
|
||||||
relationalValueSources.add(
|
|
||||||
new ColumnSourceImpl(
|
|
||||||
overrideColumn,
|
|
||||||
null,
|
|
||||||
attribute.getCustomReadFragment(),
|
|
||||||
attribute.getCustomWriteFragment(),
|
|
||||||
attribute.getCheckCondition()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ( explicitColumnCount == 1 ) {
|
|
||||||
Column column = attribute.getColumnValues().get( 0 );
|
|
||||||
if ( attributeOverride != null ) {
|
|
||||||
column.applyColumnValues( attributeOverride.getOverriddenColumnInfo() );
|
|
||||||
}
|
|
||||||
relationalValueSources.add(
|
|
||||||
new ColumnSourceImpl(
|
|
||||||
column,
|
|
||||||
null,
|
|
||||||
attribute.getCustomReadFragment(),
|
|
||||||
attribute.getCustomWriteFragment(),
|
|
||||||
attribute.getCheckCondition()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if ( attributeOverride != null ) {
|
|
||||||
throw container.getLocalBindingContext().makeMappingException(
|
|
||||||
"Cannot apply AttributeOverride to attribute mapped to more than one column : "
|
|
||||||
+ attribute.getBackingMember().toString()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( Column column : attribute.getColumnValues() ) {
|
|
||||||
relationalValueSources.add( new ColumnSourceImpl( column, null ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BasicAttribute getPersistentAttribute() {
|
|
||||||
return (BasicAttribute) super.getPersistentAttribute();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void validateConversionInfo(AttributeConversionInfo conversionInfo) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Nature getNature() {
|
|
||||||
return Nature.BASIC;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getContainingTableName() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HibernateTypeSource getTypeInformation() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<RelationalValueSource> relationalValueSources() {
|
|
||||||
return relationalValueSources;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -27,17 +27,18 @@ import org.hibernate.engine.FetchTiming;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.AbstractPersistentAttribute;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.AbstractPersistentAttribute;
|
||||||
import org.hibernate.metamodel.source.spi.FilterSource;
|
import org.hibernate.metamodel.source.spi.FilterSource;
|
||||||
import org.hibernate.metamodel.source.spi.ManyToManyPluralAttributeElementSource;
|
import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceManyToMany;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeElementNature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractManyToManyPluralAttributeElementSourceImpl
|
public abstract class AbstractPluralAttributeElementSourceAssociationManyToManyImpl
|
||||||
extends AbstractPluralAssociationElementSourceImpl
|
extends AbstractPluralElementSourceAssociationImpl
|
||||||
implements ManyToManyPluralAttributeElementSource {
|
implements PluralAttributeElementSourceManyToMany {
|
||||||
|
|
||||||
|
|
||||||
public AbstractManyToManyPluralAttributeElementSourceImpl(PluralAttributeSourceImpl pluralAttributeSource) {
|
public AbstractPluralAttributeElementSourceAssociationManyToManyImpl(PluralAttributeSourceImpl pluralAttributeSource) {
|
||||||
super( pluralAttributeSource );
|
super( pluralAttributeSource );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,8 +69,8 @@ public abstract class AbstractManyToManyPluralAttributeElementSourceImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Nature getNature() {
|
public PluralAttributeElementNature getNature() {
|
||||||
return Nature.MANY_TO_MANY;
|
return PluralAttributeElementNature.MANY_TO_MANY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
|
@ -59,11 +59,6 @@ public abstract class AbstractPluralAttributeIndexSourceImpl implements PluralAt
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isReferencedEntityAttribute() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean areValuesIncludedInInsertByDefault() {
|
public boolean areValuesIncludedInInsertByDefault() {
|
||||||
return false;
|
return false;
|
||||||
|
@ -79,7 +74,7 @@ public abstract class AbstractPluralAttributeIndexSourceImpl implements PluralAt
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PluralAttribute pluralAssociationAttribute() {
|
protected PluralAttribute pluralAttribute() {
|
||||||
return attribute;
|
return attribute;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,20 +28,20 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.hibernate.engine.spi.CascadeStyle;
|
import org.hibernate.engine.spi.CascadeStyle;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute;
|
||||||
import org.hibernate.metamodel.source.spi.AssociationPluralAttributeElementSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSource;
|
import org.hibernate.metamodel.source.spi.AttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.MappedByAssociationSource;
|
import org.hibernate.metamodel.source.spi.MappedByAssociationSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceAssociation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractPluralAssociationElementSourceImpl
|
public abstract class AbstractPluralElementSourceAssociationImpl
|
||||||
extends AbstractPluralAttributeElementSourceImpl
|
extends AbstractPluralAttributeElementSourceImpl
|
||||||
implements AssociationPluralAttributeElementSource {
|
implements PluralAttributeElementSourceAssociation {
|
||||||
|
|
||||||
private final Set<MappedByAssociationSource> ownedAssociationSources = new HashSet<MappedByAssociationSource>( );
|
private final Set<MappedByAssociationSource> ownedAssociationSources = new HashSet<MappedByAssociationSource>( );
|
||||||
|
|
||||||
public AbstractPluralAssociationElementSourceImpl(PluralAttributeSourceImpl pluralAttributeSource) {
|
public AbstractPluralElementSourceAssociationImpl(PluralAttributeSourceImpl pluralAttributeSource) {
|
||||||
super( pluralAttributeSource );
|
super( pluralAttributeSource );
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,15 +12,17 @@ import org.hibernate.metamodel.source.internal.annotations.attribute.SingularAss
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.EnumConversionHelper;
|
import org.hibernate.metamodel.source.internal.annotations.util.EnumConversionHelper;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSource;
|
import org.hibernate.metamodel.source.spi.AttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.MappedByAssociationSource;
|
import org.hibernate.metamodel.source.spi.MappedByAssociationSource;
|
||||||
import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.ToOneAttributeSource;
|
import org.hibernate.metamodel.source.spi.ToOneAttributeSource;
|
||||||
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
|
import org.hibernate.metamodel.spi.SingularAttributeNature;
|
||||||
import org.hibernate.type.ForeignKeyDirection;
|
import org.hibernate.type.ForeignKeyDirection;
|
||||||
|
|
||||||
public abstract class AbstractToOneAttributeSourceImpl extends SingularAttributeSourceImpl implements ToOneAttributeSource{
|
public abstract class AbstractToOneAttributeSourceImpl extends SingularAttributeSourceImpl implements ToOneAttributeSource{
|
||||||
private final SingularAssociationAttribute associationAttribute;
|
private final SingularAssociationAttribute associationAttribute;
|
||||||
private final Set<CascadeStyle> unifiedCascadeStyles;
|
private final Set<CascadeStyle> unifiedCascadeStyles;
|
||||||
|
|
||||||
private SingularAttributeSource.Nature nature;
|
private SingularAttributeNature singularAttributeNature;
|
||||||
private final Set<MappedByAssociationSource> ownedAssociationSources = new HashSet<MappedByAssociationSource>();
|
private final Set<MappedByAssociationSource> ownedAssociationSources = new HashSet<MappedByAssociationSource>();
|
||||||
|
|
||||||
public AbstractToOneAttributeSourceImpl(SingularAssociationAttribute associationAttribute) {
|
public AbstractToOneAttributeSourceImpl(SingularAssociationAttribute associationAttribute) {
|
||||||
|
@ -42,19 +44,19 @@ public abstract class AbstractToOneAttributeSourceImpl extends SingularAttribute
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SingularAttributeSource.Nature getNature() {
|
public SingularAttributeNature getSingularAttributeNature() {
|
||||||
return nature;
|
return singularAttributeNature;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SingularAssociationAttribute associationAttribute() {
|
protected SingularAssociationAttribute associationAttribute() {
|
||||||
return associationAttribute;
|
return associationAttribute;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setNature(SingularAttributeSource.Nature nature) {
|
protected void setSingularAttributeNature(SingularAttributeNature singularAttributeNature) {
|
||||||
if ( this.nature != null ) {
|
if ( this.singularAttributeNature != null ) {
|
||||||
throw new IllegalStateException( "nature is already initialized." );
|
throw new IllegalStateException( "nature is already initialized." );
|
||||||
}
|
}
|
||||||
this.nature = nature;
|
this.singularAttributeNature = singularAttributeNature;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -122,7 +124,7 @@ public abstract class AbstractToOneAttributeSourceImpl extends SingularAttribute
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ForeignKeyDirection getForeignKeyDirection() {
|
public ForeignKeyDirection getForeignKeyDirection() {
|
||||||
return nature == Nature.ONE_TO_ONE && !associationAttribute.isOptional()
|
return singularAttributeNature == SingularAttributeNature.ONE_TO_ONE && !associationAttribute.isOptional()
|
||||||
? ForeignKeyDirection.FROM_PARENT
|
? ForeignKeyDirection.FROM_PARENT
|
||||||
: ForeignKeyDirection.TO_PARENT;
|
: ForeignKeyDirection.TO_PARENT;
|
||||||
}
|
}
|
||||||
|
@ -131,4 +133,15 @@ public abstract class AbstractToOneAttributeSourceImpl extends SingularAttribute
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ToOneAttributeSourceImpl{role=" + associationAttribute.getRole().getFullPath() + '}';
|
return "ToOneAttributeSourceImpl{role=" + associationAttribute.getRole().getFullPath() + '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributePath getAttributePath() {
|
||||||
|
return associationAttribute.getPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributeRole getAttributeRole() {
|
||||||
|
return associationAttribute.getRole();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -28,7 +28,7 @@ import java.util.Collections;
|
||||||
|
|
||||||
import org.hibernate.id.EntityIdentifierNature;
|
import org.hibernate.id.EntityIdentifierNature;
|
||||||
import org.hibernate.metamodel.source.spi.AggregatedCompositeIdentifierSource;
|
import org.hibernate.metamodel.source.spi.AggregatedCompositeIdentifierSource;
|
||||||
import org.hibernate.metamodel.source.spi.ComponentAttributeSource;
|
import org.hibernate.metamodel.source.spi.EmbeddedAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
||||||
import org.hibernate.metamodel.spi.binding.IdentifierGeneratorDefinition;
|
import org.hibernate.metamodel.spi.binding.IdentifierGeneratorDefinition;
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class AggregatedCompositeIdentifierSourceImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ComponentAttributeSource getIdentifierAttributeSource() {
|
public EmbeddedAttributeSource getIdentifierAttributeSource() {
|
||||||
return componentAttributeSource;
|
return componentAttributeSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,9 @@ import org.hibernate.metamodel.source.internal.annotations.attribute.BasicAttrib
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.Column;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.Column;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.OverrideAndConverterCollector;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.OverrideAndConverterCollector;
|
||||||
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
||||||
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
|
import org.hibernate.metamodel.spi.SingularAttributeNature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
|
@ -61,8 +64,8 @@ public class BasicAttributeSourceImpl extends SingularAttributeSourceImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Nature getNature() {
|
public SingularAttributeNature getSingularAttributeNature() {
|
||||||
return Nature.BASIC;
|
return SingularAttributeNature.BASIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -128,4 +131,14 @@ public class BasicAttributeSourceImpl extends SingularAttributeSourceImpl {
|
||||||
|
|
||||||
return relationalValueSources;
|
return relationalValueSources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributePath getAttributePath() {
|
||||||
|
return getAnnotatedAttribute().getPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributeRole getAttributeRole() {
|
||||||
|
return getAnnotatedAttribute().getRole();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,94 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.metamodel.source.internal.annotations;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.hibernate.metamodel.internal.binder.Binder;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.Column;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
|
||||||
import org.hibernate.metamodel.source.spi.BasicPluralAttributeIndexSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
|
||||||
import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
|
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Strong Liu <stliu@hibernate.org>
|
|
||||||
*/
|
|
||||||
public class BasicPluralAttributeIndexSourceImpl extends AbstractPluralAttributeIndexSourceImpl implements BasicPluralAttributeIndexSource {
|
|
||||||
private final IndexedPluralAttributeSourceImpl indexedPluralAttributeSource;
|
|
||||||
private final List<RelationalValueSource> relationalValueSources;
|
|
||||||
private final Binder.DefaultNamingStrategy defaultNamingStrategy;
|
|
||||||
|
|
||||||
public BasicPluralAttributeIndexSourceImpl(
|
|
||||||
IndexedPluralAttributeSourceImpl indexedPluralAttributeSource,
|
|
||||||
PluralAttribute attribute,
|
|
||||||
Binder.DefaultNamingStrategy defaultNamingStrategy) {
|
|
||||||
this( indexedPluralAttributeSource, attribute, defaultNamingStrategy, createRelationalValueSources( attribute ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
public BasicPluralAttributeIndexSourceImpl(
|
|
||||||
IndexedPluralAttributeSourceImpl indexedPluralAttributeSource,
|
|
||||||
PluralAttribute attribute,
|
|
||||||
Binder.DefaultNamingStrategy defaultNamingStrategy,
|
|
||||||
List<RelationalValueSource> relationalValueSources) {
|
|
||||||
super( attribute );
|
|
||||||
this.indexedPluralAttributeSource = indexedPluralAttributeSource;
|
|
||||||
this.relationalValueSources = relationalValueSources;
|
|
||||||
this.defaultNamingStrategy = defaultNamingStrategy;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<RelationalValueSource> createRelationalValueSources(PluralAttribute attribute) {
|
|
||||||
// ugh!
|
|
||||||
// i give up for now...
|
|
||||||
AnnotationInstance columnAnnotation = attribute.getBackingMember().getAnnotations().get(
|
|
||||||
JPADotNames.ORDER_COLUMN
|
|
||||||
);
|
|
||||||
if ( columnAnnotation == null ) {
|
|
||||||
columnAnnotation = attribute.getBackingMember().getAnnotations().get(
|
|
||||||
JPADotNames.MAP_KEY_COLUMN
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Column indexColumn = new Column( columnAnnotation );
|
|
||||||
return Collections.singletonList( (RelationalValueSource) new ColumnSourceImpl( indexColumn ) );
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public PluralAttributeIndexBinding.Nature getNature() {
|
|
||||||
return PluralAttributeIndexBinding.Nature.BASIC;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Binder.DefaultNamingStrategy> getDefaultNamingStrategies() {
|
|
||||||
return Collections.singletonList( defaultNamingStrategy );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<RelationalValueSource> relationalValueSources() {
|
|
||||||
return relationalValueSources;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,134 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* JBoss, Home of Professional Open Source
|
|
||||||
* Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
|
|
||||||
* as indicated by the @authors tag. All rights reserved.
|
|
||||||
* See the copyright.txt in the distribution for a
|
|
||||||
* full listing of individual contributors.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use,
|
|
||||||
* modify, copy, or redistribute it subject to the terms and conditions
|
|
||||||
* of the GNU Lesser General Public License, v. 2.1.
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT A
|
|
||||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
||||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License,
|
|
||||||
* v.2.1 along with this distribution; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
* MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
package org.hibernate.metamodel.source.internal.annotations;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.hibernate.engine.spi.CascadeStyle;
|
|
||||||
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttributeElementDetailsEmbedded;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.entity.EmbeddableTypeMetadata;
|
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.CompositePluralAttributeElementSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
|
||||||
import org.hibernate.metamodel.spi.LocalBindingContext;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Brett Meyer
|
|
||||||
*/
|
|
||||||
public class CompositePluralAttributeElementSourceImpl
|
|
||||||
implements CompositePluralAttributeElementSource {
|
|
||||||
private final PluralAttribute pluralAttribute;
|
|
||||||
private final Set<CascadeStyle> unifiedCascadeStyles;
|
|
||||||
private final PluralAttributeElementDetailsEmbedded elementDescriptor;
|
|
||||||
|
|
||||||
private final EmbeddableTypeMetadata embeddableTypeMetadata;
|
|
||||||
|
|
||||||
private final List<AttributeSource> attributeSources;
|
|
||||||
|
|
||||||
public CompositePluralAttributeElementSourceImpl(PluralAttributeSourceImpl pluralAttributeSource) {
|
|
||||||
this.pluralAttribute = pluralAttributeSource.getPluralAttribute();
|
|
||||||
this.unifiedCascadeStyles = pluralAttributeSource.getUnifiedCascadeStyles();
|
|
||||||
|
|
||||||
this.elementDescriptor = (PluralAttributeElementDetailsEmbedded) pluralAttribute.getElementDetails();
|
|
||||||
this.embeddableTypeMetadata = elementDescriptor.getEmbeddableTypeMetadata();
|
|
||||||
|
|
||||||
this.attributeSources = SourceHelper.buildAttributeSources(
|
|
||||||
embeddableTypeMetadata,
|
|
||||||
SourceHelper.PluralAttributesDisallowedAttributeBuilder.INSTANCE
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Nature getNature() {
|
|
||||||
return Nature.AGGREGATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPath() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<AttributeSource> attributeSources() {
|
|
||||||
return attributeSources;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LocalBindingContext getLocalBindingContext() {
|
|
||||||
return pluralAttribute.getContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<CascadeStyle> getCascadeStyles() {
|
|
||||||
return unifiedCascadeStyles;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<? extends ToolingHintSource> getToolingHintSources() {
|
|
||||||
// HBM only
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JavaTypeDescriptor getTypeDescriptor() {
|
|
||||||
return elementDescriptor.getJavaType();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getParentReferenceAttributeName() {
|
|
||||||
return embeddableTypeMetadata.getParentReferencingAttributeName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getExplicitTuplizerClassName() {
|
|
||||||
|
|
||||||
// TODO ?
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// private void buildAttributeSources() {
|
|
||||||
// // TODO: Duplicates code in EmbeddedAttributeSourceImpl.
|
|
||||||
// for ( SimpleAttribute attribute : embeddableTypeMetadata.getSimpleAttributes().values() ) {
|
|
||||||
// attribute.setNaturalIdMutability( embeddableTypeMetadata.getNaturalIdMutability() );
|
|
||||||
// attributeSources.add( new SingularAttributeSourceImpl( attribute ) );
|
|
||||||
// }
|
|
||||||
// for ( EmbeddableTypeMetadata embeddable : embeddableTypeMetadata.getEmbeddedClasses().values() ) {
|
|
||||||
// embeddable.setNaturalIdMutability( embeddableTypeMetadata.getNaturalIdMutability() );
|
|
||||||
// attributeSources.add(
|
|
||||||
// new EmbeddedAttributeSourceImpl(
|
|
||||||
// embeddable,
|
|
||||||
// getPath(),
|
|
||||||
// embeddableTypeMetadata.getClassLevelAccessType()
|
|
||||||
// )
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// for ( AssociationAttribute associationAttribute : embeddableTypeMetadata.getAssociationAttributes().values() ) {
|
|
||||||
// associationAttribute.setNaturalIdMutability( embeddableTypeMetadata.getNaturalIdMutability() );
|
|
||||||
// }
|
|
||||||
// SourceHelper.resolveAssociationAttributes( embeddableTypeMetadata, attributeSources );
|
|
||||||
// }
|
|
||||||
}
|
|
|
@ -25,31 +25,65 @@ package org.hibernate.metamodel.source.internal.annotations;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.entity.EmbeddableTypeMetadata;
|
import org.hibernate.metamodel.source.internal.annotations.entity.EmbeddableTypeMetadata;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSource;
|
import org.hibernate.metamodel.source.spi.AttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSourceContainer;
|
import org.hibernate.metamodel.source.spi.EmbeddableSource;
|
||||||
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
|
import org.hibernate.metamodel.spi.LocalBindingContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractEmbeddableAdapter implements AttributeSourceContainer {
|
public class EmbeddableSourceImpl implements EmbeddableSource {
|
||||||
private final EmbeddableTypeMetadata embeddableTypeMetadata;
|
private final EmbeddableTypeMetadata embeddableTypeMetadata;
|
||||||
|
|
||||||
private final List<AttributeSource> attributeSources;
|
private final List<AttributeSource> attributeSources;
|
||||||
|
|
||||||
public AbstractEmbeddableAdapter(EmbeddableTypeMetadata embeddableTypeMetadata) {
|
public EmbeddableSourceImpl(
|
||||||
|
EmbeddableTypeMetadata embeddableTypeMetadata,
|
||||||
|
SourceHelper.AttributeBuilder attributeBuilder) {
|
||||||
this.embeddableTypeMetadata = embeddableTypeMetadata;
|
this.embeddableTypeMetadata = embeddableTypeMetadata;
|
||||||
this.attributeSources = SourceHelper.buildAttributeSources( embeddableTypeMetadata, getAttributeBuilder() );
|
this.attributeSources = SourceHelper.buildAttributeSources( embeddableTypeMetadata, attributeBuilder );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected EmbeddableTypeMetadata getEmbeddableTypeMetadata() {
|
protected EmbeddableTypeMetadata getEmbeddableTypeMetadata() {
|
||||||
return embeddableTypeMetadata;
|
return embeddableTypeMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributePath getAttributePathBase() {
|
||||||
|
return embeddableTypeMetadata.getAttributePathBase();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributeRole getAttributeRoleBase() {
|
||||||
|
return embeddableTypeMetadata.getAttributeRoleBase();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AttributeSource> attributeSources() {
|
public List<AttributeSource> attributeSources() {
|
||||||
return attributeSources;
|
return attributeSources;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract SourceHelper.AttributeBuilder getAttributeBuilder();
|
@Override
|
||||||
|
public JavaTypeDescriptor getTypeDescriptor() {
|
||||||
|
return embeddableTypeMetadata.getJavaTypeDescriptor();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getParentReferenceAttributeName() {
|
||||||
|
return embeddableTypeMetadata.getParentReferencingAttributeName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getExplicitTuplizerClassName() {
|
||||||
|
return embeddableTypeMetadata.getCustomTuplizerClassName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocalBindingContext getLocalBindingContext() {
|
||||||
|
return embeddableTypeMetadata.getLocalBindingContext();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -30,42 +30,57 @@ import java.util.Locale;
|
||||||
|
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.mapping.PropertyGeneration;
|
import org.hibernate.mapping.PropertyGeneration;
|
||||||
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.EmbeddedAttribute;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.EmbeddedAttribute;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.PersistentAttribute;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.PersistentAttribute;
|
||||||
import org.hibernate.metamodel.source.spi.ComponentAttributeSource;
|
import org.hibernate.metamodel.source.spi.EmbeddableSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.EmbeddedAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.HibernateTypeSource;
|
import org.hibernate.metamodel.source.spi.HibernateTypeSource;
|
||||||
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
||||||
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
||||||
import org.hibernate.metamodel.spi.LocalBindingContext;
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
|
import org.hibernate.metamodel.spi.SingularAttributeNature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Annotation backed implementation of {@code ComponentAttributeSource}.
|
* Annotation backed implementation of {@code EmbeddedAttributeSource}.
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
* @author Brett Meyer
|
* @author Brett Meyer
|
||||||
*/
|
*/
|
||||||
public class EmbeddedAttributeSourceImpl
|
public class EmbeddedAttributeSourceImpl implements EmbeddedAttributeSource, AnnotationAttributeSource {
|
||||||
extends AbstractEmbeddableAdapter
|
|
||||||
implements ComponentAttributeSource, AnnotationAttributeSource {
|
|
||||||
private final EmbeddedAttribute attribute;
|
private final EmbeddedAttribute attribute;
|
||||||
private final JavaTypeDescriptor embeddableJavaTypeDescriptor;
|
|
||||||
|
|
||||||
private final boolean partOfIdentifier;
|
private final EmbeddableSource embeddableSource;
|
||||||
private final boolean partOfPersistentCollection;
|
|
||||||
|
|
||||||
public EmbeddedAttributeSourceImpl(
|
public EmbeddedAttributeSourceImpl(
|
||||||
EmbeddedAttribute attribute,
|
EmbeddedAttribute attribute,
|
||||||
boolean partOfIdentifier,
|
boolean partOfIdentifier,
|
||||||
boolean partOfPersistentCollection) {
|
boolean partOfPersistentCollection) {
|
||||||
super( attribute.getEmbeddableTypeMetadata() );
|
|
||||||
|
final SourceHelper.AttributeBuilder attributeBuilder;
|
||||||
|
if ( partOfIdentifier ) {
|
||||||
|
attributeBuilder = SourceHelper.IdentifierPathAttributeBuilder.INSTANCE;
|
||||||
|
}
|
||||||
|
else if ( partOfPersistentCollection ) {
|
||||||
|
attributeBuilder = SourceHelper.PluralAttributesDisallowedAttributeBuilder.INSTANCE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
attributeBuilder = SourceHelper.StandardAttributeBuilder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.embeddableSource = new EmbeddableSourceImpl(
|
||||||
|
attribute.getEmbeddableTypeMetadata(),
|
||||||
|
attributeBuilder
|
||||||
|
);
|
||||||
|
|
||||||
this.attribute = attribute;
|
this.attribute = attribute;
|
||||||
this.embeddableJavaTypeDescriptor = attribute.getBackingMember().getType().getErasedType();
|
}
|
||||||
this.partOfIdentifier = partOfIdentifier;
|
|
||||||
this.partOfPersistentCollection = partOfPersistentCollection;
|
@Override
|
||||||
|
public EmbeddableSource getEmbeddableSource() {
|
||||||
|
return embeddableSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -79,8 +94,8 @@ public class EmbeddedAttributeSourceImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Nature getNature() {
|
public SingularAttributeNature getSingularAttributeNature() {
|
||||||
return Nature.COMPOSITE;
|
return SingularAttributeNature.COMPOSITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -88,21 +103,22 @@ public class EmbeddedAttributeSourceImpl
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public JavaTypeDescriptor getTypeDescriptor() {
|
|
||||||
return embeddableJavaTypeDescriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return attribute.getName();
|
return attribute.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getExplicitTuplizerClassName() {
|
public AttributePath getAttributePath() {
|
||||||
return attribute.getEmbeddableTypeMetadata().getCustomTuplizerClassName();
|
return attribute.getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributeRole getAttributeRole() {
|
||||||
|
return attribute.getRole();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPropertyAccessorName() {
|
public String getPropertyAccessorName() {
|
||||||
// todo : would really rather have binder decipher this...
|
// todo : would really rather have binder decipher this...
|
||||||
|
@ -111,21 +127,6 @@ public class EmbeddedAttributeSourceImpl
|
||||||
: attribute.getAccessorStrategy();
|
: attribute.getAccessorStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public LocalBindingContext getLocalBindingContext() {
|
|
||||||
return attribute.getEmbeddableTypeMetadata().getLocalBindingContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPath() {
|
|
||||||
return attribute.getPath().getFullPath();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getParentReferenceAttributeName() {
|
|
||||||
return getEmbeddableTypeMetadata().getParentReferencingAttributeName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<? extends ToolingHintSource> getToolingHintSources() {
|
public Collection<? extends ToolingHintSource> getToolingHintSources() {
|
||||||
// not relevant for annotations
|
// not relevant for annotations
|
||||||
|
@ -161,7 +162,7 @@ public class EmbeddedAttributeSourceImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SingularAttributeBinding.NaturalIdMutability getNaturalIdMutability() {
|
public NaturalIdMutability getNaturalIdMutability() {
|
||||||
return attribute.getNaturalIdMutability();
|
return attribute.getNaturalIdMutability();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,19 +189,6 @@ public class EmbeddedAttributeSourceImpl
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "EmbeddedAttributeSourceImpl{role=" + attribute.getRole().getFullPath()
|
return "EmbeddedAttributeSourceImpl{role=" + attribute.getRole().getFullPath()
|
||||||
+ ", embeddable=" + getTypeDescriptor().getName().toString() + "}";
|
+ ", embeddable=" + embeddableSource.getTypeDescriptor().getName().toString() + "}";
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected SourceHelper.AttributeBuilder getAttributeBuilder() {
|
|
||||||
if ( partOfIdentifier ) {
|
|
||||||
return SourceHelper.IdentifierPathAttributeBuilder.INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( partOfPersistentCollection ) {
|
|
||||||
return SourceHelper.PluralAttributesDisallowedAttributeBuilder.INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return SourceHelper.StandardAttributeBuilder.INSTANCE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,8 @@ import org.hibernate.metamodel.source.spi.AttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.EntityHierarchySource;
|
import org.hibernate.metamodel.source.spi.EntityHierarchySource;
|
||||||
import org.hibernate.metamodel.source.spi.IdentifiableTypeSource;
|
import org.hibernate.metamodel.source.spi.IdentifiableTypeSource;
|
||||||
import org.hibernate.metamodel.source.spi.JpaCallbackSource;
|
import org.hibernate.metamodel.source.spi.JpaCallbackSource;
|
||||||
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
import org.hibernate.metamodel.spi.LocalBindingContext;
|
import org.hibernate.metamodel.spi.LocalBindingContext;
|
||||||
import org.hibernate.metamodel.spi.binding.InheritanceType;
|
import org.hibernate.metamodel.spi.binding.InheritanceType;
|
||||||
import org.hibernate.xml.spi.Origin;
|
import org.hibernate.xml.spi.Origin;
|
||||||
|
@ -204,8 +206,13 @@ public abstract class IdentifiableTypeSourceAdapter implements IdentifiableTypeS
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPath() {
|
public AttributePath getAttributePathBase() {
|
||||||
return "";
|
return identifiableTypeMetadata.getAttributePathBase();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributeRole getAttributeRoleBase() {
|
||||||
|
return identifiableTypeMetadata.getAttributeRoleBase();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,245 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.metamodel.source.internal.annotations;
|
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
|
|
||||||
import org.hibernate.cfg.NamingStrategy;
|
|
||||||
import org.hibernate.cfg.NotYetImplementedException;
|
|
||||||
import org.hibernate.metamodel.internal.binder.Binder;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.AbstractPersistentAttribute;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.OverrideAndConverterCollector;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSourceResolutionContext;
|
|
||||||
import org.hibernate.metamodel.source.spi.ComponentAttributeSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.IdentifierSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.IndexedPluralAttributeSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.MappingException;
|
|
||||||
import org.hibernate.metamodel.source.spi.PluralAttributeIndexSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.PluralAttributeSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.SimpleIdentifierSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Strong Liu <stliu@hibernate.org>
|
|
||||||
*/
|
|
||||||
public class IndexedPluralAttributeSourceImpl extends PluralAttributeSourceImpl
|
|
||||||
implements IndexedPluralAttributeSource {
|
|
||||||
|
|
||||||
private final static EnumSet<AbstractPersistentAttribute.Nature> VALID_NATURES = EnumSet.of(
|
|
||||||
AbstractPersistentAttribute.Nature.MANY_TO_MANY,
|
|
||||||
AbstractPersistentAttribute.Nature.ONE_TO_MANY,
|
|
||||||
AbstractPersistentAttribute.Nature.ELEMENT_COLLECTION_BASIC,
|
|
||||||
AbstractPersistentAttribute.Nature.ELEMENT_COLLECTION_EMBEDDABLE
|
|
||||||
);
|
|
||||||
|
|
||||||
private PluralAttributeIndexSource indexSource;
|
|
||||||
|
|
||||||
public IndexedPluralAttributeSourceImpl(
|
|
||||||
PluralAttribute attribute,
|
|
||||||
OverrideAndConverterCollector overrideAndConverterCollector) {
|
|
||||||
super( attribute, overrideAndConverterCollector );
|
|
||||||
if ( !VALID_NATURES.contains( attribute.getNature() ) ) {
|
|
||||||
throw new MappingException(
|
|
||||||
"Indexed column could be only mapped on the MANY side",
|
|
||||||
attribute.getContext().getOrigin()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( attribute.getPluralAttributeNature() == PluralAttributeSource.Nature.ARRAY
|
|
||||||
&& !attribute.getBackingMember().getAnnotations().containsKey( JPADotNames.ORDER_COLUMN ) ) {
|
|
||||||
throw attribute.getContext().makeMappingException(
|
|
||||||
"Persistent arrays must be annotated with @OrderColumn : " + attribute.getRole()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.indexSource = determineIndexSourceInfo( attribute );
|
|
||||||
}
|
|
||||||
|
|
||||||
private PluralAttributeIndexSource determineIndexSourceInfo(final PluralAttribute attribute) {
|
|
||||||
// could be an array/list
|
|
||||||
if ( attribute.getPluralAttributeNature() == Nature.ARRAY
|
|
||||||
|| attribute.getPluralAttributeNature() == Nature.LIST ) {
|
|
||||||
final Binder.DefaultNamingStrategy defaultNamingStrategy = new Binder.DefaultNamingStrategy() {
|
|
||||||
@Override
|
|
||||||
public String defaultName(NamingStrategy namingStrategy) {
|
|
||||||
return namingStrategy.propertyToColumnName( attribute.getName() ) + "_ORDER";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return new SequentialPluralAttributeIndexSourceImpl( this, attribute, defaultNamingStrategy );
|
|
||||||
}
|
|
||||||
|
|
||||||
// or a map
|
|
||||||
return determineMapKeyInfo( attribute );
|
|
||||||
}
|
|
||||||
|
|
||||||
private PluralAttributeIndexSource determineMapKeyInfo(final PluralAttribute attribute) {
|
|
||||||
final AnnotationInstance mapKey = attribute.getBackingMember().getAnnotations().get( JPADotNames.MAP_KEY );
|
|
||||||
final AnnotationInstance mapKeyClass = attribute.getBackingMember().getAnnotations().get( JPADotNames.MAP_KEY_CLASS );
|
|
||||||
|
|
||||||
if ( mapKey != null && mapKeyClass != null ) {
|
|
||||||
// this is an error according to the spec...
|
|
||||||
throw attribute.getContext().makeMappingException(
|
|
||||||
"Map attribute [" + attribute.getName() + "] defined both " +
|
|
||||||
"@MapKey and @MapKeyClass; only one should be used"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( mapKey != null ) {
|
|
||||||
// need to wait until the ID or attribute source can be resolved.
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( mapKeyClass != null ) {
|
|
||||||
throw new NotYetImplementedException( "@MapKeyClass is not supported yet." );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
final AnnotationInstance mapKeyColumn = attribute.getBackingMember().getAnnotations().get( JPADotNames.MAP_KEY_COLUMN );
|
|
||||||
if ( mapKeyColumn != null ) {
|
|
||||||
// todo : does this cover @MapKeyType???
|
|
||||||
final Binder.DefaultNamingStrategy defaultNamingStrategy = new Binder.DefaultNamingStrategy() {
|
|
||||||
@Override
|
|
||||||
public String defaultName(NamingStrategy namingStrategy) {
|
|
||||||
return namingStrategy.propertyToColumnName( attribute.getName() ) + "_KEY";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return new BasicPluralAttributeIndexSourceImpl( this, attribute, defaultNamingStrategy );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if ( attribute.getBackingMember().getAnnotations().containsKey( JPADotNames.MAP_KEY_ENUMERATED ) ) {
|
|
||||||
// basic
|
|
||||||
throw new NotYetImplementedException( "@MapKeyEnumerated is not supported yet." );
|
|
||||||
}
|
|
||||||
else if ( attribute.getBackingMember().getAnnotations().containsKey( JPADotNames.MAP_KEY_TEMPORAL ) ) {
|
|
||||||
// basic
|
|
||||||
throw new NotYetImplementedException( "@MapKeyTemporal is not supported yet." );
|
|
||||||
}
|
|
||||||
else if ( attribute.getBackingMember().getAnnotations().containsKey( JPADotNames.MAP_KEY_JOIN_COLUMN ) ) {
|
|
||||||
// association
|
|
||||||
throw new NotYetImplementedException( "@MapKeyJoinColumn is not supported yet." );
|
|
||||||
}
|
|
||||||
else if ( attribute.getBackingMember().getAnnotations().containsKey( JPADotNames.MAP_KEY_JOIN_COLUMNS ) ) {
|
|
||||||
// association
|
|
||||||
throw new NotYetImplementedException( "@MapKeyJoinColumns is not supported yet." );
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo : some of these in general ought to move to the attribute.getIndexDetails()
|
|
||||||
|
|
||||||
|
|
||||||
// default, just assume the key is a "basic" type
|
|
||||||
final Binder.DefaultNamingStrategy defaultNamingStrategy = new Binder.DefaultNamingStrategy() {
|
|
||||||
@Override
|
|
||||||
public String defaultName(NamingStrategy namingStrategy) {
|
|
||||||
return namingStrategy.propertyToColumnName( attribute.getName() ) + "_KEY";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return new BasicPluralAttributeIndexSourceImpl( this, attribute, defaultNamingStrategy );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PluralAttributeIndexSource resolvePluralAttributeIndexSource(AttributeSourceResolutionContext attributeSourceResolutionContext) {
|
|
||||||
if ( indexSource == null ) {
|
|
||||||
final AnnotationInstance mapKey = pluralAssociationAttribute().getBackingMember().getAnnotations().get( JPADotNames.MAP_KEY );
|
|
||||||
if ( mapKey != null ) {
|
|
||||||
indexSource = resolveMapKeyPluralAttributeIndexSource( attributeSourceResolutionContext, mapKey );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new NotYetImplementedException( "cannot resolve index source." );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return indexSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
private PluralAttributeIndexSource resolveMapKeyPluralAttributeIndexSource(
|
|
||||||
AttributeSourceResolutionContext attributeSourceResolutionContext,
|
|
||||||
AnnotationInstance mapKey) {
|
|
||||||
final String attributeName = mapKey.value( "name" ).asString();
|
|
||||||
final PluralAttributeIndexSource innerIndexSource;
|
|
||||||
if ( attributeName == null ) {
|
|
||||||
final IdentifierSource identifierSource = attributeSourceResolutionContext.resolveIdentifierSource(
|
|
||||||
pluralAssociationAttribute().getElementDetails().getJavaType().getName().toString()
|
|
||||||
);
|
|
||||||
switch ( identifierSource.getNature() ) {
|
|
||||||
case SIMPLE: {
|
|
||||||
innerIndexSource = new BasicPluralAttributeIndexSourceImpl(
|
|
||||||
this,
|
|
||||||
pluralAssociationAttribute(),
|
|
||||||
null,
|
|
||||||
( (SimpleIdentifierSource) identifierSource ).getIdentifierAttributeSource().relationalValueSources() );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
throw new NotYetImplementedException( "Only simple IDs are supported for @MapKey" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
AttributeSource attributeSource = attributeSourceResolutionContext.resolveAttributeSource(
|
|
||||||
pluralAssociationAttribute().getElementDetails().getJavaType().getName().toString(),
|
|
||||||
attributeName
|
|
||||||
);
|
|
||||||
if ( ! attributeSource.isSingular() ) {
|
|
||||||
throw new MappingException(
|
|
||||||
String.format(
|
|
||||||
"Plural attribute index [%s.%s] is not a singular attribute.",
|
|
||||||
pluralAssociationAttribute().getElementDetails().getJavaType().getName().toString(),
|
|
||||||
attributeName
|
|
||||||
),
|
|
||||||
pluralAssociationAttribute().getContext().getOrigin()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
final SingularAttributeSource mapKeyAttributeSource = (SingularAttributeSource) attributeSource;
|
|
||||||
switch ( mapKeyAttributeSource.getNature() ) {
|
|
||||||
case BASIC:
|
|
||||||
innerIndexSource = new BasicPluralAttributeIndexSourceImpl(
|
|
||||||
this,
|
|
||||||
pluralAssociationAttribute(),
|
|
||||||
null,
|
|
||||||
mapKeyAttributeSource.relationalValueSources() );
|
|
||||||
break;
|
|
||||||
case COMPOSITE:
|
|
||||||
innerIndexSource = new CompositePluralAttributeIndexSourceImpl(
|
|
||||||
pluralAssociationAttribute(),
|
|
||||||
( (ComponentAttributeSource) attributeSource ).attributeSources(),
|
|
||||||
null
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new NotYetImplementedException( "Only basic plural attribute index sources are supported for @MapKey" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new MapKeyPluralAttributeIndexSourceImpl( pluralAssociationAttribute(), innerIndexSource, attributeName );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PluralAttributeIndexSource getIndexSource() {
|
|
||||||
return indexSource;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
package org.hibernate.metamodel.source.internal.annotations;
|
|
||||||
|
|
||||||
import org.hibernate.metamodel.source.spi.ManyToAnyPluralAttributeElementSource;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Hardy Ferentschik
|
|
||||||
*/
|
|
||||||
public class ManyToAnyPluralAttributeElementSourceImpl
|
|
||||||
extends AbstractPluralAssociationElementSourceImpl
|
|
||||||
implements ManyToAnyPluralAttributeElementSource {
|
|
||||||
|
|
||||||
public ManyToAnyPluralAttributeElementSourceImpl(PluralAttributeSourceImpl pluralAttributeSource) {
|
|
||||||
super( pluralAttributeSource );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Nature getNature() {
|
|
||||||
return Nature.MANY_TO_ANY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -9,11 +9,11 @@ import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
public class ManyToManyMappedByPluralAttributeElementSourceImpl
|
public class MappedByPluralAttributeElementSourceAssociationManyToManyImpl
|
||||||
extends AbstractManyToManyPluralAttributeElementSourceImpl
|
extends AbstractPluralAttributeElementSourceAssociationManyToManyImpl
|
||||||
implements MappedByAssociationSource {
|
implements MappedByAssociationSource {
|
||||||
|
|
||||||
public ManyToManyMappedByPluralAttributeElementSourceImpl(PluralAttributeSourceImpl pluralAttributeSource) {
|
public MappedByPluralAttributeElementSourceAssociationManyToManyImpl(PluralAttributeSourceImpl pluralAttributeSource) {
|
||||||
super( pluralAttributeSource );
|
super( pluralAttributeSource );
|
||||||
if ( pluralAssociationAttribute().getMappedByAttributeName() == null ) {
|
if ( pluralAssociationAttribute().getMappedByAttributeName() == null ) {
|
||||||
throw new AssertionFailure( "pluralAssociationAttribute().getMappedByAttributeName() must be non-null." );
|
throw new AssertionFailure( "pluralAssociationAttribute().getMappedByAttributeName() must be non-null." );
|
|
@ -29,10 +29,10 @@ import org.hibernate.metamodel.source.spi.MappedByAssociationSource;
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
public class OneToManyMappedByPluralAttributeElementSourceImpl
|
public class MappedByPluralAttributeElementSourceAssociationOneToManyImpl
|
||||||
extends OneToManyPluralAttributeElementSourceImpl implements MappedByAssociationSource {
|
extends PluralAttributeElementSourceAssociationOneToManyImpl implements MappedByAssociationSource {
|
||||||
|
|
||||||
public OneToManyMappedByPluralAttributeElementSourceImpl(PluralAttributeSourceImpl pluralAttributeSource) {
|
public MappedByPluralAttributeElementSourceAssociationOneToManyImpl(PluralAttributeSourceImpl pluralAttributeSource) {
|
||||||
super( pluralAttributeSource );
|
super( pluralAttributeSource );
|
||||||
if ( pluralAttributeSource.pluralAssociationAttribute().getMappedByAttributeName() == null ) {
|
if ( pluralAttributeSource.pluralAssociationAttribute().getMappedByAttributeName() == null ) {
|
||||||
throw new AssertionFailure( "pluralAssociationAttribute().getMappedByAttributeName() must be non-null." );
|
throw new AssertionFailure( "pluralAssociationAttribute().getMappedByAttributeName() must be non-null." );
|
|
@ -0,0 +1,22 @@
|
||||||
|
package org.hibernate.metamodel.source.internal.annotations;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceManyToAny;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeElementNature;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Hardy Ferentschik
|
||||||
|
*/
|
||||||
|
public class PluralAttributeElementSourceAssociationManyToAnyImpl
|
||||||
|
extends AbstractPluralElementSourceAssociationImpl
|
||||||
|
implements PluralAttributeElementSourceManyToAny {
|
||||||
|
|
||||||
|
public PluralAttributeElementSourceAssociationManyToAnyImpl(PluralAttributeSourceImpl pluralAttributeSource) {
|
||||||
|
super( pluralAttributeSource );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PluralAttributeElementNature getNature() {
|
||||||
|
return PluralAttributeElementNature.MANY_TO_ANY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.Column;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.Column;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
||||||
import org.hibernate.metamodel.source.spi.ForeignKeyContributingSource;
|
import org.hibernate.metamodel.source.spi.ForeignKeyContributingSource;
|
||||||
import org.hibernate.metamodel.source.spi.ManyToManyPluralAttributeElementSource;
|
import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceManyToMany;
|
||||||
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
||||||
import org.hibernate.metamodel.spi.relational.TableSpecification;
|
import org.hibernate.metamodel.spi.relational.TableSpecification;
|
||||||
import org.hibernate.metamodel.spi.relational.Value;
|
import org.hibernate.metamodel.spi.relational.Value;
|
||||||
|
@ -44,13 +44,13 @@ import org.jboss.jandex.AnnotationValue;
|
||||||
* @author Brett Meyer
|
* @author Brett Meyer
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
public class ManyToManyPluralAttributeElementSourceImpl
|
public class PluralAttributeElementSourceAssociationManyToManyImpl
|
||||||
extends AbstractManyToManyPluralAttributeElementSourceImpl
|
extends AbstractPluralAttributeElementSourceAssociationManyToManyImpl
|
||||||
implements ManyToManyPluralAttributeElementSource {
|
implements PluralAttributeElementSourceManyToMany {
|
||||||
|
|
||||||
private final List<RelationalValueSource> relationalValueSources = new ArrayList<RelationalValueSource>();
|
private final List<RelationalValueSource> relationalValueSources = new ArrayList<RelationalValueSource>();
|
||||||
|
|
||||||
public ManyToManyPluralAttributeElementSourceImpl(PluralAttributeSourceImpl pluralAttributeSource) {
|
public PluralAttributeElementSourceAssociationManyToManyImpl(PluralAttributeSourceImpl pluralAttributeSource) {
|
||||||
super( pluralAttributeSource );
|
super( pluralAttributeSource );
|
||||||
if ( pluralAttributeSource.getMappedBy() != null ) {
|
if ( pluralAttributeSource.getMappedBy() != null ) {
|
||||||
throw new AssertionFailure( "pluralAttributeSource.getMappedByAttributeName() must be null." );
|
throw new AssertionFailure( "pluralAttributeSource.getMappedByAttributeName() must be null." );
|
|
@ -23,22 +23,23 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.source.internal.annotations;
|
package org.hibernate.metamodel.source.internal.annotations;
|
||||||
|
|
||||||
import org.hibernate.metamodel.source.spi.OneToManyPluralAttributeElementSource;
|
import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceOneToMany;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeElementNature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
*/
|
*/
|
||||||
public class OneToManyPluralAttributeElementSourceImpl
|
public class PluralAttributeElementSourceAssociationOneToManyImpl
|
||||||
extends AbstractPluralAssociationElementSourceImpl
|
extends AbstractPluralElementSourceAssociationImpl
|
||||||
implements OneToManyPluralAttributeElementSource {
|
implements PluralAttributeElementSourceOneToMany {
|
||||||
|
|
||||||
public OneToManyPluralAttributeElementSourceImpl(PluralAttributeSourceImpl pluralAttributeSource) {
|
public PluralAttributeElementSourceAssociationOneToManyImpl(PluralAttributeSourceImpl pluralAttributeSource) {
|
||||||
super( pluralAttributeSource );
|
super( pluralAttributeSource );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Nature getNature() {
|
public PluralAttributeElementNature getNature() {
|
||||||
return Nature.ONE_TO_MANY;
|
return PluralAttributeElementNature.ONE_TO_MANY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,19 +5,20 @@ import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.Column;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.Column;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute;
|
||||||
import org.hibernate.metamodel.source.spi.BasicPluralAttributeElementSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.HibernateTypeSource;
|
import org.hibernate.metamodel.source.spi.HibernateTypeSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceBasic;
|
||||||
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeElementNature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
*/
|
*/
|
||||||
public class BasicPluralAttributeElementSourceImpl
|
public class PluralAttributeElementSourceBasicImpl
|
||||||
extends AbstractPluralAttributeElementSourceImpl
|
extends AbstractPluralAttributeElementSourceImpl
|
||||||
implements BasicPluralAttributeElementSource {
|
implements PluralAttributeElementSourceBasic {
|
||||||
private final Nature nature;
|
private final PluralAttributeElementNature nature;
|
||||||
|
|
||||||
public BasicPluralAttributeElementSourceImpl(PluralAttributeSourceImpl pluralAttributeSource) {
|
public PluralAttributeElementSourceBasicImpl(PluralAttributeSourceImpl pluralAttributeSource) {
|
||||||
super( pluralAttributeSource );
|
super( pluralAttributeSource );
|
||||||
this.nature = resolveNature( getPluralAttribute() );
|
this.nature = resolveNature( getPluralAttribute() );
|
||||||
}
|
}
|
||||||
|
@ -28,17 +29,17 @@ public class BasicPluralAttributeElementSourceImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Nature getNature() {
|
public PluralAttributeElementNature getNature() {
|
||||||
return nature;
|
return nature;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Nature resolveNature(PluralAttribute attribute){
|
private static PluralAttributeElementNature resolveNature(PluralAttribute attribute){
|
||||||
switch ( attribute.getNature() ) {
|
switch ( attribute.getNature() ) {
|
||||||
case ELEMENT_COLLECTION_BASIC: {
|
case ELEMENT_COLLECTION_BASIC: {
|
||||||
return Nature.BASIC;
|
return PluralAttributeElementNature.BASIC;
|
||||||
}
|
}
|
||||||
case ELEMENT_COLLECTION_EMBEDDABLE: {
|
case ELEMENT_COLLECTION_EMBEDDABLE: {
|
||||||
return Nature.AGGREGATE;
|
return PluralAttributeElementNature.AGGREGATE;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
throw new AssertionError(
|
throw new AssertionError(
|
|
@ -0,0 +1,78 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
|
||||||
|
* as indicated by the @authors tag. All rights reserved.
|
||||||
|
* See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use,
|
||||||
|
* modify, copy, or redistribute it subject to the terms and conditions
|
||||||
|
* of the GNU Lesser General Public License, v. 2.1.
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT A
|
||||||
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License,
|
||||||
|
* v.2.1 along with this distribution; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
package org.hibernate.metamodel.source.internal.annotations;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.hibernate.engine.spi.CascadeStyle;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttributeElementDetailsEmbedded;
|
||||||
|
import org.hibernate.metamodel.source.spi.EmbeddableSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceEmbedded;
|
||||||
|
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeElementNature;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brett Meyer
|
||||||
|
*/
|
||||||
|
public class PluralAttributeElementSourceEmbeddedImpl
|
||||||
|
implements PluralAttributeElementSourceEmbedded {
|
||||||
|
private final PluralAttribute pluralAttribute;
|
||||||
|
private final Set<CascadeStyle> unifiedCascadeStyles;
|
||||||
|
private final PluralAttributeElementDetailsEmbedded elementDescriptor;
|
||||||
|
|
||||||
|
private final EmbeddableSourceImpl embeddableSource;
|
||||||
|
|
||||||
|
public PluralAttributeElementSourceEmbeddedImpl(PluralAttributeSourceImpl pluralAttributeSource) {
|
||||||
|
this.pluralAttribute = pluralAttributeSource.getPluralAttribute();
|
||||||
|
this.unifiedCascadeStyles = pluralAttributeSource.getUnifiedCascadeStyles();
|
||||||
|
|
||||||
|
this.elementDescriptor = (PluralAttributeElementDetailsEmbedded) pluralAttribute.getElementDetails();
|
||||||
|
this.embeddableSource = new EmbeddableSourceImpl(
|
||||||
|
elementDescriptor.getEmbeddableTypeMetadata(),
|
||||||
|
SourceHelper.PluralAttributesDisallowedAttributeBuilder.INSTANCE
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PluralAttributeElementNature getNature() {
|
||||||
|
return PluralAttributeElementNature.AGGREGATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EmbeddableSource getEmbeddableSource() {
|
||||||
|
return embeddableSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<CascadeStyle> getCascadeStyles() {
|
||||||
|
return unifiedCascadeStyles;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<? extends ToolingHintSource> getToolingHintSources() {
|
||||||
|
// HBM only
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.metamodel.source.internal.annotations;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.attribute.OverrideAndConverterCollector;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class PluralAttributeIdBagSourceImpl extends PluralAttributeSourceImpl {
|
||||||
|
public PluralAttributeIdBagSourceImpl(
|
||||||
|
PluralAttribute pluralAttribute,
|
||||||
|
OverrideAndConverterCollector overrideAndConverterCollector) {
|
||||||
|
super( pluralAttribute, overrideAndConverterCollector );
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo : source contracts still need a notion of id-bag
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.metamodel.source.internal.annotations;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.attribute.AbstractPersistentAttribute;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.attribute.OverrideAndConverterCollector;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
||||||
|
import org.hibernate.metamodel.source.spi.IndexedPluralAttributeSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.MappingException;
|
||||||
|
import org.hibernate.metamodel.source.spi.PluralAttributeIndexSource;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeNature;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Strong Liu
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class PluralAttributeIndexedSourceImpl
|
||||||
|
extends PluralAttributeSourceImpl
|
||||||
|
implements IndexedPluralAttributeSource {
|
||||||
|
|
||||||
|
private final static EnumSet<AbstractPersistentAttribute.Nature> VALID_NATURES = EnumSet.of(
|
||||||
|
AbstractPersistentAttribute.Nature.MANY_TO_MANY,
|
||||||
|
AbstractPersistentAttribute.Nature.ONE_TO_MANY,
|
||||||
|
AbstractPersistentAttribute.Nature.ELEMENT_COLLECTION_BASIC,
|
||||||
|
AbstractPersistentAttribute.Nature.ELEMENT_COLLECTION_EMBEDDABLE
|
||||||
|
);
|
||||||
|
|
||||||
|
private PluralAttributeIndexSource indexSource;
|
||||||
|
|
||||||
|
public PluralAttributeIndexedSourceImpl(
|
||||||
|
PluralAttribute attribute,
|
||||||
|
OverrideAndConverterCollector overrideAndConverterCollector) {
|
||||||
|
super( attribute, overrideAndConverterCollector );
|
||||||
|
if ( !VALID_NATURES.contains( attribute.getNature() ) ) {
|
||||||
|
throw new MappingException(
|
||||||
|
"Indexed column could be only mapped on the MANY side",
|
||||||
|
attribute.getContext().getOrigin()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( attribute.getPluralAttributeNature() == PluralAttributeNature.ARRAY
|
||||||
|
&& !attribute.getBackingMember().getAnnotations().containsKey( JPADotNames.ORDER_COLUMN ) ) {
|
||||||
|
throw attribute.getContext().makeMappingException(
|
||||||
|
"Persistent arrays must be annotated with @OrderColumn : " + attribute.getRole()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.indexSource = new PluralAttributeSequentialIndexSourceImpl( attribute );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PluralAttributeIndexSource getIndexSource() {
|
||||||
|
return indexSource;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
|
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
||||||
* indicated by the @author tags or express copyright attribution
|
* indicated by the @author tags or express copyright attribution
|
||||||
* statements applied by the authors. All third-party contributions are
|
* statements applied by the authors. All third-party contributions are
|
||||||
* distributed under license by Red Hat Inc.
|
* distributed under license by Red Hat Inc.
|
||||||
|
@ -23,53 +23,50 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.source.internal.annotations;
|
package org.hibernate.metamodel.source.internal.annotations;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.metamodel.internal.binder.Binder;
|
import org.hibernate.metamodel.internal.binder.Binder;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.attribute.Column;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute;
|
||||||
import org.hibernate.metamodel.source.spi.EntityAttributePluralAttributeIndexSource;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttributeIndexDetailsMapKeyBasic;
|
||||||
import org.hibernate.metamodel.source.spi.PluralAttributeIndexSource;
|
import org.hibernate.metamodel.source.spi.PluralAttributeMapKeySourceBasic;
|
||||||
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
||||||
import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
|
import org.hibernate.metamodel.spi.PluralAttributeIndexNature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Steve Ebersole
|
||||||
|
* @author Strong Liu
|
||||||
*/
|
*/
|
||||||
public class MapKeyPluralAttributeIndexSourceImpl extends AbstractPluralAttributeIndexSourceImpl implements EntityAttributePluralAttributeIndexSource {
|
public class PluralAttributeMapKeySourceBasicImpl
|
||||||
private final PluralAttributeIndexSource pluralAttributeIndexSource;
|
extends AbstractPluralAttributeIndexSourceImpl
|
||||||
private final String attributeName;
|
implements PluralAttributeMapKeySourceBasic {
|
||||||
|
private final List<RelationalValueSource> relationalValueSources;
|
||||||
|
private final Binder.DefaultNamingStrategy defaultNamingStrategy;
|
||||||
|
|
||||||
public MapKeyPluralAttributeIndexSourceImpl(
|
public PluralAttributeMapKeySourceBasicImpl(
|
||||||
PluralAttribute attribute,
|
PluralAttribute attribute,
|
||||||
PluralAttributeIndexSource pluralAttributeIndexSource,
|
PluralAttributeIndexDetailsMapKeyBasic mapKeyDetails) {
|
||||||
String attributeName) {
|
|
||||||
super( attribute );
|
super( attribute );
|
||||||
this.pluralAttributeIndexSource = pluralAttributeIndexSource;
|
this.defaultNamingStrategy = new PluralAttributeMapSourceImpl.MapKeyColumnDefaultNaming( attribute );
|
||||||
this.attributeName = attributeName;
|
this.relationalValueSources = Collections.singletonList(
|
||||||
|
(RelationalValueSource) new ColumnSourceImpl( new Column( mapKeyDetails.getMapKeyColumnAnnotation() ) )
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAttributeName() {
|
public PluralAttributeIndexNature getNature() {
|
||||||
return attributeName;
|
return PluralAttributeIndexNature.BASIC;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PluralAttributeIndexBinding.Nature getNature() {
|
|
||||||
return pluralAttributeIndexSource.getNature();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Binder.DefaultNamingStrategy> getDefaultNamingStrategies() {
|
public List<Binder.DefaultNamingStrategy> getDefaultNamingStrategies() {
|
||||||
return pluralAttributeIndexSource.getDefaultNamingStrategies();
|
return Collections.singletonList( defaultNamingStrategy );
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isReferencedEntityAttribute() {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<RelationalValueSource> relationalValueSources() {
|
public List<RelationalValueSource> relationalValueSources() {
|
||||||
return pluralAttributeIndexSource.relationalValueSources();
|
return relationalValueSources;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -23,39 +23,48 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.source.internal.annotations;
|
package org.hibernate.metamodel.source.internal.annotations;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.metamodel.internal.binder.Binder;
|
import org.hibernate.metamodel.internal.binder.Binder;
|
||||||
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSource;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttributeIndexDetailsMapKeyEmbedded;
|
||||||
import org.hibernate.metamodel.source.spi.CompositePluralAttributeIndexSource;
|
import org.hibernate.metamodel.source.spi.EmbeddableSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.PluralAttributeMapKeySourceEmbedded;
|
||||||
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
||||||
import org.hibernate.metamodel.spi.LocalBindingContext;
|
import org.hibernate.metamodel.spi.PluralAttributeIndexNature;
|
||||||
import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
public class CompositePluralAttributeIndexSourceImpl extends AbstractPluralAttributeIndexSourceImpl implements CompositePluralAttributeIndexSource {
|
public class PluralAttributeMapKeySourceEmbeddedImpl
|
||||||
private final List<RelationalValueSource> relationalValueSources = new ArrayList<RelationalValueSource>( 1 );
|
extends AbstractPluralAttributeIndexSourceImpl
|
||||||
private final Binder.DefaultNamingStrategy defaultNamingStrategy;
|
implements PluralAttributeMapKeySourceEmbedded {
|
||||||
private final List<AttributeSource> attributeSources;
|
|
||||||
|
|
||||||
public CompositePluralAttributeIndexSourceImpl(
|
private final EmbeddableSourceImpl embeddableSource;
|
||||||
|
private final Binder.DefaultNamingStrategy defaultNamingStrategy;
|
||||||
|
|
||||||
|
public PluralAttributeMapKeySourceEmbeddedImpl(
|
||||||
PluralAttribute attribute,
|
PluralAttribute attribute,
|
||||||
List<AttributeSource> attributeSources,
|
PluralAttributeIndexDetailsMapKeyEmbedded mapKeyDetails) {
|
||||||
Binder.DefaultNamingStrategy defaultNamingStrategy) {
|
|
||||||
super( attribute );
|
super( attribute );
|
||||||
this.attributeSources = attributeSources;
|
|
||||||
this.defaultNamingStrategy = defaultNamingStrategy;
|
this.embeddableSource = new EmbeddableSourceImpl(
|
||||||
|
mapKeyDetails.getEmbeddableTypeMetadata(),
|
||||||
|
SourceHelper.IdentifierPathAttributeBuilder.INSTANCE
|
||||||
|
);
|
||||||
|
this.defaultNamingStrategy = new PluralAttributeMapSourceImpl.MapKeyColumnDefaultNaming( attribute );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PluralAttributeIndexBinding.Nature getNature() {
|
public PluralAttributeIndexNature getNature() {
|
||||||
return PluralAttributeIndexBinding.Nature.AGGREGATE;
|
return PluralAttributeIndexNature.AGGREGATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EmbeddableSource getEmbeddableSource() {
|
||||||
|
return embeddableSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -63,14 +72,9 @@ public class CompositePluralAttributeIndexSourceImpl extends AbstractPluralAttri
|
||||||
return Collections.singletonList( defaultNamingStrategy );
|
return Collections.singletonList( defaultNamingStrategy );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isReferencedEntityAttribute() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<RelationalValueSource> relationalValueSources() {
|
public List<RelationalValueSource> relationalValueSources() {
|
||||||
return relationalValueSources;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -89,21 +93,6 @@ public class CompositePluralAttributeIndexSourceImpl extends AbstractPluralAttri
|
||||||
}
|
}
|
||||||
|
|
||||||
public JavaTypeDescriptor getTypeDescriptor() {
|
public JavaTypeDescriptor getTypeDescriptor() {
|
||||||
return pluralAssociationAttribute().getIndexDetails().getJavaType();
|
return embeddableSource.getTypeDescriptor();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPath() {
|
|
||||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<AttributeSource> attributeSources() {
|
|
||||||
return attributeSources;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LocalBindingContext getLocalBindingContext() {
|
|
||||||
return pluralAssociationAttribute().getContext();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,150 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.metamodel.source.internal.annotations;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.internal.binder.Binder;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute;
|
||||||
|
import org.hibernate.metamodel.source.spi.AggregatedCompositeIdentifierSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.AttributeSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.AttributeSourceResolutionContext;
|
||||||
|
import org.hibernate.metamodel.source.spi.IdentifierSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.MappingException;
|
||||||
|
import org.hibernate.metamodel.source.spi.PluralAttributeIndexSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.PluralAttributeIndexSourceResolver;
|
||||||
|
import org.hibernate.metamodel.source.spi.PluralAttributeMapKeySourceEntityAttribute;
|
||||||
|
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.SimpleIdentifierSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeIndexNature;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modeling of the JPA {@link javax.persistence.MapKey} annotation
|
||||||
|
*
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class PluralAttributeMapKeySourceEntityAttributeImpl
|
||||||
|
extends AbstractPluralAttributeIndexSourceImpl
|
||||||
|
implements PluralAttributeMapKeySourceEntityAttribute, PluralAttributeIndexSourceResolver {
|
||||||
|
|
||||||
|
private final String mapKeyAttributeName;
|
||||||
|
private final Binder.DefaultNamingStrategy defaultNamingStrategy;
|
||||||
|
private SingularAttributeSource mapKeyAttributeSource;
|
||||||
|
|
||||||
|
public PluralAttributeMapKeySourceEntityAttributeImpl(
|
||||||
|
PluralAttribute attribute,
|
||||||
|
String mapKeyAttributeName) {
|
||||||
|
super( attribute );
|
||||||
|
this.mapKeyAttributeName = mapKeyAttributeName;
|
||||||
|
this.defaultNamingStrategy = new PluralAttributeMapSourceImpl.MapKeyColumnDefaultNaming( attribute );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PluralAttributeIndexSource resolvePluralAttributeIndexSource(AttributeSourceResolutionContext context) {
|
||||||
|
if ( mapKeyAttributeName == null ) {
|
||||||
|
final IdentifierSource identifierSource = context.resolveIdentifierSource(
|
||||||
|
pluralAttribute().getElementDetails().getJavaType().getName().toString()
|
||||||
|
);
|
||||||
|
switch ( identifierSource.getNature() ) {
|
||||||
|
case SIMPLE: {
|
||||||
|
mapKeyAttributeSource = ( (SimpleIdentifierSource) identifierSource ).getIdentifierAttributeSource();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case AGGREGATED_COMPOSITE: {
|
||||||
|
mapKeyAttributeSource = ( (AggregatedCompositeIdentifierSource) identifierSource ).getIdentifierAttributeSource();
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
throw pluralAttribute().getContext().makeMappingException(
|
||||||
|
"Non-aggregated composite identifiers are not supported for @MapKey"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
AttributeSource attributeSource = context.resolveAttributeSource(
|
||||||
|
pluralAttribute().getElementDetails().getJavaType().getName().toString(),
|
||||||
|
mapKeyAttributeName
|
||||||
|
);
|
||||||
|
if ( ! attributeSource.isSingular() ) {
|
||||||
|
throw new MappingException(
|
||||||
|
String.format(
|
||||||
|
"Plural attribute index [%s.%s] is not a singular attribute.",
|
||||||
|
pluralAttribute().getElementDetails().getJavaType().getName().toString(),
|
||||||
|
mapKeyAttributeName
|
||||||
|
),
|
||||||
|
pluralAttribute().getContext().getOrigin()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
mapKeyAttributeSource = (SingularAttributeSource) attributeSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAttributeName() {
|
||||||
|
return mapKeyAttributeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PluralAttributeIndexNature getNature() {
|
||||||
|
if ( mapKeyAttributeSource == null ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ( mapKeyAttributeSource.getSingularAttributeNature() ) {
|
||||||
|
case BASIC: {
|
||||||
|
return PluralAttributeIndexNature.BASIC;
|
||||||
|
}
|
||||||
|
case COMPOSITE: {
|
||||||
|
return PluralAttributeIndexNature.AGGREGATE;
|
||||||
|
}
|
||||||
|
case ANY: {
|
||||||
|
return PluralAttributeIndexNature.MANY_TO_ANY;
|
||||||
|
}
|
||||||
|
case MANY_TO_ONE: {
|
||||||
|
return PluralAttributeIndexNature.MANY_TO_MANY;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
throw pluralAttribute().getContext().makeMappingException(
|
||||||
|
"Unexpected attribute nature : " + mapKeyAttributeSource.getSingularAttributeNature()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Binder.DefaultNamingStrategy> getDefaultNamingStrategies() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<RelationalValueSource> relationalValueSources() {
|
||||||
|
if ( mapKeyAttributeSource == null ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return mapKeyAttributeSource.relationalValueSources();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,102 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.metamodel.source.internal.annotations;
|
||||||
|
|
||||||
|
import org.hibernate.cfg.NamingStrategy;
|
||||||
|
import org.hibernate.metamodel.internal.binder.Binder;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.attribute.OverrideAndConverterCollector;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttributeIndexDetails;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttributeIndexDetailsMapKeyBasic;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttributeIndexDetailsMapKeyEmbedded;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttributeIndexDetailsMapKeyEntityAttribute;
|
||||||
|
import org.hibernate.metamodel.source.spi.IndexedPluralAttributeSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.PluralAttributeIndexSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class PluralAttributeMapSourceImpl
|
||||||
|
extends PluralAttributeSourceImpl
|
||||||
|
implements IndexedPluralAttributeSource {
|
||||||
|
private final PluralAttributeIndexSource mapKeySource;
|
||||||
|
|
||||||
|
public PluralAttributeMapSourceImpl(
|
||||||
|
PluralAttribute attribute,
|
||||||
|
OverrideAndConverterCollector overrideAndConverterCollector) {
|
||||||
|
super( attribute, overrideAndConverterCollector );
|
||||||
|
|
||||||
|
this.mapKeySource = determineMapKeySourceInfo( attribute );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PluralAttributeIndexSource determineMapKeySourceInfo(final PluralAttribute attribute) {
|
||||||
|
final PluralAttributeIndexDetails mapKeyDetails = attribute.getIndexDetails();
|
||||||
|
|
||||||
|
if ( mapKeyDetails.getIndexNature() == null ) {
|
||||||
|
return new PluralAttributeMapKeySourceEntityAttributeImpl(
|
||||||
|
attribute,
|
||||||
|
( (PluralAttributeIndexDetailsMapKeyEntityAttribute) mapKeyDetails ).getReferencedAttributeName()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ( mapKeyDetails.getIndexNature() ) {
|
||||||
|
case BASIC: {
|
||||||
|
return new PluralAttributeMapKeySourceBasicImpl(
|
||||||
|
attribute,
|
||||||
|
(PluralAttributeIndexDetailsMapKeyBasic) mapKeyDetails
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case AGGREGATE: {
|
||||||
|
return new PluralAttributeMapKeySourceEmbeddedImpl(
|
||||||
|
attribute,
|
||||||
|
(PluralAttributeIndexDetailsMapKeyEmbedded) mapKeyDetails
|
||||||
|
);
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
throw attribute.getContext().makeMappingException(
|
||||||
|
"Support for entities as map keys is not yet implemented"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PluralAttributeIndexSource getIndexSource() {
|
||||||
|
return mapKeySource;
|
||||||
|
}
|
||||||
|
|
||||||
|
static class MapKeyColumnDefaultNaming implements Binder.DefaultNamingStrategy {
|
||||||
|
private final PluralAttribute pluralAttribute;
|
||||||
|
|
||||||
|
MapKeyColumnDefaultNaming(PluralAttribute pluralAttribute) {
|
||||||
|
this.pluralAttribute = pluralAttribute;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String defaultName(NamingStrategy namingStrategy) {
|
||||||
|
return pluralAttribute.getName() + "_KEY";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -24,26 +24,34 @@
|
||||||
package org.hibernate.metamodel.source.internal.annotations;
|
package org.hibernate.metamodel.source.internal.annotations;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.hibernate.cfg.NamingStrategy;
|
||||||
import org.hibernate.metamodel.internal.binder.Binder;
|
import org.hibernate.metamodel.internal.binder.Binder;
|
||||||
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.attribute.Column;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
||||||
import org.hibernate.metamodel.source.spi.HibernateTypeSource;
|
import org.hibernate.metamodel.source.spi.HibernateTypeSource;
|
||||||
import org.hibernate.metamodel.source.spi.SequentialPluralAttributeIndexSource;
|
import org.hibernate.metamodel.source.spi.PluralAttributeSequentialIndexSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeIndexNature;
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
public class SequentialPluralAttributeIndexSourceImpl
|
public class PluralAttributeSequentialIndexSourceImpl
|
||||||
extends BasicPluralAttributeIndexSourceImpl
|
extends AbstractPluralAttributeIndexSourceImpl
|
||||||
implements SequentialPluralAttributeIndexSource {
|
implements PluralAttributeSequentialIndexSource {
|
||||||
private final int base;
|
|
||||||
|
|
||||||
private final static HibernateTypeSource INTERGER_TYPE = new HibernateTypeSource() {
|
private final int base;
|
||||||
|
private final RelationalValueSource relationalValueSource;
|
||||||
|
private final Binder.DefaultNamingStrategy defaultNamingStrategy;
|
||||||
|
|
||||||
|
private final static HibernateTypeSource INTEGER_TYPE = new HibernateTypeSource() {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "integer";
|
return "integer";
|
||||||
|
@ -59,24 +67,44 @@ public class SequentialPluralAttributeIndexSourceImpl
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public SequentialPluralAttributeIndexSourceImpl(
|
public PluralAttributeSequentialIndexSourceImpl(final PluralAttribute attribute) {
|
||||||
IndexedPluralAttributeSourceImpl indexedPluralAttributeSource,
|
super( attribute );
|
||||||
PluralAttribute attribute,
|
|
||||||
Binder.DefaultNamingStrategy defaultNamingStrategy) {
|
|
||||||
super( indexedPluralAttributeSource, attribute, defaultNamingStrategy );
|
|
||||||
final AnnotationInstance columnAnnotation = attribute.getBackingMember().getAnnotations()
|
final AnnotationInstance columnAnnotation = attribute.getBackingMember().getAnnotations()
|
||||||
.get( JPADotNames.ORDER_COLUMN );
|
.get( JPADotNames.ORDER_COLUMN );
|
||||||
this.base = columnAnnotation.value( "base" ) != null
|
this.base = columnAnnotation.value( "base" ) != null
|
||||||
? columnAnnotation.value( "base" ).asInt()
|
? columnAnnotation.value( "base" ).asInt()
|
||||||
: 0;
|
: 0;
|
||||||
|
this.relationalValueSource = new ColumnSourceImpl( new Column( columnAnnotation ) );
|
||||||
|
this.defaultNamingStrategy = new Binder.DefaultNamingStrategy() {
|
||||||
|
@Override
|
||||||
|
public String defaultName(NamingStrategy namingStrategy) {
|
||||||
|
return attribute.getName() + "_ORDER";
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int base() {
|
public int base() {
|
||||||
return base;
|
return base;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PluralAttributeIndexNature getNature() {
|
||||||
|
return PluralAttributeIndexNature.SEQUENTIAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Binder.DefaultNamingStrategy> getDefaultNamingStrategies() {
|
||||||
|
return Collections.singletonList( defaultNamingStrategy );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HibernateTypeSource getTypeInformation() {
|
public HibernateTypeSource getTypeInformation() {
|
||||||
return INTERGER_TYPE;
|
return INTEGER_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<RelationalValueSource> relationalValueSources() {
|
||||||
|
return Collections.singletonList( relationalValueSource );
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -27,6 +27,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.hibernate.AssertionFailure;
|
import org.hibernate.AssertionFailure;
|
||||||
|
@ -37,14 +38,20 @@ import org.hibernate.engine.spi.CascadeStyles;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.metamodel.reflite.spi.ArrayDescriptor;
|
import org.hibernate.metamodel.reflite.spi.ArrayDescriptor;
|
||||||
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.attribute.CollectionIdInformation;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.attribute.Column;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.OverrideAndConverterCollector;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.OverrideAndConverterCollector;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.PersistentAttribute;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.PersistentAttribute;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.PluralAttribute;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.attribute.type.AttributeTypeResolver;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.entity.EntityBindingContext;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.EnumConversionHelper;
|
import org.hibernate.metamodel.source.internal.annotations.util.EnumConversionHelper;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
||||||
import org.hibernate.metamodel.source.spi.AssociationSource;
|
import org.hibernate.metamodel.source.spi.AssociationSource;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSource;
|
import org.hibernate.metamodel.source.spi.AttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSourceResolutionContext;
|
import org.hibernate.metamodel.source.spi.AttributeSourceResolutionContext;
|
||||||
|
import org.hibernate.metamodel.source.spi.CollectionIdSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.ColumnSource;
|
||||||
import org.hibernate.metamodel.source.spi.FilterSource;
|
import org.hibernate.metamodel.source.spi.FilterSource;
|
||||||
import org.hibernate.metamodel.source.spi.HibernateTypeSource;
|
import org.hibernate.metamodel.source.spi.HibernateTypeSource;
|
||||||
import org.hibernate.metamodel.source.spi.MappedByAssociationSource;
|
import org.hibernate.metamodel.source.spi.MappedByAssociationSource;
|
||||||
|
@ -56,6 +63,10 @@ import org.hibernate.metamodel.source.spi.Sortable;
|
||||||
import org.hibernate.metamodel.source.spi.TableSpecificationSource;
|
import org.hibernate.metamodel.source.spi.TableSpecificationSource;
|
||||||
import org.hibernate.metamodel.source.spi.ToOneAttributeSource;
|
import org.hibernate.metamodel.source.spi.ToOneAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
||||||
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeElementNature;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeNature;
|
||||||
import org.hibernate.metamodel.spi.binding.Caching;
|
import org.hibernate.metamodel.spi.binding.Caching;
|
||||||
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
||||||
|
|
||||||
|
@ -67,7 +78,7 @@ import org.jboss.jandex.AnnotationInstance;
|
||||||
public class PluralAttributeSourceImpl
|
public class PluralAttributeSourceImpl
|
||||||
implements AnnotationAttributeSource, PluralAttributeSource, Orderable, Sortable {
|
implements AnnotationAttributeSource, PluralAttributeSource, Orderable, Sortable {
|
||||||
private final PluralAttribute pluralAttribute;
|
private final PluralAttribute pluralAttribute;
|
||||||
private final Nature nature;
|
private final PluralAttributeNature nature;
|
||||||
|
|
||||||
private final Set<CascadeStyle> unifiedCascadeStyles;
|
private final Set<CascadeStyle> unifiedCascadeStyles;
|
||||||
|
|
||||||
|
@ -75,6 +86,8 @@ public class PluralAttributeSourceImpl
|
||||||
private final PluralAttributeKeySource keySource;
|
private final PluralAttributeKeySource keySource;
|
||||||
private final FilterSource[] filterSources;
|
private final FilterSource[] filterSources;
|
||||||
|
|
||||||
|
private final CollectionIdSource collectionIdSource;
|
||||||
|
|
||||||
// If it is not the owner side (i.e., mappedBy != null), then the AttributeSource
|
// If it is not the owner side (i.e., mappedBy != null), then the AttributeSource
|
||||||
// for the owner is required to determine elementSource.
|
// for the owner is required to determine elementSource.
|
||||||
private PluralAttributeElementSource elementSource;
|
private PluralAttributeElementSource elementSource;
|
||||||
|
@ -97,6 +110,16 @@ public class PluralAttributeSourceImpl
|
||||||
this.elementSource = determineElementSource( this, this );
|
this.elementSource = determineElementSource( this, this );
|
||||||
}
|
}
|
||||||
this.filterSources = determineFilterSources( pluralAttribute );
|
this.filterSources = determineFilterSources( pluralAttribute );
|
||||||
|
|
||||||
|
if ( pluralAttribute.getCollectionIdInformation() == null ) {
|
||||||
|
this.collectionIdSource = null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
collectionIdSource = new CollectionIdSourceImpl(
|
||||||
|
pluralAttribute.getCollectionIdInformation(),
|
||||||
|
pluralAttribute.getContext()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set<CascadeStyle> determineCascadeStyles(PluralAttribute pluralAttribute) {
|
private static Set<CascadeStyle> determineCascadeStyles(PluralAttribute pluralAttribute) {
|
||||||
|
@ -140,6 +163,21 @@ public class PluralAttributeSourceImpl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributePath getAttributePath() {
|
||||||
|
return pluralAttribute.getPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributeRole getAttributeRole() {
|
||||||
|
return pluralAttribute.getRole();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CollectionIdSource getCollectionIdSource() {
|
||||||
|
return collectionIdSource;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PersistentAttribute getAnnotatedAttribute() {
|
public PersistentAttribute getAnnotatedAttribute() {
|
||||||
return getPluralAttribute();
|
return getPluralAttribute();
|
||||||
|
@ -154,7 +192,7 @@ public class PluralAttributeSourceImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Nature getNature() {
|
public PluralAttributeNature getNature() {
|
||||||
return nature;
|
return nature;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,17 +248,17 @@ public class PluralAttributeSourceImpl
|
||||||
final PluralAttribute associationAttribute = pluralAttributeSource.pluralAssociationAttribute();
|
final PluralAttribute associationAttribute = pluralAttributeSource.pluralAssociationAttribute();
|
||||||
switch ( pluralAttributeSource.pluralAssociationAttribute().getNature() ) {
|
switch ( pluralAttributeSource.pluralAssociationAttribute().getNature() ) {
|
||||||
case ELEMENT_COLLECTION_BASIC: {
|
case ELEMENT_COLLECTION_BASIC: {
|
||||||
return new BasicPluralAttributeElementSourceImpl( pluralAttributeSource );
|
return new PluralAttributeElementSourceBasicImpl( pluralAttributeSource );
|
||||||
}
|
}
|
||||||
case ELEMENT_COLLECTION_EMBEDDABLE: {
|
case ELEMENT_COLLECTION_EMBEDDABLE: {
|
||||||
return new CompositePluralAttributeElementSourceImpl( pluralAttributeSource );
|
return new PluralAttributeElementSourceEmbeddedImpl( pluralAttributeSource );
|
||||||
}
|
}
|
||||||
case MANY_TO_MANY: {
|
case MANY_TO_MANY: {
|
||||||
if ( associationAttribute.getMappedByAttributeName() == null ) {
|
if ( associationAttribute.getMappedByAttributeName() == null ) {
|
||||||
return new ManyToManyPluralAttributeElementSourceImpl( pluralAttributeSource );
|
return new PluralAttributeElementSourceAssociationManyToManyImpl( pluralAttributeSource );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return new ManyToManyMappedByPluralAttributeElementSourceImpl( pluralAttributeSource );
|
return new MappedByPluralAttributeElementSourceAssociationManyToManyImpl( pluralAttributeSource );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case ONE_TO_MANY: {
|
case ONE_TO_MANY: {
|
||||||
|
@ -230,23 +268,23 @@ public class PluralAttributeSourceImpl
|
||||||
|
|
||||||
if ( usesJoinTable ) {
|
if ( usesJoinTable ) {
|
||||||
if ( associationAttribute.getMappedByAttributeName() == null ) {
|
if ( associationAttribute.getMappedByAttributeName() == null ) {
|
||||||
return new ManyToManyPluralAttributeElementSourceImpl( pluralAttributeSource );
|
return new PluralAttributeElementSourceAssociationManyToManyImpl( pluralAttributeSource );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return new ManyToManyMappedByPluralAttributeElementSourceImpl( pluralAttributeSource );
|
return new MappedByPluralAttributeElementSourceAssociationManyToManyImpl( pluralAttributeSource );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ( associationAttribute.getMappedByAttributeName() == null ) {
|
if ( associationAttribute.getMappedByAttributeName() == null ) {
|
||||||
return new OneToManyPluralAttributeElementSourceImpl( pluralAttributeSource );
|
return new PluralAttributeElementSourceAssociationOneToManyImpl( pluralAttributeSource );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return new OneToManyMappedByPluralAttributeElementSourceImpl( pluralAttributeSource );
|
return new MappedByPluralAttributeElementSourceAssociationOneToManyImpl( pluralAttributeSource );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case MANY_TO_ANY: {
|
case MANY_TO_ANY: {
|
||||||
return new ManyToAnyPluralAttributeElementSourceImpl( pluralAttributeSource );
|
return new PluralAttributeElementSourceAssociationManyToAnyImpl( pluralAttributeSource );
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
throw new AssertionError( "Unexpected plural attribute nature :" + associationAttribute.getNature() );
|
throw new AssertionError( "Unexpected plural attribute nature :" + associationAttribute.getNature() );
|
||||||
|
@ -375,7 +413,7 @@ public class PluralAttributeSourceImpl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getOrder() {
|
public String getOrder() {
|
||||||
return elementSource.getNature() == PluralAttributeElementSource.Nature.MANY_TO_MANY ?
|
return elementSource.getNature() == PluralAttributeElementNature.MANY_TO_MANY ?
|
||||||
null :
|
null :
|
||||||
pluralAttribute.getOrderBy();
|
pluralAttribute.getOrderBy();
|
||||||
}
|
}
|
||||||
|
@ -457,6 +495,96 @@ public class PluralAttributeSourceImpl
|
||||||
protected PluralAttribute pluralAssociationAttribute() {
|
protected PluralAttribute pluralAssociationAttribute() {
|
||||||
return pluralAttribute;
|
return pluralAttribute;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static class CollectionIdSourceImpl implements CollectionIdSource {
|
||||||
|
private final ColumnSourceImpl columnSource;
|
||||||
|
private final HibernateTypeSource typeSource;
|
||||||
|
private final String generatorName;
|
||||||
|
|
||||||
|
public CollectionIdSourceImpl(CollectionIdInformation collectionIdInformation, EntityBindingContext context) {
|
||||||
|
this.columnSource = interpretColumns( collectionIdInformation.getColumns(), context );
|
||||||
|
this.typeSource = createTypeSource( collectionIdInformation.getTypeResolver() );
|
||||||
|
this.generatorName = collectionIdInformation.getGeneratorDefinition().getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ColumnSourceImpl interpretColumns(List<Column> columns, EntityBindingContext context) {
|
||||||
|
if ( columns == null || columns.isEmpty() ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( columns.size() > 1 ) {
|
||||||
|
throw context.makeMappingException( "Expecting just one column for collection id" );
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ColumnSourceImpl( columns.get( 0 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private HibernateTypeSource createTypeSource(AttributeTypeResolver typeResolver) {
|
||||||
|
if ( typeResolver == null ) {
|
||||||
|
return EmptyHibernateTypeSource.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String resolvedTypeName = typeResolver.getExplicitHibernateTypeName();
|
||||||
|
if ( StringHelper.isEmpty( resolvedTypeName ) ) {
|
||||||
|
return EmptyHibernateTypeSource.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new HibernateTypeSource() {
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return resolvedTypeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> getParameters() {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JavaTypeDescriptor getJavaType() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ColumnSource getColumnSource() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HibernateTypeSource getTypeInformation() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getGeneratorName() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class EmptyHibernateTypeSource implements HibernateTypeSource {
|
||||||
|
/**
|
||||||
|
* Singleton access
|
||||||
|
*/
|
||||||
|
public static final EmptyHibernateTypeSource INSTANCE = new EmptyHibernateTypeSource();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> getParameters() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JavaTypeDescriptor getJavaType() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,7 @@ import org.hibernate.metamodel.source.internal.annotations.attribute.SingularAtt
|
||||||
import org.hibernate.metamodel.source.spi.HibernateTypeSource;
|
import org.hibernate.metamodel.source.spi.HibernateTypeSource;
|
||||||
import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
||||||
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
import static org.hibernate.metamodel.spi.binding.SingularAttributeBinding.NaturalIdMutability;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
|
|
|
@ -43,7 +43,7 @@ import org.hibernate.metamodel.source.internal.annotations.entity.ManagedTypeMet
|
||||||
import org.hibernate.metamodel.source.internal.annotations.entity.MappedSuperclassTypeMetadata;
|
import org.hibernate.metamodel.source.internal.annotations.entity.MappedSuperclassTypeMetadata;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.entity.RootEntityTypeMetadata;
|
import org.hibernate.metamodel.source.internal.annotations.entity.RootEntityTypeMetadata;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSource;
|
import org.hibernate.metamodel.source.spi.AttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.ComponentAttributeSource;
|
import org.hibernate.metamodel.source.spi.EmbeddedAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.PluralAttributeSource;
|
import org.hibernate.metamodel.source.spi.PluralAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.ToOneAttributeSource;
|
import org.hibernate.metamodel.source.spi.ToOneAttributeSource;
|
||||||
|
@ -57,7 +57,7 @@ import org.hibernate.metamodel.source.spi.ToOneAttributeSource;
|
||||||
public class SourceHelper {
|
public class SourceHelper {
|
||||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( SourceHelper.class );
|
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( SourceHelper.class );
|
||||||
|
|
||||||
// todo : the walking supers bits here is do to the total lack of understanding of MappedSuperclasses in Binder...
|
// todo : the walking supers bits here is due to the total lack of understanding of MappedSuperclasses in Binder...
|
||||||
|
|
||||||
public static List<AttributeSource> buildAttributeSources(
|
public static List<AttributeSource> buildAttributeSources(
|
||||||
ManagedTypeMetadata managedTypeMetadata,
|
ManagedTypeMetadata managedTypeMetadata,
|
||||||
|
@ -241,7 +241,7 @@ public class SourceHelper {
|
||||||
BasicAttribute attribute,
|
BasicAttribute attribute,
|
||||||
OverrideAndConverterCollector overrideAndConverterCollector);
|
OverrideAndConverterCollector overrideAndConverterCollector);
|
||||||
|
|
||||||
public ComponentAttributeSource buildEmbeddedAttribute(
|
public EmbeddedAttributeSource buildEmbeddedAttribute(
|
||||||
EmbeddedAttribute attribute,
|
EmbeddedAttribute attribute,
|
||||||
OverrideAndConverterCollector overrideAndConverterCollector);
|
OverrideAndConverterCollector overrideAndConverterCollector);
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ public class SourceHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ComponentAttributeSource buildEmbeddedAttribute(
|
public EmbeddedAttributeSource buildEmbeddedAttribute(
|
||||||
EmbeddedAttribute attribute,
|
EmbeddedAttribute attribute,
|
||||||
OverrideAndConverterCollector overrideAndConverterCollector) {
|
OverrideAndConverterCollector overrideAndConverterCollector) {
|
||||||
return new EmbeddedAttributeSourceImpl( attribute, false, false );
|
return new EmbeddedAttributeSourceImpl( attribute, false, false );
|
||||||
|
@ -304,10 +304,15 @@ public class SourceHelper {
|
||||||
case SET: {
|
case SET: {
|
||||||
return new PluralAttributeSourceImpl( attribute, overrideAndConverterCollector );
|
return new PluralAttributeSourceImpl( attribute, overrideAndConverterCollector );
|
||||||
}
|
}
|
||||||
|
case ID_BAG: {
|
||||||
|
return new PluralAttributeIdBagSourceImpl( attribute, overrideAndConverterCollector );
|
||||||
|
}
|
||||||
|
case MAP: {
|
||||||
|
return new PluralAttributeMapSourceImpl( attribute, overrideAndConverterCollector );
|
||||||
|
}
|
||||||
case ARRAY:
|
case ARRAY:
|
||||||
case MAP:
|
|
||||||
case LIST: {
|
case LIST: {
|
||||||
return new IndexedPluralAttributeSourceImpl( attribute, overrideAndConverterCollector );
|
return new PluralAttributeIndexedSourceImpl( attribute, overrideAndConverterCollector );
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
throw new AssertionFailure(
|
throw new AssertionFailure(
|
||||||
|
@ -343,7 +348,7 @@ public class SourceHelper {
|
||||||
public static final PluralAttributesDisallowedAttributeBuilder INSTANCE = new PluralAttributesDisallowedAttributeBuilder();
|
public static final PluralAttributesDisallowedAttributeBuilder INSTANCE = new PluralAttributesDisallowedAttributeBuilder();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ComponentAttributeSource buildEmbeddedAttribute(
|
public EmbeddedAttributeSource buildEmbeddedAttribute(
|
||||||
EmbeddedAttribute attribute,
|
EmbeddedAttribute attribute,
|
||||||
OverrideAndConverterCollector overrideAndConverterCollector) {
|
OverrideAndConverterCollector overrideAndConverterCollector) {
|
||||||
return new EmbeddedAttributeSourceImpl( attribute, false, true );
|
return new EmbeddedAttributeSourceImpl( attribute, false, true );
|
||||||
|
@ -402,7 +407,7 @@ public class SourceHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ComponentAttributeSource buildEmbeddedAttribute(
|
public EmbeddedAttributeSource buildEmbeddedAttribute(
|
||||||
EmbeddedAttribute attribute,
|
EmbeddedAttribute attribute,
|
||||||
OverrideAndConverterCollector overrideAndConverterCollector) {
|
OverrideAndConverterCollector overrideAndConverterCollector) {
|
||||||
return new EmbeddedAttributeSourceImpl( attribute, true, false );
|
return new EmbeddedAttributeSourceImpl( attribute, true, false );
|
||||||
|
|
|
@ -46,10 +46,14 @@ import org.hibernate.metamodel.source.spi.AttributeSourceResolutionContext;
|
||||||
import org.hibernate.metamodel.source.spi.ForeignKeyContributingSource;
|
import org.hibernate.metamodel.source.spi.ForeignKeyContributingSource;
|
||||||
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
||||||
import org.hibernate.metamodel.source.spi.ToOneAttributeSource;
|
import org.hibernate.metamodel.source.spi.ToOneAttributeSource;
|
||||||
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
|
import org.hibernate.metamodel.spi.SingularAttributeNature;
|
||||||
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding;
|
import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.relational.TableSpecification;
|
import org.hibernate.metamodel.spi.relational.TableSpecification;
|
||||||
import org.hibernate.metamodel.spi.relational.Value;
|
import org.hibernate.metamodel.spi.relational.Value;
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,30 +87,30 @@ public class ToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl i
|
||||||
|
|
||||||
// Need to initialize logicalJoinTableName before determining nature.
|
// Need to initialize logicalJoinTableName before determining nature.
|
||||||
this.containingTableName = resolveContainingTableName( associationAttribute, relationalValueSources );
|
this.containingTableName = resolveContainingTableName( associationAttribute, relationalValueSources );
|
||||||
setNature( determineNatureIfPossible( associationAttribute ) );
|
setSingularAttributeNature( determineNatureIfPossible( associationAttribute ) );
|
||||||
this.foreignKeyDelegate = new ForeignKeyDelegate(
|
this.foreignKeyDelegate = new ForeignKeyDelegate(
|
||||||
associationAttribute().getBackingMember().getAnnotations(), cls);
|
associationAttribute().getBackingMember().getAnnotations(), cls);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Nature determineNatureIfPossible(
|
private SingularAttributeNature determineNatureIfPossible(
|
||||||
SingularAssociationAttribute associationAttribute) {
|
SingularAssociationAttribute associationAttribute) {
|
||||||
if ( AbstractPersistentAttribute.Nature.MANY_TO_ONE.equals( associationAttribute.getNature() ) ) {
|
if ( AbstractPersistentAttribute.Nature.MANY_TO_ONE.equals( associationAttribute.getNature() ) ) {
|
||||||
return Nature.MANY_TO_ONE;
|
return SingularAttributeNature.MANY_TO_ONE;
|
||||||
}
|
}
|
||||||
else if ( AbstractPersistentAttribute.Nature.ONE_TO_ONE.equals( associationAttribute.getNature() ) ) {
|
else if ( AbstractPersistentAttribute.Nature.ONE_TO_ONE.equals( associationAttribute.getNature() ) ) {
|
||||||
if ( getContainingTableName() != null ) {
|
if ( getContainingTableName() != null ) {
|
||||||
return Nature.MANY_TO_ONE;
|
return SingularAttributeNature.MANY_TO_ONE;
|
||||||
}
|
}
|
||||||
else if ( associationAttribute.hasPrimaryKeyJoinColumn() ) {
|
else if ( associationAttribute.hasPrimaryKeyJoinColumn() ) {
|
||||||
return Nature.ONE_TO_ONE;
|
return SingularAttributeNature.ONE_TO_ONE;
|
||||||
}
|
}
|
||||||
else if ( associationAttribute.isId() ) {
|
else if ( associationAttribute.isId() ) {
|
||||||
// if this association is part of the ID then this can't be a one-to-one
|
// if this association is part of the ID then this can't be a one-to-one
|
||||||
return Nature.MANY_TO_ONE;
|
return SingularAttributeNature.MANY_TO_ONE;
|
||||||
}
|
}
|
||||||
else if ( associationAttribute.getJoinColumnValues() == null ||
|
else if ( associationAttribute.getJoinColumnValues() == null ||
|
||||||
associationAttribute.getJoinColumnValues().isEmpty() ) {
|
associationAttribute.getJoinColumnValues().isEmpty() ) {
|
||||||
return Nature.MANY_TO_ONE;
|
return SingularAttributeNature.MANY_TO_ONE;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return null;
|
return null;
|
||||||
|
@ -120,7 +124,7 @@ public class ToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl i
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resolveToOneAttributeSource(AttributeSourceResolutionContext context) {
|
public void resolveToOneAttributeSource(AttributeSourceResolutionContext context) {
|
||||||
if ( getNature() != null ) {
|
if ( getSingularAttributeNature() != null ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// It would be nice to have the following block in determineNatureIfPossible(),
|
// It would be nice to have the following block in determineNatureIfPossible(),
|
||||||
|
@ -128,7 +132,7 @@ public class ToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl i
|
||||||
if ( AbstractPersistentAttribute.Nature.ONE_TO_ONE.equals( associationAttribute().getNature() ) ) {
|
if ( AbstractPersistentAttribute.Nature.ONE_TO_ONE.equals( associationAttribute().getNature() ) ) {
|
||||||
final List<org.hibernate.metamodel.spi.relational.Column> idColumns = context.resolveIdentifierColumns();
|
final List<org.hibernate.metamodel.spi.relational.Column> idColumns = context.resolveIdentifierColumns();
|
||||||
if ( associationAttribute().getJoinColumnValues().size() != idColumns.size() ) {
|
if ( associationAttribute().getJoinColumnValues().size() != idColumns.size() ) {
|
||||||
setNature( Nature.MANY_TO_ONE );
|
setSingularAttributeNature( SingularAttributeNature.MANY_TO_ONE );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Set<String> joinColumnNames = new HashSet<String>( associationAttribute().getJoinColumnValues().size() );
|
Set<String> joinColumnNames = new HashSet<String>( associationAttribute().getJoinColumnValues().size() );
|
||||||
|
@ -143,23 +147,29 @@ public class ToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl i
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setNature( areJoinColumnsSameAsIdColumns ? Nature.ONE_TO_ONE : Nature.MANY_TO_ONE );
|
setSingularAttributeNature(
|
||||||
|
areJoinColumnsSameAsIdColumns ?
|
||||||
|
SingularAttributeNature.ONE_TO_ONE :
|
||||||
|
SingularAttributeNature.MANY_TO_ONE
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( getNature() == null ) {
|
if ( getSingularAttributeNature() == null ) {
|
||||||
throw new NotYetImplementedException( "unknown type of to-one attribute." );
|
throw new NotYetImplementedException( "unknown type of to-one attribute." );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Binder.DefaultNamingStrategy> getDefaultNamingStrategies(
|
public List<Binder.DefaultNamingStrategy> getDefaultNamingStrategies(
|
||||||
final String entityName, final String tableName, final AttributeBinding referencedAttributeBinding) {
|
final String entityName,
|
||||||
if ( CompositeAttributeBinding.class.isInstance( referencedAttributeBinding ) ) {
|
final String tableName,
|
||||||
CompositeAttributeBinding compositeAttributeBinding = CompositeAttributeBinding.class.cast(
|
final AttributeBinding referencedAttributeBinding) {
|
||||||
|
if ( EmbeddedAttributeBinding.class.isInstance( referencedAttributeBinding ) ) {
|
||||||
|
EmbeddedAttributeBinding embeddedAttributeBinding = EmbeddedAttributeBinding.class.cast(
|
||||||
referencedAttributeBinding
|
referencedAttributeBinding
|
||||||
);
|
);
|
||||||
List<Binder.DefaultNamingStrategy> result = new ArrayList<Binder.DefaultNamingStrategy>( );
|
List<Binder.DefaultNamingStrategy> result = new ArrayList<Binder.DefaultNamingStrategy>( );
|
||||||
for ( final AttributeBinding attributeBinding : compositeAttributeBinding.attributeBindings() ) {
|
for ( final AttributeBinding attributeBinding : embeddedAttributeBinding.getEmbeddableBinding().attributeBindings() ) {
|
||||||
result.addAll( getDefaultNamingStrategies( entityName, tableName, attributeBinding ) );
|
result.addAll( getDefaultNamingStrategies( entityName, tableName, attributeBinding ) );
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -281,6 +291,16 @@ public class ToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl i
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributePath getAttributePath() {
|
||||||
|
return getAnnotatedAttribute().getPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributeRole getAttributeRole() {
|
||||||
|
return getAnnotatedAttribute().getRole();
|
||||||
|
}
|
||||||
|
|
||||||
public class AnnotationJoinColumnResolutionDelegate
|
public class AnnotationJoinColumnResolutionDelegate
|
||||||
implements ForeignKeyContributingSource.JoinColumnResolutionDelegate {
|
implements ForeignKeyContributingSource.JoinColumnResolutionDelegate {
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.hibernate.metamodel.source.spi.AttributeSourceResolutionContext;
|
||||||
import org.hibernate.metamodel.source.spi.MappedByAssociationSource;
|
import org.hibernate.metamodel.source.spi.MappedByAssociationSource;
|
||||||
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
||||||
import org.hibernate.metamodel.source.spi.ToOneAttributeSource;
|
import org.hibernate.metamodel.source.spi.ToOneAttributeSource;
|
||||||
|
import org.hibernate.metamodel.spi.SingularAttributeNature;
|
||||||
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,7 +63,7 @@ public class ToOneMappedByAttributeSourceImpl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resolveToOneAttributeSource(AttributeSourceResolutionContext context) {
|
public void resolveToOneAttributeSource(AttributeSourceResolutionContext context) {
|
||||||
if ( getNature() != null && owner != null) {
|
if ( getSingularAttributeNature() != null && owner != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( owner == null ) {
|
if ( owner == null ) {
|
||||||
|
@ -72,17 +73,17 @@ public class ToOneMappedByAttributeSourceImpl
|
||||||
);
|
);
|
||||||
owner.addMappedByAssociationSource( this );
|
owner.addMappedByAssociationSource( this );
|
||||||
}
|
}
|
||||||
if ( getNature() == null ) {
|
if ( getSingularAttributeNature() == null ) {
|
||||||
final Nature nature;
|
final SingularAttributeNature singularAttributeNature;
|
||||||
if ( AbstractPersistentAttribute.Nature.MANY_TO_ONE.equals( associationAttribute().getNature() ) ) {
|
if ( AbstractPersistentAttribute.Nature.MANY_TO_ONE.equals( associationAttribute().getNature() ) ) {
|
||||||
nature = Nature.MANY_TO_ONE;
|
singularAttributeNature = SingularAttributeNature.MANY_TO_ONE;
|
||||||
}
|
}
|
||||||
else if ( AbstractPersistentAttribute.Nature.ONE_TO_ONE.equals( associationAttribute().getNature() ) ) {
|
else if ( AbstractPersistentAttribute.Nature.ONE_TO_ONE.equals( associationAttribute().getNature() ) ) {
|
||||||
if ( owner.getContainingTableName() != null ) {
|
if ( owner.getContainingTableName() != null ) {
|
||||||
nature = Nature.MANY_TO_ONE;
|
singularAttributeNature = SingularAttributeNature.MANY_TO_ONE;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
nature = Nature.ONE_TO_ONE;
|
singularAttributeNature = SingularAttributeNature.ONE_TO_ONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -91,7 +92,7 @@ public class ToOneMappedByAttributeSourceImpl
|
||||||
associationAttribute().getNature(), associationAttribute().getRole()
|
associationAttribute().getNature(), associationAttribute().getRole()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
setNature( nature );
|
setSingularAttributeNature( singularAttributeNature );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,7 @@ package org.hibernate.metamodel.source.internal.annotations;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.BasicAttribute;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.BasicAttribute;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.OverrideAndConverterCollector;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.OverrideAndConverterCollector;
|
||||||
import org.hibernate.metamodel.source.spi.VersionAttributeSource;
|
import org.hibernate.metamodel.source.spi.VersionAttributeSource;
|
||||||
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
import static org.hibernate.metamodel.spi.binding.SingularAttributeBinding.NaturalIdMutability;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
|
|
|
@ -38,14 +38,13 @@ import org.hibernate.metamodel.source.internal.annotations.util.AnnotationParser
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper;
|
import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper;
|
||||||
import org.hibernate.metamodel.source.spi.AttributePath;
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeRole;
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
import org.jboss.jandex.AnnotationValue;
|
import org.jboss.jandex.AnnotationValue;
|
||||||
|
|
||||||
import static org.hibernate.metamodel.spi.binding.SingularAttributeBinding.NaturalIdMutability;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for the different types of persistent attributes
|
* Base class for the different types of persistent attributes
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.metamodel.source.internal.annotations.attribute;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
||||||
|
import org.hibernate.metamodel.reflite.spi.MemberDescriptor;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.attribute.type.AttributeTypeResolver;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.attribute.type.AttributeTypeResolverComposition;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.attribute.type.EnumeratedTypeResolver;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.attribute.type.HibernateTypeResolver;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.attribute.type.TemporalTypeResolver;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PluralAttributeIndexDetails implementation for describing the key of a Map
|
||||||
|
*
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public abstract class AbstractPluralAttributeIndexDetailsMapKey implements PluralAttributeIndexDetails {
|
||||||
|
private final PluralAttribute pluralAttribute;
|
||||||
|
private final JavaTypeDescriptor resolvedMapKeyType;
|
||||||
|
private final AttributeTypeResolver typeResolver;
|
||||||
|
|
||||||
|
public AbstractPluralAttributeIndexDetailsMapKey(
|
||||||
|
PluralAttribute pluralAttribute,
|
||||||
|
MemberDescriptor backingMember,
|
||||||
|
JavaTypeDescriptor resolvedMapKeyType) {
|
||||||
|
this.pluralAttribute = pluralAttribute;
|
||||||
|
this.resolvedMapKeyType = resolvedMapKeyType;
|
||||||
|
|
||||||
|
this.typeResolver = new AttributeTypeResolverComposition(
|
||||||
|
resolvedMapKeyType,
|
||||||
|
pluralAttribute.getContext(),
|
||||||
|
HibernateTypeResolver.createCollectionIndexTypeResolver( pluralAttribute, resolvedMapKeyType ),
|
||||||
|
EnumeratedTypeResolver.createCollectionIndexTypeResolver( pluralAttribute, resolvedMapKeyType ),
|
||||||
|
TemporalTypeResolver.createCollectionIndexTypeResolver( pluralAttribute, resolvedMapKeyType )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JavaTypeDescriptor getJavaType() {
|
||||||
|
return resolvedMapKeyType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributeTypeResolver getTypeResolver() {
|
||||||
|
return typeResolver;
|
||||||
|
}
|
||||||
|
}
|
|
@ -32,9 +32,10 @@ import org.hibernate.metamodel.source.internal.annotations.entity.ManagedTypeMet
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.ConverterAndOverridesHelper;
|
import org.hibernate.metamodel.source.internal.annotations.util.ConverterAndOverridesHelper;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
||||||
import org.hibernate.metamodel.source.spi.AttributePath;
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeRole;
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -176,7 +177,7 @@ public abstract class AbstractSingularAttribute
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SingularAttributeBinding.NaturalIdMutability getNaturalIdMutability() {
|
public NaturalIdMutability getNaturalIdMutability() {
|
||||||
return super.getNaturalIdMutability();
|
return super.getNaturalIdMutability();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,10 +48,10 @@ import org.hibernate.metamodel.source.internal.annotations.util.EnumConversionHe
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper;
|
import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper;
|
||||||
import org.hibernate.metamodel.source.spi.AttributePath;
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeRole;
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
import org.hibernate.metamodel.spi.binding.IdentifierGeneratorDefinition;
|
import org.hibernate.metamodel.spi.binding.IdentifierGeneratorDefinition;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
import org.jboss.jandex.AnnotationValue;
|
import org.jboss.jandex.AnnotationValue;
|
||||||
|
@ -164,7 +164,7 @@ public class BasicAttribute extends AbstractSingularAttribute {
|
||||||
this.propertyGeneration = propertyGeneration;
|
this.propertyGeneration = propertyGeneration;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( getNaturalIdMutability() == SingularAttributeBinding.NaturalIdMutability.IMMUTABLE ) {
|
if ( getNaturalIdMutability() == NaturalIdMutability.IMMUTABLE ) {
|
||||||
this.updateability.disable();
|
this.updateability.disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,9 +34,9 @@ import org.hibernate.metamodel.source.internal.annotations.attribute.type.Hibern
|
||||||
import org.hibernate.metamodel.source.internal.annotations.entity.EmbeddableTypeMetadata;
|
import org.hibernate.metamodel.source.internal.annotations.entity.EmbeddableTypeMetadata;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.entity.ManagedTypeMetadata;
|
import org.hibernate.metamodel.source.internal.annotations.entity.ManagedTypeMetadata;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
||||||
import org.hibernate.metamodel.source.spi.AttributePath;
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeRole;
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ public class EmbeddedAttribute extends AbstractSingularAttribute implements Embe
|
||||||
updateability.disable();
|
updateability.disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( getNaturalIdMutability() == SingularAttributeBinding.NaturalIdMutability.IMMUTABLE ) {
|
if ( getNaturalIdMutability() == NaturalIdMutability.IMMUTABLE ) {
|
||||||
updateability.disable();
|
updateability.disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ public class EmbeddedAttribute extends AbstractSingularAttribute implements Embe
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SingularAttributeBinding.NaturalIdMutability getContainerNaturalIdMutability() {
|
public NaturalIdMutability getContainerNaturalIdMutability() {
|
||||||
return super.getNaturalIdMutability();
|
return super.getNaturalIdMutability();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,8 @@ package org.hibernate.metamodel.source.internal.annotations.attribute;
|
||||||
|
|
||||||
import org.hibernate.metamodel.reflite.spi.MemberDescriptor;
|
import org.hibernate.metamodel.reflite.spi.MemberDescriptor;
|
||||||
import org.hibernate.metamodel.source.internal.AttributeConversionInfo;
|
import org.hibernate.metamodel.source.internal.AttributeConversionInfo;
|
||||||
import org.hibernate.metamodel.source.spi.AttributePath;
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the container of an embedded value. Acts as the container for
|
* Defines the container of an embedded value. Acts as the container for
|
||||||
|
@ -43,7 +43,7 @@ public interface EmbeddedContainer extends OverrideAndConverterCollector {
|
||||||
|
|
||||||
public AssociationOverride locateAssociationOverride(AttributePath attributePath);
|
public AssociationOverride locateAssociationOverride(AttributePath attributePath);
|
||||||
|
|
||||||
public SingularAttributeBinding.NaturalIdMutability getContainerNaturalIdMutability();
|
public NaturalIdMutability getContainerNaturalIdMutability();
|
||||||
|
|
||||||
boolean getContainerOptionality();
|
boolean getContainerOptionality();
|
||||||
boolean getContainerUpdatability();
|
boolean getContainerUpdatability();
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
package org.hibernate.metamodel.source.internal.annotations.attribute;
|
package org.hibernate.metamodel.source.internal.annotations.attribute;
|
||||||
|
|
||||||
import org.hibernate.metamodel.source.internal.AttributeConversionInfo;
|
import org.hibernate.metamodel.source.internal.AttributeConversionInfo;
|
||||||
import org.hibernate.metamodel.source.spi.AttributePath;
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contract used in normalizing AttributeConverters, AttributeOverrides and
|
* Contract used in normalizing AttributeConverters, AttributeOverrides and
|
||||||
|
|
|
@ -32,8 +32,8 @@ import org.hibernate.metamodel.source.internal.annotations.entity.EntityBindingC
|
||||||
import org.hibernate.metamodel.source.internal.annotations.entity.ManagedTypeMetadata;
|
import org.hibernate.metamodel.source.internal.annotations.entity.ManagedTypeMetadata;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
||||||
import org.hibernate.metamodel.source.spi.AttributePath;
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeRole;
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
|
|
||||||
import org.jboss.jandex.DotName;
|
import org.jboss.jandex.DotName;
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
package org.hibernate.metamodel.source.internal.annotations.attribute;
|
package org.hibernate.metamodel.source.internal.annotations.attribute;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -31,7 +32,6 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
|
||||||
import javax.persistence.AccessType;
|
import javax.persistence.AccessType;
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
|
|
||||||
|
@ -59,17 +59,32 @@ import org.hibernate.metamodel.source.internal.annotations.util.ConverterAndOver
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper;
|
import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper;
|
||||||
import org.hibernate.metamodel.source.spi.AttributePath;
|
|
||||||
import org.hibernate.metamodel.source.spi.AttributeRole;
|
|
||||||
import org.hibernate.metamodel.source.spi.MappingException;
|
import org.hibernate.metamodel.source.spi.MappingException;
|
||||||
import org.hibernate.metamodel.source.spi.PluralAttributeSource;
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeNature;
|
||||||
import org.hibernate.metamodel.spi.binding.Caching;
|
import org.hibernate.metamodel.spi.binding.Caching;
|
||||||
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
||||||
import org.hibernate.metamodel.spi.binding.IdentifierGeneratorDefinition;
|
import org.hibernate.metamodel.spi.binding.IdentifierGeneratorDefinition;
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
import org.jboss.jandex.AnnotationValue;
|
import org.jboss.jandex.AnnotationValue;
|
||||||
import org.jboss.jandex.DotName;
|
import org.jboss.jandex.DotName;
|
||||||
|
|
||||||
|
import static org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames.LOADER;
|
||||||
|
import static org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames.ON_DELETE;
|
||||||
|
import static org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames.PERSISTER;
|
||||||
|
import static org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames.WHERE;
|
||||||
|
import static org.hibernate.metamodel.source.internal.annotations.util.JPADotNames.EMBEDDABLE;
|
||||||
|
import static org.hibernate.metamodel.source.internal.annotations.util.JPADotNames.ENTITY;
|
||||||
|
import static org.hibernate.metamodel.source.internal.annotations.util.JPADotNames.MAP_KEY;
|
||||||
|
import static org.hibernate.metamodel.source.internal.annotations.util.JPADotNames.MAP_KEY_CLASS;
|
||||||
|
import static org.hibernate.metamodel.source.internal.annotations.util.JPADotNames.MAP_KEY_COLUMN;
|
||||||
|
import static org.hibernate.metamodel.source.internal.annotations.util.JPADotNames.MAP_KEY_ENUMERATED;
|
||||||
|
import static org.hibernate.metamodel.source.internal.annotations.util.JPADotNames.MAP_KEY_TEMPORAL;
|
||||||
|
import static org.hibernate.metamodel.source.internal.annotations.util.JPADotNames.ORDER_BY;
|
||||||
|
import static org.hibernate.metamodel.source.internal.annotations.util.JPADotNames.ORDER_COLUMN;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a plural persistent attribute.
|
* Represents a plural persistent attribute.
|
||||||
*
|
*
|
||||||
|
@ -80,11 +95,11 @@ import org.jboss.jandex.DotName;
|
||||||
public class PluralAttribute
|
public class PluralAttribute
|
||||||
extends AbstractPersistentAttribute
|
extends AbstractPersistentAttribute
|
||||||
implements FetchableAttribute, AssociationAttribute {
|
implements FetchableAttribute, AssociationAttribute {
|
||||||
private static final EnumSet<PluralAttributeSource.Nature> CANNOT_HAVE_COLLECTION_ID = EnumSet.of(
|
private static final EnumSet<PluralAttributeNature> CANNOT_HAVE_COLLECTION_ID = EnumSet.of(
|
||||||
PluralAttributeSource.Nature.SET,
|
PluralAttributeNature.SET,
|
||||||
PluralAttributeSource.Nature.MAP,
|
PluralAttributeNature.MAP,
|
||||||
PluralAttributeSource.Nature.LIST,
|
PluralAttributeNature.LIST,
|
||||||
PluralAttributeSource.Nature.ARRAY
|
PluralAttributeNature.ARRAY
|
||||||
);
|
);
|
||||||
|
|
||||||
private final String mappedByAttributeName;
|
private final String mappedByAttributeName;
|
||||||
|
@ -100,7 +115,7 @@ public class PluralAttribute
|
||||||
|
|
||||||
// information about the collection
|
// information about the collection
|
||||||
private final CollectionIdInformation collectionIdInformation;
|
private final CollectionIdInformation collectionIdInformation;
|
||||||
private final PluralAttributeSource.Nature pluralAttributeNature;
|
private final PluralAttributeNature pluralAttributeNature;
|
||||||
private final String customPersister;
|
private final String customPersister;
|
||||||
private final Caching caching;
|
private final Caching caching;
|
||||||
private final String comparatorName;
|
private final String comparatorName;
|
||||||
|
@ -357,7 +372,7 @@ public class PluralAttribute
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private PluralAttributeSource.Nature resolvePluralAttributeNature(
|
private PluralAttributeNature resolvePluralAttributeNature(
|
||||||
MemberDescriptor backingMember,
|
MemberDescriptor backingMember,
|
||||||
CollectionIdInformation collectionIdInformation) {
|
CollectionIdInformation collectionIdInformation) {
|
||||||
//TODO org.hibernate.cfg.annotations.CollectionBinder#hasToBeSorted
|
//TODO org.hibernate.cfg.annotations.CollectionBinder#hasToBeSorted
|
||||||
|
@ -365,21 +380,21 @@ public class PluralAttribute
|
||||||
final JavaTypeDescriptor pluralType = backingMember.getType().getErasedType();
|
final JavaTypeDescriptor pluralType = backingMember.getType().getErasedType();
|
||||||
|
|
||||||
if ( ArrayDescriptor.class.isInstance( pluralType ) ) {
|
if ( ArrayDescriptor.class.isInstance( pluralType ) ) {
|
||||||
return PluralAttributeSource.Nature.ARRAY;
|
return PluralAttributeNature.ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( getContext().getJavaTypeDescriptorRepository().jdkMapDescriptor().isAssignableFrom( pluralType ) ) {
|
if ( getContext().getJavaTypeDescriptorRepository().jdkMapDescriptor().isAssignableFrom( pluralType ) ) {
|
||||||
return PluralAttributeSource.Nature.MAP;
|
return PluralAttributeNature.MAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( getContext().getJavaTypeDescriptorRepository().jdkSetDescriptor().isAssignableFrom( pluralType ) ) {
|
if ( getContext().getJavaTypeDescriptorRepository().jdkSetDescriptor().isAssignableFrom( pluralType ) ) {
|
||||||
return PluralAttributeSource.Nature.SET;
|
return PluralAttributeNature.SET;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( getContext().getJavaTypeDescriptorRepository().jdkListDescriptor().isAssignableFrom( pluralType ) ) {
|
if ( getContext().getJavaTypeDescriptorRepository().jdkListDescriptor().isAssignableFrom( pluralType ) ) {
|
||||||
// we have a LIST nature as long as there is an @OrderColumn annotation
|
// we have a LIST nature as long as there is an @OrderColumn annotation
|
||||||
if ( backingMember.getAnnotations().containsKey( JPADotNames.ORDER_COLUMN ) ) {
|
if ( backingMember.getAnnotations().containsKey( ORDER_COLUMN ) ) {
|
||||||
return PluralAttributeSource.Nature.LIST;
|
return PluralAttributeNature.LIST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,8 +410,8 @@ public class PluralAttribute
|
||||||
|
|
||||||
// todo : does ID_BAG really need a separate nature?
|
// todo : does ID_BAG really need a separate nature?
|
||||||
return collectionIdInformation != null
|
return collectionIdInformation != null
|
||||||
? PluralAttributeSource.Nature.ID_BAG
|
? PluralAttributeNature.ID_BAG
|
||||||
: PluralAttributeSource.Nature.BAG;
|
: PluralAttributeNature.BAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PluralAttributeElementDetails resolveElementDetails(
|
private PluralAttributeElementDetails resolveElementDetails(
|
||||||
|
@ -427,28 +442,129 @@ public class PluralAttribute
|
||||||
|
|
||||||
private PluralAttributeIndexDetails resolveIndexDetails(
|
private PluralAttributeIndexDetails resolveIndexDetails(
|
||||||
MemberDescriptor backingMember,
|
MemberDescriptor backingMember,
|
||||||
PluralAttributeSource.Nature pluralAttributeNature,
|
PluralAttributeNature pluralAttributeNature,
|
||||||
JavaTypeDescriptor indexType) {
|
JavaTypeDescriptor indexType) {
|
||||||
// could be an array/list
|
// could be an array/list
|
||||||
if ( pluralAttributeNature == PluralAttributeSource.Nature.ARRAY
|
if ( pluralAttributeNature == PluralAttributeNature.ARRAY
|
||||||
|| pluralAttributeNature == PluralAttributeSource.Nature.LIST ) {
|
|| pluralAttributeNature == PluralAttributeNature.LIST ) {
|
||||||
return new PluralAttributeSequentialIndexDetails( this, backingMember );
|
return new PluralAttributeIndexDetailsSequential( this, backingMember );
|
||||||
}
|
}
|
||||||
|
|
||||||
// or a map
|
// or a map
|
||||||
if ( pluralAttributeNature != PluralAttributeSource.Nature.MAP ) {
|
if ( pluralAttributeNature != PluralAttributeNature.MAP ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new PluralAttributeMapKeyDetails( this, backingMember, indexType );
|
final AnnotationInstance mapKeyAnnotation = backingMember.getAnnotations().get( MAP_KEY );
|
||||||
|
final AnnotationInstance mapKeyClassAnnotation = backingMember.getAnnotations().get( MAP_KEY_CLASS );
|
||||||
|
final AnnotationInstance mapKeyColumnAnnotation = backingMember.getAnnotations().get( MAP_KEY_COLUMN );
|
||||||
|
final AnnotationInstance mapKeyEnumeratedAnnotation = backingMember.getAnnotations().get( MAP_KEY_ENUMERATED );
|
||||||
|
final AnnotationInstance mapKeyTemporalAnnotation = backingMember.getAnnotations().get( MAP_KEY_TEMPORAL );
|
||||||
|
|
||||||
|
final List<AnnotationInstance> mapKeyJoinColumnAnnotations = collectMapKeyJoinColumnAnnotations( backingMember );
|
||||||
|
|
||||||
|
if ( mapKeyAnnotation != null && mapKeyClassAnnotation != null ) {
|
||||||
|
// this is an error according to the spec...
|
||||||
|
throw getContext().makeMappingException(
|
||||||
|
"Map attribute defined both @MapKey and @MapKeyClass; only one should be used : " +
|
||||||
|
backingMember.toLoggableForm()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// Level 1 : @MapKey
|
||||||
|
|
||||||
|
if ( mapKeyAnnotation != null ) {
|
||||||
|
final AnnotationValue value = mapKeyAnnotation.value( "name" );
|
||||||
|
String mapKeyAttributeName = null;
|
||||||
|
if ( value != null ) {
|
||||||
|
mapKeyAttributeName = StringHelper.nullIfEmpty( value.asString() );
|
||||||
|
}
|
||||||
|
return new PluralAttributeIndexDetailsMapKeyEntityAttribute( this, backingMember, indexType, mapKeyAttributeName );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// Level 2 : @MapKeyEnumerated / @MapKeyTemporal imply basic key
|
||||||
|
|
||||||
|
if ( mapKeyEnumeratedAnnotation != null || mapKeyTemporalAnnotation != null ) {
|
||||||
|
return new PluralAttributeIndexDetailsMapKeyBasic( this, backingMember, indexType, mapKeyColumnAnnotation );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// Level 3 : if we could not decode a specific key type, we assume basic
|
||||||
|
|
||||||
|
JavaTypeDescriptor mapKeyType = indexType;
|
||||||
|
if ( mapKeyClassAnnotation != null ) {
|
||||||
|
final DotName name = mapKeyClassAnnotation.value().asClass().name();
|
||||||
|
mapKeyType = getContext().getJavaTypeDescriptorRepository().getType( name );
|
||||||
|
}
|
||||||
|
if ( mapKeyType == null ) {
|
||||||
|
if ( !mapKeyJoinColumnAnnotations.isEmpty() ) {
|
||||||
|
throw getContext().makeMappingException(
|
||||||
|
"Map key type could not be resolved (to determine entity name to use as key), " +
|
||||||
|
"but @MapKeyJoinColumn(s) was present. Map should either use generics or " +
|
||||||
|
"use @MapKeyClass to specify entity class"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return new PluralAttributeIndexDetailsMapKeyBasic( this, backingMember, indexType, mapKeyColumnAnnotation );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// Level 4 : if @MapKeyJoinColumn(s) were specified, we have an entity
|
||||||
|
|
||||||
|
if ( !mapKeyJoinColumnAnnotations.isEmpty() ) {
|
||||||
|
throw new NotYetImplementedException( "Entities as map keys not yet implemented" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// Level 5 : if decode the nature of the map key type
|
||||||
|
|
||||||
|
if ( mapKeyType.findTypeAnnotation( EMBEDDABLE ) != null ) {
|
||||||
|
return new PluralAttributeIndexDetailsMapKeyEmbedded( this, backingMember, indexType );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( mapKeyType.findTypeAnnotation( ENTITY ) != null ) {
|
||||||
|
throw new NotYetImplementedException( "Entities as map keys not yet implemented" );
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PluralAttributeIndexDetailsMapKeyBasic( this, backingMember, indexType, mapKeyColumnAnnotation );
|
||||||
}
|
}
|
||||||
|
|
||||||
private JavaTypeDescriptor resolveIndicatedMapKeyClass(AnnotationInstance mapKeyClass) {
|
private List<AnnotationInstance> collectMapKeyJoinColumnAnnotations(MemberDescriptor backingMember) {
|
||||||
final AnnotationValue value = mapKeyClass.value();
|
final AnnotationInstance singular = backingMember.getAnnotations().get( JPADotNames.MAP_KEY_JOIN_COLUMN );
|
||||||
if ( value == null ) {
|
final AnnotationInstance plural = backingMember.getAnnotations().get( JPADotNames.MAP_KEY_JOIN_COLUMNS );
|
||||||
throw new IllegalStateException( "Unexpected null value for @MapKeyClass#value" );
|
|
||||||
|
if ( singular != null && plural != null ) {
|
||||||
|
throw getContext().makeMappingException(
|
||||||
|
"Attribute [" + backingMember.toLoggableForm() +
|
||||||
|
"] declared both @MapKeyJoinColumn and " +
|
||||||
|
"@MapKeyJoinColumns; should only use one or the other"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return getContext().getJavaTypeDescriptorRepository().getType( value.asClass().name() );
|
|
||||||
|
if ( singular == null && plural == null ) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( singular != null ) {
|
||||||
|
return Collections.singletonList( singular );
|
||||||
|
}
|
||||||
|
|
||||||
|
final AnnotationInstance[] annotations = JandexHelper.extractAnnotationsValue(
|
||||||
|
plural,
|
||||||
|
"value"
|
||||||
|
);
|
||||||
|
if ( annotations == null || annotations.length == 0 ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Arrays.asList( annotations );
|
||||||
}
|
}
|
||||||
|
|
||||||
private Caching determineCachingSettings(MemberDescriptor backingMember) {
|
private Caching determineCachingSettings(MemberDescriptor backingMember) {
|
||||||
|
@ -487,14 +603,14 @@ public class PluralAttribute
|
||||||
}
|
}
|
||||||
|
|
||||||
private String determineCustomLoaderName(MemberDescriptor backingMember) {
|
private String determineCustomLoaderName(MemberDescriptor backingMember) {
|
||||||
final AnnotationInstance loaderAnnotation = backingMember.getAnnotations().get( HibernateDotNames.LOADER );
|
final AnnotationInstance loaderAnnotation = backingMember.getAnnotations().get( LOADER );
|
||||||
return loaderAnnotation == null
|
return loaderAnnotation == null
|
||||||
? null
|
? null
|
||||||
: StringHelper.nullIfEmpty( loaderAnnotation.value( "namedQuery" ).asString() );
|
: StringHelper.nullIfEmpty( loaderAnnotation.value( "namedQuery" ).asString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private String determineCustomPersister(MemberDescriptor backingMember) {
|
private String determineCustomPersister(MemberDescriptor backingMember) {
|
||||||
final AnnotationInstance persisterAnnotation = backingMember.getAnnotations().get( HibernateDotNames.PERSISTER );
|
final AnnotationInstance persisterAnnotation = backingMember.getAnnotations().get( PERSISTER );
|
||||||
return persisterAnnotation == null
|
return persisterAnnotation == null
|
||||||
? null
|
? null
|
||||||
: StringHelper.nullIfEmpty( persisterAnnotation.value( "impl" ).asString() );
|
: StringHelper.nullIfEmpty( persisterAnnotation.value( "impl" ).asString() );
|
||||||
|
@ -502,7 +618,7 @@ public class PluralAttribute
|
||||||
|
|
||||||
private OnDeleteAction determineOnDeleteAction(MemberDescriptor backingMember) {
|
private OnDeleteAction determineOnDeleteAction(MemberDescriptor backingMember) {
|
||||||
final AnnotationInstance onDeleteAnnotation = backingMember.getAnnotations().get(
|
final AnnotationInstance onDeleteAnnotation = backingMember.getAnnotations().get(
|
||||||
HibernateDotNames.ON_DELETE
|
ON_DELETE
|
||||||
);
|
);
|
||||||
return onDeleteAnnotation == null
|
return onDeleteAnnotation == null
|
||||||
? null
|
? null
|
||||||
|
@ -510,7 +626,7 @@ public class PluralAttribute
|
||||||
}
|
}
|
||||||
|
|
||||||
private String determineWereClause(MemberDescriptor backingMember) {
|
private String determineWereClause(MemberDescriptor backingMember) {
|
||||||
final AnnotationInstance whereAnnotation = backingMember.getAnnotations().get( HibernateDotNames.WHERE );
|
final AnnotationInstance whereAnnotation = backingMember.getAnnotations().get( WHERE );
|
||||||
return whereAnnotation == null
|
return whereAnnotation == null
|
||||||
? null
|
? null
|
||||||
: StringHelper.nullIfEmpty( whereAnnotation.value( "clause" ).asString() );
|
: StringHelper.nullIfEmpty( whereAnnotation.value( "clause" ).asString() );
|
||||||
|
@ -518,7 +634,7 @@ public class PluralAttribute
|
||||||
|
|
||||||
private String determineOrderBy(MemberDescriptor backingMember) {
|
private String determineOrderBy(MemberDescriptor backingMember) {
|
||||||
final AnnotationInstance hbmOrderBy = backingMember.getAnnotations().get( HibernateDotNames.ORDER_BY );
|
final AnnotationInstance hbmOrderBy = backingMember.getAnnotations().get( HibernateDotNames.ORDER_BY );
|
||||||
final AnnotationInstance jpaOrderBy = backingMember.getAnnotations().get( JPADotNames.ORDER_BY );
|
final AnnotationInstance jpaOrderBy = backingMember.getAnnotations().get( ORDER_BY );
|
||||||
|
|
||||||
if ( hbmOrderBy != null && jpaOrderBy != null ) {
|
if ( hbmOrderBy != null && jpaOrderBy != null ) {
|
||||||
throw getContext().makeMappingException(
|
throw getContext().makeMappingException(
|
||||||
|
@ -569,8 +685,8 @@ public class PluralAttribute
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkSortedTypeIsSortable() {
|
private void checkSortedTypeIsSortable() {
|
||||||
if ( pluralAttributeNature != PluralAttributeSource.Nature.MAP
|
if ( pluralAttributeNature != PluralAttributeNature.MAP
|
||||||
&& pluralAttributeNature != PluralAttributeSource.Nature.SET ) {
|
&& pluralAttributeNature != PluralAttributeNature.SET ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -677,7 +793,7 @@ public class PluralAttribute
|
||||||
return indexDetails;
|
return indexDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluralAttributeSource.Nature getPluralAttributeNature() {
|
public PluralAttributeNature getPluralAttributeNature() {
|
||||||
return pluralAttributeNature;
|
return pluralAttributeNature;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ package org.hibernate.metamodel.source.internal.annotations.attribute;
|
||||||
|
|
||||||
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.type.AttributeTypeResolver;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.type.AttributeTypeResolver;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeElementNature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Presents metadata about the elements of a plural attribute
|
* Presents metadata about the elements of a plural attribute
|
||||||
|
@ -39,6 +40,13 @@ public interface PluralAttributeElementDetails {
|
||||||
*/
|
*/
|
||||||
public JavaTypeDescriptor getJavaType();
|
public JavaTypeDescriptor getJavaType();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the nature of the element values.
|
||||||
|
*
|
||||||
|
* @return The element nature
|
||||||
|
*/
|
||||||
|
public PluralAttributeElementNature getElementNature();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the type resolver for the collection elements.
|
* Get the type resolver for the collection elements.
|
||||||
*
|
*
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.hibernate.metamodel.source.internal.annotations.attribute.type.Hibern
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.type.LobTypeResolver;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.type.LobTypeResolver;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.type.TemporalTypeResolver;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.type.TemporalTypeResolver;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeElementNature;
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
import org.jboss.jandex.AnnotationValue;
|
import org.jboss.jandex.AnnotationValue;
|
||||||
|
@ -93,6 +94,11 @@ public class PluralAttributeElementDetailsBasic implements PluralAttributeElemen
|
||||||
return javaType;
|
return javaType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PluralAttributeElementNature getElementNature() {
|
||||||
|
return PluralAttributeElementNature.BASIC;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AttributeTypeResolver getTypeResolver() {
|
public AttributeTypeResolver getTypeResolver() {
|
||||||
return typeResolver;
|
return typeResolver;
|
||||||
|
|
|
@ -32,8 +32,11 @@ import org.hibernate.metamodel.source.internal.annotations.attribute.type.Attrib
|
||||||
import org.hibernate.metamodel.source.internal.annotations.entity.EmbeddableTypeMetadata;
|
import org.hibernate.metamodel.source.internal.annotations.entity.EmbeddableTypeMetadata;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
||||||
import org.hibernate.metamodel.source.spi.AttributePath;
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeElementNature;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeNature;
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
import org.jboss.jandex.AnnotationValue;
|
import org.jboss.jandex.AnnotationValue;
|
||||||
|
@ -99,12 +102,20 @@ public class PluralAttributeElementDetailsEmbedded implements PluralAttributeEle
|
||||||
}
|
}
|
||||||
|
|
||||||
private EmbeddableTypeMetadata buildEmbeddedMetadata(PluralAttribute pluralAttribute, ClassDescriptor javaType) {
|
private EmbeddableTypeMetadata buildEmbeddedMetadata(PluralAttribute pluralAttribute, ClassDescriptor javaType) {
|
||||||
|
final boolean isMap = pluralAttribute.getPluralAttributeNature() == PluralAttributeNature.MAP;
|
||||||
|
final AttributeRole role = isMap
|
||||||
|
? pluralAttribute.getRole().append( "value" )
|
||||||
|
: pluralAttribute.getRole().append( "element" );
|
||||||
|
final AttributePath path = isMap
|
||||||
|
? pluralAttribute.getPath().append( "value" )
|
||||||
|
: pluralAttribute.getPath();
|
||||||
|
|
||||||
// we pass `this` (as EmbeddedContainer) in order to route calls back properly.
|
// we pass `this` (as EmbeddedContainer) in order to route calls back properly.
|
||||||
return new EmbeddableTypeMetadata(
|
return new EmbeddableTypeMetadata(
|
||||||
javaType,
|
javaType,
|
||||||
this,
|
this,
|
||||||
pluralAttribute.getRole().append( "element" ),
|
role,
|
||||||
pluralAttribute.getPath(),
|
path,
|
||||||
pluralAttribute.getAccessType(),
|
pluralAttribute.getAccessType(),
|
||||||
pluralAttribute.getAccessorStrategy(),
|
pluralAttribute.getAccessorStrategy(),
|
||||||
pluralAttribute.getContext()
|
pluralAttribute.getContext()
|
||||||
|
@ -116,6 +127,11 @@ public class PluralAttributeElementDetailsEmbedded implements PluralAttributeEle
|
||||||
return javaType;
|
return javaType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PluralAttributeElementNature getElementNature() {
|
||||||
|
return PluralAttributeElementNature.AGGREGATE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AttributeTypeResolver getTypeResolver() {
|
public AttributeTypeResolver getTypeResolver() {
|
||||||
return typeResolver;
|
return typeResolver;
|
||||||
|
@ -149,7 +165,7 @@ public class PluralAttributeElementDetailsEmbedded implements PluralAttributeEle
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SingularAttributeBinding.NaturalIdMutability getContainerNaturalIdMutability() {
|
public NaturalIdMutability getContainerNaturalIdMutability() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.type.AttributeTypeResolver;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.type.AttributeTypeResolver;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeElementNature;
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
import org.jboss.jandex.AnnotationValue;
|
import org.jboss.jandex.AnnotationValue;
|
||||||
|
@ -37,6 +38,7 @@ import org.jboss.jandex.AnnotationValue;
|
||||||
*/
|
*/
|
||||||
public class PluralAttributeElementDetailsEntity implements PluralAttributeElementDetails {
|
public class PluralAttributeElementDetailsEntity implements PluralAttributeElementDetails {
|
||||||
private final ClassDescriptor javaType;
|
private final ClassDescriptor javaType;
|
||||||
|
private final PluralAttributeElementNature elementNature;
|
||||||
private final AttributeTypeResolver typeResolver;
|
private final AttributeTypeResolver typeResolver;
|
||||||
|
|
||||||
public PluralAttributeElementDetailsEntity(
|
public PluralAttributeElementDetailsEntity(
|
||||||
|
@ -51,6 +53,7 @@ public class PluralAttributeElementDetailsEntity implements PluralAttributeEleme
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.elementNature = decodeElementNature( pluralAttribute );
|
||||||
this.typeResolver = buildTypeResolver( pluralAttribute, javaType );
|
this.typeResolver = buildTypeResolver( pluralAttribute, javaType );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,6 +102,25 @@ public class PluralAttributeElementDetailsEntity implements PluralAttributeEleme
|
||||||
return (ClassDescriptor) inferredElementType;
|
return (ClassDescriptor) inferredElementType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PluralAttributeElementNature decodeElementNature(PluralAttribute pluralAttribute) {
|
||||||
|
switch ( pluralAttribute.getNature() ) {
|
||||||
|
case MANY_TO_ANY: {
|
||||||
|
return PluralAttributeElementNature.MANY_TO_ANY;
|
||||||
|
}
|
||||||
|
case MANY_TO_MANY: {
|
||||||
|
return PluralAttributeElementNature.MANY_TO_MANY;
|
||||||
|
}
|
||||||
|
case ONE_TO_MANY: {
|
||||||
|
return PluralAttributeElementNature.ONE_TO_MANY;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
throw pluralAttribute.getContext().makeMappingException(
|
||||||
|
"Unexpected plural attribute nature : " + pluralAttribute.getNature()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private AttributeTypeResolver buildTypeResolver(PluralAttribute pluralAttribute, ClassDescriptor javaType) {
|
private AttributeTypeResolver buildTypeResolver(PluralAttribute pluralAttribute, ClassDescriptor javaType) {
|
||||||
// todo : No idea what this should be for entities : return the entity name as type name? return no type name?
|
// todo : No idea what this should be for entities : return the entity name as type name? return no type name?
|
||||||
return null;
|
return null;
|
||||||
|
@ -109,6 +131,11 @@ public class PluralAttributeElementDetailsEntity implements PluralAttributeEleme
|
||||||
return javaType;
|
return javaType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PluralAttributeElementNature getElementNature() {
|
||||||
|
return elementNature;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AttributeTypeResolver getTypeResolver() {
|
public AttributeTypeResolver getTypeResolver() {
|
||||||
return typeResolver;
|
return typeResolver;
|
||||||
|
|
|
@ -25,6 +25,7 @@ package org.hibernate.metamodel.source.internal.annotations.attribute;
|
||||||
|
|
||||||
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.type.AttributeTypeResolver;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.type.AttributeTypeResolver;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeIndexNature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Presents metadata about the elements of a plural attribute.
|
* Presents metadata about the elements of a plural attribute.
|
||||||
|
@ -42,6 +43,14 @@ public interface PluralAttributeIndexDetails {
|
||||||
*/
|
*/
|
||||||
public JavaTypeDescriptor getJavaType();
|
public JavaTypeDescriptor getJavaType();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the nature of the collection index. To a large degree, this is
|
||||||
|
* used to know what further, more specific type-casts can be performed.
|
||||||
|
*
|
||||||
|
* @return The nature of the collection index
|
||||||
|
*/
|
||||||
|
public PluralAttributeIndexNature getIndexNature();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the type resolver for the collection index.
|
* Get the type resolver for the collection index.
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.metamodel.source.internal.annotations.attribute;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
||||||
|
import org.hibernate.metamodel.reflite.spi.MemberDescriptor;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeIndexNature;
|
||||||
|
|
||||||
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class PluralAttributeIndexDetailsMapKeyBasic extends AbstractPluralAttributeIndexDetailsMapKey {
|
||||||
|
private final AnnotationInstance mapKeyColumnAnnotation;
|
||||||
|
|
||||||
|
public PluralAttributeIndexDetailsMapKeyBasic(
|
||||||
|
PluralAttribute pluralAttribute,
|
||||||
|
MemberDescriptor backingMember,
|
||||||
|
JavaTypeDescriptor resolvedMapKeyType,
|
||||||
|
AnnotationInstance mapKeyColumnAnnotation) {
|
||||||
|
super( pluralAttribute, backingMember, resolvedMapKeyType );
|
||||||
|
this.mapKeyColumnAnnotation = mapKeyColumnAnnotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AnnotationInstance getMapKeyColumnAnnotation() {
|
||||||
|
return mapKeyColumnAnnotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PluralAttributeIndexNature getIndexNature() {
|
||||||
|
return PluralAttributeIndexNature.BASIC;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,129 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.metamodel.source.internal.annotations.attribute;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
||||||
|
import org.hibernate.metamodel.reflite.spi.MemberDescriptor;
|
||||||
|
import org.hibernate.metamodel.source.internal.AttributeConversionInfo;
|
||||||
|
import org.hibernate.metamodel.source.internal.annotations.entity.EmbeddableTypeMetadata;
|
||||||
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeIndexNature;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class PluralAttributeIndexDetailsMapKeyEmbedded
|
||||||
|
extends AbstractPluralAttributeIndexDetailsMapKey
|
||||||
|
implements EmbeddedContainer {
|
||||||
|
|
||||||
|
private final PluralAttribute pluralAttribute;
|
||||||
|
private final EmbeddableTypeMetadata embeddableTypeMetadata;
|
||||||
|
|
||||||
|
public PluralAttributeIndexDetailsMapKeyEmbedded(
|
||||||
|
PluralAttribute pluralAttribute,
|
||||||
|
MemberDescriptor backingMember,
|
||||||
|
JavaTypeDescriptor resolvedMapKeyType) {
|
||||||
|
super( pluralAttribute, backingMember, resolvedMapKeyType );
|
||||||
|
this.pluralAttribute = pluralAttribute;
|
||||||
|
|
||||||
|
// we pass `this` (as EmbeddedContainer) in order to route calls back properly.
|
||||||
|
this.embeddableTypeMetadata = new EmbeddableTypeMetadata(
|
||||||
|
resolvedMapKeyType,
|
||||||
|
this,
|
||||||
|
pluralAttribute.getRole().append( "key" ),
|
||||||
|
pluralAttribute.getPath().append( "key" ),
|
||||||
|
pluralAttribute.getAccessType(),
|
||||||
|
pluralAttribute.getAccessorStrategy(),
|
||||||
|
pluralAttribute.getContext()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EmbeddableTypeMetadata getEmbeddableTypeMetadata() {
|
||||||
|
return embeddableTypeMetadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PluralAttributeIndexNature getIndexNature() {
|
||||||
|
return PluralAttributeIndexNature.AGGREGATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// EmbeddedContainer impl
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MemberDescriptor getBackingMember() {
|
||||||
|
return pluralAttribute.getBackingMember();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributeConversionInfo locateConversionInfo(AttributePath attributePath) {
|
||||||
|
return pluralAttribute.getContainer().locateConversionInfo( attributePath );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributeOverride locateAttributeOverride(AttributePath attributePath) {
|
||||||
|
return pluralAttribute.getContainer().locateAttributeOverride( attributePath );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AssociationOverride locateAssociationOverride(AttributePath attributePath) {
|
||||||
|
return pluralAttribute.getContainer().locateAssociationOverride( attributePath );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NaturalIdMutability getContainerNaturalIdMutability() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getContainerOptionality() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getContainerUpdatability() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getContainerInsertability() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerConverter(AttributePath attributePath, AttributeConversionInfo conversionInfo) {
|
||||||
|
pluralAttribute.getContainer().registerConverter( attributePath, conversionInfo );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerAttributeOverride(AttributePath attributePath, AttributeOverride override) {
|
||||||
|
pluralAttribute.getContainer().registerAttributeOverride( attributePath, override );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerAssociationOverride(AttributePath attributePath, AssociationOverride override) {
|
||||||
|
pluralAttribute.getContainer().registerAssociationOverride( attributePath, override );
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.metamodel.source.internal.annotations.attribute;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
||||||
|
import org.hibernate.metamodel.reflite.spi.MemberDescriptor;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeIndexNature;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class PluralAttributeIndexDetailsMapKeyEntityAttribute extends AbstractPluralAttributeIndexDetailsMapKey {
|
||||||
|
private final String referencedAttributeName;
|
||||||
|
|
||||||
|
public PluralAttributeIndexDetailsMapKeyEntityAttribute(
|
||||||
|
PluralAttribute pluralAttribute,
|
||||||
|
MemberDescriptor backingMember,
|
||||||
|
JavaTypeDescriptor resolvedMapKeyType,
|
||||||
|
String referencedAttributeName) {
|
||||||
|
super( pluralAttribute, backingMember, resolvedMapKeyType );
|
||||||
|
this.referencedAttributeName = referencedAttributeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getReferencedAttributeName() {
|
||||||
|
return referencedAttributeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PluralAttributeIndexNature getIndexNature() {
|
||||||
|
// we don't know until we can resolve the referenced entity attribute
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,6 +26,7 @@ package org.hibernate.metamodel.source.internal.annotations.attribute;
|
||||||
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
||||||
import org.hibernate.metamodel.reflite.spi.MemberDescriptor;
|
import org.hibernate.metamodel.reflite.spi.MemberDescriptor;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.type.AttributeTypeResolver;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.type.AttributeTypeResolver;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeIndexNature;
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
import org.jboss.jandex.AnnotationValue;
|
import org.jboss.jandex.AnnotationValue;
|
||||||
|
@ -36,13 +37,13 @@ import static org.hibernate.metamodel.source.internal.annotations.util.JPADotNam
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class PluralAttributeSequentialIndexDetails implements PluralAttributeIndexDetails {
|
public class PluralAttributeIndexDetailsSequential implements PluralAttributeIndexDetails {
|
||||||
private final PluralAttribute pluralAttribute;
|
private final PluralAttribute pluralAttribute;
|
||||||
|
|
||||||
private final Column orderColumn;
|
private final Column orderColumn;
|
||||||
private final int base;
|
private final int base;
|
||||||
|
|
||||||
public PluralAttributeSequentialIndexDetails(PluralAttribute pluralAttribute, MemberDescriptor backingMember) {
|
public PluralAttributeIndexDetailsSequential(PluralAttribute pluralAttribute, MemberDescriptor backingMember) {
|
||||||
this.pluralAttribute = pluralAttribute;
|
this.pluralAttribute = pluralAttribute;
|
||||||
|
|
||||||
this.orderColumn = determineOrderColumn( backingMember );
|
this.orderColumn = determineOrderColumn( backingMember );
|
||||||
|
@ -84,6 +85,11 @@ public class PluralAttributeSequentialIndexDetails implements PluralAttributeInd
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PluralAttributeIndexNature getIndexNature() {
|
||||||
|
return PluralAttributeIndexNature.SEQUENTIAL;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AttributeTypeResolver getTypeResolver() {
|
public AttributeTypeResolver getTypeResolver() {
|
||||||
return null;
|
return null;
|
|
@ -1,171 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.metamodel.source.internal.annotations.attribute;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
|
||||||
import org.hibernate.metamodel.reflite.spi.MemberDescriptor;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.type.AttributeTypeResolver;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.type.AttributeTypeResolverComposition;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.type.EnumeratedTypeResolver;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.type.HibernateTypeResolver;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.type.TemporalTypeResolver;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper;
|
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
|
||||||
import org.jboss.jandex.AnnotationValue;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PluralAttributeIndexDetails implementation for describing the key of a Map
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
|
||||||
*/
|
|
||||||
public class PluralAttributeMapKeyDetails implements PluralAttributeIndexDetails {
|
|
||||||
private final PluralAttribute pluralAttribute;
|
|
||||||
|
|
||||||
private final AnnotationInstance mapKeyAnnotation;
|
|
||||||
private final AnnotationInstance mapKeyClassAnnotation;
|
|
||||||
|
|
||||||
private final AnnotationInstance mapKeyColumnAnnotation;
|
|
||||||
private final List<AnnotationInstance> mapKeyJoinColumnAnnotations;
|
|
||||||
|
|
||||||
private final JavaTypeDescriptor resolvedMapKeyType;
|
|
||||||
private final AttributeTypeResolver typeResolver;
|
|
||||||
|
|
||||||
public PluralAttributeMapKeyDetails(
|
|
||||||
PluralAttribute pluralAttribute,
|
|
||||||
MemberDescriptor backingMember,
|
|
||||||
JavaTypeDescriptor resolvedMapKeyType) {
|
|
||||||
this.pluralAttribute = pluralAttribute;
|
|
||||||
|
|
||||||
this.mapKeyAnnotation = backingMember.getAnnotations().get( JPADotNames.MAP_KEY );
|
|
||||||
this.mapKeyClassAnnotation = backingMember.getAnnotations().get( JPADotNames.MAP_KEY_CLASS );
|
|
||||||
|
|
||||||
if ( mapKeyAnnotation != null && mapKeyClassAnnotation != null ) {
|
|
||||||
// this is an error according to the spec...
|
|
||||||
throw pluralAttribute.getContext().makeMappingException(
|
|
||||||
"Map attribute defined both @MapKey and @MapKeyClass; only one should be used : " +
|
|
||||||
backingMember.toLoggableForm()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.mapKeyColumnAnnotation = backingMember.getAnnotations().get( JPADotNames.MAP_KEY_COLUMN );
|
|
||||||
this.mapKeyJoinColumnAnnotations = collectMapKeyJoinColumnAnnotations( backingMember );
|
|
||||||
|
|
||||||
this.resolvedMapKeyType = determineMapKeyJavaType( backingMember, resolvedMapKeyType, mapKeyClassAnnotation );
|
|
||||||
|
|
||||||
this.typeResolver = new AttributeTypeResolverComposition(
|
|
||||||
resolvedMapKeyType,
|
|
||||||
pluralAttribute.getContext(),
|
|
||||||
HibernateTypeResolver.createCollectionIndexTypeResolver( pluralAttribute, resolvedMapKeyType ),
|
|
||||||
EnumeratedTypeResolver.createCollectionIndexTypeResolver( pluralAttribute, resolvedMapKeyType ),
|
|
||||||
TemporalTypeResolver.createCollectionIndexTypeResolver( pluralAttribute, resolvedMapKeyType )
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private JavaTypeDescriptor determineMapKeyJavaType(
|
|
||||||
MemberDescriptor backingMember,
|
|
||||||
JavaTypeDescriptor resolvedMapKeyType,
|
|
||||||
AnnotationInstance mapKeyClassAnnotation) {
|
|
||||||
if ( mapKeyClassAnnotation != null ) {
|
|
||||||
final AnnotationValue value = mapKeyClassAnnotation.value();
|
|
||||||
assert value != null : "Unexpected null from @MapKeyClass.value : " + backingMember.toLoggableForm();
|
|
||||||
return pluralAttribute.getContext().getJavaTypeDescriptorRepository().getType( value.asClass().name() );
|
|
||||||
}
|
|
||||||
|
|
||||||
return resolvedMapKeyType;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<AnnotationInstance> collectMapKeyJoinColumnAnnotations(MemberDescriptor backingMember) {
|
|
||||||
final AnnotationInstance singular = backingMember.getAnnotations().get( JPADotNames.MAP_KEY_JOIN_COLUMN );
|
|
||||||
final AnnotationInstance plural = backingMember.getAnnotations().get( JPADotNames.MAP_KEY_JOIN_COLUMNS );
|
|
||||||
|
|
||||||
if ( singular != null && plural != null ) {
|
|
||||||
throw pluralAttribute.getContext().makeMappingException(
|
|
||||||
"Attribute [" + backingMember.toLoggableForm() +
|
|
||||||
"] declared both @MapKeyJoinColumn and " +
|
|
||||||
"@MapKeyJoinColumns; should only use one or the other"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( singular == null && plural == null ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( singular != null ) {
|
|
||||||
return Collections.singletonList( singular );
|
|
||||||
}
|
|
||||||
|
|
||||||
final AnnotationInstance[] annotations = JandexHelper.extractAnnotationsValue(
|
|
||||||
plural,
|
|
||||||
"value"
|
|
||||||
);
|
|
||||||
if ( annotations == null || annotations.length == 0 ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Arrays.asList( annotations );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the {@link javax.persistence.MapKey} annotation descriptor, if one.
|
|
||||||
*
|
|
||||||
* @return The @MapKey annotation, or {@code null}
|
|
||||||
*/
|
|
||||||
public AnnotationInstance getMapKeyAnnotation() {
|
|
||||||
return mapKeyAnnotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the {@link javax.persistence.MapKeyClass} annotation descriptor, if one.
|
|
||||||
*
|
|
||||||
* @return The @MapKeyClass annotation, or {@code null}
|
|
||||||
*/
|
|
||||||
public AnnotationInstance getMapKeyClassAnnotation() {
|
|
||||||
return mapKeyClassAnnotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AnnotationInstance getMapKeyColumnAnnotation() {
|
|
||||||
return mapKeyColumnAnnotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<AnnotationInstance> getMapKeyJoinColumnAnnotations() {
|
|
||||||
return mapKeyJoinColumnAnnotations;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JavaTypeDescriptor getJavaType() {
|
|
||||||
return resolvedMapKeyType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AttributeTypeResolver getTypeResolver() {
|
|
||||||
return typeResolver;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -25,7 +25,6 @@ package org.hibernate.metamodel.source.internal.annotations.attribute;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.persistence.AccessType;
|
import javax.persistence.AccessType;
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
|
|
||||||
|
@ -39,8 +38,9 @@ import org.hibernate.metamodel.source.internal.annotations.entity.ManagedTypeMet
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.AssociationHelper;
|
import org.hibernate.metamodel.source.internal.annotations.util.AssociationHelper;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
||||||
import org.hibernate.metamodel.source.spi.AttributePath;
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeRole;
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,7 +26,7 @@ package org.hibernate.metamodel.source.internal.annotations.attribute;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.metamodel.source.internal.AttributeConversionInfo;
|
import org.hibernate.metamodel.source.internal.AttributeConversionInfo;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a singular persistent attribute.
|
* Represents a singular persistent attribute.
|
||||||
|
@ -38,7 +38,7 @@ public interface SingularAttribute extends PersistentAttribute {
|
||||||
|
|
||||||
boolean isVersion();
|
boolean isVersion();
|
||||||
|
|
||||||
SingularAttributeBinding.NaturalIdMutability getNaturalIdMutability();
|
NaturalIdMutability getNaturalIdMutability();
|
||||||
|
|
||||||
AttributeConversionInfo getConversionInfo();
|
AttributeConversionInfo getConversionInfo();
|
||||||
|
|
||||||
|
|
|
@ -35,9 +35,9 @@ import org.hibernate.metamodel.source.internal.annotations.attribute.EmbeddedCon
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.ConverterAndOverridesHelper;
|
import org.hibernate.metamodel.source.internal.annotations.util.ConverterAndOverridesHelper;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper;
|
import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper;
|
||||||
import org.hibernate.metamodel.source.spi.AttributePath;
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeRole;
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ import static org.hibernate.metamodel.source.internal.annotations.util.Hibernate
|
||||||
*/
|
*/
|
||||||
public class EmbeddableTypeMetadata extends ManagedTypeMetadata {
|
public class EmbeddableTypeMetadata extends ManagedTypeMetadata {
|
||||||
private final EmbeddedContainer container;
|
private final EmbeddedContainer container;
|
||||||
private final SingularAttributeBinding.NaturalIdMutability naturalIdMutability;
|
private final NaturalIdMutability naturalIdMutability;
|
||||||
private final String parentReferencingAttributeName;
|
private final String parentReferencingAttributeName;
|
||||||
private final String customTuplizerClassName;
|
private final String customTuplizerClassName;
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ public class EmbeddableTypeMetadata extends ManagedTypeMetadata {
|
||||||
return parentReferencingAttributeName;
|
return parentReferencingAttributeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SingularAttributeBinding.NaturalIdMutability getNaturalIdMutability() {
|
public NaturalIdMutability getNaturalIdMutability() {
|
||||||
return naturalIdMutability;
|
return naturalIdMutability;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,14 +179,14 @@ public class EmbeddableTypeMetadata extends ManagedTypeMetadata {
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("SimplifiableIfStatement")
|
@SuppressWarnings("SimplifiableIfStatement")
|
||||||
public boolean canAttributesBeUpdatable() {
|
public boolean canAttributesBeUpdatable() {
|
||||||
if ( naturalIdMutability == SingularAttributeBinding.NaturalIdMutability.IMMUTABLE ) {
|
if ( naturalIdMutability == NaturalIdMutability.IMMUTABLE ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return container.getContainerUpdatability();
|
return container.getContainerUpdatability();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SingularAttributeBinding.NaturalIdMutability getContainerNaturalIdMutability() {
|
public NaturalIdMutability getContainerNaturalIdMutability() {
|
||||||
return naturalIdMutability;
|
return naturalIdMutability;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,8 +46,8 @@ import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.JPAListenerHelper;
|
import org.hibernate.metamodel.source.internal.annotations.util.JPAListenerHelper;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper;
|
import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper;
|
||||||
import org.hibernate.metamodel.source.internal.jandex.PseudoJpaDotNames;
|
import org.hibernate.metamodel.source.internal.jandex.PseudoJpaDotNames;
|
||||||
import org.hibernate.metamodel.source.spi.AttributePath;
|
|
||||||
import org.hibernate.metamodel.source.spi.JpaCallbackSource;
|
import org.hibernate.metamodel.source.spi.JpaCallbackSource;
|
||||||
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
import org.hibernate.metamodel.spi.binding.InheritanceType;
|
import org.hibernate.metamodel.spi.binding.InheritanceType;
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
|
|
|
@ -64,10 +64,10 @@ import org.hibernate.metamodel.source.internal.annotations.util.AnnotationParser
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper;
|
import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper;
|
||||||
import org.hibernate.metamodel.source.spi.AttributePath;
|
|
||||||
import org.hibernate.metamodel.source.spi.AttributeRole;
|
|
||||||
import org.hibernate.metamodel.source.spi.MappingException;
|
import org.hibernate.metamodel.source.spi.MappingException;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
import org.hibernate.xml.spi.Origin;
|
import org.hibernate.xml.spi.Origin;
|
||||||
import org.hibernate.xml.spi.SourceType;
|
import org.hibernate.xml.spi.SourceType;
|
||||||
|
|
||||||
|
@ -388,6 +388,10 @@ public abstract class ManagedTypeMetadata implements OverrideAndConverterCollect
|
||||||
return attributeRoleBase;
|
return attributeRoleBase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AttributePath getAttributePathBase() {
|
||||||
|
return attributePathBase;
|
||||||
|
}
|
||||||
|
|
||||||
public JavaTypeDescriptor getJavaTypeDescriptor() {
|
public JavaTypeDescriptor getJavaTypeDescriptor() {
|
||||||
return javaTypeDescriptor;
|
return javaTypeDescriptor;
|
||||||
}
|
}
|
||||||
|
@ -1071,7 +1075,7 @@ public abstract class ManagedTypeMetadata implements OverrideAndConverterCollect
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SingularAttributeBinding.NaturalIdMutability getContainerNaturalIdMutability() {
|
public NaturalIdMutability getContainerNaturalIdMutability() {
|
||||||
return SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID;
|
return NaturalIdMutability.NOT_NATURAL_ID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.AnnotationBindingContext;
|
import org.hibernate.metamodel.source.internal.annotations.AnnotationBindingContext;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.PrimaryKeyJoinColumn;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.PrimaryKeyJoinColumn;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.ConverterAndOverridesHelper;
|
import org.hibernate.metamodel.source.internal.annotations.util.ConverterAndOverridesHelper;
|
||||||
import org.hibernate.metamodel.source.spi.AttributePath;
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ import org.hibernate.internal.util.collections.CollectionHelper;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.AnnotationBindingContext;
|
import org.hibernate.metamodel.source.internal.annotations.AnnotationBindingContext;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper;
|
import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper;
|
||||||
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding;
|
import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding;
|
import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAssociationAttributeBinding;
|
import org.hibernate.metamodel.spi.binding.SingularAssociationAttributeBinding;
|
||||||
|
@ -255,11 +255,11 @@ public class SqlResultSetProcessor {
|
||||||
String reducedName = name.substring( 0, dotIndex );
|
String reducedName = name.substring( 0, dotIndex );
|
||||||
AttributeBinding attributeBinding = entityBinding.locateAttributeBinding( reducedName );
|
AttributeBinding attributeBinding = entityBinding.locateAttributeBinding( reducedName );
|
||||||
Iterable<? extends AttributeBinding> attributeBindings = null;
|
Iterable<? extends AttributeBinding> attributeBindings = null;
|
||||||
if ( CompositeAttributeBinding.class.isInstance( attributeBinding ) ) {
|
if ( EmbeddedAttributeBinding.class.isInstance( attributeBinding ) ) {
|
||||||
CompositeAttributeBinding compositeAttributeBinding = CompositeAttributeBinding.class.cast(
|
EmbeddedAttributeBinding embeddedAttributeBinding = EmbeddedAttributeBinding.class.cast(
|
||||||
attributeBinding
|
attributeBinding
|
||||||
);
|
);
|
||||||
attributeBindings = compositeAttributeBinding.attributeBindings();
|
attributeBindings = embeddedAttributeBinding.getEmbeddableBinding().attributeBindings();
|
||||||
|
|
||||||
}
|
}
|
||||||
else if ( ManyToOneAttributeBinding.class.isInstance( attributeBinding ) ) {
|
else if ( ManyToOneAttributeBinding.class.isInstance( attributeBinding ) ) {
|
||||||
|
@ -287,8 +287,9 @@ public class SqlResultSetProcessor {
|
||||||
SingularAttributeBinding identifierAttributeBinding = referencedEntityBinding.getHierarchyDetails()
|
SingularAttributeBinding identifierAttributeBinding = referencedEntityBinding.getHierarchyDetails()
|
||||||
.getEntityIdentifier()
|
.getEntityIdentifier()
|
||||||
.getAttributeBinding();
|
.getAttributeBinding();
|
||||||
if ( CompositeAttributeBinding.class.isInstance( identifierAttributeBinding ) ) {
|
if ( EmbeddedAttributeBinding.class.isInstance( identifierAttributeBinding ) ) {
|
||||||
attributeBindings = CompositeAttributeBinding.class.cast( identifierAttributeBinding )
|
attributeBindings = EmbeddedAttributeBinding.class.cast( identifierAttributeBinding )
|
||||||
|
.getEmbeddableBinding()
|
||||||
.attributeBindings();
|
.attributeBindings();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -33,8 +33,8 @@ import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
||||||
import org.hibernate.metamodel.reflite.spi.MemberDescriptor;
|
import org.hibernate.metamodel.reflite.spi.MemberDescriptor;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.entity.EntityBindingContext;
|
import org.hibernate.metamodel.source.internal.annotations.entity.EntityBindingContext;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.entity.ManagedTypeMetadata;
|
import org.hibernate.metamodel.source.internal.annotations.entity.ManagedTypeMetadata;
|
||||||
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
import org.jboss.jandex.ClassInfo;
|
import org.jboss.jandex.ClassInfo;
|
||||||
|
@ -180,7 +180,7 @@ public class AnnotationParserHelper {
|
||||||
return mapKeyType;
|
return mapKeyType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SingularAttributeBinding.NaturalIdMutability determineNaturalIdMutability(
|
public static NaturalIdMutability determineNaturalIdMutability(
|
||||||
ManagedTypeMetadata container,
|
ManagedTypeMetadata container,
|
||||||
MemberDescriptor member) {
|
MemberDescriptor member) {
|
||||||
final AnnotationInstance naturalIdAnnotation = member.getAnnotations().get( HibernateDotNames.NATURAL_ID );
|
final AnnotationInstance naturalIdAnnotation = member.getAnnotations().get( HibernateDotNames.NATURAL_ID );
|
||||||
|
@ -191,8 +191,8 @@ public class AnnotationParserHelper {
|
||||||
final boolean mutable = naturalIdAnnotation.value( "mutable" ) != null
|
final boolean mutable = naturalIdAnnotation.value( "mutable" ) != null
|
||||||
&& naturalIdAnnotation.value( "mutable" ).asBoolean();
|
&& naturalIdAnnotation.value( "mutable" ).asBoolean();
|
||||||
return mutable
|
return mutable
|
||||||
? SingularAttributeBinding.NaturalIdMutability.MUTABLE
|
? NaturalIdMutability.MUTABLE
|
||||||
: SingularAttributeBinding.NaturalIdMutability.IMMUTABLE;
|
: NaturalIdMutability.IMMUTABLE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ import org.hibernate.metamodel.source.internal.annotations.attribute.OverrideAnd
|
||||||
import org.hibernate.metamodel.source.internal.annotations.attribute.PersistentAttribute;
|
import org.hibernate.metamodel.source.internal.annotations.attribute.PersistentAttribute;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.entity.EntityBindingContext;
|
import org.hibernate.metamodel.source.internal.annotations.entity.EntityBindingContext;
|
||||||
import org.hibernate.metamodel.source.internal.annotations.entity.ManagedTypeMetadata;
|
import org.hibernate.metamodel.source.internal.annotations.entity.ManagedTypeMetadata;
|
||||||
import org.hibernate.metamodel.source.spi.AttributePath;
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
import org.jboss.jandex.AnnotationValue;
|
import org.jboss.jandex.AnnotationValue;
|
||||||
|
|
|
@ -0,0 +1,129 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.metamodel.source.internal.hbm;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbAnyElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbArrayElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbBagElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbComponentElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbDynamicComponentElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyManyToOneElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyPropertyElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToOneElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbMapElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbNestedCompositeElementElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOneToOneElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPrimitiveArrayElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertiesElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertyElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSetElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public abstract class AbstractEmbeddableJaxbSource implements EmbeddableJaxbSource {
|
||||||
|
@Override
|
||||||
|
public List<JaxbKeyPropertyElement> getKeyPropertyElementList() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbKeyManyToOneElement> getKeyManyToOneElementList() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbPropertyElement> getPropertyElementList() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbManyToOneElement> getManyToOneElementList() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbOneToOneElement> getOneToOneElementList() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbComponentElement> getComponentElementList() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbNestedCompositeElementElement> getNestedCompositeElementList() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbDynamicComponentElement> getDynamicComponentElementList() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbPropertiesElement> getPropertiesElementList() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbAnyElement> getAnyElementList() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbMapElement> getMapElementList() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbSetElement> getSetElementList() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbListElement> getListElementList() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbBagElement> getBagElementList() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbArrayElement> getArrayElementList() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbPrimitiveArrayElement> getPrimitiveArrayElementList() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,150 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.metamodel.source.internal.hbm;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.mapping.PropertyGeneration;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.ComponentSourceElement;
|
||||||
|
import org.hibernate.metamodel.source.spi.AttributeSourceContainer;
|
||||||
|
import org.hibernate.metamodel.source.spi.EmbeddableSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.EmbeddedAttributeSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.HibernateTypeSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
||||||
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
|
import org.hibernate.metamodel.spi.SingularAttributeNature;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common bas class for <component/> and <composite-id/> mappings.
|
||||||
|
*
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public abstract class AbstractEmbeddedAttributeSourceImpl
|
||||||
|
extends AbstractHbmSourceNode
|
||||||
|
implements EmbeddedAttributeSource {
|
||||||
|
|
||||||
|
private final ComponentSourceElement jaxbComponentSourceElement;
|
||||||
|
private final EmbeddableSourceImpl embeddableSource;
|
||||||
|
|
||||||
|
protected AbstractEmbeddedAttributeSourceImpl(
|
||||||
|
MappingDocument sourceMappingDocument,
|
||||||
|
AttributeSourceContainer parentContainer,
|
||||||
|
AttributeRole attributeRoleBase,
|
||||||
|
AttributePath attributePathBase,
|
||||||
|
ComponentSourceElement jaxbComponentSourceElement,
|
||||||
|
EmbeddableJaxbSource embeddableJaxbSource,
|
||||||
|
NaturalIdMutability naturalIdMutability,
|
||||||
|
String logicalTableName) {
|
||||||
|
super( sourceMappingDocument );
|
||||||
|
this.jaxbComponentSourceElement = jaxbComponentSourceElement;
|
||||||
|
this.embeddableSource = new EmbeddableSourceImpl(
|
||||||
|
sourceMappingDocument,
|
||||||
|
attributeRoleBase,
|
||||||
|
attributePathBase,
|
||||||
|
embeddableJaxbSource,
|
||||||
|
logicalTableName,
|
||||||
|
naturalIdMutability
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ComponentSourceElement jaxbComponentSourceElement() {
|
||||||
|
return jaxbComponentSourceElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EmbeddableSource getEmbeddableSource() {
|
||||||
|
return embeddableSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return jaxbComponentSourceElement.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSingular() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isVirtualAttribute() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SingularAttributeNature getSingularAttributeNature() {
|
||||||
|
return SingularAttributeNature.COMPOSITE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HibernateTypeSource getTypeInformation() {
|
||||||
|
// <component/> does not support type information.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPropertyAccessorName() {
|
||||||
|
return jaxbComponentSourceElement.getAccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NaturalIdMutability getNaturalIdMutability() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<? extends ToolingHintSource> getToolingHintSources() {
|
||||||
|
return jaxbComponentSourceElement.getMeta();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PropertyGeneration getGeneration() {
|
||||||
|
// todo : is this correct here?
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean areValuesNullableByDefault() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// relational value source info comes from the individual sub-attributes
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getContainingTableName() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<RelationalValueSource> relationalValueSources() {
|
||||||
|
// none, they are defined on the simple sub-attributes
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -34,7 +34,6 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.hibernate.EntityMode;
|
import org.hibernate.EntityMode;
|
||||||
import org.hibernate.TruthValue;
|
import org.hibernate.TruthValue;
|
||||||
import org.hibernate.cfg.NotYetImplementedException;
|
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.EntityElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.EntityElement;
|
||||||
|
@ -66,9 +65,11 @@ import org.hibernate.metamodel.source.spi.JpaCallbackSource;
|
||||||
import org.hibernate.metamodel.source.spi.SecondaryTableSource;
|
import org.hibernate.metamodel.source.spi.SecondaryTableSource;
|
||||||
import org.hibernate.metamodel.source.spi.SubclassEntitySource;
|
import org.hibernate.metamodel.source.spi.SubclassEntitySource;
|
||||||
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
||||||
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
import org.hibernate.metamodel.spi.LocalBindingContext;
|
import org.hibernate.metamodel.spi.LocalBindingContext;
|
||||||
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
|
||||||
import org.hibernate.xml.spi.Origin;
|
import org.hibernate.xml.spi.Origin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,6 +86,9 @@ public abstract class AbstractEntitySourceImpl
|
||||||
private final String entityName;
|
private final String entityName;
|
||||||
private final String jpaEntityName;
|
private final String jpaEntityName;
|
||||||
|
|
||||||
|
private final AttributeRole attributeRoleBase;
|
||||||
|
private final AttributePath attributePathBase;
|
||||||
|
|
||||||
private List<IdentifiableTypeSource> subclassEntitySources = new ArrayList<IdentifiableTypeSource>();
|
private List<IdentifiableTypeSource> subclassEntitySources = new ArrayList<IdentifiableTypeSource>();
|
||||||
|
|
||||||
private int inLineViewCount = 0;
|
private int inLineViewCount = 0;
|
||||||
|
@ -109,6 +113,10 @@ public abstract class AbstractEntitySourceImpl
|
||||||
this.entityName = className;
|
this.entityName = className;
|
||||||
this.jpaEntityName = StringHelper.unqualify( className );
|
this.jpaEntityName = StringHelper.unqualify( className );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.attributePathBase = new AttributePath();
|
||||||
|
this.attributeRoleBase = new AttributeRole( entityName );
|
||||||
|
|
||||||
this.filterSources = buildFilterSources();
|
this.filterSources = buildFilterSources();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,6 +125,16 @@ public abstract class AbstractEntitySourceImpl
|
||||||
return StringHelper.isNotEmpty( className ) ? className : entityName;
|
return StringHelper.isNotEmpty( className ) ? className : entityName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributePath getAttributePathBase() {
|
||||||
|
return attributePathBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributeRole getAttributeRoleBase() {
|
||||||
|
return attributeRoleBase;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<IdentifiableTypeSource> getSubTypes() {
|
public Collection<IdentifiableTypeSource> getSubTypes() {
|
||||||
return subclassEntitySources;
|
return subclassEntitySources;
|
||||||
|
@ -166,14 +184,14 @@ public abstract class AbstractEntitySourceImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<AttributeSource> buildAttributeSources(List<AttributeSource> attributeSources) {
|
protected List<AttributeSource> buildAttributeSources(List<AttributeSource> attributeSources) {
|
||||||
return buildAttributeSources( entityElement, attributeSources, null, SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID );
|
return buildAttributeSources( entityElement, attributeSources, null, NaturalIdMutability.NOT_NATURAL_ID );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<AttributeSource> buildAttributeSources(
|
protected List<AttributeSource> buildAttributeSources(
|
||||||
EntityElement element,
|
EntityElement element,
|
||||||
List<AttributeSource> attributeSources,
|
List<AttributeSource> attributeSources,
|
||||||
String logicTalbeName,
|
String logicTalbeName,
|
||||||
SingularAttributeBinding.NaturalIdMutability naturalIdMutability){
|
NaturalIdMutability naturalIdMutability){
|
||||||
processPropertyAttributes( attributeSources, element.getProperty(), logicTalbeName, naturalIdMutability );
|
processPropertyAttributes( attributeSources, element.getProperty(), logicTalbeName, naturalIdMutability );
|
||||||
processComponentAttributes(
|
processComponentAttributes(
|
||||||
attributeSources,
|
attributeSources,
|
||||||
|
@ -218,11 +236,12 @@ public abstract class AbstractEntitySourceImpl
|
||||||
List<AttributeSource> results,
|
List<AttributeSource> results,
|
||||||
List<JaxbPropertyElement> propertyElements,
|
List<JaxbPropertyElement> propertyElements,
|
||||||
String logicalTableName,
|
String logicalTableName,
|
||||||
SingularAttributeBinding.NaturalIdMutability naturalIdMutability) {
|
NaturalIdMutability naturalIdMutability) {
|
||||||
for ( JaxbPropertyElement element : propertyElements ) {
|
for ( JaxbPropertyElement element : propertyElements ) {
|
||||||
results.add(
|
results.add(
|
||||||
new PropertyAttributeSourceImpl(
|
new PropertyAttributeSourceImpl(
|
||||||
sourceMappingDocument(),
|
sourceMappingDocument(),
|
||||||
|
this,
|
||||||
element,
|
element,
|
||||||
logicalTableName,
|
logicalTableName,
|
||||||
naturalIdMutability
|
naturalIdMutability
|
||||||
|
@ -253,15 +272,15 @@ public abstract class AbstractEntitySourceImpl
|
||||||
protected void processComponentAttributes(List<AttributeSource> results,
|
protected void processComponentAttributes(List<AttributeSource> results,
|
||||||
List<JaxbComponentElement> elements,
|
List<JaxbComponentElement> elements,
|
||||||
String logicalTableName,
|
String logicalTableName,
|
||||||
SingularAttributeBinding.NaturalIdMutability naturalIdMutability) {
|
NaturalIdMutability naturalIdMutability) {
|
||||||
for ( JaxbComponentElement element : elements ) {
|
for ( JaxbComponentElement element : elements ) {
|
||||||
results.add(
|
results.add(
|
||||||
new ComponentAttributeSourceImpl(
|
new EmbeddedAttributeSourceImpl(
|
||||||
sourceMappingDocument(),
|
sourceMappingDocument(),
|
||||||
element,
|
|
||||||
this,
|
this,
|
||||||
logicalTableName,
|
element,
|
||||||
naturalIdMutability
|
naturalIdMutability,
|
||||||
|
logicalTableName
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -270,18 +289,19 @@ public abstract class AbstractEntitySourceImpl
|
||||||
protected void processDynamicComponentAttributes(List<AttributeSource> results,
|
protected void processDynamicComponentAttributes(List<AttributeSource> results,
|
||||||
List<JaxbDynamicComponentElement> elements,
|
List<JaxbDynamicComponentElement> elements,
|
||||||
String logicalTableName,
|
String logicalTableName,
|
||||||
SingularAttributeBinding.NaturalIdMutability naturalIdMutability) {
|
NaturalIdMutability naturalIdMutability) {
|
||||||
// todo : implement
|
// todo : implement
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void processManyToOneAttributes(List<AttributeSource> results,
|
protected void processManyToOneAttributes(List<AttributeSource> results,
|
||||||
List<JaxbManyToOneElement> elements,
|
List<JaxbManyToOneElement> elements,
|
||||||
String logicalTableName,
|
String logicalTableName,
|
||||||
SingularAttributeBinding.NaturalIdMutability naturalIdMutability) {
|
NaturalIdMutability naturalIdMutability) {
|
||||||
for ( JaxbManyToOneElement element : elements ) {
|
for ( JaxbManyToOneElement element : elements ) {
|
||||||
results.add(
|
results.add(
|
||||||
new ManyToOneAttributeSourceImpl(
|
new ManyToOneAttributeSourceImpl(
|
||||||
sourceMappingDocument(),
|
sourceMappingDocument(),
|
||||||
|
this,
|
||||||
element,
|
element,
|
||||||
logicalTableName,
|
logicalTableName,
|
||||||
naturalIdMutability
|
naturalIdMutability
|
||||||
|
@ -292,11 +312,12 @@ public abstract class AbstractEntitySourceImpl
|
||||||
protected void processOneToOneAttributes(List<AttributeSource> results,
|
protected void processOneToOneAttributes(List<AttributeSource> results,
|
||||||
List<JaxbOneToOneElement> elements,
|
List<JaxbOneToOneElement> elements,
|
||||||
String logicalTableName,
|
String logicalTableName,
|
||||||
SingularAttributeBinding.NaturalIdMutability naturalIdMutability) {
|
NaturalIdMutability naturalIdMutability) {
|
||||||
for ( JaxbOneToOneElement element : elements ) {
|
for ( JaxbOneToOneElement element : elements ) {
|
||||||
results.add(
|
results.add(
|
||||||
new OneToOneAttributeSourceImpl(
|
new OneToOneAttributeSourceImpl(
|
||||||
sourceMappingDocument(),
|
sourceMappingDocument(),
|
||||||
|
this,
|
||||||
element,
|
element,
|
||||||
logicalTableName,
|
logicalTableName,
|
||||||
naturalIdMutability
|
naturalIdMutability
|
||||||
|
@ -308,7 +329,7 @@ public abstract class AbstractEntitySourceImpl
|
||||||
protected void processAnyAttributes(List<AttributeSource> results,
|
protected void processAnyAttributes(List<AttributeSource> results,
|
||||||
List<JaxbAnyElement> elements,
|
List<JaxbAnyElement> elements,
|
||||||
String logicalTableName,
|
String logicalTableName,
|
||||||
SingularAttributeBinding.NaturalIdMutability naturalIdMutability) {
|
NaturalIdMutability naturalIdMutability) {
|
||||||
// todo : implement
|
// todo : implement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,15 +378,24 @@ public abstract class AbstractEntitySourceImpl
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected void processIdBagAttributes(List<AttributeSource> results,
|
|
||||||
List<JaxbIdbagElement> propertyElements){
|
|
||||||
|
|
||||||
if ( !propertyElements.isEmpty() ) {
|
protected void processIdBagAttributes(
|
||||||
throw new NotYetImplementedException( "<idbag> is not supported yet" );
|
List<AttributeSource> results,
|
||||||
|
List<JaxbIdbagElement> elements){
|
||||||
|
for ( JaxbIdbagElement element : elements ) {
|
||||||
|
results.add(
|
||||||
|
new IdBagSourceImpl(
|
||||||
|
sourceMappingDocument(),
|
||||||
|
element,
|
||||||
|
this
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected void processBagAttributes(List<AttributeSource> results,
|
|
||||||
List<JaxbBagElement> propertyElements) {
|
protected void processBagAttributes(
|
||||||
|
List<AttributeSource> results,
|
||||||
|
List<JaxbBagElement> propertyElements) {
|
||||||
for ( JaxbBagElement element : propertyElements ) {
|
for ( JaxbBagElement element : propertyElements ) {
|
||||||
results.add(
|
results.add(
|
||||||
new BagSourceImpl(
|
new BagSourceImpl(
|
||||||
|
@ -393,7 +423,7 @@ public abstract class AbstractEntitySourceImpl
|
||||||
secondaryTableSources.add( secondaryTableSource );
|
secondaryTableSources.add( secondaryTableSource );
|
||||||
|
|
||||||
final String logicalTableName = secondaryTableSource.getLogicalTableNameForContainedColumns();
|
final String logicalTableName = secondaryTableSource.getLogicalTableNameForContainedColumns();
|
||||||
final SingularAttributeBinding.NaturalIdMutability naturalIdMutability = SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID;
|
final NaturalIdMutability naturalIdMutability = NaturalIdMutability.NOT_NATURAL_ID;
|
||||||
processAnyAttributes(
|
processAnyAttributes(
|
||||||
attributeSources,
|
attributeSources,
|
||||||
joinElement.getAny(),
|
joinElement.getAny(),
|
||||||
|
@ -558,11 +588,6 @@ public abstract class AbstractEntitySourceImpl
|
||||||
return entityElement.getMeta();
|
return entityElement.getMeta();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPath() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AttributeSource> attributeSources() {
|
public List<AttributeSource> attributeSources() {
|
||||||
return attributeSources;
|
return attributeSources;
|
||||||
|
|
|
@ -31,12 +31,12 @@ import org.hibernate.AssertionFailure;
|
||||||
import org.hibernate.cfg.NotYetImplementedException;
|
import org.hibernate.cfg.NotYetImplementedException;
|
||||||
import org.hibernate.engine.FetchStyle;
|
import org.hibernate.engine.FetchStyle;
|
||||||
import org.hibernate.engine.FetchTiming;
|
import org.hibernate.engine.FetchTiming;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
|
||||||
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbFilterElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbFilterElement;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.PluralAttributeElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.PluralAttributeElement;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSourceContainer;
|
import org.hibernate.metamodel.source.spi.AttributeSourceContainer;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSourceResolutionContext;
|
import org.hibernate.metamodel.source.spi.AttributeSourceResolutionContext;
|
||||||
|
import org.hibernate.metamodel.source.spi.CollectionIdSource;
|
||||||
import org.hibernate.metamodel.source.spi.FilterSource;
|
import org.hibernate.metamodel.source.spi.FilterSource;
|
||||||
import org.hibernate.metamodel.source.spi.HibernateTypeSource;
|
import org.hibernate.metamodel.source.spi.HibernateTypeSource;
|
||||||
import org.hibernate.metamodel.source.spi.MappingException;
|
import org.hibernate.metamodel.source.spi.MappingException;
|
||||||
|
@ -45,6 +45,8 @@ import org.hibernate.metamodel.source.spi.PluralAttributeKeySource;
|
||||||
import org.hibernate.metamodel.source.spi.PluralAttributeSource;
|
import org.hibernate.metamodel.source.spi.PluralAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.TableSpecificationSource;
|
import org.hibernate.metamodel.source.spi.TableSpecificationSource;
|
||||||
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
||||||
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
import org.hibernate.metamodel.spi.binding.Caching;
|
import org.hibernate.metamodel.spi.binding.Caching;
|
||||||
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
||||||
|
|
||||||
|
@ -58,6 +60,9 @@ public abstract class AbstractPluralAttributeSourceImpl
|
||||||
private final PluralAttributeElement pluralAttributeElement;
|
private final PluralAttributeElement pluralAttributeElement;
|
||||||
private final AttributeSourceContainer container;
|
private final AttributeSourceContainer container;
|
||||||
|
|
||||||
|
private final AttributeRole attributeRole;
|
||||||
|
private final AttributePath attributePath;
|
||||||
|
|
||||||
private final HibernateTypeSource typeInformation;
|
private final HibernateTypeSource typeInformation;
|
||||||
|
|
||||||
private final PluralAttributeKeySource keySource;
|
private final PluralAttributeKeySource keySource;
|
||||||
|
@ -75,6 +80,9 @@ public abstract class AbstractPluralAttributeSourceImpl
|
||||||
this.pluralAttributeElement = pluralAttributeElement;
|
this.pluralAttributeElement = pluralAttributeElement;
|
||||||
this.container = container;
|
this.container = container;
|
||||||
|
|
||||||
|
this.attributeRole = container.getAttributeRoleBase().append( pluralAttributeElement.getName() );
|
||||||
|
this.attributePath = container.getAttributePathBase().append( pluralAttributeElement.getName() );
|
||||||
|
|
||||||
this.keySource = new PluralAttributeKeySourceImpl(
|
this.keySource = new PluralAttributeKeySourceImpl(
|
||||||
sourceMappingDocument(),
|
sourceMappingDocument(),
|
||||||
pluralAttributeElement.getKey(),
|
pluralAttributeElement.getKey(),
|
||||||
|
@ -82,10 +90,7 @@ public abstract class AbstractPluralAttributeSourceImpl
|
||||||
);
|
);
|
||||||
this.elementSource = interpretElementType();
|
this.elementSource = interpretElementType();
|
||||||
|
|
||||||
this.caching = Helper.createCaching(
|
this.caching = Helper.createCaching( pluralAttributeElement.getCache() );
|
||||||
pluralAttributeElement.getCache(),
|
|
||||||
StringHelper.qualify( container().getPath(), getName() )
|
|
||||||
);
|
|
||||||
|
|
||||||
this.typeInformation = new HibernateTypeSource() {
|
this.typeInformation = new HibernateTypeSource() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -126,7 +131,7 @@ public abstract class AbstractPluralAttributeSourceImpl
|
||||||
// If so, getType is currently null.
|
// If so, getType is currently null.
|
||||||
// elementClassReference = makeClassReference(pluralAttributeElement
|
// elementClassReference = makeClassReference(pluralAttributeElement
|
||||||
// .getElement().getType().getName());
|
// .getElement().getType().getName());
|
||||||
return new BasicPluralAttributeElementSourceImpl(
|
return new PluralAttributeElementSourceBasicImpl(
|
||||||
sourceMappingDocument(),
|
sourceMappingDocument(),
|
||||||
pluralAttributeElement.getElement()
|
pluralAttributeElement.getElement()
|
||||||
);
|
);
|
||||||
|
@ -136,8 +141,9 @@ public abstract class AbstractPluralAttributeSourceImpl
|
||||||
pluralAttributeElement
|
pluralAttributeElement
|
||||||
.getCompositeElement().getClazz()
|
.getCompositeElement().getClazz()
|
||||||
);
|
);
|
||||||
return new CompositePluralAttributeElementSourceImpl(
|
return new PluralAttributeElementSourceEmbeddedImpl(
|
||||||
sourceMappingDocument(),
|
sourceMappingDocument(),
|
||||||
|
this,
|
||||||
pluralAttributeElement.getCompositeElement(),
|
pluralAttributeElement.getCompositeElement(),
|
||||||
pluralAttributeElement.getCascade()
|
pluralAttributeElement.getCascade()
|
||||||
);
|
);
|
||||||
|
@ -147,7 +153,7 @@ public abstract class AbstractPluralAttributeSourceImpl
|
||||||
pluralAttributeElement
|
pluralAttributeElement
|
||||||
.getOneToMany().getClazz()
|
.getOneToMany().getClazz()
|
||||||
);
|
);
|
||||||
return new OneToManyPluralAttributeElementSourceImpl(
|
return new PluralAttributeElementSourceOneToManyImpl(
|
||||||
sourceMappingDocument(),
|
sourceMappingDocument(),
|
||||||
this,
|
this,
|
||||||
pluralAttributeElement.getOneToMany(),
|
pluralAttributeElement.getOneToMany(),
|
||||||
|
@ -159,7 +165,7 @@ public abstract class AbstractPluralAttributeSourceImpl
|
||||||
pluralAttributeElement
|
pluralAttributeElement
|
||||||
.getManyToMany().getClazz()
|
.getManyToMany().getClazz()
|
||||||
);
|
);
|
||||||
return new ManyToManyPluralAttributeElementSourceImpl(
|
return new PluralAttributeElementSourceManyToManyImpl(
|
||||||
sourceMappingDocument(),
|
sourceMappingDocument(),
|
||||||
this,
|
this,
|
||||||
pluralAttributeElement.getManyToMany(),
|
pluralAttributeElement.getManyToMany(),
|
||||||
|
@ -178,6 +184,16 @@ public abstract class AbstractPluralAttributeSourceImpl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributePath getAttributePath() {
|
||||||
|
return attributePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributeRole getAttributeRole() {
|
||||||
|
return attributeRole;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PluralAttributeElementSource resolvePluralAttributeElementSource(AttributeSourceResolutionContext context) {
|
public PluralAttributeElementSource resolvePluralAttributeElementSource(AttributeSourceResolutionContext context) {
|
||||||
// elementSource is already resolved; nothing to do.
|
// elementSource is already resolved; nothing to do.
|
||||||
|
@ -252,7 +268,12 @@ public abstract class AbstractPluralAttributeSourceImpl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String inferInLineViewName() {
|
public String inferInLineViewName() {
|
||||||
return container().getPath() + "." + pluralAttributeElement.getName();
|
return getAttributeRole().getFullPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CollectionIdSource getCollectionIdSource() {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -39,9 +39,9 @@ import org.hibernate.metamodel.source.spi.HibernateTypeSource;
|
||||||
import org.hibernate.metamodel.source.spi.MappedByAssociationSource;
|
import org.hibernate.metamodel.source.spi.MappedByAssociationSource;
|
||||||
import org.hibernate.metamodel.source.spi.MappingException;
|
import org.hibernate.metamodel.source.spi.MappingException;
|
||||||
import org.hibernate.metamodel.source.spi.ToOneAttributeSource;
|
import org.hibernate.metamodel.source.spi.ToOneAttributeSource;
|
||||||
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding;
|
import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
|
||||||
import org.hibernate.metamodel.spi.relational.TableSpecification;
|
import org.hibernate.metamodel.spi.relational.TableSpecification;
|
||||||
import org.hibernate.metamodel.spi.relational.Value;
|
import org.hibernate.metamodel.spi.relational.Value;
|
||||||
|
|
||||||
|
@ -49,13 +49,13 @@ import org.hibernate.metamodel.spi.relational.Value;
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractToOneAttributeSourceImpl extends AbstractHbmSourceNode implements ToOneAttributeSource{
|
public abstract class AbstractToOneAttributeSourceImpl extends AbstractHbmSourceNode implements ToOneAttributeSource{
|
||||||
private final SingularAttributeBinding.NaturalIdMutability naturalIdMutability;
|
private final NaturalIdMutability naturalIdMutability;
|
||||||
private final String propertyRef;
|
private final String propertyRef;
|
||||||
private final Set<MappedByAssociationSource> ownedAssociationSources = new HashSet<MappedByAssociationSource>( );
|
private final Set<MappedByAssociationSource> ownedAssociationSources = new HashSet<MappedByAssociationSource>( );
|
||||||
|
|
||||||
AbstractToOneAttributeSourceImpl(
|
AbstractToOneAttributeSourceImpl(
|
||||||
MappingDocument sourceMappingDocument,
|
MappingDocument sourceMappingDocument,
|
||||||
SingularAttributeBinding.NaturalIdMutability naturalIdMutability,
|
NaturalIdMutability naturalIdMutability,
|
||||||
String propertyRef) {
|
String propertyRef) {
|
||||||
super( sourceMappingDocument );
|
super( sourceMappingDocument );
|
||||||
this.naturalIdMutability = naturalIdMutability;
|
this.naturalIdMutability = naturalIdMutability;
|
||||||
|
@ -68,7 +68,7 @@ public abstract class AbstractToOneAttributeSourceImpl extends AbstractHbmSource
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SingularAttributeBinding.NaturalIdMutability getNaturalIdMutability() {
|
public NaturalIdMutability getNaturalIdMutability() {
|
||||||
return naturalIdMutability;
|
return naturalIdMutability;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,12 +182,12 @@ public abstract class AbstractToOneAttributeSourceImpl extends AbstractHbmSource
|
||||||
final String entityName,
|
final String entityName,
|
||||||
final String tableName,
|
final String tableName,
|
||||||
final AttributeBinding referencedAttributeBinding) {
|
final AttributeBinding referencedAttributeBinding) {
|
||||||
if ( CompositeAttributeBinding.class.isInstance( referencedAttributeBinding ) ) {
|
if ( EmbeddedAttributeBinding.class.isInstance( referencedAttributeBinding ) ) {
|
||||||
CompositeAttributeBinding compositeAttributeBinding = CompositeAttributeBinding.class.cast(
|
EmbeddedAttributeBinding embeddedAttributeBinding = EmbeddedAttributeBinding.class.cast(
|
||||||
referencedAttributeBinding
|
referencedAttributeBinding
|
||||||
);
|
);
|
||||||
List<Binder.DefaultNamingStrategy> result = new ArrayList<Binder.DefaultNamingStrategy>();
|
List<Binder.DefaultNamingStrategy> result = new ArrayList<Binder.DefaultNamingStrategy>();
|
||||||
for ( final AttributeBinding attributeBinding : compositeAttributeBinding.attributeBindings() ) {
|
for ( final AttributeBinding attributeBinding : embeddedAttributeBinding.getEmbeddableBinding().attributeBindings() ) {
|
||||||
result.addAll( getDefaultNamingStrategies( entityName, tableName, attributeBinding ) );
|
result.addAll( getDefaultNamingStrategies( entityName, tableName, attributeBinding ) );
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -23,21 +23,20 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.source.internal.hbm;
|
package org.hibernate.metamodel.source.internal.hbm;
|
||||||
|
|
||||||
import org.hibernate.AssertionFailure;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbArrayElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbArrayElement;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListIndexElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListIndexElement;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSourceContainer;
|
import org.hibernate.metamodel.source.spi.AttributeSourceContainer;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSourceResolutionContext;
|
|
||||||
import org.hibernate.metamodel.source.spi.IndexedPluralAttributeSource;
|
import org.hibernate.metamodel.source.spi.IndexedPluralAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.PluralAttributeIndexSource;
|
import org.hibernate.metamodel.source.spi.PluralAttributeIndexSource;
|
||||||
import org.hibernate.metamodel.source.spi.SequentialPluralAttributeIndexSource;
|
import org.hibernate.metamodel.source.spi.PluralAttributeSequentialIndexSource;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeNature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Brett Meyer
|
* @author Brett Meyer
|
||||||
*/
|
*/
|
||||||
public class ArraySourceImpl extends AbstractPluralAttributeSourceImpl implements IndexedPluralAttributeSource {
|
public class ArraySourceImpl extends AbstractPluralAttributeSourceImpl implements IndexedPluralAttributeSource {
|
||||||
|
|
||||||
private final SequentialPluralAttributeIndexSource indexSource;
|
private final PluralAttributeSequentialIndexSource indexSource;
|
||||||
|
|
||||||
public ArraySourceImpl(
|
public ArraySourceImpl(
|
||||||
MappingDocument sourceMappingDocument,
|
MappingDocument sourceMappingDocument,
|
||||||
|
@ -46,20 +45,12 @@ public class ArraySourceImpl extends AbstractPluralAttributeSourceImpl implement
|
||||||
super( sourceMappingDocument, arrayElement, container );
|
super( sourceMappingDocument, arrayElement, container );
|
||||||
JaxbListIndexElement listIndexElement = arrayElement.getListIndex();
|
JaxbListIndexElement listIndexElement = arrayElement.getListIndex();
|
||||||
if ( listIndexElement == null ) {
|
if ( listIndexElement == null ) {
|
||||||
this.indexSource = new SequentialPluralAttributeIndexSourceImpl( sourceMappingDocument(), arrayElement.getIndex() );
|
this.indexSource = new PluralAttributeSequentialIndexSourceImpl( sourceMappingDocument(), arrayElement.getIndex() );
|
||||||
} else {
|
} else {
|
||||||
this.indexSource = new SequentialPluralAttributeIndexSourceImpl( sourceMappingDocument(), listIndexElement );
|
this.indexSource = new PluralAttributeSequentialIndexSourceImpl( sourceMappingDocument(), listIndexElement );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public PluralAttributeIndexSource resolvePluralAttributeIndexSource(AttributeSourceResolutionContext context) {
|
|
||||||
if ( indexSource == null ) {
|
|
||||||
throw new AssertionFailure( "Array index source should have been resolved already." );
|
|
||||||
}
|
|
||||||
return indexSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PluralAttributeIndexSource getIndexSource() {
|
public PluralAttributeIndexSource getIndexSource() {
|
||||||
return indexSource;
|
return indexSource;
|
||||||
|
@ -76,7 +67,7 @@ public class ArraySourceImpl extends AbstractPluralAttributeSourceImpl implement
|
||||||
* @see org.hibernate.metamodel.source.spi.PluralAttributeSource#getNature()
|
* @see org.hibernate.metamodel.source.spi.PluralAttributeSource#getNature()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Nature getNature() {
|
public PluralAttributeNature getNature() {
|
||||||
return Nature.ARRAY;
|
return PluralAttributeNature.ARRAY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbBagElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbBagElement;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSourceContainer;
|
import org.hibernate.metamodel.source.spi.AttributeSourceContainer;
|
||||||
import org.hibernate.metamodel.source.spi.Orderable;
|
import org.hibernate.metamodel.source.spi.Orderable;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeNature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
|
@ -40,8 +41,8 @@ public class BagSourceImpl extends AbstractPluralAttributeSourceImpl implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Nature getNature() {
|
public PluralAttributeNature getNature() {
|
||||||
return Nature.BAG;
|
return PluralAttributeNature.BAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,164 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.metamodel.source.internal.hbm;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.hibernate.EntityMode;
|
|
||||||
import org.hibernate.internal.util.StringHelper;
|
|
||||||
import org.hibernate.mapping.PropertyGeneration;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbAnyElement;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbArrayElement;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbBagElement;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbComponentElement;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbDynamicComponentElement;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListElement;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToOneElement;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbMapElement;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOneToOneElement;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPrimitiveArrayElement;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertyElement;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSetElement;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbTuplizerElement;
|
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSourceContainer;
|
|
||||||
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Steve Ebersole
|
|
||||||
*/
|
|
||||||
class ComponentAttributeSourceImpl extends AbstractComponentAttributeSourceImpl {
|
|
||||||
public ComponentAttributeSourceImpl(
|
|
||||||
MappingDocument sourceMappingDocument,
|
|
||||||
JaxbComponentElement componentElement,
|
|
||||||
AttributeSourceContainer parentContainer,
|
|
||||||
String logicalTableName,
|
|
||||||
SingularAttributeBinding.NaturalIdMutability naturalIdMutability) {
|
|
||||||
super( sourceMappingDocument, componentElement, parentContainer, logicalTableName, naturalIdMutability );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected JaxbComponentElement componentElement() {
|
|
||||||
return (JaxbComponentElement) super.componentSourceElement();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<AttributeSource> buildAttributeSources() {
|
|
||||||
List<AttributeSource> attributeSources = new ArrayList<AttributeSource>();
|
|
||||||
for(final JaxbPropertyElement element : componentElement().getProperty()){
|
|
||||||
attributeSources.add( buildAttributeSource( element ) );
|
|
||||||
}
|
|
||||||
for(final JaxbManyToOneElement element : componentElement().getManyToOne()){
|
|
||||||
attributeSources.add( buildAttributeSource( element ) );
|
|
||||||
}
|
|
||||||
for(final JaxbOneToOneElement element: componentElement().getOneToOne()){
|
|
||||||
attributeSources.add( buildAttributeSource( element ) );
|
|
||||||
}
|
|
||||||
for(final JaxbComponentElement element: componentElement().getComponent()){
|
|
||||||
attributeSources.add( buildAttributeSource( element ) );
|
|
||||||
}
|
|
||||||
for(final JaxbDynamicComponentElement element: componentElement().getDynamicComponent()){
|
|
||||||
attributeSources.add( buildAttributeSource(element) );
|
|
||||||
}
|
|
||||||
for(final JaxbAnyElement element: componentElement().getAny()){
|
|
||||||
attributeSources.add( buildAttributeSource( element ) );
|
|
||||||
}
|
|
||||||
for(final JaxbMapElement element: componentElement().getMap()){
|
|
||||||
attributeSources.add( buildAttributeSource( element ) );
|
|
||||||
}
|
|
||||||
for(final JaxbSetElement element: componentElement().getSet()){
|
|
||||||
attributeSources.add( buildAttributeSource( element ) );
|
|
||||||
}
|
|
||||||
for(final JaxbListElement element: componentElement().getList()){
|
|
||||||
attributeSources.add( buildAttributeSource( element ) );
|
|
||||||
}
|
|
||||||
for(final JaxbBagElement element: componentElement().getBag()){
|
|
||||||
attributeSources.add( buildAttributeSource( element ) );
|
|
||||||
}
|
|
||||||
for(final JaxbArrayElement element: componentElement().getArray()){
|
|
||||||
attributeSources.add( buildAttributeSource( element ) );
|
|
||||||
}
|
|
||||||
for(final JaxbPrimitiveArrayElement element: componentElement().getPrimitiveArray()){
|
|
||||||
attributeSources.add( buildAttributeSource( element ) );
|
|
||||||
}
|
|
||||||
return attributeSources;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getParentReferenceAttributeName() {
|
|
||||||
return componentElement().getParent() == null ? null : componentElement().getParent().getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getExplicitTuplizerClassName() {
|
|
||||||
if ( componentElement().getTuplizer() == null ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
final EntityMode entityMode = StringHelper.isEmpty( componentElement().getClazz() ) ? EntityMode.MAP : EntityMode.POJO;
|
|
||||||
for ( JaxbTuplizerElement tuplizerElement : componentElement().getTuplizer() ) {
|
|
||||||
if ( entityMode == EntityMode.parse( tuplizerElement.getEntityMode().value() ) ) {
|
|
||||||
return tuplizerElement.getClazz();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PropertyGeneration getGeneration() {
|
|
||||||
// todo : is this correct here?
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isLazy() {
|
|
||||||
return componentElement().isLazy();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isIncludedInOptimisticLocking() {
|
|
||||||
return componentElement().isOptimisticLock();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areValuesIncludedInInsertByDefault() {
|
|
||||||
return componentElement().isInsert();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areValuesIncludedInUpdateByDefault() {
|
|
||||||
return componentElement().isUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areValuesNullableByDefault() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<RelationalValueSource> relationalValueSources() {
|
|
||||||
// none, they are defined on the simple sub-attributes
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,182 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.metamodel.source.internal.hbm;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.hibernate.EntityMode;
|
|
||||||
import org.hibernate.cfg.NotYetImplementedException;
|
|
||||||
import org.hibernate.engine.spi.CascadeStyle;
|
|
||||||
import org.hibernate.internal.util.StringHelper;
|
|
||||||
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbAnyElement;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbCompositeElementElement;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToOneElement;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbNestedCompositeElementElement;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertyElement;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbTuplizerElement;
|
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.CompositePluralAttributeElementSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
|
||||||
import org.hibernate.metamodel.spi.LocalBindingContext;
|
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Steve Ebersole
|
|
||||||
* @author Gail Badner
|
|
||||||
*/
|
|
||||||
public class CompositePluralAttributeElementSourceImpl
|
|
||||||
extends AbstractHbmSourceNode
|
|
||||||
implements CompositePluralAttributeElementSource {
|
|
||||||
|
|
||||||
private final JaxbCompositeElementElement compositeElement;
|
|
||||||
private final Set<CascadeStyle> cascadeStyles;
|
|
||||||
private final List<AttributeSource> attributeSources;
|
|
||||||
|
|
||||||
public CompositePluralAttributeElementSourceImpl(
|
|
||||||
MappingDocument mappingDocument,
|
|
||||||
JaxbCompositeElementElement compositeElement,
|
|
||||||
String cascadeString) {
|
|
||||||
super( mappingDocument );
|
|
||||||
this.compositeElement = compositeElement;
|
|
||||||
this.cascadeStyles = Helper.interpretCascadeStyles( cascadeString, bindingContext() );
|
|
||||||
this.attributeSources = buildAttributeSources( mappingDocument, compositeElement );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Nature getNature() {
|
|
||||||
return Nature.AGGREGATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JavaTypeDescriptor getTypeDescriptor() {
|
|
||||||
return bindingContext().typeDescriptor( compositeElement.getClazz() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getParentReferenceAttributeName() {
|
|
||||||
return compositeElement.getParent() != null
|
|
||||||
? compositeElement.getParent().getName()
|
|
||||||
: null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getExplicitTuplizerClassName() {
|
|
||||||
if ( compositeElement.getTuplizer() == null ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
final EntityMode entityMode = StringHelper.isEmpty( compositeElement.getClazz() ) ? EntityMode.MAP : EntityMode.POJO;
|
|
||||||
for ( JaxbTuplizerElement tuplizerElement : compositeElement.getTuplizer() ) {
|
|
||||||
if ( entityMode == EntityMode.parse( tuplizerElement.getEntityMode().value() ) ) {
|
|
||||||
return tuplizerElement.getClazz();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPath() {
|
|
||||||
// todo : implementing this requires passing in the collection source and being able to resolve the collection's role
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<AttributeSource> attributeSources() {
|
|
||||||
return attributeSources;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<AttributeSource> buildAttributeSources(
|
|
||||||
MappingDocument mappingDocument,
|
|
||||||
JaxbCompositeElementElement compositeElement) {
|
|
||||||
List<AttributeSource> attributeSources = new ArrayList<AttributeSource>();
|
|
||||||
for( final JaxbAnyElement element : compositeElement.getAny() ) {
|
|
||||||
attributeSources.add( buildAttributeSource( mappingDocument, element ) );
|
|
||||||
}
|
|
||||||
for( final JaxbManyToOneElement element : compositeElement.getManyToOne() ) {
|
|
||||||
attributeSources.add( buildAttributeSource( mappingDocument, element ) );
|
|
||||||
}
|
|
||||||
for( final JaxbNestedCompositeElementElement element : compositeElement.getNestedCompositeElement() ) {
|
|
||||||
attributeSources.add( buildAttributeSource( mappingDocument, element ) );
|
|
||||||
}
|
|
||||||
for( final JaxbPropertyElement element : compositeElement.getProperty() ) {
|
|
||||||
attributeSources.add( buildAttributeSource( mappingDocument, element ) );
|
|
||||||
}
|
|
||||||
return attributeSources;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LocalBindingContext getLocalBindingContext() {
|
|
||||||
return bindingContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<CascadeStyle> getCascadeStyles() {
|
|
||||||
return cascadeStyles;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static AttributeSource buildAttributeSource(
|
|
||||||
MappingDocument sourceMappingDocument,
|
|
||||||
JaxbAnyElement attributeElement) {
|
|
||||||
// todo : implement
|
|
||||||
throw new NotYetImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static SingularAttributeSource buildAttributeSource(
|
|
||||||
MappingDocument sourceMappingDocument,
|
|
||||||
JaxbPropertyElement attributeElement) {
|
|
||||||
return new PropertyAttributeSourceImpl(
|
|
||||||
sourceMappingDocument,
|
|
||||||
attributeElement,
|
|
||||||
null,
|
|
||||||
SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static AttributeSource buildAttributeSource(
|
|
||||||
MappingDocument sourceMappingDocument,
|
|
||||||
JaxbManyToOneElement attributeElement) {
|
|
||||||
return new ManyToOneAttributeSourceImpl(
|
|
||||||
sourceMappingDocument,
|
|
||||||
JaxbManyToOneElement.class.cast( attributeElement ),
|
|
||||||
null,
|
|
||||||
SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static AttributeSource buildAttributeSource(
|
|
||||||
MappingDocument sourceMappingDocument,
|
|
||||||
JaxbNestedCompositeElementElement attributeElement) {
|
|
||||||
// todo : implement
|
|
||||||
throw new NotYetImplementedException( "Nested composite element is not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<? extends ToolingHintSource> getToolingHintSources() {
|
|
||||||
return compositeElement.getMeta();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,175 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.metamodel.source.internal.hbm;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.hibernate.metamodel.internal.binder.Binder;
|
|
||||||
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbCompositeIndexElement;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbCompositeMapKeyElement;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyManyToOneElement;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyPropertyElement;
|
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.CompositePluralAttributeIndexSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.HibernateTypeSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
|
||||||
import org.hibernate.metamodel.spi.LocalBindingContext;
|
|
||||||
import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
|
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Gail Badner
|
|
||||||
*/
|
|
||||||
public class CompositePluralAttributeIndexSourceImpl
|
|
||||||
extends AbstractHbmSourceNode
|
|
||||||
implements CompositePluralAttributeIndexSource {
|
|
||||||
|
|
||||||
private final String className;
|
|
||||||
private final List<AttributeSource> attributeSources;
|
|
||||||
|
|
||||||
public CompositePluralAttributeIndexSourceImpl(
|
|
||||||
MappingDocument mappingDocument,
|
|
||||||
JaxbCompositeIndexElement compositeIndexElement) {
|
|
||||||
this(
|
|
||||||
mappingDocument,
|
|
||||||
compositeIndexElement.getClazz(),
|
|
||||||
compositeIndexElement.getKeyProperty(),
|
|
||||||
compositeIndexElement.getKeyManyToOne()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompositePluralAttributeIndexSourceImpl(
|
|
||||||
MappingDocument mappingDocument,
|
|
||||||
JaxbCompositeMapKeyElement compositeMapKeyElement) {
|
|
||||||
this(
|
|
||||||
mappingDocument,
|
|
||||||
compositeMapKeyElement.getClazz(),
|
|
||||||
compositeMapKeyElement.getKeyProperty(),
|
|
||||||
compositeMapKeyElement.getKeyManyToOne()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private CompositePluralAttributeIndexSourceImpl(
|
|
||||||
MappingDocument mappingDocument,
|
|
||||||
String className,
|
|
||||||
List<JaxbKeyPropertyElement> keyPropertyElements,
|
|
||||||
List<JaxbKeyManyToOneElement> keyManyToOneElements) {
|
|
||||||
super( mappingDocument );
|
|
||||||
this.className = bindingContext().qualifyClassName( className );
|
|
||||||
this.attributeSources = buildAttributeSources(
|
|
||||||
mappingDocument,
|
|
||||||
keyPropertyElements,
|
|
||||||
keyManyToOneElements
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PluralAttributeIndexBinding.Nature getNature() {
|
|
||||||
return PluralAttributeIndexBinding.Nature.AGGREGATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Binder.DefaultNamingStrategy> getDefaultNamingStrategies() {
|
|
||||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HibernateTypeSource getTypeInformation() {
|
|
||||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isReferencedEntityAttribute() {
|
|
||||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JavaTypeDescriptor getTypeDescriptor() {
|
|
||||||
return bindingContext().typeDescriptor( className );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPath() {
|
|
||||||
// todo : implementing this requires passing in the collection source and being able to resolve the collection's role
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<AttributeSource> attributeSources() {
|
|
||||||
return attributeSources;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<AttributeSource> buildAttributeSources(
|
|
||||||
MappingDocument mappingDocument,
|
|
||||||
List<JaxbKeyPropertyElement> keyPropertyElements,
|
|
||||||
List<JaxbKeyManyToOneElement> keyManyToOneElements) {
|
|
||||||
List<AttributeSource> attributeSources = new ArrayList<AttributeSource>();
|
|
||||||
for ( JaxbKeyPropertyElement keyProperty : keyPropertyElements ){
|
|
||||||
attributeSources.add(
|
|
||||||
new KeyAttributeSourceImpl(
|
|
||||||
mappingDocument,
|
|
||||||
keyProperty,
|
|
||||||
SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
for (JaxbKeyManyToOneElement keyManyToOne :keyManyToOneElements ){
|
|
||||||
attributeSources.add(
|
|
||||||
new KeyManyToOneSourceImpl(
|
|
||||||
mappingDocument,
|
|
||||||
keyManyToOne,
|
|
||||||
SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return attributeSources;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LocalBindingContext getLocalBindingContext() {
|
|
||||||
return bindingContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<RelationalValueSource> relationalValueSources() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areValuesIncludedInInsertByDefault() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areValuesIncludedInUpdateByDefault() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areValuesNullableByDefault() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,95 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.metamodel.source.internal.hbm;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbAnyElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbArrayElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbBagElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbComponentElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbDynamicComponentElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyManyToOneElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyPropertyElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToOneElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbMapElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbNestedCompositeElementElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOneToOneElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPrimitiveArrayElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertiesElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertyElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSetElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes the JAXB source (HBM) for embeddable (composite) information. The
|
||||||
|
* HBM XML schema unfortunately did not define these consistently between
|
||||||
|
* {@code <component/>} and {@code <composite-id/>}, so this contract unifies
|
||||||
|
* access to this information.
|
||||||
|
*
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public interface EmbeddableJaxbSource {
|
||||||
|
public String getClazz();
|
||||||
|
|
||||||
|
public String findParent();
|
||||||
|
public String findTuplizer();
|
||||||
|
|
||||||
|
// todo : ultimately would be nice to remove the distinction between:
|
||||||
|
// * getKeyPropertyElementList() / getPropertyElementList()
|
||||||
|
// * getKeyManyToOneElementList() / getManyToOneElementList()
|
||||||
|
// the difference is really a matter of the "container", not the attribute
|
||||||
|
|
||||||
|
public List<JaxbKeyPropertyElement> getKeyPropertyElementList();
|
||||||
|
|
||||||
|
public List<JaxbKeyManyToOneElement> getKeyManyToOneElementList();
|
||||||
|
|
||||||
|
public List<JaxbPropertyElement> getPropertyElementList();
|
||||||
|
|
||||||
|
public List<JaxbManyToOneElement> getManyToOneElementList();
|
||||||
|
|
||||||
|
public List<JaxbOneToOneElement> getOneToOneElementList();
|
||||||
|
|
||||||
|
public List<JaxbComponentElement> getComponentElementList();
|
||||||
|
|
||||||
|
public List<JaxbNestedCompositeElementElement> getNestedCompositeElementList();
|
||||||
|
|
||||||
|
public List<JaxbDynamicComponentElement> getDynamicComponentElementList();
|
||||||
|
|
||||||
|
public List<JaxbPropertiesElement> getPropertiesElementList();
|
||||||
|
|
||||||
|
public List<JaxbAnyElement> getAnyElementList();
|
||||||
|
|
||||||
|
public List<JaxbMapElement> getMapElementList();
|
||||||
|
|
||||||
|
public List<JaxbSetElement> getSetElementList();
|
||||||
|
|
||||||
|
public List<JaxbListElement> getListElementList();
|
||||||
|
|
||||||
|
public List<JaxbBagElement> getBagElementList();
|
||||||
|
|
||||||
|
public List<JaxbArrayElement> getArrayElementList();
|
||||||
|
|
||||||
|
public List<JaxbPrimitiveArrayElement> getPrimitiveArrayElementList();
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
|
||||||
* indicated by the @author tags or express copyright attribution
|
* indicated by the @author tags or express copyright attribution
|
||||||
* statements applied by the authors. All third-party contributions are
|
* statements applied by the authors. All third-party contributions are
|
||||||
* distributed under license by Red Hat Inc.
|
* distributed under license by Red Hat Inc.
|
||||||
|
@ -23,73 +23,188 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.source.internal.hbm;
|
package org.hibernate.metamodel.source.internal.hbm;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.cfg.NotYetImplementedException;
|
import org.hibernate.cfg.NotYetImplementedException;
|
||||||
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.ComponentSourceElement;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbAnyElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbAnyElement;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbArrayElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbArrayElement;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbBagElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbBagElement;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbComponentElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbComponentElement;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbDynamicComponentElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbDynamicComponentElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyManyToOneElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyPropertyElement;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListElement;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToManyElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToManyElement;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToOneElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToOneElement;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbMapElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbMapElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbNestedCompositeElementElement;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOneToManyElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOneToManyElement;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOneToOneElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOneToOneElement;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPrimitiveArrayElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPrimitiveArrayElement;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertyElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertyElement;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSetElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSetElement;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSource;
|
import org.hibernate.metamodel.source.spi.AttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSourceContainer;
|
import org.hibernate.metamodel.source.spi.EmbeddableSource;
|
||||||
import org.hibernate.metamodel.source.spi.ComponentAttributeSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.HibernateTypeSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
import org.hibernate.metamodel.spi.LocalBindingContext;
|
import org.hibernate.metamodel.spi.LocalBindingContext;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractComponentAttributeSourceImpl extends AbstractHbmSourceNode implements ComponentAttributeSource {
|
public class EmbeddableSourceImpl extends AbstractHbmSourceNode implements EmbeddableSource {
|
||||||
private final ComponentSourceElement componentSourceElement;
|
private final EmbeddableJaxbSource embeddableSource;
|
||||||
private final AttributeSourceContainer parentContainer;
|
private final JavaTypeDescriptor typeDescriptor;
|
||||||
private final List<AttributeSource> subAttributeSources;
|
|
||||||
private final SingularAttributeBinding.NaturalIdMutability naturalIdMutability;
|
private final AttributeRole attributeRoleBase;
|
||||||
private final JavaTypeDescriptor componentTypeDescriptor;
|
private final AttributePath attributePathBase;
|
||||||
|
|
||||||
private final String logicalTableName;
|
private final String logicalTableName;
|
||||||
private final String path;
|
private final NaturalIdMutability naturalIdMutability;
|
||||||
|
|
||||||
protected AbstractComponentAttributeSourceImpl(
|
private final List<AttributeSource> attributeSources;
|
||||||
MappingDocument sourceMappingDocument,
|
|
||||||
ComponentSourceElement componentSourceElement,
|
public EmbeddableSourceImpl(
|
||||||
AttributeSourceContainer parentContainer,
|
MappingDocument mappingDocument,
|
||||||
|
AttributeRole attributeRoleBase,
|
||||||
|
AttributePath attributePathBase,
|
||||||
|
EmbeddableJaxbSource embeddableJaxbSource,
|
||||||
String logicalTableName,
|
String logicalTableName,
|
||||||
SingularAttributeBinding.NaturalIdMutability naturalIdMutability) {
|
NaturalIdMutability naturalIdMutability) {
|
||||||
super( sourceMappingDocument );
|
super( mappingDocument );
|
||||||
this.componentSourceElement = componentSourceElement;
|
this.attributeRoleBase = attributeRoleBase;
|
||||||
this.parentContainer = parentContainer;
|
this.attributePathBase = attributePathBase;
|
||||||
this.naturalIdMutability = naturalIdMutability;
|
this.embeddableSource = embeddableJaxbSource;
|
||||||
this.componentTypeDescriptor = typeDescriptor( componentSourceElement.getClazz() );
|
|
||||||
this.logicalTableName = logicalTableName;
|
this.logicalTableName = logicalTableName;
|
||||||
this.path = parentContainer.getPath() + '.' + componentSourceElement.getName();
|
this.naturalIdMutability = naturalIdMutability;
|
||||||
|
|
||||||
this.subAttributeSources = buildAttributeSources();
|
this.typeDescriptor = typeDescriptor( embeddableJaxbSource.getClazz() );
|
||||||
|
|
||||||
|
this.attributeSources = buildAttributeSources( embeddableJaxbSource, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getContainingTableName() {
|
public JavaTypeDescriptor getTypeDescriptor() {
|
||||||
return logicalTableName;
|
return typeDescriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getParentReferenceAttributeName() {
|
||||||
|
return embeddableSource.findParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getExplicitTuplizerClassName() {
|
||||||
|
return embeddableSource.findTuplizer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributePath getAttributePathBase() {
|
||||||
|
return attributePathBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributeRole getAttributeRoleBase() {
|
||||||
|
return attributeRoleBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AttributeSource> attributeSources() {
|
||||||
|
return attributeSources;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocalBindingContext getLocalBindingContext() {
|
||||||
|
return bindingContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// Attribute building
|
||||||
|
|
||||||
|
protected static List<AttributeSource> buildAttributeSources(
|
||||||
|
EmbeddableJaxbSource container,
|
||||||
|
EmbeddableSourceImpl embeddableSource) {
|
||||||
|
final List<AttributeSource> attributeSources = new ArrayList<AttributeSource>();
|
||||||
|
|
||||||
|
for ( JaxbPropertyElement element : container.getPropertyElementList() ) {
|
||||||
|
attributeSources.add( embeddableSource.buildAttributeSource( element ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( JaxbManyToOneElement element : container.getManyToOneElementList() ) {
|
||||||
|
attributeSources.add( embeddableSource.buildAttributeSource( element ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( JaxbOneToOneElement element: container.getOneToOneElementList() ) {
|
||||||
|
attributeSources.add( embeddableSource.buildAttributeSource( element ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( JaxbComponentElement element: container.getComponentElementList() ) {
|
||||||
|
attributeSources.add( embeddableSource.buildAttributeSource( element ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( JaxbNestedCompositeElementElement element: container.getNestedCompositeElementList() ) {
|
||||||
|
attributeSources.add( embeddableSource.buildAttributeSource( element ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( JaxbDynamicComponentElement element: container.getDynamicComponentElementList() ) {
|
||||||
|
attributeSources.add( embeddableSource.buildAttributeSource(element) );
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( JaxbAnyElement element: container.getAnyElementList() ) {
|
||||||
|
attributeSources.add( embeddableSource.buildAttributeSource( element ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( JaxbMapElement element: container.getMapElementList() ) {
|
||||||
|
attributeSources.add( embeddableSource.buildAttributeSource( element ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( JaxbSetElement element: container.getSetElementList() ) {
|
||||||
|
attributeSources.add( embeddableSource.buildAttributeSource( element ) );
|
||||||
|
}
|
||||||
|
for ( JaxbListElement element: container.getListElementList() ) {
|
||||||
|
attributeSources.add( embeddableSource.buildAttributeSource( element ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( JaxbBagElement element: container.getBagElementList() ) {
|
||||||
|
attributeSources.add( embeddableSource.buildAttributeSource( element ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( JaxbArrayElement element: container.getArrayElementList() ) {
|
||||||
|
attributeSources.add( embeddableSource.buildAttributeSource( element ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( JaxbPrimitiveArrayElement element: container.getPrimitiveArrayElementList() ) {
|
||||||
|
attributeSources.add( embeddableSource.buildAttributeSource( element ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( JaxbKeyPropertyElement element : container.getKeyPropertyElementList() ) {
|
||||||
|
attributeSources.add( embeddableSource.buildAttributeSource( element ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( JaxbKeyManyToOneElement element : container.getKeyManyToOneElementList() ) {
|
||||||
|
attributeSources.add( embeddableSource.buildAttributeSource( element ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
return attributeSources;
|
||||||
|
}
|
||||||
|
|
||||||
|
private AttributeSource buildAttributeSource(JaxbKeyPropertyElement element) {
|
||||||
|
return new IdentifierKeyAttributeSourceImpl( sourceMappingDocument(), this, element );
|
||||||
|
}
|
||||||
|
|
||||||
|
private AttributeSource buildAttributeSource(JaxbKeyManyToOneElement element) {
|
||||||
|
return new IdentifierKeyManyToOneSourceImpl( sourceMappingDocument(), this, element );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract List<AttributeSource> buildAttributeSources();
|
|
||||||
protected SingularAttributeSource buildAttributeSource(JaxbPropertyElement attributeElement) {
|
protected SingularAttributeSource buildAttributeSource(JaxbPropertyElement attributeElement) {
|
||||||
return new PropertyAttributeSourceImpl(
|
return new PropertyAttributeSourceImpl(
|
||||||
sourceMappingDocument(),
|
sourceMappingDocument(),
|
||||||
|
this,
|
||||||
attributeElement,
|
attributeElement,
|
||||||
logicalTableName,
|
logicalTableName,
|
||||||
naturalIdMutability
|
naturalIdMutability
|
||||||
|
@ -97,21 +212,29 @@ public abstract class AbstractComponentAttributeSourceImpl extends AbstractHbmSo
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AttributeSource buildAttributeSource(JaxbComponentElement attributeElement) {
|
protected AttributeSource buildAttributeSource(JaxbComponentElement attributeElement) {
|
||||||
return new ComponentAttributeSourceImpl(
|
return new EmbeddedAttributeSourceImpl(
|
||||||
sourceMappingDocument(),
|
sourceMappingDocument(),
|
||||||
attributeElement,
|
|
||||||
this,
|
this,
|
||||||
logicalTableName,
|
attributeElement,
|
||||||
naturalIdMutability
|
naturalIdMutability,
|
||||||
|
logicalTableName
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
protected AttributeSource buildAttributeSource(JaxbDynamicComponentElement attributeElement){
|
|
||||||
|
private AttributeSource buildAttributeSource(JaxbNestedCompositeElementElement element) {
|
||||||
// todo : implement
|
// todo : implement
|
||||||
throw new NotYetImplementedException();
|
throw new NotYetImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected AttributeSource buildAttributeSource(JaxbDynamicComponentElement attributeElement) {
|
||||||
|
// todo : implement
|
||||||
|
throw new NotYetImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
protected AttributeSource buildAttributeSource(JaxbManyToOneElement attributeElement) {
|
protected AttributeSource buildAttributeSource(JaxbManyToOneElement attributeElement) {
|
||||||
return new ManyToOneAttributeSourceImpl(
|
return new ManyToOneAttributeSourceImpl(
|
||||||
sourceMappingDocument(),
|
sourceMappingDocument(),
|
||||||
|
this,
|
||||||
attributeElement,
|
attributeElement,
|
||||||
logicalTableName,
|
logicalTableName,
|
||||||
naturalIdMutability
|
naturalIdMutability
|
||||||
|
@ -121,6 +244,7 @@ public abstract class AbstractComponentAttributeSourceImpl extends AbstractHbmSo
|
||||||
protected AttributeSource buildAttributeSource(JaxbOneToOneElement attributeElement) {
|
protected AttributeSource buildAttributeSource(JaxbOneToOneElement attributeElement) {
|
||||||
return new OneToOneAttributeSourceImpl(
|
return new OneToOneAttributeSourceImpl(
|
||||||
sourceMappingDocument(),
|
sourceMappingDocument(),
|
||||||
|
this,
|
||||||
attributeElement,
|
attributeElement,
|
||||||
logicalTableName,
|
logicalTableName,
|
||||||
naturalIdMutability
|
naturalIdMutability
|
||||||
|
@ -141,110 +265,44 @@ public abstract class AbstractComponentAttributeSourceImpl extends AbstractHbmSo
|
||||||
// todo : implement
|
// todo : implement
|
||||||
throw new NotYetImplementedException();
|
throw new NotYetImplementedException();
|
||||||
}
|
}
|
||||||
// todo duplicated with org.hibernate.metamodel.internal.source.hbm.AbstractEntitySourceImpl
|
|
||||||
protected AttributeSource buildAttributeSource(JaxbMapElement attributeElement){
|
protected AttributeSource buildAttributeSource(JaxbMapElement attributeElement) {
|
||||||
return new MapSourceImpl(
|
return new MapSourceImpl(
|
||||||
sourceMappingDocument(),
|
sourceMappingDocument(),
|
||||||
attributeElement,
|
attributeElement,
|
||||||
parentContainer
|
this
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
protected AttributeSource buildAttributeSource(JaxbSetElement attributeElement) {
|
protected AttributeSource buildAttributeSource(JaxbSetElement attributeElement) {
|
||||||
return new SetSourceImpl(
|
return new SetSourceImpl(
|
||||||
sourceMappingDocument(),
|
sourceMappingDocument(),
|
||||||
attributeElement,
|
attributeElement,
|
||||||
parentContainer
|
this
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
protected AttributeSource buildAttributeSource(JaxbListElement attributeElement) {
|
protected AttributeSource buildAttributeSource(JaxbListElement attributeElement) {
|
||||||
return new ListSourceImpl(
|
return new ListSourceImpl(
|
||||||
sourceMappingDocument(),
|
sourceMappingDocument(),
|
||||||
attributeElement,
|
attributeElement,
|
||||||
parentContainer
|
this
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
protected AttributeSource buildAttributeSource(JaxbBagElement attributeElement) {
|
protected AttributeSource buildAttributeSource(JaxbBagElement attributeElement) {
|
||||||
return new BagSourceImpl(
|
return new BagSourceImpl(
|
||||||
sourceMappingDocument(),
|
sourceMappingDocument(),
|
||||||
attributeElement,
|
attributeElement,
|
||||||
parentContainer
|
this
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
protected AttributeSource buildAttributeSource(JaxbArrayElement attributeElement) {
|
protected AttributeSource buildAttributeSource(JaxbArrayElement attributeElement) {
|
||||||
return new ArraySourceImpl(
|
return new ArraySourceImpl(
|
||||||
sourceMappingDocument(),
|
sourceMappingDocument(),
|
||||||
attributeElement,
|
attributeElement,
|
||||||
parentContainer
|
this
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
protected AttributeSource buildAttributeSource(JaxbPrimitiveArrayElement attributeElement) {
|
protected AttributeSource buildAttributeSource(JaxbPrimitiveArrayElement attributeElement) {
|
||||||
// todo : implement
|
// todo : implement
|
||||||
throw new NotYetImplementedException();
|
throw new NotYetImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected ComponentSourceElement componentSourceElement() {
|
|
||||||
return componentSourceElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JavaTypeDescriptor getTypeDescriptor() {
|
|
||||||
return componentTypeDescriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPath() {
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LocalBindingContext getLocalBindingContext() {
|
|
||||||
return parentContainer.getLocalBindingContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<AttributeSource> attributeSources() {
|
|
||||||
return subAttributeSources;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isVirtualAttribute() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Nature getNature() {
|
|
||||||
return Nature.COMPOSITE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HibernateTypeSource getTypeInformation() {
|
|
||||||
// <component/> does not support type information.
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return componentSourceElement.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSingular() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPropertyAccessorName() {
|
|
||||||
return componentSourceElement.getAccess();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SingularAttributeBinding.NaturalIdMutability getNaturalIdMutability() {
|
|
||||||
return naturalIdMutability;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<? extends ToolingHintSource> getToolingHintSources() {
|
|
||||||
return componentSourceElement.getMeta();
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -0,0 +1,211 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.metamodel.source.internal.hbm;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.EntityMode;
|
||||||
|
import org.hibernate.internal.util.StringHelper;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbAnyElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbArrayElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbBagElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbComponentElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbDynamicComponentElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToOneElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbMapElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOneToOneElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPrimitiveArrayElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertiesElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertyElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSetElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbTuplizerElement;
|
||||||
|
import org.hibernate.metamodel.source.spi.AttributeSourceContainer;
|
||||||
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The source information for a singular attribute whose type is composite
|
||||||
|
* (embedded in JPA terms).
|
||||||
|
*
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
class EmbeddedAttributeSourceImpl extends AbstractEmbeddedAttributeSourceImpl {
|
||||||
|
public EmbeddedAttributeSourceImpl(
|
||||||
|
MappingDocument sourceMappingDocument,
|
||||||
|
AttributeSourceContainer parentContainer,
|
||||||
|
JaxbComponentElement jaxbComponentElement,
|
||||||
|
NaturalIdMutability naturalIdMutability,
|
||||||
|
String logicalTableName) {
|
||||||
|
super(
|
||||||
|
sourceMappingDocument,
|
||||||
|
parentContainer,
|
||||||
|
parentContainer.getAttributeRoleBase().append( jaxbComponentElement.getName() ),
|
||||||
|
parentContainer.getAttributePathBase().append( jaxbComponentElement.getName() ),
|
||||||
|
jaxbComponentElement,
|
||||||
|
new EmbeddableJaxbSourceImpl( jaxbComponentElement ),
|
||||||
|
naturalIdMutability,
|
||||||
|
logicalTableName
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JaxbComponentElement jaxbComponentSourceElement() {
|
||||||
|
return (JaxbComponentElement) super.jaxbComponentSourceElement();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLazy() {
|
||||||
|
return jaxbComponentSourceElement().isLazy();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributePath getAttributePath() {
|
||||||
|
return getEmbeddableSource().getAttributePathBase();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributeRole getAttributeRole() {
|
||||||
|
return getEmbeddableSource().getAttributeRoleBase();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isIncludedInOptimisticLocking() {
|
||||||
|
return jaxbComponentSourceElement().isOptimisticLock();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean areValuesIncludedInInsertByDefault() {
|
||||||
|
return jaxbComponentSourceElement().isInsert();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean areValuesIncludedInUpdateByDefault() {
|
||||||
|
return jaxbComponentSourceElement().isUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EmbeddableJaxbSourceImpl extends AbstractEmbeddableJaxbSource {
|
||||||
|
private final JaxbComponentElement jaxbComponentElement;
|
||||||
|
|
||||||
|
public EmbeddableJaxbSourceImpl(JaxbComponentElement jaxbComponentElement) {
|
||||||
|
this.jaxbComponentElement = jaxbComponentElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getClazz() {
|
||||||
|
return jaxbComponentElement.getClazz();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String findParent() {
|
||||||
|
return jaxbComponentElement.getParent() == null
|
||||||
|
? null
|
||||||
|
: jaxbComponentElement.getParent().getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String findTuplizer() {
|
||||||
|
if ( jaxbComponentElement.getTuplizer() == null ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final EntityMode entityMode = StringHelper.isEmpty( jaxbComponentElement.getClazz() )
|
||||||
|
? EntityMode.MAP
|
||||||
|
: EntityMode.POJO;
|
||||||
|
|
||||||
|
for ( JaxbTuplizerElement tuplizerElement : jaxbComponentElement.getTuplizer() ) {
|
||||||
|
if ( entityMode == EntityMode.parse( tuplizerElement.getEntityMode().value() ) ) {
|
||||||
|
return tuplizerElement.getClazz();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbPropertyElement> getPropertyElementList() {
|
||||||
|
return jaxbComponentElement.getProperty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbManyToOneElement> getManyToOneElementList() {
|
||||||
|
return jaxbComponentElement.getManyToOne();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbOneToOneElement> getOneToOneElementList() {
|
||||||
|
return jaxbComponentElement.getOneToOne();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbComponentElement> getComponentElementList() {
|
||||||
|
return jaxbComponentElement.getComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbDynamicComponentElement> getDynamicComponentElementList() {
|
||||||
|
return jaxbComponentElement.getDynamicComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbPropertiesElement> getPropertiesElementList() {
|
||||||
|
return jaxbComponentElement.getProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbAnyElement> getAnyElementList() {
|
||||||
|
return jaxbComponentElement.getAny();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbMapElement> getMapElementList() {
|
||||||
|
return jaxbComponentElement.getMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbSetElement> getSetElementList() {
|
||||||
|
return jaxbComponentElement.getSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbListElement> getListElementList() {
|
||||||
|
return jaxbComponentElement.getList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbBagElement> getBagElementList() {
|
||||||
|
return jaxbComponentElement.getBag();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbArrayElement> getArrayElementList() {
|
||||||
|
return jaxbComponentElement.getArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbPrimitiveArrayElement> getPrimitiveArrayElementList() {
|
||||||
|
return jaxbComponentElement.getPrimitiveArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -32,7 +32,6 @@ import org.hibernate.TruthValue;
|
||||||
import org.hibernate.engine.OptimisticLockStyle;
|
import org.hibernate.engine.OptimisticLockStyle;
|
||||||
import org.hibernate.id.EntityIdentifierNature;
|
import org.hibernate.id.EntityIdentifierNature;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.mapping.PropertyGeneration;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbClassElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbClassElement;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbCompositeIdElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbCompositeIdElement;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbDiscriminatorElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbDiscriminatorElement;
|
||||||
|
@ -41,9 +40,8 @@ import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyPropertyElement;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbMultiTenancyElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbMultiTenancyElement;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPolymorphismAttribute;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPolymorphismAttribute;
|
||||||
import org.hibernate.metamodel.source.spi.AggregatedCompositeIdentifierSource;
|
import org.hibernate.metamodel.source.spi.AggregatedCompositeIdentifierSource;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.ComponentAttributeSource;
|
|
||||||
import org.hibernate.metamodel.source.spi.DiscriminatorSource;
|
import org.hibernate.metamodel.source.spi.DiscriminatorSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.EmbeddedAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.EntityHierarchySource;
|
import org.hibernate.metamodel.source.spi.EntityHierarchySource;
|
||||||
import org.hibernate.metamodel.source.spi.EntitySource;
|
import org.hibernate.metamodel.source.spi.EntitySource;
|
||||||
import org.hibernate.metamodel.source.spi.IdentifierSource;
|
import org.hibernate.metamodel.source.spi.IdentifierSource;
|
||||||
|
@ -56,10 +54,12 @@ import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.SizeSource;
|
import org.hibernate.metamodel.source.spi.SizeSource;
|
||||||
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
||||||
import org.hibernate.metamodel.source.spi.VersionAttributeSource;
|
import org.hibernate.metamodel.source.spi.VersionAttributeSource;
|
||||||
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
import org.hibernate.metamodel.spi.binding.Caching;
|
import org.hibernate.metamodel.spi.binding.Caching;
|
||||||
import org.hibernate.metamodel.spi.binding.IdentifierGeneratorDefinition;
|
import org.hibernate.metamodel.spi.binding.IdentifierGeneratorDefinition;
|
||||||
import org.hibernate.metamodel.spi.binding.InheritanceType;
|
import org.hibernate.metamodel.spi.binding.InheritanceType;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
|
@ -74,7 +74,7 @@ public class EntityHierarchySourceImpl implements EntityHierarchySource {
|
||||||
this.rootEntitySource = rootEntitySource;
|
this.rootEntitySource = rootEntitySource;
|
||||||
this.rootEntitySource.injectHierarchy( this );
|
this.rootEntitySource.injectHierarchy( this );
|
||||||
|
|
||||||
this.caching = Helper.createCaching( entityElement().getCache(), getEntityName() );
|
this.caching = Helper.createCaching( entityElement().getCache() );
|
||||||
this.naturalIdCaching = Helper.createNaturalIdCaching(
|
this.naturalIdCaching = Helper.createNaturalIdCaching(
|
||||||
rootEntitySource.entityElement().getNaturalIdCache()
|
rootEntitySource.entityElement().getNaturalIdCache()
|
||||||
);
|
);
|
||||||
|
@ -147,12 +147,14 @@ public class EntityHierarchySourceImpl implements EntityHierarchySource {
|
||||||
if ( entityElement().getVersion() != null ) {
|
if ( entityElement().getVersion() != null ) {
|
||||||
return new VersionAttributeSourceImpl(
|
return new VersionAttributeSourceImpl(
|
||||||
rootEntitySource.sourceMappingDocument(),
|
rootEntitySource.sourceMappingDocument(),
|
||||||
|
rootEntitySource,
|
||||||
entityElement().getVersion()
|
entityElement().getVersion()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else if ( entityElement().getTimestamp() != null ) {
|
else if ( entityElement().getTimestamp() != null ) {
|
||||||
return new TimestampAttributeSourceImpl(
|
return new TimestampAttributeSourceImpl(
|
||||||
rootEntitySource.sourceMappingDocument(),
|
rootEntitySource.sourceMappingDocument(),
|
||||||
|
rootEntitySource,
|
||||||
entityElement().getTimestamp()
|
entityElement().getTimestamp()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -339,7 +341,7 @@ public class EntityHierarchySourceImpl implements EntityHierarchySource {
|
||||||
private class SimpleIdentifierSourceImpl implements SimpleIdentifierSource {
|
private class SimpleIdentifierSourceImpl implements SimpleIdentifierSource {
|
||||||
@Override
|
@Override
|
||||||
public SingularAttributeSource getIdentifierAttributeSource() {
|
public SingularAttributeSource getIdentifierAttributeSource() {
|
||||||
return new SingularIdentifierAttributeSourceImpl( sourceMappingDocument(), entityElement().getId() );
|
return new SingularIdentifierAttributeSourceImpl( sourceMappingDocument(), rootEntitySource, entityElement().getId() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -388,11 +390,11 @@ public class EntityHierarchySourceImpl implements EntityHierarchySource {
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AggregatedCompositeIdentifierSourceImpl implements AggregatedCompositeIdentifierSource {
|
private class AggregatedCompositeIdentifierSourceImpl implements AggregatedCompositeIdentifierSource {
|
||||||
private final CompositeIdentifierComponentAttributeSourceImpl componentAttributeSource
|
private final CompositeIdentifierEmbeddedAttributeSourceImpl componentAttributeSource
|
||||||
= new CompositeIdentifierComponentAttributeSourceImpl();
|
= new CompositeIdentifierEmbeddedAttributeSourceImpl();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ComponentAttributeSource getIdentifierAttributeSource() {
|
public EmbeddedAttributeSource getIdentifierAttributeSource() {
|
||||||
return componentAttributeSource;
|
return componentAttributeSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,56 +449,34 @@ public class EntityHierarchySourceImpl implements EntityHierarchySource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class CompositeIdentifierComponentAttributeSourceImpl extends AbstractComponentAttributeSourceImpl {
|
private class CompositeIdentifierEmbeddedAttributeSourceImpl extends AbstractEmbeddedAttributeSourceImpl {
|
||||||
protected CompositeIdentifierComponentAttributeSourceImpl() {
|
private final List<JaxbKeyPropertyElement> keyPropertyElementList;
|
||||||
|
private final List<JaxbKeyManyToOneElement> keyManyToOneElementList;
|
||||||
|
|
||||||
|
protected CompositeIdentifierEmbeddedAttributeSourceImpl() {
|
||||||
super(
|
super(
|
||||||
EntityHierarchySourceImpl.this.sourceMappingDocument(),
|
EntityHierarchySourceImpl.this.sourceMappingDocument(),
|
||||||
entityElement().getCompositeId(),
|
|
||||||
rootEntitySource,
|
rootEntitySource,
|
||||||
null,
|
rootEntitySource.getAttributeRoleBase().append( "id" ),
|
||||||
SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID
|
rootEntitySource.getAttributePathBase().append( "id" ),
|
||||||
|
entityElement().getCompositeId(),
|
||||||
|
new EmbeddableJaxbSourceImpl( entityElement().getCompositeId() ),
|
||||||
|
NaturalIdMutability.NOT_NATURAL_ID,
|
||||||
|
null
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
protected JaxbCompositeIdElement compositeIdElement() {
|
this.keyPropertyElementList = new ArrayList<JaxbKeyPropertyElement>();
|
||||||
return (JaxbCompositeIdElement) componentSourceElement();
|
this.keyManyToOneElementList = new ArrayList<JaxbKeyManyToOneElement>();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
final JaxbCompositeIdElement compositeIdElement = entityElement().getCompositeId();
|
||||||
protected List<AttributeSource> buildAttributeSources() {
|
for ( final Object obj : compositeIdElement.getKeyPropertyOrKeyManyToOne() ) {
|
||||||
List<AttributeSource> attributeSources = new ArrayList<AttributeSource>();
|
|
||||||
final JaxbCompositeIdElement compositeId = entityElement().getCompositeId();
|
|
||||||
final List list = compositeId.getKeyPropertyOrKeyManyToOne();
|
|
||||||
for ( final Object obj : list ) {
|
|
||||||
if ( JaxbKeyPropertyElement.class.isInstance( obj ) ) {
|
if ( JaxbKeyPropertyElement.class.isInstance( obj ) ) {
|
||||||
JaxbKeyPropertyElement key = JaxbKeyPropertyElement.class.cast( obj );
|
keyPropertyElementList.add( JaxbKeyPropertyElement.class.cast( obj ) );
|
||||||
attributeSources.add( new IdentifierKeyAttributeSourceImpl( sourceMappingDocument(), key ) );
|
|
||||||
}
|
}
|
||||||
if ( JaxbKeyManyToOneElement.class.isInstance( obj ) ) {
|
else if ( JaxbKeyManyToOneElement.class.isInstance( obj ) ) {
|
||||||
JaxbKeyManyToOneElement key = JaxbKeyManyToOneElement.class.cast( obj );
|
keyManyToOneElementList.add( JaxbKeyManyToOneElement.class.cast( obj ) );
|
||||||
attributeSources.add( new IdentifierKeyManyToOneSourceImpl( sourceMappingDocument(), key ) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return attributeSources;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getParentReferenceAttributeName() {
|
|
||||||
// composite-id cannot name parent
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getExplicitTuplizerClassName() {
|
|
||||||
// composite-id cannot name tuplizer
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PropertyGeneration getGeneration() {
|
|
||||||
// identifiers have implicit generation
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -505,13 +485,18 @@ public class EntityHierarchySourceImpl implements EntityHierarchySource {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isIncludedInOptimisticLocking() {
|
public AttributePath getAttributePath() {
|
||||||
return false;
|
return getEmbeddableSource().getAttributePathBase();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<RelationalValueSource> relationalValueSources() {
|
public AttributeRole getAttributeRole() {
|
||||||
return null;
|
return getEmbeddableSource().getAttributeRoleBase();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isIncludedInOptimisticLocking() {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -530,6 +515,7 @@ public class EntityHierarchySourceImpl implements EntityHierarchySource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private class NonAggregatedCompositeIdentifierSourceImpl implements NonAggregatedCompositeIdentifierSource {
|
private class NonAggregatedCompositeIdentifierSourceImpl implements NonAggregatedCompositeIdentifierSource {
|
||||||
@Override
|
@Override
|
||||||
public Class getLookupIdClass() {
|
public Class getLookupIdClass() {
|
||||||
|
@ -549,11 +535,23 @@ public class EntityHierarchySourceImpl implements EntityHierarchySource {
|
||||||
for ( final Object obj : list ) {
|
for ( final Object obj : list ) {
|
||||||
if ( JaxbKeyPropertyElement.class.isInstance( obj ) ) {
|
if ( JaxbKeyPropertyElement.class.isInstance( obj ) ) {
|
||||||
JaxbKeyPropertyElement key = JaxbKeyPropertyElement.class.cast( obj );
|
JaxbKeyPropertyElement key = JaxbKeyPropertyElement.class.cast( obj );
|
||||||
attributeSources.add( new IdentifierKeyAttributeSourceImpl( sourceMappingDocument(), key ) );
|
attributeSources.add(
|
||||||
|
new IdentifierKeyAttributeSourceImpl(
|
||||||
|
sourceMappingDocument(),
|
||||||
|
rootEntitySource,
|
||||||
|
key
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if ( JaxbKeyManyToOneElement.class.isInstance( obj ) ) {
|
if ( JaxbKeyManyToOneElement.class.isInstance( obj ) ) {
|
||||||
JaxbKeyManyToOneElement key = JaxbKeyManyToOneElement.class.cast( obj );
|
JaxbKeyManyToOneElement key = JaxbKeyManyToOneElement.class.cast( obj );
|
||||||
attributeSources.add( new IdentifierKeyManyToOneSourceImpl( sourceMappingDocument(), key ) );
|
attributeSources.add(
|
||||||
|
new IdentifierKeyManyToOneSourceImpl(
|
||||||
|
sourceMappingDocument(),
|
||||||
|
rootEntitySource,
|
||||||
|
key
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -601,6 +599,55 @@ public class EntityHierarchySourceImpl implements EntityHierarchySource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class EmbeddableJaxbSourceImpl extends AbstractEmbeddableJaxbSource {
|
||||||
|
private final JaxbCompositeIdElement compositeIdElement;
|
||||||
|
|
||||||
|
private final List<JaxbKeyPropertyElement> keyPropertyElementList;
|
||||||
|
private final List<JaxbKeyManyToOneElement> keyManyToOneElementList;
|
||||||
|
|
||||||
|
public EmbeddableJaxbSourceImpl(JaxbCompositeIdElement compositeIdElement) {
|
||||||
|
this.compositeIdElement = compositeIdElement;
|
||||||
|
|
||||||
|
this.keyPropertyElementList = new ArrayList<JaxbKeyPropertyElement>();
|
||||||
|
this.keyManyToOneElementList = new ArrayList<JaxbKeyManyToOneElement>();
|
||||||
|
|
||||||
|
for ( final Object obj : compositeIdElement.getKeyPropertyOrKeyManyToOne() ) {
|
||||||
|
if ( JaxbKeyPropertyElement.class.isInstance( obj ) ) {
|
||||||
|
keyPropertyElementList.add( JaxbKeyPropertyElement.class.cast( obj ) );
|
||||||
|
}
|
||||||
|
else if ( JaxbKeyManyToOneElement.class.isInstance( obj ) ) {
|
||||||
|
keyManyToOneElementList.add( JaxbKeyManyToOneElement.class.cast( obj ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getClazz() {
|
||||||
|
return compositeIdElement.getClazz();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String findParent() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String findTuplizer() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbKeyPropertyElement> getKeyPropertyElementList() {
|
||||||
|
return keyPropertyElementList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbKeyManyToOneElement> getKeyManyToOneElementList() {
|
||||||
|
return keyManyToOneElementList;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private Class determineJpaIdClass() {
|
private Class determineJpaIdClass() {
|
||||||
// this would be a <composite-id/> defined with mapped="false"
|
// this would be a <composite-id/> defined with mapped="false"
|
||||||
final JaxbCompositeIdElement compositeId = entityElement().getCompositeId();
|
final JaxbCompositeIdElement compositeId = entityElement().getCompositeId();
|
||||||
|
|
|
@ -62,16 +62,12 @@ import org.hibernate.metamodel.spi.binding.Caching;
|
||||||
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
||||||
import org.hibernate.metamodel.spi.binding.InheritanceType;
|
import org.hibernate.metamodel.spi.binding.InheritanceType;
|
||||||
import org.hibernate.metamodel.spi.binding.MetaAttribute;
|
import org.hibernate.metamodel.spi.binding.MetaAttribute;
|
||||||
import org.hibernate.metamodel.spi.relational.Identifier;
|
|
||||||
import org.hibernate.metamodel.spi.relational.Schema;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A helper for dealing with
|
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
public class Helper {
|
public class Helper {
|
||||||
private static final String NATURAL_ID_CACHE_SUFFIX = "##NaturalId";
|
|
||||||
public static final HibernateTypeSource TO_ONE_ATTRIBUTE_TYPE_SOURCE = new HibernateTypeSource() {
|
public static final HibernateTypeSource TO_ONE_ATTRIBUTE_TYPE_SOURCE = new HibernateTypeSource() {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -168,16 +164,22 @@ public class Helper {
|
||||||
: qualifyIfNeeded( entityElement.getName(), unqualifiedClassPackage );
|
: qualifyIfNeeded( entityElement.getName(), unqualifiedClassPackage );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Caching createCaching(final JaxbCacheElement cacheElement, final String defaultRegionName) {
|
public static Caching createCaching(JaxbCacheElement cacheElement) {
|
||||||
if ( cacheElement == null ) {
|
if ( cacheElement == null ) {
|
||||||
// I'd really rather this be UNKNOWN, but the annotation version resolves this to TRUE/FALSE
|
// I'd really rather this be UNKNOWN, but the annotation version resolves this to TRUE/FALSE
|
||||||
return new Caching( TruthValue.FALSE );
|
return new Caching( TruthValue.FALSE );
|
||||||
}
|
}
|
||||||
final String region = cacheElement.getRegion() != null ? cacheElement.getRegion() : defaultRegionName;
|
|
||||||
final AccessType accessType = AccessType.fromExternalName( cacheElement.getUsage().value() );
|
final AccessType accessType = AccessType.fromExternalName( cacheElement.getUsage().value() );
|
||||||
final boolean cacheLazyProps = cacheElement.getInclude() == null
|
final boolean cacheLazyProps = cacheElement.getInclude() == null
|
||||||
|| !"non-lazy".equals( cacheElement.getInclude().value() );
|
|| !"non-lazy".equals( cacheElement.getInclude().value() );
|
||||||
return new Caching( region, accessType, cacheLazyProps, TruthValue.TRUE );
|
|
||||||
|
return new Caching(
|
||||||
|
cacheElement.getRegion(),
|
||||||
|
accessType,
|
||||||
|
cacheLazyProps,
|
||||||
|
TruthValue.TRUE
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Caching createNaturalIdCaching(JaxbNaturalIdCacheElement cacheElement) {
|
public static Caching createNaturalIdCaching(JaxbNaturalIdCacheElement cacheElement) {
|
||||||
|
@ -272,36 +274,11 @@ public class Helper {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Schema.Name determineDatabaseSchemaName(
|
|
||||||
String explicitSchemaName,
|
|
||||||
String explicitCatalogName,
|
|
||||||
LocalBindingContext bindingContext) {
|
|
||||||
return new Schema.Name(
|
|
||||||
resolveIdentifier(
|
|
||||||
explicitCatalogName,
|
|
||||||
bindingContext.getMappingDefaults().getCatalogName(),
|
|
||||||
bindingContext.quoteIdentifiersInContext()
|
|
||||||
), resolveIdentifier(
|
|
||||||
explicitSchemaName,
|
|
||||||
bindingContext.getMappingDefaults().getSchemaName(),
|
|
||||||
bindingContext.quoteIdentifiersInContext()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Identifier resolveIdentifier(String explicitName, String defaultName, boolean globalQuoting) {
|
|
||||||
String name = StringHelper.isNotEmpty( explicitName ) ? explicitName : defaultName;
|
|
||||||
if ( globalQuoting ) {
|
|
||||||
name = StringHelper.quote( name );
|
|
||||||
}
|
|
||||||
return Identifier.toIdentifier( name );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Operates like SQL coalesce expression, except empty strings are treated as null. Return the first non-empty value
|
* Operates like SQL coalesce expression, except empty strings are treated as null. Return the first non-empty value
|
||||||
*
|
*
|
||||||
* @param values The list of values.
|
* @param values The list of values.
|
||||||
* @param <T>
|
* @param <T> Generic type of values to coalesce
|
||||||
*
|
*
|
||||||
* @return The first non-empty value, or null if all values were empty
|
* @return The first non-empty value, or null if all values were empty
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,178 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.metamodel.source.internal.hbm;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.hibernate.internal.util.StringHelper;
|
||||||
|
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbBagElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement;
|
||||||
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbIdbagElement;
|
||||||
|
import org.hibernate.metamodel.source.spi.CollectionIdSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.ColumnSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.HibernateTypeSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.Orderable;
|
||||||
|
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
||||||
|
import org.hibernate.metamodel.source.spi.SizeSource;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeNature;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class IdBagSourceImpl extends AbstractPluralAttributeSourceImpl implements Orderable {
|
||||||
|
public final CollectionIdSource collectionIdSource;
|
||||||
|
|
||||||
|
public IdBagSourceImpl(
|
||||||
|
MappingDocument mappingDocument,
|
||||||
|
final JaxbIdbagElement element,
|
||||||
|
AbstractEntitySourceImpl abstractEntitySource) {
|
||||||
|
super( mappingDocument, element, abstractEntitySource );
|
||||||
|
|
||||||
|
final List<RelationalValueSource> relationalValueSources = Helper.buildValueSources(
|
||||||
|
sourceMappingDocument(),
|
||||||
|
new Helper.ValueSourcesAdapter() {
|
||||||
|
@Override
|
||||||
|
public String getColumnAttribute() {
|
||||||
|
return element.getCollectionId().getColumnAttribute();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SizeSource getSizeSource() {
|
||||||
|
return Helper.createSizeSourceIfMapped(
|
||||||
|
element.getCollectionId().getLength(),
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JaxbColumnElement> getColumn() {
|
||||||
|
return element.getCollectionId().getColumn();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isIncludedInInsertByDefault() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isForceNotNull() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
ColumnSource collectionIdColumnSource = null;
|
||||||
|
if ( relationalValueSources != null && relationalValueSources.isEmpty() ) {
|
||||||
|
if ( relationalValueSources.size() > 1 ) {
|
||||||
|
throw makeMappingException( "Expecting just a single column for collection id (idbag)" );
|
||||||
|
}
|
||||||
|
|
||||||
|
final RelationalValueSource relationalValueSource = relationalValueSources.get( 0 );
|
||||||
|
if ( !ColumnSource.class.isInstance( relationalValueSource ) ) {
|
||||||
|
throw makeMappingException( "Expecting column for collection id (idbag), but found formula" );
|
||||||
|
}
|
||||||
|
|
||||||
|
collectionIdColumnSource = (ColumnSource) relationalValueSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
final HibernateTypeSource typeSource = new HibernateTypeSource() {
|
||||||
|
private final String name = element.getCollectionId().getType();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> getParameters() {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JavaTypeDescriptor getJavaType() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.collectionIdSource = new CollectionIdSourceImpl(
|
||||||
|
collectionIdColumnSource,
|
||||||
|
typeSource,
|
||||||
|
element.getCollectionId().getGenerator().getClazz()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PluralAttributeNature getNature() {
|
||||||
|
return PluralAttributeNature.ID_BAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JaxbBagElement getPluralAttributeElement() {
|
||||||
|
return (JaxbBagElement) super.getPluralAttributeElement();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isOrdered() {
|
||||||
|
return StringHelper.isNotEmpty( getOrder() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getOrder() {
|
||||||
|
return getPluralAttributeElement().getOrderBy();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class CollectionIdSourceImpl implements CollectionIdSource {
|
||||||
|
private final ColumnSource columnSource;
|
||||||
|
private final HibernateTypeSource typeSource;
|
||||||
|
private final String generator;
|
||||||
|
|
||||||
|
public CollectionIdSourceImpl(
|
||||||
|
ColumnSource columnSource,
|
||||||
|
HibernateTypeSource typeSource,
|
||||||
|
String generator) {
|
||||||
|
this.columnSource = columnSource;
|
||||||
|
this.typeSource = typeSource;
|
||||||
|
this.generator = generator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ColumnSource getColumnSource() {
|
||||||
|
return columnSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HibernateTypeSource getTypeInformation() {
|
||||||
|
return typeSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getGeneratorName() {
|
||||||
|
return generator;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,17 +24,18 @@
|
||||||
package org.hibernate.metamodel.source.internal.hbm;
|
package org.hibernate.metamodel.source.internal.hbm;
|
||||||
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyPropertyElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyPropertyElement;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
import org.hibernate.metamodel.source.spi.AttributeSourceContainer;
|
||||||
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
public class IdentifierKeyAttributeSourceImpl extends KeyAttributeSourceImpl {
|
public class IdentifierKeyAttributeSourceImpl extends KeyAttributeSourceImpl {
|
||||||
|
|
||||||
public IdentifierKeyAttributeSourceImpl(
|
public IdentifierKeyAttributeSourceImpl(
|
||||||
MappingDocument mappingDocument,
|
MappingDocument mappingDocument,
|
||||||
final JaxbKeyPropertyElement keyPropertyElement) {
|
AttributeSourceContainer container,
|
||||||
super( mappingDocument, keyPropertyElement, SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID );
|
JaxbKeyPropertyElement keyPropertyElement) {
|
||||||
|
super( mappingDocument, keyPropertyElement, container, NaturalIdMutability.NOT_NATURAL_ID );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -24,7 +24,8 @@
|
||||||
package org.hibernate.metamodel.source.internal.hbm;
|
package org.hibernate.metamodel.source.internal.hbm;
|
||||||
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyManyToOneElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyManyToOneElement;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
import org.hibernate.metamodel.source.spi.AttributeSourceContainer;
|
||||||
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
|
@ -33,8 +34,9 @@ public class IdentifierKeyManyToOneSourceImpl extends KeyManyToOneSourceImpl {
|
||||||
|
|
||||||
public IdentifierKeyManyToOneSourceImpl(
|
public IdentifierKeyManyToOneSourceImpl(
|
||||||
MappingDocument mappingDocument,
|
MappingDocument mappingDocument,
|
||||||
final JaxbKeyManyToOneElement keyManyToOneElement) {
|
AttributeSourceContainer container,
|
||||||
super( mappingDocument, keyManyToOneElement, SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID );
|
JaxbKeyManyToOneElement keyManyToOneElement) {
|
||||||
|
super( mappingDocument, container, keyManyToOneElement, NaturalIdMutability.NOT_NATURAL_ID );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -31,12 +31,16 @@ import org.hibernate.mapping.PropertyGeneration;
|
||||||
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyPropertyElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyPropertyElement;
|
||||||
|
import org.hibernate.metamodel.source.spi.AttributeSourceContainer;
|
||||||
import org.hibernate.metamodel.source.spi.HibernateTypeSource;
|
import org.hibernate.metamodel.source.spi.HibernateTypeSource;
|
||||||
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
||||||
import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.SizeSource;
|
import org.hibernate.metamodel.source.spi.SizeSource;
|
||||||
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
|
import org.hibernate.metamodel.spi.SingularAttributeNature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation for {@code <key-property/>} mappings
|
* Implementation for {@code <key-property/>} mappings
|
||||||
|
@ -47,14 +51,17 @@ class KeyAttributeSourceImpl
|
||||||
extends AbstractHbmSourceNode
|
extends AbstractHbmSourceNode
|
||||||
implements SingularAttributeSource {
|
implements SingularAttributeSource {
|
||||||
private final JaxbKeyPropertyElement keyPropertyElement;
|
private final JaxbKeyPropertyElement keyPropertyElement;
|
||||||
private final SingularAttributeBinding.NaturalIdMutability naturalIdMutability;
|
private final NaturalIdMutability naturalIdMutability;
|
||||||
private final HibernateTypeSource typeSource;
|
private final HibernateTypeSource typeSource;
|
||||||
private final List<RelationalValueSource> valueSources;
|
private final List<RelationalValueSource> valueSources;
|
||||||
|
|
||||||
|
private final AttributePath attributePath;
|
||||||
|
private final AttributeRole attributeRole;
|
||||||
|
|
||||||
public KeyAttributeSourceImpl(
|
public KeyAttributeSourceImpl(
|
||||||
MappingDocument mappingDocument,
|
MappingDocument mappingDocument,
|
||||||
final JaxbKeyPropertyElement keyPropertyElement,
|
final JaxbKeyPropertyElement keyPropertyElement,
|
||||||
final SingularAttributeBinding.NaturalIdMutability naturalIdMutability) {
|
AttributeSourceContainer container, final NaturalIdMutability naturalIdMutability) {
|
||||||
super( mappingDocument );
|
super( mappingDocument );
|
||||||
this.keyPropertyElement = keyPropertyElement;
|
this.keyPropertyElement = keyPropertyElement;
|
||||||
this.naturalIdMutability = naturalIdMutability;
|
this.naturalIdMutability = naturalIdMutability;
|
||||||
|
@ -116,6 +123,9 @@ class KeyAttributeSourceImpl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.attributePath = container.getAttributePathBase().append( getName() );
|
||||||
|
this.attributeRole = container.getAttributeRoleBase().append( getName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -123,6 +133,16 @@ class KeyAttributeSourceImpl
|
||||||
return keyPropertyElement.getName();
|
return keyPropertyElement.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributePath getAttributePath() {
|
||||||
|
return attributePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributeRole getAttributeRole() {
|
||||||
|
return attributeRole;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HibernateTypeSource getTypeInformation() {
|
public HibernateTypeSource getTypeInformation() {
|
||||||
return typeSource;
|
return typeSource;
|
||||||
|
@ -144,7 +164,7 @@ class KeyAttributeSourceImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SingularAttributeBinding.NaturalIdMutability getNaturalIdMutability() {
|
public NaturalIdMutability getNaturalIdMutability() {
|
||||||
return naturalIdMutability;
|
return naturalIdMutability;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,8 +174,8 @@ class KeyAttributeSourceImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Nature getNature() {
|
public SingularAttributeNature getSingularAttributeNature() {
|
||||||
return Nature.BASIC;
|
return SingularAttributeNature.BASIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -32,10 +32,14 @@ import org.hibernate.engine.spi.CascadeStyle;
|
||||||
import org.hibernate.engine.spi.CascadeStyles;
|
import org.hibernate.engine.spi.CascadeStyles;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyManyToOneElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyManyToOneElement;
|
||||||
|
import org.hibernate.metamodel.source.spi.AttributeSourceContainer;
|
||||||
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
||||||
import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
import org.hibernate.metamodel.source.spi.SingularAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
|
import org.hibernate.metamodel.spi.SingularAttributeNature;
|
||||||
import org.hibernate.type.ForeignKeyDirection;
|
import org.hibernate.type.ForeignKeyDirection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,10 +53,14 @@ class KeyManyToOneSourceImpl
|
||||||
private final JaxbKeyManyToOneElement keyManyToOneElement;
|
private final JaxbKeyManyToOneElement keyManyToOneElement;
|
||||||
private final List<RelationalValueSource> valueSources;
|
private final List<RelationalValueSource> valueSources;
|
||||||
|
|
||||||
|
private final AttributePath attributePath;
|
||||||
|
private final AttributeRole attributeRole;
|
||||||
|
|
||||||
public KeyManyToOneSourceImpl(
|
public KeyManyToOneSourceImpl(
|
||||||
MappingDocument mappingDocument,
|
MappingDocument mappingDocument,
|
||||||
|
AttributeSourceContainer container,
|
||||||
final JaxbKeyManyToOneElement keyManyToOneElement,
|
final JaxbKeyManyToOneElement keyManyToOneElement,
|
||||||
final SingularAttributeBinding.NaturalIdMutability naturalIdMutability) {
|
final NaturalIdMutability naturalIdMutability) {
|
||||||
super( mappingDocument, naturalIdMutability, null );
|
super( mappingDocument, naturalIdMutability, null );
|
||||||
this.keyManyToOneElement = keyManyToOneElement;
|
this.keyManyToOneElement = keyManyToOneElement;
|
||||||
this.valueSources = Helper.buildValueSources(
|
this.valueSources = Helper.buildValueSources(
|
||||||
|
@ -94,6 +102,9 @@ class KeyManyToOneSourceImpl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.attributePath = container.getAttributePathBase().append( getName() );
|
||||||
|
this.attributeRole = container.getAttributeRoleBase().append( getName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -101,6 +112,16 @@ class KeyManyToOneSourceImpl
|
||||||
return keyManyToOneElement.getName();
|
return keyManyToOneElement.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributePath getAttributePath() {
|
||||||
|
return attributePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributeRole getAttributeRole() {
|
||||||
|
return attributeRole;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPropertyAccessorName() {
|
public String getPropertyAccessorName() {
|
||||||
return keyManyToOneElement.getAccess();
|
return keyManyToOneElement.getAccess();
|
||||||
|
@ -112,8 +133,8 @@ class KeyManyToOneSourceImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Nature getNature() {
|
public SingularAttributeNature getSingularAttributeNature() {
|
||||||
return Nature.MANY_TO_ONE;
|
return SingularAttributeNature.MANY_TO_ONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -23,27 +23,17 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.source.internal.hbm;
|
package org.hibernate.metamodel.source.internal.hbm;
|
||||||
|
|
||||||
import org.hibernate.AssertionFailure;
|
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListElement;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListIndexElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListIndexElement;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSourceContainer;
|
import org.hibernate.metamodel.source.spi.AttributeSourceContainer;
|
||||||
import org.hibernate.metamodel.source.spi.AttributeSourceResolutionContext;
|
|
||||||
import org.hibernate.metamodel.source.spi.IndexedPluralAttributeSource;
|
import org.hibernate.metamodel.source.spi.IndexedPluralAttributeSource;
|
||||||
import org.hibernate.metamodel.source.spi.PluralAttributeIndexSource;
|
import org.hibernate.metamodel.source.spi.PluralAttributeIndexSource;
|
||||||
import org.hibernate.metamodel.source.spi.SequentialPluralAttributeIndexSource;
|
import org.hibernate.metamodel.source.spi.PluralAttributeSequentialIndexSource;
|
||||||
|
import org.hibernate.metamodel.spi.PluralAttributeNature;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ListSourceImpl extends AbstractPluralAttributeSourceImpl implements IndexedPluralAttributeSource {
|
public class ListSourceImpl extends AbstractPluralAttributeSourceImpl implements IndexedPluralAttributeSource {
|
||||||
|
private final PluralAttributeSequentialIndexSource indexSource;
|
||||||
|
|
||||||
private final SequentialPluralAttributeIndexSource indexSource;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param sourceMappingDocument
|
|
||||||
* @param listElement
|
|
||||||
* @param container
|
|
||||||
*/
|
|
||||||
public ListSourceImpl(
|
public ListSourceImpl(
|
||||||
MappingDocument sourceMappingDocument,
|
MappingDocument sourceMappingDocument,
|
||||||
JaxbListElement listElement,
|
JaxbListElement listElement,
|
||||||
|
@ -51,9 +41,10 @@ public class ListSourceImpl extends AbstractPluralAttributeSourceImpl implements
|
||||||
super( sourceMappingDocument, listElement, container );
|
super( sourceMappingDocument, listElement, container );
|
||||||
JaxbListIndexElement listIndexElement = listElement.getListIndex();
|
JaxbListIndexElement listIndexElement = listElement.getListIndex();
|
||||||
if ( listIndexElement == null ) {
|
if ( listIndexElement == null ) {
|
||||||
this.indexSource = new SequentialPluralAttributeIndexSourceImpl( sourceMappingDocument(), listElement.getIndex() );
|
this.indexSource = new PluralAttributeSequentialIndexSourceImpl( sourceMappingDocument(), listElement.getIndex() );
|
||||||
} else {
|
}
|
||||||
this.indexSource = new SequentialPluralAttributeIndexSourceImpl( sourceMappingDocument(), listIndexElement );
|
else {
|
||||||
|
this.indexSource = new PluralAttributeSequentialIndexSourceImpl( sourceMappingDocument(), listIndexElement );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,21 +58,9 @@ public class ListSourceImpl extends AbstractPluralAttributeSourceImpl implements
|
||||||
return ( JaxbListElement ) super.getPluralAttributeElement();
|
return ( JaxbListElement ) super.getPluralAttributeElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
* @see org.hibernate.metamodel.source.spi.PluralAttributeSource#getNature()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Nature getNature() {
|
public PluralAttributeNature getNature() {
|
||||||
return Nature.LIST;
|
return PluralAttributeNature.LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public PluralAttributeIndexSource resolvePluralAttributeIndexSource(AttributeSourceResolutionContext context) {
|
|
||||||
if ( indexSource == null ) {
|
|
||||||
throw new AssertionFailure( "Array index source should have been resolved already." );
|
|
||||||
}
|
|
||||||
return indexSource;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,13 @@ import java.util.Set;
|
||||||
import org.hibernate.engine.spi.CascadeStyle;
|
import org.hibernate.engine.spi.CascadeStyle;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement;
|
||||||
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToOneElement;
|
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToOneElement;
|
||||||
|
import org.hibernate.metamodel.source.spi.AttributeSourceContainer;
|
||||||
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
import org.hibernate.metamodel.source.spi.RelationalValueSource;
|
||||||
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
import org.hibernate.metamodel.source.spi.ToolingHintSource;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
import org.hibernate.metamodel.spi.AttributePath;
|
||||||
|
import org.hibernate.metamodel.spi.AttributeRole;
|
||||||
|
import org.hibernate.metamodel.spi.NaturalIdMutability;
|
||||||
|
import org.hibernate.metamodel.spi.SingularAttributeNature;
|
||||||
import org.hibernate.type.ForeignKeyDirection;
|
import org.hibernate.type.ForeignKeyDirection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,11 +49,15 @@ class ManyToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl {
|
||||||
private final String containingTableName;
|
private final String containingTableName;
|
||||||
private final List<RelationalValueSource> valueSources;
|
private final List<RelationalValueSource> valueSources;
|
||||||
|
|
||||||
|
private final AttributeRole attributeRole;
|
||||||
|
private final AttributePath attributePath;
|
||||||
|
|
||||||
ManyToOneAttributeSourceImpl(
|
ManyToOneAttributeSourceImpl(
|
||||||
MappingDocument sourceMappingDocument,
|
MappingDocument sourceMappingDocument,
|
||||||
|
AttributeSourceContainer container,
|
||||||
final JaxbManyToOneElement manyToOneElement,
|
final JaxbManyToOneElement manyToOneElement,
|
||||||
final String logicalTableName,
|
final String logicalTableName,
|
||||||
SingularAttributeBinding.NaturalIdMutability naturalIdMutability) {
|
NaturalIdMutability naturalIdMutability) {
|
||||||
super( sourceMappingDocument, naturalIdMutability, manyToOneElement.getPropertyRef() );
|
super( sourceMappingDocument, naturalIdMutability, manyToOneElement.getPropertyRef() );
|
||||||
this.manyToOneElement = manyToOneElement;
|
this.manyToOneElement = manyToOneElement;
|
||||||
this.containingTableName = logicalTableName;
|
this.containingTableName = logicalTableName;
|
||||||
|
@ -92,6 +100,9 @@ class ManyToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.attributeRole = container.getAttributeRoleBase().append( manyToOneElement.getName() );
|
||||||
|
this.attributePath = container.getAttributePathBase().append( manyToOneElement.getName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -99,6 +110,16 @@ class ManyToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl {
|
||||||
return manyToOneElement.getName();
|
return manyToOneElement.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributePath getAttributePath() {
|
||||||
|
return attributePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributeRole getAttributeRole() {
|
||||||
|
return attributeRole;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPropertyAccessorName() {
|
public String getPropertyAccessorName() {
|
||||||
return manyToOneElement.getAccess();
|
return manyToOneElement.getAccess();
|
||||||
|
@ -146,8 +167,8 @@ class ManyToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Nature getNature() {
|
public SingularAttributeNature getSingularAttributeNature() {
|
||||||
return Nature.MANY_TO_ONE;
|
return SingularAttributeNature.MANY_TO_ONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue