Skip to content

Commit da9aac3

Browse files
David EllingsworthDavid Ellingsworth
David Ellingsworth
authored and
David Ellingsworth
committed
Fix async caching of OneToOneType from second level cache.
1 parent 9a4aece commit da9aac3

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

src/NHibernate/Async/Type/OneToOneType.cs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -123,39 +123,36 @@ public override async Task<object> HydrateAsync(DbDataReader rs, string[] names,
123123
return identifier;
124124
}
125125

126-
public override Task<object> DisassembleAsync(object value, ISessionImplementor session, object owner, CancellationToken cancellationToken)
126+
public override async Task<object> DisassembleAsync(object value, ISessionImplementor session, object owner, CancellationToken cancellationToken)
127127
{
128-
if (cancellationToken.IsCancellationRequested)
129-
{
130-
return Task.FromCanceled<object>(cancellationToken);
131-
}
132-
try
128+
cancellationToken.ThrowIfCancellationRequested();
129+
if (value == null)
133130
{
134-
return Task.FromResult<object>(Disassemble(value, session, owner));
131+
return null;
135132
}
136-
catch (Exception ex)
133+
134+
object id = await (ForeignKeys.GetEntityIdentifierIfNotUnsavedAsync(GetAssociatedEntityName(), value, session, cancellationToken)).ConfigureAwait(false);
135+
136+
if (id == null)
137137
{
138-
return Task.FromException<object>(ex);
138+
throw new AssertionFailure("cannot cache a reference to an object with a null id: " + GetAssociatedEntityName());
139139
}
140+
141+
return await (GetIdentifierType(session).DisassembleAsync(id, session, owner, cancellationToken)).ConfigureAwait(false);
140142
}
141143

142-
public override Task<object> AssembleAsync(object cached, ISessionImplementor session, object owner, CancellationToken cancellationToken)
144+
public override async Task<object> AssembleAsync(object cached, ISessionImplementor session, object owner, CancellationToken cancellationToken)
143145
{
144-
if (cancellationToken.IsCancellationRequested)
145-
{
146-
return Task.FromCanceled<object>(cancellationToken);
147-
}
148-
try
149-
{
150-
//this should be a call to resolve(), not resolveIdentifier(),
151-
//'cos it might be a property-ref, and we did not cache the
152-
//referenced value
153-
return ResolveIdentifierAsync(session.GetContextEntityIdentifier(owner), session, owner, cancellationToken);
154-
}
155-
catch (Exception ex)
146+
cancellationToken.ThrowIfCancellationRequested();
147+
// the owner of the association is not the owner of the id
148+
object id = await (GetIdentifierType(session).AssembleAsync(cached, session, null, cancellationToken)).ConfigureAwait(false);
149+
150+
if (id == null)
156151
{
157-
return Task.FromException<object>(ex);
152+
return null;
158153
}
154+
155+
return await (ResolveIdentifierAsync(id, session, cancellationToken)).ConfigureAwait(false);
159156
}
160157
}
161158
}

0 commit comments

Comments
 (0)