protected virtual IList GetResultList(IList results) { for (int i = 0; i < loaders.Count; i++) { CriteriaLoader loader = loaders[i]; results[i] = loader.GetResultList((IList)results[i], parameters[i].ResultTransformer); IList tmpResults; if (resultCollectionGenericType[i] == typeof(object)) { tmpResults = new ArrayList(); } else { tmpResults = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(resultCollectionGenericType[i])); } ArrayHelper.AddAll(tmpResults, (IList)results[i]); results[i] = tmpResults; } if (resultTransformer != null) { for (int i = 0; i < results.Count; i++) { results[i] = resultTransformer.TransformList((IList)results[i]); } } return(results); }
protected virtual IList GetResultList(IList results) { var resultCollections = new List <object>(resultCollectionGenericType.Count); for (int i = 0; i < criteriaQueries.Count; i++) { if (resultCollectionGenericType[i] == typeof(object)) { resultCollections.Add(new List <object>()); } else { resultCollections.Add(Activator.CreateInstance(typeof(List <>).MakeGenericType(resultCollectionGenericType[i]))); } } for (int i = 0; i < loaders.Count; i++) { CriteriaLoader loader = loaders[i]; var resultList = loader.GetResultList((IList)results[i], parameters[i].ResultTransformer); var criteriaIndex = loaderCriteriaMap[i]; ArrayHelper.AddAll((IList)resultCollections[criteriaIndex], resultList); } if (resultTransformer != null) { for (int i = 0; i < results.Count; i++) { resultCollections[i] = resultTransformer.TransformList((IList)resultCollections[i]); } } return(resultCollections); }
public void BindGenerator(SimpleValue id, HbmGenerator generatorMapping) { if (generatorMapping != null) { if (generatorMapping.@class == null) { throw new MappingException("no class given for generator"); } // NH Differen behavior : specific feature NH-1817 TypeDef typeDef = mappings.GetTypeDef(generatorMapping.@class); if (typeDef != null) { id.IdentifierGeneratorStrategy = typeDef.TypeClass; // parameters on the property mapping should override parameters in the typedef var allParameters = new Dictionary <string, string>(typeDef.Parameters); ArrayHelper.AddAll(allParameters, GetGeneratorProperties(generatorMapping, id.Table.Schema)); id.IdentifierGeneratorProperties = allParameters; } else { id.IdentifierGeneratorStrategy = generatorMapping.@class; id.IdentifierGeneratorProperties = GetGeneratorProperties(generatorMapping, id.Table.Schema); } } }
protected virtual IList GetResultList(IList results) { var resultCollections = new List <object>(resultCollectionGenericType.Count); for (int i = 0; i < queries.Count; i++) { if (resultCollectionGenericType[i] == typeof(object)) { resultCollections.Add(new List <object>()); } else { resultCollections.Add(Activator.CreateInstance(typeof(List <>).MakeGenericType(resultCollectionGenericType[i]))); } } var multiqueryHolderInstatiator = GetMultiQueryHolderInstatiator(); for (int i = 0; i < results.Count; i++) { // First use the transformer of each query transforming each row and then the list // DONE: The behavior when the query has a 'new' instead a transformer is delegated to the Loader var resultList = translators[i].Loader.GetResultList((IList)results[i], Parameters[i].ResultTransformer); // then use the MultiQueryTransformer (if it has some sense...) using, as source, the transformed result. resultList = GetTransformedResults(resultList, multiqueryHolderInstatiator); var queryIndex = translatorQueryMap[i]; ArrayHelper.AddAll((IList)resultCollections[queryIndex], resultList); } return(resultCollections); }
public void AddingNullToNonGenericListShouldNotThrow() { var a1 = new ArrayList { null }; var a2 = new ArrayList(); Assert.DoesNotThrow(() => ArrayHelper.AddAll(a2, a1)); }
public async Task EqualsSnapshotAsync() { var a = new A { Name = "first generic type" }; var i0 = new B { Name = "1" }; var i4 = new B { Name = "4" }; a.Items = new List <B> { i0, i0, new B { Name = "2" }, new B { Name = "3" }, i4, i4, }; var lastIdx = a.Items.Count - 1; using (var s = OpenSession()) { await(s.SaveAsync(a)); await(s.FlushAsync()); var collection = (IPersistentCollection)a.Items; var collectionPersister = Sfi.GetCollectionPersister(collection.Role); a.Items[0] = i4; Assert.Multiple( async() => { Assert.That(await(collection.EqualsSnapshotAsync(collectionPersister, CancellationToken.None)), Is.False, "modify first collection element"); a.Items[lastIdx] = i0; Assert.That(await(collection.EqualsSnapshotAsync(collectionPersister, CancellationToken.None)), Is.True, "swap elements in collection"); a.Items[0] = i0; a.Items[lastIdx] = i0; Assert.That(await(collection.EqualsSnapshotAsync(collectionPersister, CancellationToken.None)), Is.False, "modify last collection element"); a.Items[lastIdx] = i4; var reversed = a.Items.Reverse().ToArray(); a.Items.Clear(); ArrayHelper.AddAll(a.Items, reversed); Assert.That(await(collection.EqualsSnapshotAsync(collectionPersister, CancellationToken.None)), Is.True, "reverse collection elements"); }); } }
public string[] GetColumnAliases(int position, ICriteria criteria, ICriteriaQuery criteriaQuery) { var result = new List <object>(Length); for (var i = 0; i < Length; i++) { var colAliases = GetColumnAliases(position, criteria, criteriaQuery, this[i]); ArrayHelper.AddAll(result, colAliases); position += colAliases.Length; } return(ArrayHelper.ToStringArray(result)); }
public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery) { var typedValues = new List <TypedValue>(); foreach (ICriterion criterion in this.criteria) { TypedValue[] subvalues = criterion.GetTypedValues(criteria, criteriaQuery); ArrayHelper.AddAll(typedValues, subvalues); } return(typedValues.ToArray()); }
public string[] GetColumnAliases(int position, ICriteria criteria, ICriteriaQuery criteriaQuery) { IList result = new ArrayList(this.Length); for (int i = 0; i < this.Length; i++) { string[] colAliases = ProjectionList.GetColumnAliases(position, criteria, criteriaQuery, this[i]); ArrayHelper.AddAll(result, colAliases); position += colAliases.Length; } return(ArrayHelper.ToStringArray(result)); }
public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery) { ArrayList typedValues = new ArrayList(); foreach (ICriterion criterion in this.criteria) { TypedValue[] subvalues = criterion.GetTypedValues(criteria, criteriaQuery); ArrayHelper.AddAll(typedValues, subvalues); } return((TypedValue[])typedValues.ToArray(typeof(TypedValue))); }
/// <summary> Constructs some form of non-scalar return descriptor </summary> /// <param name="alias">The result alias </param> /// <param name="propertyResults">Any user-supplied column->property mappings </param> /// <param name="lockMode">The lock mode to apply to the return. </param> protected internal NativeSQLQueryNonScalarReturn(string alias, IDictionary <string, string[]> propertyResults, LockMode lockMode) { if (string.IsNullOrEmpty(alias)) { throw new ArgumentNullException("alias", "A valid scalar alias must be specified."); } this.alias = alias; this.lockMode = lockMode; if (propertyResults != null) { ArrayHelper.AddAll(this.propertyResults, propertyResults); } }
/// <summary> /// Loads all loaders results to single typed list /// </summary> internal static List <T> LoadAllToList <T>(this IList <CriteriaLoader> loaders, ISessionImplementor session) { var subresults = new List <IList>(loaders.Count); foreach (var l in loaders) { subresults.Add(l.List(session)); } var results = new List <T>(subresults.Sum(r => r.Count)); foreach (var list in subresults) { ArrayHelper.AddAll(results, list); } return(results); }
/// <summary> /// Loads all loaders results to single typed list /// </summary> internal static async Task <List <T> > LoadAllToListAsync <T>(this IList <CriteriaLoader> loaders, ISessionImplementor session, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var subresults = new List <IList>(loaders.Count); foreach (var l in loaders) { subresults.Add(await(l.ListAsync(session, cancellationToken)).ConfigureAwait(false)); } var results = new List <T>(subresults.Sum(r => r.Count)); foreach (var list in subresults) { ArrayHelper.AddAll(results, list); } return(results); }
protected List <T> GetTypedResults <T>() { if (_loaderResults == null) { throw new HibernateException("Batch wasn't executed. You must call IQueryBatch.Execute() before accessing results."); } List <T> results = new List <T>(_loaderResults.Sum(tr => tr.Count)); for (int i = 0; i < _queryInfos.Count; i++) { var list = _queryInfos[i].Loader.GetResultList( _loaderResults[i], _queryInfos[i].Parameters.ResultTransformer); ArrayHelper.AddAll(results, list); } return(results); }
public SQLCustomQuery(INativeSQLQueryReturn[] queryReturns, string sqlQuery, ICollection <string> additionalQuerySpaces, ISessionFactoryImplementor factory) { log.Debug("starting processing of sql query [" + sqlQuery + "]"); SQLQueryReturnProcessor processor = new SQLQueryReturnProcessor(queryReturns, factory); SQLQueryReturnProcessor.ResultAliasContext aliasContext = processor.Process(); SQLQueryParser parser = new SQLQueryParser(sqlQuery, new ParserContext(aliasContext)); sql = parser.Process(); ArrayHelper.AddAll(namedParameterBindPoints, parser.NamedParameters); ArrayHelper.AddAll(customQueryReturns, processor.GenerateCustomReturns(parser.QueryHasAliases)); if (additionalQuerySpaces != null) { querySpaces.AddAll(additionalQuerySpaces); } }
public override void ListCustomQuery(ICustomQuery customQuery, QueryParameters queryParameters, IList results) { using (BeginProcess()) { var loader = new CustomLoader(customQuery, Factory); var success = false; try { ArrayHelper.AddAll(results, loader.List(this, queryParameters)); success = true; } finally { AfterOperation(success); } temporaryPersistenceContext.Clear(); } }
public SQLCustomQuery(INativeSQLQueryReturn[] queryReturns, string sqlQuery, ICollection <string> additionalQuerySpaces, ISessionFactoryImplementor factory) { log.Debug("starting processing of sql query [{0}]", sqlQuery); SQLQueryReturnProcessor processor = new SQLQueryReturnProcessor(queryReturns, factory); SQLQueryReturnProcessor.ResultAliasContext aliasContext = processor.Process(); SQLQueryParser parser = new SQLQueryParser(factory, sqlQuery, new ParserContext(aliasContext)); sql = parser.Process(); ArrayHelper.AddAll(customQueryReturns, processor.GenerateCustomReturns(parser.QueryHasAliases)); parametersSpecifications = parser.CollectedParametersSpecifications.ToList(); if (additionalQuerySpaces != null) { querySpaces.UnionWith(additionalQuerySpaces); } }
protected List <T> GetTypedResults <T>() { ThrowIfNotInitialized(); if (_queryInfos.Any(qi => qi.Result == null)) { throw new InvalidOperationException("Some query results are missing, batch is likely not fully executed yet."); } var results = new List <T>(_queryInfos.Sum(qi => qi.Result.Count)); foreach (var queryInfo in _queryInfos) { var list = queryInfo.Loader.GetResultList( queryInfo.Result, queryInfo.Parameters.ResultTransformer); ArrayHelper.AddAll(results, list); } return(results); }
public override async Task ListCustomQueryAsync(ICustomQuery customQuery, QueryParameters queryParameters, IList results, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); using (BeginProcess()) { var loader = new CustomLoader(customQuery, Factory); var success = false; try { ArrayHelper.AddAll(results, await(loader.ListAsync(this, queryParameters, cancellationToken)).ConfigureAwait(false)); success = true; } finally { await(AfterOperationAsync(success, cancellationToken)).ConfigureAwait(false); } temporaryPersistenceContext.Clear(); } }
public override async Task ListAsync(CriteriaImpl criteria, IList results, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); using (new SessionIdLoggingContext(SessionId)) { CheckAndUpdateSessionStatus(); string[] implementors = Factory.GetImplementors(criteria.EntityOrClassName); int size = implementors.Length; CriteriaLoader[] loaders = new CriteriaLoader[size]; for (int i = 0; i < size; i++) { loaders[i] = new CriteriaLoader(GetOuterJoinLoadable(implementors[i]), Factory, criteria, implementors[i], EnabledFilters); } bool success = false; try { for (int i = size - 1; i >= 0; i--) { ArrayHelper.AddAll(results, await(loaders[i].ListAsync(this, cancellationToken)).ConfigureAwait(false)); } success = true; } catch (HibernateException) { // Do not call Convert on HibernateExceptions throw; } catch (Exception sqle) { throw Convert(sqle, "Unable to perform find"); } finally { await(AfterOperationAsync(success, cancellationToken)).ConfigureAwait(false); } temporaryPersistenceContext.Clear(); } }
public override void ListCustomQuery(ICustomQuery customQuery, QueryParameters queryParameters, IList results) { using (new SessionIdLoggingContext(SessionId)) { CheckAndUpdateSessionStatus(); CustomLoader loader = new CustomLoader(customQuery, Factory); bool success = false; try { ArrayHelper.AddAll(results, loader.List(this, queryParameters)); success = true; } finally { AfterOperation(success); } temporaryPersistenceContext.Clear(); } }
public void ManyToManyCriteriaJoin() { ISession s = OpenSession(); ITransaction t = s.BeginTransaction(); Parent p = new Parent("foo"); p.Children.Add(new Child("foo1")); p.Children.Add(new Child("foo2")); Parent q = new Parent("bar"); q.Children.Add(new Child("bar1")); q.Children.Add(new Child("bar2")); ArrayHelper.AddAll(q.MoreChildren, p.Children); s.Save(p); s.Save(q); t.Commit(); s.Close(); s = OpenSession(); t = s.BeginTransaction(); s.CreateCriteria(typeof(Parent)) .AddOrder(Order.Desc("Name")) // H3 has this after CreateCriteria("Friends"), but it's not yet supported in NH .CreateCriteria("MoreChildren") .CreateCriteria("Friends") .List(); IList parents = s.CreateCriteria(typeof(Parent)) .SetFetchMode("MoreChildren", FetchMode.Join) .SetFetchMode("MoreChildren.Friends", FetchMode.Join) .AddOrder(Order.Desc("Name")) .List(); s.Delete(parents[0]); s.Delete(parents[1]); t.Commit(); s.Close(); }
public async Task ManyToManyCriteriaJoinAsync() { ISession s = OpenSession(); ITransaction t = s.BeginTransaction(); Parent p = new Parent("foo"); p.Children.Add(new Child("foo1")); p.Children.Add(new Child("foo2")); Parent q = new Parent("bar"); q.Children.Add(new Child("bar1")); q.Children.Add(new Child("bar2")); ArrayHelper.AddAll(q.MoreChildren, p.Children); await(s.SaveAsync(p)); await(s.SaveAsync(q)); await(t.CommitAsync()); s.Close(); s = OpenSession(); t = s.BeginTransaction(); await(s.CreateCriteria(typeof(Parent)) .AddOrder(Order.Desc("Name")) // H3 has this after CreateCriteria("Friends"), but it's not yet supported in NH .CreateCriteria("MoreChildren") .CreateCriteria("Friends") .ListAsync()); IList parents = await(s.CreateCriteria(typeof(Parent)) .Fetch("MoreChildren") .Fetch("MoreChildren.Friends") .AddOrder(Order.Desc("Name")) .ListAsync()); await(s.DeleteAsync(parents[0])); await(s.DeleteAsync(parents[1])); await(t.CommitAsync()); s.Close(); }
public override void List(CriteriaImpl criteria, IList results) { using (BeginProcess()) { string[] implementors = Factory.GetImplementors(criteria.EntityOrClassName); int size = implementors.Length; CriteriaLoader[] loaders = new CriteriaLoader[size]; for (int i = 0; i < size; i++) { loaders[i] = new CriteriaLoader(GetOuterJoinLoadable(implementors[i]), Factory, criteria, implementors[i], EnabledFilters); } bool success = false; try { for (int i = size - 1; i >= 0; i--) { ArrayHelper.AddAll(results, loaders[i].List(this)); } success = true; } catch (HibernateException) { // Do not call Convert on HibernateExceptions throw; } catch (Exception sqle) { throw Convert(sqle, "Unable to perform find"); } finally { AfterOperation(success); } temporaryPersistenceContext.Clear(); } }
protected virtual IList GetResultList(IList results) { var rawResultCollections = new List <IList>(resultCollectionGenericType.Count); for (var i = 0; i < queries.Count; i++) { var query = queries[i] as ExpressionQueryImpl; // Linq queries may override the query type, finishing the work with a post execute transformer, // which with multi queries are executed through the multi-query result trasformer. var rawElementType = query?.QueryExpression?.Type ?? resultCollectionGenericType[i]; var resultList = rawElementType == typeof(object) ? new List <object>() : (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(rawElementType)); rawResultCollections.Add(resultList); } for (var i = 0; i < results.Count; i++) { // First use the transformer of each query transforming each row and then the list // DONE: The behavior when the query has a 'new' instead a transformer is delegated to the Loader var resultList = translators[i].Loader.GetResultList((IList)results[i], Parameters[i].ResultTransformer); var queryIndex = translatorQueryMap[i]; ArrayHelper.AddAll(rawResultCollections[queryIndex], resultList); } var resultCollections = new List <object>(resultCollectionGenericType.Count); for (var i = 0; i < queries.Count; i++) { // Once polymorpic queries aggregated in one result per query (previous loop), use the // MultiQueryTransformer using, as source, the aggregated result. var resultList = GetTransformedResults(rawResultCollections[i]); resultCollections.Add(resultList); } return(resultCollections); }
public override void ListCustomQuery(ICustomQuery customQuery, QueryParameters queryParameters, IList results) { using (BeginProcess()) { // We need to flush the batcher. Otherwise it may have pending operations which will not already have reached the database, // and the query may yield stale data. Flush(); var loader = new CustomLoader(customQuery, Factory); var success = false; try { ArrayHelper.AddAll(results, loader.List(this, queryParameters)); success = true; } finally { AfterOperation(success); } temporaryPersistenceContext.Clear(); } }
public override async Task ListCustomQueryAsync(ICustomQuery customQuery, QueryParameters queryParameters, IList results, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); using (BeginProcess()) { // We need to flush the batcher. Otherwise it may have pending operations which will not already have reached the database, // and the query may yield stale data. await(FlushAsync(cancellationToken)).ConfigureAwait(false); var loader = new CustomLoader(customQuery, Factory); var success = false; try { ArrayHelper.AddAll(results, await(loader.ListAsync(this, queryParameters, cancellationToken)).ConfigureAwait(false)); success = true; } finally { await(AfterOperationAsync(success, cancellationToken)).ConfigureAwait(false); } temporaryPersistenceContext.Clear(); } }
public IIdentifierGenerator CreateIdentifierGenerator(Dialect.Dialect dialect, string defaultCatalog, string defaultSchema, RootClass rootClass) { Dictionary <string, string> @params = new Dictionary <string, string>(); //if the hibernate-mapping did not specify a schema/catalog, use the defaults //specified by properties - but note that if the schema/catalog were specified //in hibernate-mapping, or as params, they will already be initialized and //will override the values set here (they are in identifierGeneratorProperties) if (!string.IsNullOrEmpty(defaultSchema)) { @params[PersistentIdGeneratorParmsNames.Schema] = defaultSchema; } if (!string.IsNullOrEmpty(defaultCatalog)) { @params[PersistentIdGeneratorParmsNames.Catalog] = defaultCatalog; } //pass the entity-name, if not a collection-id if (rootClass != null) { @params[IdGeneratorParmsNames.EntityName] = rootClass.EntityName; } //init the table here instead of earlier, so that we can get a quoted table name //TODO: would it be better to simply pass the qualified table name, instead of // splitting it up into schema/catalog/table names string tableName = Table.GetQuotedName(dialect); @params[PersistentIdGeneratorParmsNames.Table] = tableName; //pass the column name (a generated id almost always has a single column and is not a formula) IEnumerator enu = ColumnIterator.GetEnumerator(); enu.MoveNext(); string columnName = ((Column)enu.Current).GetQuotedName(dialect); @params[PersistentIdGeneratorParmsNames.PK] = columnName; if (rootClass != null) { StringBuilder tables = new StringBuilder(); bool commaNeeded = false; foreach (Table identityTable in rootClass.IdentityTables) { if (commaNeeded) { tables.Append(StringHelper.CommaSpace); } commaNeeded = true; tables.Append(identityTable.GetQuotedName(dialect)); } @params[PersistentIdGeneratorParmsNames.Tables] = tables.ToString(); } else { @params[PersistentIdGeneratorParmsNames.Tables] = tableName; } if (identifierGeneratorProperties != null) { ArrayHelper.AddAll(@params, identifierGeneratorProperties); } return(IdentifierGeneratorFactory.Create(identifierGeneratorStrategy, Type, @params, dialect)); }
//TODO 6.0: Remove (use base class implementation) public override async Task ListAsync(CriteriaImpl criteria, IList results, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); ArrayHelper.AddAll(results, await(ListAsync(criteria, cancellationToken)).ConfigureAwait(false)); }
//TODO 6.0: Remove (use base class implementation) public override void List(CriteriaImpl criteria, IList results) { ArrayHelper.AddAll(results, List(criteria)); }