HHH-7916 @NotFound.IGNORE

This commit is contained in:
Strong Liu 2013-01-11 02:06:04 +08:00
parent ee50c8b2a4
commit 029badbba6
15 changed files with 55 additions and 6 deletions

View File

@ -121,7 +121,7 @@ public class ToOneFkSecondPass extends FkSecondPass {
if ( !manyToOne.isIgnoreNotFound() ) manyToOne.createPropertyRefConstraints( persistentClasses );
}
else if ( value instanceof OneToOne ) {
( (OneToOne) value ).createForeignKey();
value.createForeignKey();
}
else {
throw new AssertionFailure( "FkSecondPass for a wrong value type: " + value.getClass().getName() );

View File

@ -1099,6 +1099,7 @@ public class Binder {
propertyAccessorName( attributeSource ),
attributeSource.isIncludedInOptimisticLocking(),
attributeSource.isLazy(),
attributeSource.isNotFoundAnException(),
attributeSource.getNaturalIdMutability(),
createMetaAttributeContext( attributeBindingContainer, attributeSource ),
referencedEntityBinding,
@ -1117,12 +1118,14 @@ public class Binder {
idAttributeBinding == referencedAttributeBinding ?
null :
getRelativePathFromEntityName( referencedAttributeBinding );
// final boolean isNotFoundAnException = SingularAssociationAttributeBinding.class.isInstance( )
return metadata.getTypeResolver().getTypeFactory().manyToOne(
referencedEntityBinding.getEntity().getName(),
uniqueKeyAttributeName,
attributeSource.getFetchTiming() != FetchTiming.IMMEDIATE,
attributeSource.isUnWrapProxy(),
false, //TODO: should be attributeBinding.isIgnoreNotFound(),
!attributeSource.isNotFoundAnException(),
false //TODO: determine if isLogicalOneToOne
);
}
@ -1731,7 +1734,7 @@ public class Binder {
null,
false,
false,
false, //TODO: should be attributeBinding.isIgnoreNotFound(),
!elementSource.isNotFoundAnException(), //TODO: should be attributeBinding.isIgnoreNotFound(),
false
);
final HibernateTypeDescriptor hibernateTypeDescriptor = elementBinding.getHibernateTypeDescriptor();

View File

@ -374,7 +374,7 @@ class HibernateTypeHelper {
elementSource.getReferencedEntityAttributeName(),
false,
false,
false, //TODO: should be attributeBinding.isIgnoreNotFound(),
!elementSource.isNotFoundAnException(),
false
);
final HibernateTypeDescriptor hibernateTypeDescriptor = elementBinding.getHibernateTypeDescriptor();

View File

@ -86,6 +86,11 @@ public class ToOneAttributeSourceImpl extends SingularAttributeSourceImpl implem
return associationAttribute.getReferencedEntityType();
}
@Override
public boolean isNotFoundAnException() {
return !associationAttribute.isIgnoreNotFound();
}
@Override
public List<Binder.DefaultNamingStrategy> getDefaultNamingStrategies(
final String entityName, final String tableName, final AttributeBinding referencedAttributeBinding) {

View File

@ -80,6 +80,11 @@ public abstract class AbstractToOneAttributeSourceImpl extends AbstractHbmSource
return PropertyGeneration.NEVER;
}
@Override
public boolean isNotFoundAnException() {
return true;
}
@Override
public boolean isLazy() {
return getFetchTiming() != FetchTiming.IMMEDIATE;

View File

@ -102,6 +102,11 @@ class ManyToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl {
return manyToOneElement.getAccess();
}
@Override
public boolean isNotFoundAnException() {
return manyToOneElement.getNotFound() == null || !"ignore".equals( manyToOneElement.getNotFound().value() );
}
@Override
public boolean isIncludedInOptimisticLocking() {
return manyToOneElement.isOptimisticLock();

View File

@ -179,6 +179,7 @@ public abstract class AbstractAttributeBindingContainer implements AttributeBind
String propertyAccessorName,
boolean includedInOptimisticLocking,
boolean lazy,
boolean isNotFoundAnException,
SingularAttributeBinding.NaturalIdMutability naturalIdMutability,
MetaAttributeContext metaAttributeContext,
EntityBinding referencedEntityBinding,
@ -190,6 +191,7 @@ public abstract class AbstractAttributeBindingContainer implements AttributeBind
propertyAccessorName,
includedInOptimisticLocking,
lazy,
isNotFoundAnException,
naturalIdMutability,
metaAttributeContext,
referencedEntityBinding,

View File

@ -176,6 +176,7 @@ public abstract class AbstractCompositeAttributeBindingContainer
String propertyAccessorName,
boolean includedInOptimisticLocking,
boolean lazy,
boolean isNotFoundAnException,
SingularAttributeBinding.NaturalIdMutability naturalIdMutability,
MetaAttributeContext metaAttributeContext,
EntityBinding referencedEntityBinding,
@ -189,6 +190,7 @@ public abstract class AbstractCompositeAttributeBindingContainer
propertyAccessorName,
includedInOptimisticLocking,
lazy,
isNotFoundAnException,
naturalIdMutability,
metaAttributeContext,
referencedEntityBinding,

View File

@ -46,8 +46,20 @@ public class AbstractSingularAssociationAttributeBinding extends AbstractSingula
private FetchTiming fetchTiming;
private FetchStyle fetchStyle;
private boolean isUnWrapProxy;
private final boolean isNotFoundAnException;
public AbstractSingularAssociationAttributeBinding(AttributeBindingContainer container, SingularAttribute attribute, String propertyAccessorName, boolean includedInOptimisticLocking, boolean isLazy, NaturalIdMutability naturalIdMutability, MetaAttributeContext metaAttributeContext, EntityBinding referencedEntityBinding, List<RelationalValueBinding> relationalValueBindings, SingularAttributeBinding referencedAttributeBinding) {
public AbstractSingularAssociationAttributeBinding(
AttributeBindingContainer container,
SingularAttribute attribute,
String propertyAccessorName,
boolean includedInOptimisticLocking,
boolean isLazy,
boolean isNotFoundAnException,
NaturalIdMutability naturalIdMutability,
MetaAttributeContext metaAttributeContext,
EntityBinding referencedEntityBinding,
List<RelationalValueBinding> relationalValueBindings,
SingularAttributeBinding referencedAttributeBinding) {
super(
container,
attribute,
@ -66,6 +78,7 @@ public class AbstractSingularAssociationAttributeBinding extends AbstractSingula
this.referencedEntityBinding = referencedEntityBinding;
this.relationalValueBindings = Collections.unmodifiableList( relationalValueBindings );
this.referencedAttributeBinding = referencedAttributeBinding;
this.isNotFoundAnException = isNotFoundAnException;
}
@Override
@ -73,6 +86,11 @@ public class AbstractSingularAssociationAttributeBinding extends AbstractSingula
return relationalValueBindings;
}
@Override
public boolean isNotFoundAnException() {
return isNotFoundAnException;
}
@Override
public boolean hasDerivedValue() {
// TODO: support derived value

View File

@ -209,6 +209,7 @@ public interface AttributeBindingContainer {
String propertyAccessorName,
boolean includedInOptimisticLocking,
boolean lazy,
boolean isNotFoundAnException,
SingularAttributeBinding.NaturalIdMutability naturalIdMutability,
MetaAttributeContext metaAttributeContext,
EntityBinding referencedEntityBinding,

View File

@ -426,6 +426,7 @@ public class CompositeAttributeBinding
String propertyAccessorName,
boolean includedInOptimisticLocking,
boolean lazy,
boolean isNotFoundAnException,
NaturalIdMutability naturalIdMutability,
MetaAttributeContext metaAttributeContext,
EntityBinding referencedEntityBinding,
@ -436,6 +437,7 @@ public class CompositeAttributeBinding
propertyAccessorName,
includedInOptimisticLocking,
lazy,
isNotFoundAnException,
naturalIdMutability,
metaAttributeContext,
referencedEntityBinding,

View File

@ -43,6 +43,7 @@ public class ManyToOneAttributeBinding
String propertyAccessorName,
boolean includedInOptimisticLocking,
boolean lazy,
boolean isNotFoundAnException,
NaturalIdMutability naturalIdMutability,
MetaAttributeContext metaAttributeContext,
EntityBinding referencedEntityBinding,
@ -54,6 +55,7 @@ public class ManyToOneAttributeBinding
propertyAccessorName,
includedInOptimisticLocking,
lazy,
isNotFoundAnException,
naturalIdMutability,
metaAttributeContext,
referencedEntityBinding, relationalValueBindings, referencedAttributeBinding
@ -65,4 +67,5 @@ public class ManyToOneAttributeBinding
return hasNullableRelationalValueBinding( relationalValueBindings );
}
}

View File

@ -57,6 +57,7 @@ public class OneToOneAttributeBinding
propertyAccessorName,
includedInOptimisticLocking,
lazy,
true, //always true
naturalIdMutability,
metaAttributeContext,
referencedEntityBinding,
@ -70,5 +71,4 @@ public class OneToOneAttributeBinding
public boolean isNullable() {
return !isConstrained;
}
}

View File

@ -41,4 +41,6 @@ public interface SingularAssociationAttributeBinding extends SingularAttributeBi
public EntityBinding getReferencedEntityBinding();
public SingularAttributeBinding getReferencedAttributeBinding();
public boolean isNotFoundAnException();
}

View File

@ -44,6 +44,7 @@ public interface ToOneAttributeSource
* @return The name of the referenced entity
*/
public String getReferencedEntityName();
public boolean isNotFoundAnException();
public boolean isUnWrapProxy();
ForeignKeyDirection getForeignKeyDirection();
public List<Binder.DefaultNamingStrategy> getDefaultNamingStrategies(final String entityName, final String tableName, final AttributeBinding referencedAttributeBinding);