HHH-7851 - basic collection is not indexable yet (annotaiton side)
This commit is contained in:
parent
1b2469325d
commit
d1ba07080c
|
@ -53,6 +53,7 @@ import org.hibernate.metamodel.spi.source.EntitySource;
|
|||
import org.hibernate.metamodel.spi.source.JpaCallbackSource;
|
||||
import org.hibernate.metamodel.spi.source.LocalBindingContext;
|
||||
import org.hibernate.metamodel.spi.source.MetaAttributeSource;
|
||||
import org.hibernate.metamodel.spi.source.PluralAttributeSource;
|
||||
import org.hibernate.metamodel.spi.source.PrimaryKeyJoinColumnSource;
|
||||
import org.hibernate.metamodel.spi.source.SecondaryTableSource;
|
||||
import org.hibernate.metamodel.spi.source.SubclassEntitySource;
|
||||
|
@ -238,14 +239,14 @@ public class EntitySourceImpl implements EntitySource {
|
|||
}
|
||||
case MANY_TO_MANY:
|
||||
case ONE_TO_MANY:
|
||||
AttributeSource source = ((PluralAssociationAttribute)associationAttribute).isIndexed() ?
|
||||
new IndexedPluralAttributeSourceImpl((PluralAssociationAttribute) associationAttribute, entityClass )
|
||||
:new PluralAttributeSourceImpl( ( PluralAssociationAttribute ) associationAttribute, entityClass );
|
||||
attributeList.add( source );
|
||||
break;
|
||||
case ELEMENT_COLLECTION_BASIC:
|
||||
case ELEMENT_COLLECTION_EMBEDDABLE: {
|
||||
source = new PluralAttributeSourceImpl( ( PluralAssociationAttribute ) associationAttribute, entityClass );
|
||||
PluralAssociationAttribute pluralAssociationAttribute = (PluralAssociationAttribute) associationAttribute;
|
||||
PluralAttributeSource.Nature pluralAttributeNature = pluralAssociationAttribute.getPluralAttributeNature();
|
||||
|
||||
AttributeSource source = pluralAssociationAttribute.isIndexed() ?
|
||||
new IndexedPluralAttributeSourceImpl( pluralAssociationAttribute, entityClass )
|
||||
: new PluralAttributeSourceImpl( pluralAssociationAttribute, entityClass );
|
||||
attributeList.add( source );
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.hibernate.metamodel.internal.source.annotations;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute;
|
||||
import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute;
|
||||
import org.hibernate.metamodel.internal.source.annotations.entity.EntityClass;
|
||||
|
@ -13,17 +15,16 @@ import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
|
|||
public class IndexedPluralAttributeSourceImpl extends PluralAttributeSourceImpl
|
||||
implements IndexedPluralAttributeSource {
|
||||
private final PluralAttributeIndexSource indexSource;
|
||||
private final static EnumSet<MappedAttribute.Nature> validNatures = EnumSet.of(
|
||||
MappedAttribute.Nature.MANY_TO_MANY,
|
||||
MappedAttribute.Nature.ONE_TO_MANY,
|
||||
MappedAttribute.Nature.ELEMENT_COLLECTION_BASIC,
|
||||
MappedAttribute.Nature.ELEMENT_COLLECTION_EMBEDDABLE);
|
||||
|
||||
public IndexedPluralAttributeSourceImpl(PluralAssociationAttribute attribute,
|
||||
EntityClass entityClass ) {
|
||||
super( attribute, entityClass );
|
||||
if ( getNature() == org.hibernate.metamodel.spi.source.PluralAttributeSource.Nature.SET || getNature() == org.hibernate.metamodel.spi.source.PluralAttributeSource.Nature.MAP ) {
|
||||
throw new MappingException(
|
||||
"Set / Map could not be an indexed column",
|
||||
attribute.getContext().getOrigin()
|
||||
);
|
||||
}
|
||||
if ( attribute.getNature() != MappedAttribute.Nature.MANY_TO_MANY && attribute.getNature() != MappedAttribute.Nature.ONE_TO_MANY ) {
|
||||
if ( !validNatures.contains( attribute.getNature() ) ) {
|
||||
throw new MappingException(
|
||||
"Indexed column could be only mapped on the MANY side",
|
||||
attribute.getContext().getOrigin()
|
||||
|
|
|
@ -28,6 +28,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jboss.jandex.AnnotationInstance;
|
||||
|
||||
import org.hibernate.engine.FetchStyle;
|
||||
import org.hibernate.engine.FetchTiming;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
|
@ -62,11 +64,11 @@ public class PluralAttributeSourceImpl implements PluralAttributeSource, Orderab
|
|||
final PluralAssociationAttribute associationAttribute,
|
||||
final EntityClass entityClass ) {
|
||||
this.associationAttribute = associationAttribute;
|
||||
this.nature = resolveAttributeNature();
|
||||
this.entityClass = entityClass;
|
||||
this.keySource = new PluralAttributeKeySourceImpl( associationAttribute );
|
||||
this.elementSource = determineElementSource();
|
||||
this.typeSource = new ExplicitHibernateTypeSourceImpl( associationAttribute );
|
||||
this.nature = associationAttribute.getPluralAttributeNature();
|
||||
this.elementSource = determineElementSource( associationAttribute, entityClass );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -91,12 +93,7 @@ public class PluralAttributeSourceImpl implements PluralAttributeSource, Orderab
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMappedBy() {
|
||||
return associationAttribute.getMappedBy();
|
||||
}
|
||||
|
||||
private PluralAttributeElementSource determineElementSource() {
|
||||
private static PluralAttributeElementSource determineElementSource(PluralAssociationAttribute associationAttribute, EntityClass entityClass) {
|
||||
switch ( associationAttribute.getNature() ) {
|
||||
case MANY_TO_MANY:
|
||||
return new ManyToManyPluralAttributeElementSourceImpl( associationAttribute );
|
||||
|
@ -109,7 +106,8 @@ public class PluralAttributeSourceImpl implements PluralAttributeSource, Orderab
|
|||
case ELEMENT_COLLECTION_EMBEDDABLE: {
|
||||
// TODO: cascadeStyles?
|
||||
return new CompositePluralAttributeElementSourceImpl(
|
||||
associationAttribute, entityClass );
|
||||
associationAttribute, entityClass
|
||||
);
|
||||
}
|
||||
}
|
||||
throw new AssertionError( "Unexpected attribute nature for a association:" + associationAttribute.getNature() );
|
||||
|
@ -124,13 +122,8 @@ public class PluralAttributeSourceImpl implements PluralAttributeSource, Orderab
|
|||
public TableSpecificationSource getCollectionTableSpecificationSource() {
|
||||
// todo - see org.hibernate.metamodel.internal.Binder#bindOneToManyCollectionKey
|
||||
// todo - needs to cater for @CollectionTable and @JoinTable
|
||||
|
||||
if ( associationAttribute.getJoinTableAnnotation() == null ) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return new TableSourceImpl( associationAttribute.getJoinTableAnnotation() );
|
||||
}
|
||||
final AnnotationInstance joinTableAnnotation = associationAttribute.getJoinTableAnnotation();
|
||||
return joinTableAnnotation == null ? null : new TableSourceImpl( joinTableAnnotation );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -158,9 +151,14 @@ public class PluralAttributeSourceImpl implements PluralAttributeSource, Orderab
|
|||
return associationAttribute.getWhereClause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMappedBy() {
|
||||
return associationAttribute.getMappedBy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInverse() {
|
||||
return associationAttribute.getMappedBy() != null;
|
||||
return getMappedBy() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -244,33 +242,20 @@ public class PluralAttributeSourceImpl implements PluralAttributeSource, Orderab
|
|||
if ( associationAttribute.isExtraLazy() ) {
|
||||
return FetchTiming.EXTRA_DELAYED;
|
||||
}
|
||||
if ( associationAttribute.isLazy() ) {
|
||||
else if ( associationAttribute.isLazy() ) {
|
||||
return FetchTiming.DELAYED;
|
||||
}
|
||||
else {
|
||||
return FetchTiming.IMMEDIATE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchStyle getFetchStyle() {
|
||||
return associationAttribute.getFetchStyle();
|
||||
}
|
||||
|
||||
private Nature resolveAttributeNature() {
|
||||
if ( Map.class.isAssignableFrom( associationAttribute.getAttributeType() ) ) {
|
||||
return PluralAttributeSource.Nature.MAP;
|
||||
}
|
||||
else if ( List.class.isAssignableFrom( associationAttribute.getAttributeType() ) ) {
|
||||
return associationAttribute.isIndexed()? Nature.LIST : Nature.BAG;
|
||||
}
|
||||
else if ( Set.class.isAssignableFrom( associationAttribute.getAttributeType() ) ) {
|
||||
return PluralAttributeSource.Nature.SET;
|
||||
} else if ( associationAttribute.getAttributeType().isArray() ) {
|
||||
return PluralAttributeSource.Nature.ARRAY;
|
||||
}
|
||||
else {
|
||||
return PluralAttributeSource.Nature.BAG;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ package org.hibernate.metamodel.internal.source.annotations.attribute;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.FetchType;
|
||||
|
||||
|
@ -47,6 +48,7 @@ import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
|
|||
import org.hibernate.metamodel.spi.binding.Caching;
|
||||
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
||||
import org.hibernate.metamodel.spi.source.MappingException;
|
||||
import org.hibernate.metamodel.spi.source.PluralAttributeSource;
|
||||
|
||||
/**
|
||||
* Represents an collection (collection, list, set, map) association attribute.
|
||||
|
@ -74,6 +76,8 @@ public class PluralAssociationAttribute extends AssociationAttribute {
|
|||
private final String inverseForeignKeyName;
|
||||
private final String explicitForeignKeyName;
|
||||
|
||||
private final PluralAttributeSource.Nature pluralAttributeNature;
|
||||
|
||||
private LazyCollectionOption lazyOption;
|
||||
|
||||
public static PluralAssociationAttribute createPluralAssociationAttribute(ClassInfo entityClassInfo,
|
||||
|
@ -96,6 +100,10 @@ public class PluralAssociationAttribute extends AssociationAttribute {
|
|||
);
|
||||
}
|
||||
|
||||
public PluralAttributeSource.Nature getPluralAttributeNature() {
|
||||
return pluralAttributeNature;
|
||||
}
|
||||
|
||||
public String getWhereClause() {
|
||||
return whereClause;
|
||||
}
|
||||
|
@ -240,7 +248,26 @@ public class PluralAssociationAttribute extends AssociationAttribute {
|
|||
);
|
||||
}
|
||||
this.isIndexed = orderColumnAnnotation != null || indexColumnAnnotation != null;
|
||||
this.pluralAttributeNature = resolvePluralAttributeNature();
|
||||
}
|
||||
|
||||
private PluralAttributeSource.Nature resolvePluralAttributeNature() {
|
||||
|
||||
if ( Map.class.isAssignableFrom( getAttributeType() ) ) {
|
||||
return PluralAttributeSource.Nature.MAP;
|
||||
}
|
||||
else if ( List.class.isAssignableFrom( getAttributeType() ) ) {
|
||||
return isIndexed() ? PluralAttributeSource.Nature.LIST : PluralAttributeSource.Nature.BAG;
|
||||
}
|
||||
else if ( Set.class.isAssignableFrom( getAttributeType() ) ) {
|
||||
return PluralAttributeSource.Nature.SET;
|
||||
}
|
||||
else if ( getAttributeType().isArray() ) {
|
||||
return PluralAttributeSource.Nature.ARRAY;
|
||||
}
|
||||
else {
|
||||
return PluralAttributeSource.Nature.BAG;
|
||||
}
|
||||
}
|
||||
|
||||
private OnDeleteAction determineOnDeleteAction() {
|
||||
|
|
Loading…
Reference in New Issue