public object Load(EntityInfo entityInfo) { InitThisProjectionFlag(entityInfo); if (projectThis == true) { foreach (int index in entityInfo.IndexesOfThis) { entityInfo.Projection[index] = objectLoader.Load(entityInfo); } } return(transformer != null ? transformer.TransformTuple(entityInfo.Projection, aliases) : entityInfo.Projection); }
/// <inheritdoc /> public async ValueTask <Object> LoadAsync(EntityInfo entityInfo, CancellationToken token = default) { InitThisProjectionFlag(entityInfo); if (projectThis == true) { foreach (int index in entityInfo.IndexesOfThis) { entityInfo.Projection[index] = await objectLoader.LoadAsync(entityInfo, token); } } return(transformer != null ? transformer.TransformTuple(entityInfo.Projection, aliases) : entityInfo.Projection); }
// rows iterator public object TransformTuple(object[] tuple, string[] aliases) { var list = new List <string>(aliases); var propertyAliases = new List <string>(list); var complexAliases = new List <string>(); for (var i = 0; i < list.Count; i++) { var alias = list[i]; // Aliase with the '.' represents complex IPersistentEntity chain if (alias.Contains(_complexChar)) { complexAliases.Add(alias); propertyAliases[i] = null; } } // be smart use what is already available // the standard properties string, valueTypes var result = _baseTransformer.TransformTuple(tuple, propertyAliases.ToArray()); TransformPersistentChain(tuple, complexAliases, result, list); return(result); }
public object Instantiate(object[] row) { if (transformer == null) { return(row); } else { return(transformer.TransformTuple(row, queryReturnAliases)); } }
/// <summary> /// Re-transforms, if necessary, a List of values previously /// transformed by this (or an equivalent) CacheableResultTransformer. /// Each element of the list is re-transformed in place (i.e, List /// elements are replaced with re-transformed values) and the original /// List is returned. If re-transformation is unnecessary, the original List is returned /// unchanged. /// </summary> /// <param name="transformedResults">Results that were previously transformed.</param> /// <param name="aliases">The aliases that correspond to the untransformed tuple.</param> /// <param name="transformer">The transformer for the re-transformation.</param> /// <param name="includeInTuple"></param> /// <returns>transformedResults, with each element re-transformed (if necessary).</returns> public IList RetransformResults(IList transformedResults, string[] aliases, IResultTransformer transformer, bool[] includeInTuple) { if (transformer == null) { throw new ArgumentNullException(nameof(transformer)); } if (_includeInTuple == null) { throw new InvalidOperationException("This transformer is not initialized"); } if (!HasSameParameters(Create(transformer, aliases, includeInTuple, false, null, _skipTransformer))) { throw new InvalidOperationException( "this CacheableResultTransformer is inconsistent with specified arguments; cannot re-transform" ); } bool requiresRetransform = true; string[] aliasesToUse = aliases == null ? null : Index(aliases); if (_skipTransformer) { } else if (transformer.Equals(_actualTransformer)) { requiresRetransform = false; } else if (transformer is ITupleSubsetResultTransformer) { requiresRetransform = !((ITupleSubsetResultTransformer)transformer).IsTransformedValueATupleElement(aliasesToUse, _tupleLength); } if (requiresRetransform) { for (int i = 0; i < transformedResults.Count; i++) { object[] tuple = _actualTransformer.UntransformToTuple( transformedResults[i], _tupleSubsetLength == 1 ); transformedResults[i] = transformer.TransformTuple(tuple, aliasesToUse); } } return(transformedResults); }
public override IList GetResultList(IList results, IResultTransformer customResultTransformer) { if (customResultTransformer == null) { // apply the defaut transformer of criteria aka RootEntityResultTransformer return(results); } for (int i = 0; i < results.Count; i++) { var row = results[i] as object[] ?? new object[] { results[i] }; object result = customResultTransformer.TransformTuple(row, translator.HasProjection ? translator.ProjectedAliases : userAliases); results[i] = result; } return(customResultTransformer.TransformList(results)); }
private IList GetTransformedResults(IList source) { if (resultTransformer == null) { return(source); } //MultiCriteria does not call TransformTuple here for (var j = 0; j < source.Count; j++) { var row = source[j] as object[] ?? new[] { source[j] }; source[j] = resultTransformer.TransformTuple(row, null); } return(resultTransformer.TransformList(source)); }
public override IList GetResultList(IList results, IResultTransformer resultTransformer) { // meant to handle dynamic instantiation queries...(Copy from QueryLoader) var returnAliases = ReturnAliasesForTransformer; if (resultTransformer != null) { for (var i = 0; i < results.Count; i++) { var row = (object[])results[i]; results[i] = resultTransformer.TransformTuple(row, returnAliases); } return(resultTransformer.TransformList(results)); } return(results); }
private void PostMoveNext(bool hasNext) { _startedReading = true; _hasNext = hasNext; _currentRow++; if (_selection != null && _selection.MaxRows != RowSelection.NoValue) { _hasNext = _hasNext && (_currentRow < _selection.MaxRows); } bool sessionDefaultReadOnlyOrig = _session.DefaultReadOnly; _session.DefaultReadOnly = _readOnly; try { if (!_hasNext) { // there are no more records in the DataReader so clean up log.Debug("exhausted results"); _currentResult = null; _session.Batcher.CloseCommand(_cmd, _reader); } else { log.Debug("retrieving next results"); if (_single && _resultTransformer == null) { _currentResult = _types[0].NullSafeGet(_reader, _names[0], _session, null); } else { object[] currentResults = new object[_types.Length]; // move through each of the ITypes contained in the DbDataReader and convert them // to their objects. for (int i = 0; i < _types.Length; i++) { // The IType knows how to extract its value out of the DbDataReader. If the IType // is a value type then the value will simply be pulled out of the DbDataReader. If // the IType is an Entity type then the IType will extract the id from the DbDataReader // and use the ISession to load an instance of the object. currentResults[i] = _types[i].NullSafeGet(_reader, _names[i], _session, null); } if (_resultTransformer != null) { _currentResult = _resultTransformer.TransformTuple(currentResults, _returnAliases); } else { _currentResult = currentResults; } } } } finally { _session.DefaultReadOnly = sessionDefaultReadOnlyOrig; } }
public override IList GetResultList(IList results, IResultTransformer customResultTransformer) { if (customResultTransformer == null) { // apply the defaut transformer of criteria aka RootEntityResultTransformer return results; } for (int i = 0; i < results.Count; i++) { var row = results[i] as object[] ?? new object[] { results[i] }; object result = customResultTransformer.TransformTuple(row, translator.HasProjection ? translator.ProjectedAliases : userAliases); results[i] = result; } return customResultTransformer.TransformList(results); }
internal object GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, LockMode[] lockModeArray, EntityKey optionalObjectKey, IList hydratedObjects, EntityKey[] keys, bool returnProxies, IResultTransformer forcedResultTransformer) { ILoadable[] persisters = EntityPersisters; int entitySpan = persisters.Length; for (int i = 0; i < entitySpan; i++) { keys[i] = GetKeyFromResultSet(i, persisters[i], i == entitySpan - 1 ? queryParameters.OptionalId : null, resultSet, session); //TODO: the i==entitySpan-1 bit depends upon subclass implementation (very bad) } RegisterNonExists(keys, session); // this call is side-effecty object[] row = GetRow(resultSet, persisters, keys, queryParameters.OptionalObject, optionalObjectKey, lockModeArray, hydratedObjects, session); ReadCollectionElements(row, resultSet, session); if (returnProxies) { // now get an existing proxy for each row element (if there is one) for (int i = 0; i < entitySpan; i++) { object entity = row[i]; object proxy = session.PersistenceContext.ProxyFor(persisters[i], keys[i], entity); if (entity != proxy) { // Force the proxy to resolve itself ((INHibernateProxy)proxy).HibernateLazyInitializer.SetImplementation(entity); row[i] = proxy; } } } return forcedResultTransformer == null ? GetResultColumnOrRow(row, queryParameters.ResultTransformer, resultSet, session) : forcedResultTransformer.TransformTuple(GetResultRow(row, resultSet, session), ResultRowAliases); }