Skip to content

Commit

Permalink
HHH-7529 Bind @LazyCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
stliu committed Aug 17, 2012
1 parent 1c26ef3 commit cee1fc8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 10 deletions.
Expand Up @@ -240,6 +240,8 @@ public List<AttributeSource> attributeSources() {
break;
}
case ONE_TO_MANY:
attributeList.add( new PluralAttributeSourceImpl( ( PluralAssociationAttribute ) associationAttribute ) );
break;
default: {
throw new NotYetImplementedException();
}
Expand Down
Expand Up @@ -51,14 +51,15 @@
*/
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;
}
Expand All @@ -73,6 +74,11 @@ else if ( Set.class.isAssignableFrom( attribute.getAttributeType() ) ) {
}
}

@Override
public PluralAttributeNature getPluralAttributeNature() {
return nature;
}

@Override
public PluralAttributeKeySource getKeySource() {
return null; //To change body of implemented methods use File | Settings | File Templates.
Expand Down Expand Up @@ -148,12 +154,12 @@ public CustomSQL getCustomSqlDelete() {

@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
Expand Down Expand Up @@ -184,17 +190,23 @@ public Iterable<MetaAttributeSource> getMetaAttributeSources() {

@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 {
Expand Down
Expand Up @@ -107,7 +107,7 @@ public static AssociationAttribute createAssociationAttribute(
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 );

Expand Down Expand Up @@ -226,7 +226,7 @@ private boolean determineOrphanRemoval(AnnotationInstance associationAnnotation)
return orphanRemoval;
}

private boolean determineFetchType(AnnotationInstance associationAnnotation) {
protected boolean determinIsLazy(AnnotationInstance associationAnnotation) {
boolean lazy = false;
AnnotationValue fetchValue = associationAnnotation.value( "fetch" );
if ( fetchValue != null ) {
Expand Down
Expand Up @@ -32,6 +32,7 @@

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;
Expand All @@ -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
Expand Down Expand Up @@ -123,6 +126,7 @@ private PluralAssociationAttribute(ClassInfo entityClassInfo,
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()
Expand Down Expand Up @@ -161,6 +165,29 @@ private String determineInverseForeignKeyName() {
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;

Expand Down

0 comments on commit cee1fc8

Please sign in to comment.