public void AddDuplicateAlias(string alias, FromElement element) { if (alias != null) { _fromElementByClassAlias.Add(alias, element); } }
public void AddKeyValue() { //non-null key nullableDictionary.Add(_itemKey, _itemValue); Assert.AreEqual(1, nullableDictionary.Count); Assert.AreEqual(nullableDictionary[_itemKey], _itemValue); //null key nullableDictionary.Add(_nullItemKey, _nullItemValue); Assert.AreEqual(2, nullableDictionary.Count); Assert.AreEqual(nullableDictionary[_nullItemKey], _nullItemValue); }
public void AddCollectionJoinFromElementByPath(string path, FromElement destination) { if (Log.IsDebugEnabled) { Log.Debug("addCollectionJoinFromElementByPath() : " + path + " -> " + destination); } _collectionJoinFromElementsByPath.Add(path, destination); // Add the new node to the map so that we don't create it twice. }
public void AddJoinByPathMap(string path, FromElement destination) { if (Log.IsDebugEnabled) { Log.Debug("addJoinByPathMap() : " + path + " -> " + destination); } _fromElementsByPath.Add(path, destination); }
public void AddJoinByPathMap(string path, FromElement destination) { if (Log.IsDebugEnabled()) { Log.Debug("addJoinByPathMap() : {0} -> {1}", path, destination); } _fromElementsByPath.Add(path, destination); }
public void AddTest() { foreach (var num in _random.UniqueNumberList()) { _nullableDictionary.Add(num.ToString(), num); _dictionary.Add(num.ToString(), num); } CollectionAssert.AreEquivalent(_dictionary, _nullableDictionary); }
public ParameterTranslationsImpl(IEnumerable <IParameterSpecification> parameterSpecifications) { List <ParameterInfo> ordinalParameterList = new List <ParameterInfo>(); NullableDictionary <string, NamedParamTempHolder> namedParameterMap = new NullableDictionary <string, NamedParamTempHolder>(); int i = 0; foreach (IParameterSpecification spec in parameterSpecifications) { if (spec is PositionalParameterSpecification) { PositionalParameterSpecification ordinalSpec = ( PositionalParameterSpecification )spec; ordinalParameterList.Add(new ParameterInfo(i, ordinalSpec.ExpectedType)); } else if (spec is NamedParameterSpecification) { NamedParameterSpecification namedSpec = ( NamedParameterSpecification )spec; NamedParamTempHolder paramHolder = namedParameterMap[namedSpec.Name]; if (paramHolder == null) { paramHolder = new NamedParamTempHolder(); paramHolder.name = namedSpec.Name; paramHolder.type = namedSpec.ExpectedType; namedParameterMap.Add(namedSpec.Name, paramHolder); } paramHolder.positions.Add(i); } else { // don't care about other param types here, just those explicitly user-defined... // Steve Strong Note: The original Java does not do this decrement; it increments i for // every parameter type. However, within the Loader.GetParameterTypes() method, this introduces // nulls into the paramTypeList array, which in turn causes Loader.ConvertITypesToSqlTypes() to crash // with a null dereference. An alternative fix is to change the Loader to handle the null. I'm // not sure which fix is the most appropriate. // Legacy.FumTest.CompositeIDQuery() shows the bug if you remove the decrement below... i--; } i++; } _ordinalParameters = ordinalParameterList.ToArray(); _namedParameters = new Dictionary <string, ParameterInfo>(); foreach (NamedParamTempHolder holder in namedParameterMap.Values) { _namedParameters.Add(holder.name, new ParameterInfo(ArrayHelper.ToIntArray(holder.positions), holder.type)); } }
public ParameterTranslationsImpl(IEnumerable<IParameterSpecification> parameterSpecifications) { List<ParameterInfo> ordinalParameterList = new List<ParameterInfo>(); NullableDictionary<string, NamedParamTempHolder> namedParameterMap = new NullableDictionary<string, NamedParamTempHolder>(); int i = 0; foreach (IParameterSpecification spec in parameterSpecifications) { if ( spec is PositionalParameterSpecification) { PositionalParameterSpecification ordinalSpec = ( PositionalParameterSpecification ) spec; ordinalParameterList.Add( new ParameterInfo( i, ordinalSpec.ExpectedType) ); } else if ( spec is NamedParameterSpecification ) { NamedParameterSpecification namedSpec = ( NamedParameterSpecification ) spec; NamedParamTempHolder paramHolder = namedParameterMap[namedSpec.Name]; if ( paramHolder == null ) { paramHolder = new NamedParamTempHolder(); paramHolder.name = namedSpec.Name; paramHolder.type = namedSpec.ExpectedType; namedParameterMap.Add( namedSpec.Name, paramHolder ); } paramHolder.positions.Add( i ); } else { // don't care about other param types here, just those explicitly user-defined... // Steve Strong Note: The original Java does not do this decrement; it increments i for // every parameter type. However, within the Loader.GetParameterTypes() method, this introduces // nulls into the paramTypeList array, which in turn causes Loader.ConvertITypesToSqlTypes() to crash // with a null dereference. An alternative fix is to change the Loader to handle the null. I'm // not sure which fix is the most appropriate. // Legacy.FumTest.CompositeIDQuery() shows the bug if you remove the decrement below... i--; } i++; } _ordinalParameters = ordinalParameterList.ToArray(); _namedParameters = new Dictionary<string, ParameterInfo>(); foreach (NamedParamTempHolder holder in namedParameterMap.Values) { _namedParameters.Add(holder.name, new ParameterInfo( ArrayHelper.ToIntArray( holder.positions ), holder.type )); } }
// This method collects rows into groups by the group-defining column. It is shared by // both GroupBy overloads. private NullableDictionary <object, List <int> > FindGroups(NamedList groupByColumn) { NullableDictionary <object, List <int> > groups = new NullableDictionary <object, List <int> >(); for (int r = 0; r < this.map.Count; r++) { int index = this.map[r]; object value = groupByColumn.GetItem(index); List <int> members; if (!groups.TryGetValue(value, out members)) { members = new List <int>(); groups.Add(value, members); } members.Add(index); } return(groups); }
/// <summary> /// Locate the collection persister by the collection role, requiring that /// such a persister exist. /// </summary> /// <param name="role">The collection role name.</param> /// <returns>The defined CollectionPersister for this collection role.</returns> public IQueryableCollection RequireQueryableCollection(string role) { try { IQueryableCollection queryableCollection = (IQueryableCollection)_sfi.GetCollectionPersister(role); if (queryableCollection != null) { _collectionPropertyMappingByRole.Add(role, new CollectionPropertyMapping(queryableCollection)); } return(queryableCollection); } catch (InvalidCastException cce) { throw new QueryException("collection role is not queryable: " + role, cce); } catch (Exception e) { throw new QueryException("collection role not found: " + role, e); } }
private void TrackNamedParameterPositions(string name) { int loc = _parameterCount++; object o = _namedParameters[name]; if (o == null) { _namedParameters.Add(name, loc); } else if (o is int) { List <int> list = new List <int>(4) { (int)o, loc }; _namedParameters[name] = list; } else { ((List <int>)o).Add(loc); } }
private void Initialize(SelectClause selectClause) { IList <FromElement> fromElementList = selectClause.FromElementsForLoad; _hasScalars = selectClause.IsScalarSelect; _scalarColumnNames = selectClause.ColumnNames; //sqlResultTypes = selectClause.getSqlResultTypes(); _queryReturnTypes = selectClause.QueryReturnTypes; _selectNewTransformer = HolderInstantiator.CreateSelectNewTransformer(selectClause.Constructor, selectClause.IsMap, selectClause.IsList); _queryReturnAliases = selectClause.QueryReturnAliases; IList <FromElement> collectionFromElements = selectClause.CollectionFromElements; if (collectionFromElements != null && collectionFromElements.Count != 0) { int length = collectionFromElements.Count; _collectionPersisters = new IQueryableCollection[length]; _collectionOwners = new int[length]; _collectionSuffixes = new string[length]; for (int i = 0; i < length; i++) { FromElement collectionFromElement = collectionFromElements[i]; _collectionPersisters[i] = collectionFromElement.QueryableCollection; _collectionOwners[i] = fromElementList.IndexOf(collectionFromElement.Origin); // collectionSuffixes[i] = collectionFromElement.getColumnAliasSuffix(); // collectionSuffixes[i] = Integer.toString( i ) + "_"; _collectionSuffixes[i] = collectionFromElement.CollectionSuffix; } } int size = fromElementList.Count; _entityPersisters = new IQueryable[size]; _entityEagerPropertyFetches = new bool[size]; _entityAliases = new String[size]; _sqlAliases = new String[size]; _sqlAliasSuffixes = new String[size]; _includeInSelect = new bool[size]; _owners = new int[size]; _ownerAssociationTypes = new EntityType[size]; for (int i = 0; i < size; i++) { FromElement element = fromElementList[i]; _entityPersisters[i] = (IQueryable)element.EntityPersister; if (_entityPersisters[i] == null) { throw new InvalidOperationException("No entity persister for " + element); } _entityEagerPropertyFetches[i] = element.IsAllPropertyFetch; _sqlAliases[i] = element.TableAlias; _entityAliases[i] = element.ClassAlias; _sqlAliasByEntityAlias.Add(_entityAliases[i], _sqlAliases[i]); // TODO should we just collect these like with the collections above? _sqlAliasSuffixes[i] = (size == 1) ? "" : i + "_"; // sqlAliasSuffixes[i] = element.getColumnAliasSuffix(); _includeInSelect[i] = !element.IsFetch; if (_includeInSelect[i]) { _selectLength++; } _owners[i] = -1; //by default if (element.IsFetch) { if (element.IsCollectionJoin || element.QueryableCollection != null) { // This is now handled earlier in this method. } else if (element.DataType.IsEntityType) { var entityType = (EntityType)element.DataType; if (entityType.IsOneToOne) { _owners[i] = fromElementList.IndexOf(element.Origin); } _ownerAssociationTypes[i] = entityType; } } } //NONE, because its the requested lock mode, not the actual! _defaultLockModes = ArrayHelper.Fill(LockMode.None, size); }
private void Initialize(SelectClause selectClause) { IList <FromElement> fromElementList = selectClause.FromElementsForLoad; _hasScalars = selectClause.IsScalarSelect; _scalarColumnNames = selectClause.ColumnNames; //sqlResultTypes = selectClause.getSqlResultTypes(); ResultTypes = selectClause.QueryReturnTypes; _selectNewTransformer = GetSelectNewTransformer(selectClause); _queryReturnAliases = selectClause.QueryReturnAliases; IList <FromElement> collectionFromElements = selectClause.CollectionFromElements; if (collectionFromElements != null && collectionFromElements.Count != 0) { int length = collectionFromElements.Count; _collectionPersisters = new IQueryableCollection[length]; _collectionOwners = new int[length]; _collectionSuffixes = new string[length]; CollectionFetches = new bool[length]; if (collectionFromElements.Any(qc => qc.QueryableCollection.IsManyToMany)) { _collectionUserProvidedAliases = new Dictionary <string, string[]> [length]; } for (int i = 0; i < length; i++) { FromElement collectionFromElement = collectionFromElements[i]; _collectionPersisters[i] = collectionFromElement.QueryableCollection; _collectionOwners[i] = fromElementList.IndexOf(collectionFromElement.Origin); // collectionSuffixes[i] = collectionFromElement.getColumnAliasSuffix(); // collectionSuffixes[i] = Integer.toString( i ) + "_"; _collectionSuffixes[i] = collectionFromElement.CollectionSuffix; CollectionFetches[i] = collectionFromElement.IsFetch; } } int size = fromElementList.Count; _entityPersisters = new IQueryable[size]; _entityEagerPropertyFetches = new bool[size]; _entityFetchLazyProperties = new HashSet <string> [size]; _entityAliases = new String[size]; _sqlAliases = new String[size]; _sqlAliasSuffixes = new String[size]; _includeInSelect = new bool[size]; _owners = new int[size]; _ownerAssociationTypes = new EntityType[size]; EntityFetches = new bool[size]; var cacheTypes = new List <IType>(ResultTypes); for (int i = 0; i < size; i++) { FromElement element = fromElementList[i]; _entityPersisters[i] = (IQueryable)element.EntityPersister; if (_entityPersisters[i] == null) { throw new InvalidOperationException("No entity persister for " + element); } _entityEagerPropertyFetches[i] = element.IsAllPropertyFetch; _entityFetchLazyProperties[i] = element.FetchLazyProperties != null ? new HashSet <string>(element.FetchLazyProperties) : null; _sqlAliases[i] = element.TableAlias; _entityAliases[i] = element.ClassAlias; _sqlAliasByEntityAlias.Add(_entityAliases[i], _sqlAliases[i]); // TODO should we just collect these like with the collections above? _sqlAliasSuffixes[i] = (size == 1) ? "" : i + "_"; // sqlAliasSuffixes[i] = element.getColumnAliasSuffix(); _includeInSelect[i] = !element.IsFetch; EntityFetches[i] = element.IsFetch; if (element.IsFetch) { cacheTypes.Add(_entityPersisters[i].Type); } if (_includeInSelect[i]) { _selectLength++; } if (collectionFromElements != null && element.IsFetch && element.QueryableCollection?.IsManyToMany == true && element.QueryableCollection.IsManyToManyFiltered(_queryTranslator.EnabledFilters)) { var collectionIndex = collectionFromElements.IndexOf(element); if (collectionIndex >= 0) { // When many-to-many is filtered we need to populate collection from element persister and not from bridge table. // As bridge table will contain not-null values for filtered elements // So do alias substitution for collection persister with element persister // See test TestFilteredLinqQuery for details _collectionUserProvidedAliases[collectionIndex] = new Dictionary <string, string[]> { { CollectionPersister.PropElement, _entityPersisters[i].GetIdentifierAliases(Suffixes[i]) } }; } } _owners[i] = -1; //by default if (element.IsFetch) { if (element.IsCollectionJoin || element.QueryableCollection != null) { // This is now handled earlier in this method. } else if (element.DataType.IsEntityType) { _owners[i] = fromElementList.IndexOf(element.Origin); _ownerAssociationTypes[i] = (EntityType)element.DataType; } } } if (_collectionPersisters != null) { cacheTypes.AddRange(_collectionPersisters.Where((t, i) => CollectionFetches[i]).Select(t => t.CollectionType)); } _cacheTypes = cacheTypes.ToArray(); //NONE, because its the requested lock mode, not the actual! _defaultLockModes = ArrayHelper.Fill(LockMode.None, size); _uncacheableCollectionPersisters = _queryTranslator.UncacheableCollectionPersisters; }