HHH-7529 Bind @LazyCollection

This commit is contained in:
Strong Liu 2012-08-17 19:23:41 +08:00
parent 1c26ef34cc
commit cee1fc8b20
4 changed files with 51 additions and 10 deletions

View File

@ -240,6 +240,8 @@ public class EntitySourceImpl implements EntitySource {
break;
}
case ONE_TO_MANY:
attributeList.add( new PluralAttributeSourceImpl( ( PluralAssociationAttribute ) associationAttribute ) );
break;
default: {
throw new NotYetImplementedException();
}

View File

@ -51,14 +51,15 @@ import org.hibernate.metamodel.spi.source.TableSpecificationSource;
*/
public class PluralAttributeSourceImpl implements PluralAttributeSource {
PluralAssociationAttribute attribute;
private final PluralAssociationAttribute attribute;
private final PluralAttributeNature nature;
public PluralAttributeSourceImpl(PluralAssociationAttribute attribute) {
this.attribute = attribute;
this.nature = resolveAttributeNature();
}
@Override
public PluralAttributeNature getPluralAttributeNature() {
private PluralAttributeNature resolveAttributeNature(){
if ( Map.class.isAssignableFrom( attribute.getAttributeType() ) ) {
return PluralAttributeNature.MAP;
}
@ -73,6 +74,11 @@ public class PluralAttributeSourceImpl implements PluralAttributeSource {
}
}
@Override
public PluralAttributeNature getPluralAttributeNature() {
return nature;
}
@Override
public PluralAttributeKeySource getKeySource() {
return null; //To change body of implemented methods use File | Settings | File Templates.
@ -148,12 +154,12 @@ public class PluralAttributeSourceImpl implements PluralAttributeSource {
@Override
public CustomSQL getCustomSqlDeleteAll() {
return null; //To change body of implemented methods use File | Settings | File Templates.
return null;
}
@Override
public String getName() {
return null; //To change body of implemented methods use File | Settings | File Templates.
return attribute.getName();
}
@Override
@ -184,17 +190,23 @@ public class PluralAttributeSourceImpl implements PluralAttributeSource {
@Override
public FetchMode getFetchMode() {
return null; //To change body of implemented methods use File | Settings | File Templates.
return attribute.getFetchMode();
}
@Override
public FetchTiming getFetchTiming() {
return null; //To change body of implemented methods use File | Settings | File Templates.
if ( attribute.isExtraLazy() ) {
return FetchTiming.EXTRA_DELAYED;
}
if ( attribute.isLazy() ) {
return FetchTiming.DELAYED;
}
return FetchTiming.IMMEDIATE;
}
@Override
public FetchStyle getFetchStyle() {
return null; //To change body of implemented methods use File | Settings | File Templates.
return attribute.getFetchStyle();
}
private class OneToManyPluralAttributeElementSourceImpl implements OneToManyPluralAttributeElementSource {

View File

@ -107,7 +107,7 @@ public class AssociationAttribute extends MappedAttribute {
this.referencedEntityType = determineReferencedEntityType( associationAnnotation );
this.mappedBy = determineMappedByAttributeName( associationAnnotation );
this.isOptional = determineOptionality( associationAnnotation );
this.isLazy = determineFetchType( associationAnnotation );
this.isLazy = determinIsLazy( associationAnnotation );
this.isOrphanRemoval = determineOrphanRemoval( associationAnnotation );
this.cascadeTypes = determineCascadeTypes( associationAnnotation );
@ -226,7 +226,7 @@ public class AssociationAttribute extends MappedAttribute {
return orphanRemoval;
}
private boolean determineFetchType(AnnotationInstance associationAnnotation) {
protected boolean determinIsLazy(AnnotationInstance associationAnnotation) {
boolean lazy = false;
AnnotationValue fetchValue = associationAnnotation.value( "fetch" );
if ( fetchValue != null ) {

View File

@ -32,6 +32,7 @@ import org.jboss.jandex.DotName;
import org.hibernate.AnnotationException;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext;
import org.hibernate.metamodel.internal.source.annotations.util.AnnotationParserHelper;
@ -55,6 +56,8 @@ public class PluralAssociationAttribute extends AssociationAttribute {
private final CustomSQL customUpdate;
private final CustomSQL customDelete;
private final ClassInfo entityClassInfo;
private final boolean isExtraLazy;
private LazyCollectionOption lazyOption;
// Used for the non-owning side of a ManyToMany relationship
@ -123,6 +126,7 @@ public class PluralAssociationAttribute extends AssociationAttribute {
this.orderBy = determineOrderBy();
this.inverseForeignKeyName = determineInverseForeignKeyName();
this.caching = determineCachingSettings();
this.isExtraLazy = lazyOption == LazyCollectionOption.EXTRA;
this.customPersister = determineCustomPersister();
this.customInsert = AnnotationParserHelper.processCustomSqlAnnotation(
HibernateDotNames.SQL_INSERT, annotations()
@ -161,6 +165,29 @@ public class PluralAssociationAttribute extends AssociationAttribute {
return foreignKeyName;
}
@Override
protected boolean determinIsLazy(AnnotationInstance associationAnnotation) {
boolean lazy = super.determinIsLazy( associationAnnotation );
final AnnotationInstance lazyCollectionAnnotationInstance = JandexHelper.getSingleAnnotation(
annotations(),
HibernateDotNames.LAZY_COLLECTION
);
if ( lazyCollectionAnnotationInstance != null ) {
LazyCollectionOption option = JandexHelper.getEnumValue(
lazyCollectionAnnotationInstance,
"value",
LazyCollectionOption.class
);
return option == LazyCollectionOption.TRUE;
}
return lazy;
}
public boolean isExtraLazy() {
return isExtraLazy;
}
private String determineWereClause() {
String where = null;