|
| 1 | +//------------------------------------------------------------------------------ |
| 2 | +// <auto-generated> |
| 3 | +// This code was generated by AsyncGenerator. |
| 4 | +// |
| 5 | +// Changes to this file may cause incorrect behavior and will be lost if |
| 6 | +// the code is regenerated. |
| 7 | +// </auto-generated> |
| 8 | +//------------------------------------------------------------------------------ |
| 9 | + |
| 10 | + |
| 11 | +using System; |
| 12 | +using System.Collections.Generic; |
| 13 | +using System.Data; |
| 14 | +using System.Data.Common; |
| 15 | +using System.Text; |
| 16 | +using System.Linq; |
| 17 | +using NHibernate.Cache; |
| 18 | +using NHibernate.Engine; |
| 19 | +using NHibernate.Impl; |
| 20 | +using NHibernate.Intercept; |
| 21 | +using NHibernate.Mapping; |
| 22 | +using NHibernate.Properties; |
| 23 | +using NHibernate.SqlCommand; |
| 24 | +using NHibernate.Type; |
| 25 | +using NHibernate.Util; |
| 26 | + |
| 27 | +namespace NHibernate.Persister.Entity |
| 28 | +{ |
| 29 | + using System.Threading.Tasks; |
| 30 | + using System.Threading; |
| 31 | + public partial class SingleTableEntityPersister : AbstractEntityPersister, IQueryable |
| 32 | + { |
| 33 | + |
| 34 | + public override async Task<object[]> HydrateAsync(DbDataReader rs, object id, object obj, string[][] suffixedPropertyColumns, bool allProperties, ISessionImplementor session, CancellationToken cancellationToken) |
| 35 | + { |
| 36 | + cancellationToken.ThrowIfCancellationRequested(); |
| 37 | + if (!hasSequentialSelects) |
| 38 | + { |
| 39 | + return await (base.HydrateAsync(rs, id, obj, suffixedPropertyColumns, allProperties, session, cancellationToken)).ConfigureAwait(false); |
| 40 | + } |
| 41 | + |
| 42 | + if (log.IsDebugEnabled()) |
| 43 | + { |
| 44 | + log.Debug("Hydrating entity: {0}", MessageHelper.InfoString(this, id, Factory)); |
| 45 | + } |
| 46 | + |
| 47 | + DbCommand sequentialSelect = null; |
| 48 | + DbDataReader sequentialResultSet = null; |
| 49 | + bool sequentialSelectEmpty = false; |
| 50 | + using (session.BeginProcess()) |
| 51 | + { |
| 52 | + try |
| 53 | + { |
| 54 | + var sql = GetSequentialSelect(); |
| 55 | + if (sql != null) |
| 56 | + { |
| 57 | + //TODO: I am not so sure about the exception handling in this bit! |
| 58 | + sequentialSelect = await (session.Batcher.PrepareCommandAsync( |
| 59 | + CommandType.Text, |
| 60 | + sql, |
| 61 | + IdentifierType.SqlTypes(Factory), cancellationToken)).ConfigureAwait(false); |
| 62 | + await (IdentifierType.NullSafeSetAsync(sequentialSelect, id, 0, session, cancellationToken)).ConfigureAwait(false); |
| 63 | + sequentialResultSet = await (session.Batcher.ExecuteReaderAsync(sequentialSelect, cancellationToken)).ConfigureAwait(false); |
| 64 | + if (!await (sequentialResultSet.ReadAsync(cancellationToken)).ConfigureAwait(false)) |
| 65 | + { |
| 66 | + // TODO: Deal with the "optional" attribute in the <join> mapping; |
| 67 | + // this code assumes that optional defaults to "true" because it |
| 68 | + // doesn't actually seem to work in the fetch="join" code |
| 69 | + // |
| 70 | + // Note that actual proper handling of optional-ality here is actually |
| 71 | + // more involved than this patch assumes. Remember that we might have |
| 72 | + // multiple <join/> mappings associated with a single entity. Really |
| 73 | + // a couple of things need to happen to properly handle optional here: |
| 74 | + // 1) First and foremost, when handling multiple <join/>s, we really |
| 75 | + // should be using the entity root table as the driving table; |
| 76 | + // another option here would be to choose some non-optional joined |
| 77 | + // table to use as the driving table. In all likelihood, just using |
| 78 | + // the root table is much simplier |
| 79 | + // 2) Need to add the FK columns corresponding to each joined table |
| 80 | + // to the generated select list; these would then be used when |
| 81 | + // iterating the result set to determine whether all non-optional |
| 82 | + // data is present |
| 83 | + // My initial thoughts on the best way to deal with this would be |
| 84 | + // to introduce a new SequentialSelect abstraction that actually gets |
| 85 | + // generated in the persisters (ok, SingleTable...) and utilized here. |
| 86 | + // It would encapsulated all this required optional-ality checking... |
| 87 | + sequentialSelectEmpty = true; |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + IType[] types = PropertyTypes; |
| 92 | + object[] values = new object[types.Length]; |
| 93 | + bool[] laziness = PropertyLaziness; |
| 94 | + |
| 95 | + for (int i = 0; i < types.Length; i++) |
| 96 | + { |
| 97 | + if (!propertySelectable[i]) |
| 98 | + { |
| 99 | + values[i] = BackrefPropertyAccessor.Unknown; |
| 100 | + } |
| 101 | + else if (allProperties || !laziness[i]) |
| 102 | + { |
| 103 | + //decide which ResultSet to get the property value from: |
| 104 | + var propertyIsDeferred = subclassTableSequentialSelect[GetSubclassPropertyTableNumber(i)]; |
| 105 | + if (propertyIsDeferred && sequentialSelectEmpty) |
| 106 | + { |
| 107 | + values[i] = null; |
| 108 | + } |
| 109 | + else |
| 110 | + { |
| 111 | + var propertyResultSet = propertyIsDeferred ? sequentialResultSet : rs; |
| 112 | + string[] cols = propertyIsDeferred |
| 113 | + ? propertyColumnAliases[i] |
| 114 | + : suffixedPropertyColumns[i]; |
| 115 | + values[i] = await (types[i].HydrateAsync(propertyResultSet, cols, session, obj, cancellationToken)).ConfigureAwait(false); |
| 116 | + } |
| 117 | + } |
| 118 | + else |
| 119 | + { |
| 120 | + values[i] = LazyPropertyInitializer.UnfetchedProperty; |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + return values; |
| 125 | + } |
| 126 | + finally |
| 127 | + { |
| 128 | + sequentialResultSet?.Close(); |
| 129 | + if (sequentialSelect != null) |
| 130 | + { |
| 131 | + session.Batcher.CloseCommand(sequentialSelect, sequentialResultSet); |
| 132 | + } |
| 133 | + } |
| 134 | + } |
| 135 | + } |
| 136 | + } |
| 137 | +} |
0 commit comments