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