protected override object ProcessCollection(object collection, CollectionType type)
		{
			if (collection != null)
			{
				SessionImpl session = Session;
				IPersistentCollection coll;

				if (type.IsArrayType)
				{
					coll = session.GetArrayHolder(collection);
					// if no array holder we found an unwrappered array (this can't occur,
					// because we now always call wrap() before getting to here)
					// return (ah==null) ? true : searchForDirtyCollections(ah, type);
				}
				else
				{
					// if not wrappered yet, its dirty (this can't occur, because 
					// we now always call wrap() before getting to here) 
					// return ( ! (obj is AbstractPersistentCollection) ) ?
					//	true : SearchForDirtyCollections( (AbstractPersistentCollection) obj, type );
					coll = (IPersistentCollection) collection;
				}

				if (coll.IsDirty)
				{
					_dirty = true;
					return null; // NOTE: early exit
				}
			}
			return null;
		}
Ejemplo n.º 2
0
        /// <summary> 
        /// Initialize the role of the collection. 
        /// </summary>
        /// <param name="collection">The collection to be updated by reachibility. </param>
        /// <param name="type">The type of the collection. </param>
        /// <param name="entity">The owner of the collection. </param>
        /// <param name="session">The session.</param>
        public static void ProcessReachableCollection(IPersistentCollection collection, CollectionType type, object entity, ISessionImplementor session)
        {
            collection.Owner = entity;
            CollectionEntry ce = session.PersistenceContext.GetCollectionEntry(collection);

            if (ce == null)
            {
                // refer to comment in StatefulPersistenceContext.addCollection()
                throw new HibernateException(string.Format("Found two representations of same collection: {0}", type.Role));
            }

            // The CollectionEntry.isReached() stuff is just to detect any silly users
            // who set up circular or shared references between/to collections.
            if (ce.IsReached)
            {
                // We've been here before
                throw new HibernateException(string.Format("Found shared references to a collection: {0}", type.Role));
            }
            ce.IsReached = true;

            ISessionFactoryImplementor factory = session.Factory;
            ICollectionPersister persister = factory.GetCollectionPersister(type.Role);
            ce.CurrentPersister = persister;
            ce.CurrentKey = type.GetKeyOfOwner(entity, session); //TODO: better to pass the id in as an argument?

            if (log.IsDebugEnabled)
            {
                log.Debug("Collection found: " +
                    MessageHelper.InfoString(persister, ce.CurrentKey, factory) + ", was: " +
                    MessageHelper.InfoString(ce.LoadedPersister, ce.LoadedKey, factory) +
                    (collection.WasInitialized ? " (initialized)" : " (uninitialized)"));
            }

            PrepareCollectionForUpdate(collection, ce);
        }
		internal override object ProcessCollection(object collection, CollectionType type)
		{

			if (collection != null)
			{
				ISessionImplementor session = Session;
				IPersistentCollection persistentCollection;

				if (type.IsArrayType)
				{
					persistentCollection = session.PersistenceContext.GetCollectionHolder(collection);
					// if no array holder we found an unwrappered array (this can't occur,
					// because we now always call wrap() before getting to here)
					// return (ah==null) ? true : searchForDirtyCollections(ah, type);
				}
				else
				{
					// if not wrappered yet, its dirty (this can't occur, because
					// we now always call wrap() before getting to here)
					// return ( ! (obj instanceof PersistentCollection) ) ?
					//true : searchForDirtyCollections( (PersistentCollection) obj, type );
					persistentCollection = (IPersistentCollection)collection;
				}

				if (persistentCollection.IsDirty)
				{
					//we need to check even if it was not initialized, because of delayed adds!
					dirty = true;
					return null; //NOTE: EARLY EXIT!
				}
			}
			return null;
		}
Ejemplo n.º 4
0
		private object ProcessArrayOrNewCollection(object collection, CollectionType collectionType)
		{
			if (collection == null)
			{
				return null;
			}

			ICollectionPersister persister = Session.GetCollectionPersister(collectionType.Role);

			if (collectionType.IsArrayType)
			{
				PersistentArrayHolder ah = Session.GetArrayHolder(collection);
				if (ah == null)
				{
					ah = new PersistentArrayHolder(Session, collection);
					Session.AddNewCollection(ah, persister);
					Session.AddArrayHolder(ah);
				}
				return null;
			}
			else
			{
				IPersistentCollection persistentCollection = collectionType.Wrap(Session, collection);
				Session.AddNewCollection(persistentCollection, persister);

				if (log.IsDebugEnabled)
				{
					log.Debug("Wrapped collection in role: " + collectionType.Role);
				}

				return persistentCollection; //Force a substitution!
			}
		}
		protected override object ProcessCollection(object collection, CollectionType type)
		{
			SessionImpl session = Session;
			object key = Key;
			ICollectionPersister persister = session.GetCollectionPersister(type.Role);

			session.RemoveCollection(persister, key);

			if (collection != null && (collection is IPersistentCollection))
			{
				IPersistentCollection wrapper = collection as IPersistentCollection;
				wrapper.SetCurrentSession(session);
				if (wrapper.WasInitialized)
				{
					session.AddNewCollection(wrapper, persister);
				}
				else
				{
					session.ReattachCollection(wrapper, wrapper.CollectionSnapshot);
				}
			}
			else
			{
				// otherwise a null or brand new collection 
				// this will also (inefficiently) handle arrays, which 
				// have no snapshot, so we can't do any better
				//processArrayOrNewCollection(collection, type);
			}

			return null;
		}
Ejemplo n.º 6
0
		internal override object ProcessCollection(object collection, CollectionType type)
		{

			if (collection != null)
				EvictCollection(collection, type);

			return null;
		}
Ejemplo n.º 7
0
		protected override object ProcessCollection(object collection, CollectionType type)
		{
			if (collection != null)
			{
				Session.EvictCollection(collection, type);
			}

			return null;
		}
Ejemplo n.º 8
0
        internal override object ProcessCollection(object collection, CollectionType type)
        {
            ISessionImplementor session = Session;
            ICollectionPersister persister = session.Factory.GetCollectionPersister(type.Role);

            if (collection == null)
            {
                //do nothing
            }
            else
            {
                IPersistentCollection persistentCollection = collection as IPersistentCollection;
                if (persistentCollection != null)
                {
                    if (persistentCollection.SetCurrentSession(session))
                    {
                        ICollectionSnapshot snapshot = persistentCollection.CollectionSnapshot;
                        if (IsOwnerUnchanged(snapshot, persister, ExtractCollectionKeyFromOwner(persister)))
                        {
                            // a "detached" collection that originally belonged to the same entity
                            if (persistentCollection.IsDirty)
                            {
                                throw new HibernateException("reassociated object has dirty collection");
                            }
                            ReattachCollection(persistentCollection, snapshot);
                        }
                        else
                        {
                            // a "detached" collection that belonged to a different entity
                            throw new HibernateException("reassociated object has dirty collection reference");
                        }
                    }
                    else
                    {
                        // a collection loaded in the current session
                        // can not possibly be the collection belonging
                        // to the entity passed to update()
                        throw new HibernateException("reassociated object has dirty collection reference");
                    }
                }
                else
                {
                    // brand new collection
                    //TODO: or an array!! we can't lock objects with arrays now??
                    throw new HibernateException("reassociated object has dirty collection reference (or an array)");
                }
            }
            return null;
        }
Ejemplo n.º 9
0
		protected override object ProcessCollection(object collection, CollectionType collectionType)
		{
			if (collection != null && (collection is IPersistentCollection))
			{
				IPersistentCollection coll = collection as IPersistentCollection;
				if (coll.SetCurrentSession(Session))
				{
					Session.ReattachCollection(coll, coll.CollectionSnapshot);
				}
				return null;
			}
			else
			{
				return ProcessArrayOrNewCollection(collection, collectionType);
			}
		}
Ejemplo n.º 10
0
		protected override object ProcessCollection(object collection, CollectionType type)
		{
			ICollectionPersister persister = Session.GetCollectionPersister(type.Role);

			if (collection == null)
			{
				// Do nothing
			}
			else if (collection is IPersistentCollection)
			{
				IPersistentCollection coll = (IPersistentCollection) collection;

				if (coll.SetCurrentSession(Session))
				{
					ICollectionSnapshot snapshot = coll.CollectionSnapshot;
					if (SessionImpl.IsOwnerUnchanged(snapshot, persister, this.Key))
					{
						// a "detached" collection that originally belonged to the same entity
						if (coll.IsDirty)
						{
							throw new HibernateException("reassociated object has dirty collection");
						}
						Session.ReattachCollection(coll, snapshot);
					}
					else
					{
						// a "detached" collection that belonged to a different entity
						throw new HibernateException("reassociated object has dirty collection reference");
					}
				}
				else
				{
					// a collection loaded in the current session
					// can not possibly be the collection belonging
					// to the entity passed to update()
					throw new HibernateException("reassociated object has dirty collection reference");
				}
			}
			else
			{
				// brand new collection
				//TODO: or an array!! we can't lock objects with arrays now??
				throw new HibernateException("reassociated object has dirty collection reference");
			}

			return null;
		}
Ejemplo n.º 11
0
		internal override object ProcessCollection(object collection, CollectionType collectionType)
		{
			IPersistentCollection coll = collection as IPersistentCollection;
			if (coll != null)
			{
				ISessionImplementor session = Session;
				if (coll.SetCurrentSession(session))
				{
					ReattachCollection(coll, collectionType);
				}
				return null;
			}
			else
			{
				return ProcessArrayOrNewCollection(collection, collectionType);
			}
		}
Ejemplo n.º 12
0
		/// <summary> 
		/// Reattach a detached (disassociated) initialized or uninitialized
		/// collection wrapper, using a snapshot carried with the collection wrapper
		/// </summary>
		protected internal void ReattachCollection(IPersistentCollection collection, CollectionType type)
		{
			if (collection.WasInitialized)
			{
				ICollectionPersister collectionPersister = Session.Factory.GetCollectionPersister(type.Role);
				Session.PersistenceContext.AddInitializedDetachedCollection(collectionPersister, collection);
			}
			else
			{
				if (!IsCollectionSnapshotValid(collection))
				{
					throw new HibernateException("could not reassociate uninitialized transient collection");
				}
				ICollectionPersister collectionPersister = Session.Factory.GetCollectionPersister(collection.Role);
				Session.PersistenceContext.AddUninitializedDetachedCollection(collectionPersister, collection);
			}
		}
Ejemplo n.º 13
0
        internal override object ProcessCollection(object collection, CollectionType type)
        {
            if (collection == CollectionType.UnfetchedCollection)
            {
                return null;
            }

            IEventSource session = Session;
            ICollectionPersister persister = session.Factory.GetCollectionPersister(type.Role);

            object collectionKey = ExtractCollectionKeyFromOwner(persister);
            IPersistentCollection wrapper = collection as IPersistentCollection;
            if (wrapper != null)
            {
                if (wrapper.SetCurrentSession(session))
                {
                    //a "detached" collection!
                    ICollectionSnapshot snapshot = wrapper.CollectionSnapshot;
                    if (!IsOwnerUnchanged(snapshot, persister, collectionKey))
                    {
                        // if the collection belonged to a different entity,
                        // clean up the existing state of the collection
                        RemoveCollection(persister, collectionKey, session);
                    }
                    ReattachCollection(wrapper, snapshot);
                }
                else
                {
                    // a collection loaded in the current session
                    // can not possibly be the collection belonging
                    // to the entity passed to update()
                    RemoveCollection(persister, collectionKey, session);
                }
            }
            else
            {
                // null or brand new collection
                // this will also (inefficiently) handle arrays, which have
                // no snapshot, so we can't do any better
                RemoveCollection(persister, collectionKey, session);
            }

            return null;
        }
Ejemplo n.º 14
0
		public virtual void EvictCollection(object value, CollectionType type)
		{
			IPersistentCollection pc;
			if (type.IsArrayType)
			{
				pc = Session.PersistenceContext.RemoveCollectionHolder(value);
			}
			else if (value is IPersistentCollection)
			{
				pc = (IPersistentCollection)value;
			}
			else
			{
				return; //EARLY EXIT!
			}

			IPersistentCollection collection = pc;
			if (collection.UnsetSession(Session))
				EvictCollection(collection);
		}
		protected override object ProcessCollection(object collection, CollectionType type)
		{
			ICollectionPersister persister = Session.GetCollectionPersister(type.Role);

			if (collection is IPersistentCollection)
			{
				IPersistentCollection wrapper = (IPersistentCollection) collection;

				if (wrapper.SetCurrentSession(Session))
				{
					//a "detached" collection!
					ICollectionSnapshot snapshot = wrapper.CollectionSnapshot;

					if (!SessionImpl.IsOwnerUnchanged(snapshot, persister, Key))
					{
						// if the collection belonged to a different entity,
						// clean up the existing state of the collection
						Session.RemoveCollection(persister, Key);
					}

					Session.ReattachCollection(wrapper, snapshot);
				}
				else
				{
					// a collection loaded in the current session
					// can not possibly be the collection belonging
					// to the entity passed to update()
					Session.RemoveCollection(persister, Key);
				}
			}
			else
			{
				// null or brand new collection
				// this will also (inefficiently) handle arrays, which have
				// no snapshot, so we can't do any better
				Session.RemoveCollection(persister, Key);
				//processArrayOrNewCollection(collection, type);
			}

			return null;
		}
Ejemplo n.º 16
0
		private object ProcessArrayOrNewCollection(object collection, CollectionType collectionType)
		{
			if (collection == null)
			{
				//do nothing
				return null;
			}

			ISessionImplementor session = Session;

			ICollectionPersister persister = session.Factory.GetCollectionPersister(collectionType.Role);
			
			IPersistenceContext persistenceContext = session.PersistenceContext;
			//TODO: move into collection type, so we can use polymorphism!

			if (collectionType.IsArrayType)
			{
				//if (collection == CollectionType.UNFETCHED_COLLECTION)
				//  return null;

				PersistentArrayHolder ah = persistenceContext.GetCollectionHolder(collection) as PersistentArrayHolder;
				if (ah == null)
				{
					//ah = collectionType.Wrap(session, collection);
					ah = new PersistentArrayHolder(session, collection);
					persistenceContext.AddNewCollection(persister, ah);
					persistenceContext.AddCollectionHolder(ah);
				}
				return null;
			}
			else
			{
				IPersistentCollection persistentCollection = collectionType.Wrap(session, collection);
				persistenceContext.AddNewCollection(persister, persistentCollection);

				if (log.IsDebugEnabled)
					log.Debug("Wrapped collection in role: " + collectionType.Role);

				return persistentCollection; //Force a substitution!
			}
		}
Ejemplo n.º 17
0
		protected override object ProcessCollection(object collection, CollectionType type)
		{
			if (log.IsDebugEnabled)
			{
				log.Debug(string.Format("Processing collection for role {0}", type.Role));
			}

			if (collection != null)
			{
				IPersistentCollection coll;
				if (type.IsArrayType)
				{
					coll = Session.GetArrayHolder(collection);
				}
				else
				{
					coll = (IPersistentCollection) collection;
				}
				Session.UpdateReachableCollection(coll, type, _owner);
			}
			return null;
		}
Ejemplo n.º 18
0
		internal override object ProcessCollection(object collection, CollectionType type)
		{
			if (collection == CollectionType.UnfetchedCollection)
			{
				return null;
			}

			if (collection != null)
			{
				IPersistentCollection coll;
				if (type.IsArrayType)
				{
					coll = Session.PersistenceContext.GetCollectionHolder(collection);
				}
				else
				{
					coll = (IPersistentCollection)collection;
				}

				Collections.ProcessReachableCollection(coll, type, owner, Session);
			}
			return null;
		}
Ejemplo n.º 19
0
        internal override object ProcessCollection(object collection, CollectionType type)
        {
            if (collection == CollectionType.UnfetchedCollection)
            {
                return null;
            }

            IEventSource session = Session;
            ICollectionPersister persister = session.Factory.GetCollectionPersister(type.Role);

            if (isUpdate)
            {
                RemoveCollection(persister, ExtractCollectionKeyFromOwner(persister), session);
            }
            IPersistentCollection wrapper = collection as IPersistentCollection;
            if (wrapper != null)
            {
                wrapper.SetCurrentSession(session);
                if (wrapper.WasInitialized)
                {
                    session.PersistenceContext.AddNewCollection(persister, wrapper);
                }
                else
                {
                    ReattachCollection(wrapper, wrapper.CollectionSnapshot);
                }
            }
            else
            {
                // otherwise a null or brand new collection
                // this will also (inefficiently) handle arrays, which
                // have no snapshot, so we can't do any better
                //processArrayOrNewCollection(collection, type);
            }

            return null;
        }
 public override IEnumerable GetCascadableChildrenIterator(IEventSource session, CollectionType collectionType, object collection)
 {
     return GetLoadedElementsIterator(session, collectionType, collection);
 }
Ejemplo n.º 21
0
		/// <summary> 
		/// Iterate just the elements of the collection that are already there. Don't load
		/// any new elements from the database.
		/// </summary>
		public static IEnumerable GetLoadedElementsIterator(ISessionImplementor session, CollectionType collectionType, object collection)
		{
			if (CollectionIsInitialized(collection))
			{
				// handles arrays and newly instantiated collections
				return collectionType.GetElementsIterator(collection, session);
			}
			else
			{
				// does not handle arrays (that's ok, cos they can't be lazy)
				// or newly instantiated collections, so we can do the cast
				return ((IPersistentCollection)collection).QueuedAdditionIterator;
			}
		}
Ejemplo n.º 22
0
		/// <summary> 
		/// Given a collection, get an iterator of all its children, loading them
		/// from the database if necessary. 
		/// </summary>
		/// <param name="session">The session within which the cascade is occurring. </param>
		/// <param name="collectionType">The mapping type of the collection. </param>
		/// <param name="collection">The collection instance. </param>
		/// <returns> The children iterator. </returns>
		private static IEnumerable GetAllElementsIterator(IEventSource session, CollectionType collectionType, object collection)
		{
			return collectionType.GetElementsIterator(collection, session);
		}
Ejemplo n.º 23
0
			public override IEnumerable GetCascadableChildrenIterator(IEventSource session, CollectionType collectionType, object collection)
			{
				// replicate does cascade to uninitialized collections
				return GetLoadedElementsIterator(session, collectionType, collection);
			}
Ejemplo n.º 24
0
		/// <summary> 
		/// Given a collection, get an iterator of the children upon which the
		/// current cascading action should be visited. 
		/// </summary>
		/// <param name="session">The session within which the cascade is occurring. </param>
		/// <param name="collectionType">The mapping type of the collection. </param>
		/// <param name="collection">The collection instance. </param>
		/// <returns> The children iterator. </returns>
		public abstract IEnumerable GetCascadableChildrenIterator(IEventSource session, CollectionType collectionType, object collection);
Ejemplo n.º 25
0
			public override IEnumerable GetCascadableChildrenIterator(IEventSource session, CollectionType collectionType, object collection)
			{
				// persists don't cascade to uninitialized collections
				return GetAllElementsIterator(session, collectionType, collection);
			}
Ejemplo n.º 26
0
			public override IEnumerable GetCascadableChildrenIterator(IEventSource session, CollectionType collectionType, object collection)
			{
				// merges don't cascade to uninitialized collections
				//TODO: perhaps this does need to cascade after all....
				return GetLoadedElementsIterator(session, collectionType, collection);
			}
		public AbstractCollectionPersister(Mapping.Collection collection, ICacheConcurrencyStrategy cache, Configuration cfg,
		                                   ISessionFactoryImplementor factory)
		{
			this.factory = factory;
			this.cache = cache;
			if (factory.Settings.IsStructuredCacheEntriesEnabled)
			{
				cacheEntryStructure = collection.IsMap
				                      	? (ICacheEntryStructure) new StructuredMapCacheEntry()
				                      	: (ICacheEntryStructure) new StructuredCollectionCacheEntry();
			}
			else
			{
				cacheEntryStructure = new UnstructuredCacheEntry();
			}

			dialect = factory.Dialect;
			sqlExceptionConverter = factory.SQLExceptionConverter;
			collectionType = collection.CollectionType;
			role = collection.Role;
			entityName = collection.OwnerEntityName;
			ownerPersister = factory.GetEntityPersister(entityName);
			queryLoaderName = collection.LoaderName;
			nodeName = collection.NodeName;
			isMutable = collection.IsMutable;

			Table table = collection.CollectionTable;
			fetchMode = collection.Element.FetchMode;
			elementType = collection.Element.Type;
			isPrimitiveArray = collection.IsPrimitiveArray;
			isArray = collection.IsArray;
			subselectLoadable = collection.IsSubselectLoadable;
			qualifiedTableName = table.GetQualifiedName(dialect, factory.Settings.DefaultCatalogName, factory.Settings.DefaultSchemaName);

			int spacesSize = 1 + collection.SynchronizedTables.Count;
			spaces = new string[spacesSize];
			int ispa = 0;
			spaces[ispa++] = qualifiedTableName;
			foreach (string s in collection.SynchronizedTables)
			{
				spaces[ispa++] = s;
			}

			sqlOrderByString = collection.OrderBy;
			hasOrder = sqlOrderByString != null;
			sqlOrderByStringTemplate = hasOrder
			                           	? Template.RenderOrderByStringTemplate(sqlOrderByString, dialect,
			                           	                                       factory.SQLFunctionRegistry)
			                           	: null;
			sqlWhereString = !string.IsNullOrEmpty(collection.Where) ? '(' + collection.Where + ')' : null;
			hasWhere = sqlWhereString != null;
			sqlWhereStringTemplate = hasWhere
			                         	? Template.RenderWhereStringTemplate(sqlWhereString, dialect, factory.SQLFunctionRegistry)
			                         	: null;
			hasOrphanDelete = collection.HasOrphanDelete;
			int batch = collection.BatchSize;
			if (batch == -1)
			{
				batch = factory.Settings.DefaultBatchFetchSize;
			}
			batchSize = batch;

			isVersioned = collection.IsOptimisticLocked;

			keyType = collection.Key.Type;
			int keySpan = collection.Key.ColumnSpan;
			keyColumnNames = new string[keySpan];
			keyColumnAliases = new string[keySpan];
			int k = 0;
			foreach (Column col in collection.Key.ColumnIterator)
			{
				keyColumnNames[k] = col.GetQuotedName(dialect);
				keyColumnAliases[k] = col.GetAlias(dialect);
				k++;
			}
			ISet distinctColumns = new HashedSet();
			CheckColumnDuplication(distinctColumns, collection.Key.ColumnIterator);

			#region Element

			IValue element = collection.Element;
			if (!collection.IsOneToMany)
			{
				CheckColumnDuplication(distinctColumns, element.ColumnIterator);
			}

			string elemNode = collection.ElementNodeName;
			if (elementType.IsEntityType)
			{
				string _entityName = ((EntityType) elementType).GetAssociatedEntityName();
				elementPersister = factory.GetEntityPersister(_entityName);
				if (elemNode == null)
				{
					elemNode = cfg.GetClassMapping(_entityName).NodeName;
				}
				// NativeSQL: collect element column and auto-aliases
			}
			else
			{
				elementPersister = null;
			}
			elementNodeName = elemNode;

			int elementSpan = element.ColumnSpan;
			elementColumnAliases = new string[elementSpan];
			elementColumnNames = new string[elementSpan];
			elementFormulaTemplates = new string[elementSpan];
			elementFormulas = new string[elementSpan];
			elementColumnIsSettable = new bool[elementSpan];
			elementColumnIsInPrimaryKey = new bool[elementSpan];
			bool isPureFormula = true;
			bool hasNotNullableColumns = false;
			int j = 0;
			foreach (ISelectable selectable in element.ColumnIterator)
			{
				elementColumnAliases[j] = selectable.GetAlias(dialect);
				if (selectable.IsFormula)
				{
					Formula form = (Formula) selectable;
					elementFormulaTemplates[j] = form.GetTemplate(dialect, factory.SQLFunctionRegistry);
					elementFormulas[j] = form.FormulaString;
				}
				else
				{
					Column col = (Column) selectable;
					elementColumnNames[j] = col.GetQuotedName(dialect);
					elementColumnIsSettable[j] = true;
					elementColumnIsInPrimaryKey[j] = !col.IsNullable;
					if (!col.IsNullable)
					{
						hasNotNullableColumns = true;
					}

					isPureFormula = false;
				}
				j++;
			}
			elementIsPureFormula = isPureFormula;

			//workaround, for backward compatibility of sets with no
			//not-null columns, assume all columns are used in the
			//row locator SQL
			if (!hasNotNullableColumns)
			{
				ArrayHelper.Fill(elementColumnIsInPrimaryKey, true);
			}

			#endregion

			#region INDEX AND ROW SELECT

			hasIndex = collection.IsIndexed;
			if (hasIndex)
			{
				// NativeSQL: collect index column and auto-aliases
				IndexedCollection indexedCollection = (IndexedCollection) collection;
				indexType = indexedCollection.Index.Type;
				int indexSpan = indexedCollection.Index.ColumnSpan;
				indexColumnNames = new string[indexSpan];
				indexFormulaTemplates = new string[indexSpan];
				indexFormulas = new string[indexSpan];
				indexColumnIsSettable = new bool[indexSpan];
				indexColumnAliases = new string[indexSpan];
				bool hasFormula = false;
				int i = 0;
				foreach (ISelectable selectable in indexedCollection.Index.ColumnIterator)
				{
					indexColumnAliases[i] = selectable.GetAlias(dialect);
					if (selectable.IsFormula)
					{
						Formula indexForm = (Formula) selectable;
						indexFormulaTemplates[i] = indexForm.GetTemplate(dialect, factory.SQLFunctionRegistry);
						indexFormulas[i] = indexForm.FormulaString;
						hasFormula = true;
					}
					else
					{
						Column indexCol = (Column) selectable;
						indexColumnNames[i] = indexCol.GetQuotedName(dialect);
						indexColumnIsSettable[i] = true;
					}
					i++;
				}
				indexContainsFormula = hasFormula;
				baseIndex = indexedCollection.IsList ? ((List) indexedCollection).BaseIndex : 0;

				indexNodeName = indexedCollection.IndexNodeName;
				CheckColumnDuplication(distinctColumns, indexedCollection.Index.ColumnIterator);
			}
			else
			{
				indexContainsFormula = false;
				indexColumnIsSettable = null;
				indexFormulaTemplates = null;
				indexFormulas = null;
				indexType = null;
				indexColumnNames = null;
				indexColumnAliases = null;
				baseIndex = 0;
				indexNodeName = null;
			}

			hasIdentifier = collection.IsIdentified;
			if (hasIdentifier)
			{
				if (collection.IsOneToMany)
				{
					throw new MappingException("one-to-many collections with identifiers are not supported.");
				}
				IdentifierCollection idColl = (IdentifierCollection) collection;
				identifierType = idColl.Identifier.Type;

				Column col = null;
				foreach (Column column in idColl.Identifier.ColumnIterator)
				{
					col = column;
					break;
				}

				identifierColumnName = col.GetQuotedName(dialect);
				identifierColumnAlias = col.GetAlias(dialect);
				identifierGenerator =
					idColl.Identifier.CreateIdentifierGenerator(factory.Dialect, factory.Settings.DefaultCatalogName,
					                                            factory.Settings.DefaultSchemaName, null);
				// NH see : identityDelegate declaration
				IPostInsertIdentifierGenerator pig = (identifierGenerator as IPostInsertIdentifierGenerator);
				if (pig != null)
				{
					identityDelegate = pig.GetInsertGeneratedIdentifierDelegate(this, Factory, UseGetGeneratedKeys());
				}
				else
				{
					identityDelegate = null;
				}

				CheckColumnDuplication(distinctColumns, idColl.Identifier.ColumnIterator);
			}
			else
			{
				identifierType = null;
				identifierColumnName = null;
				identifierColumnAlias = null;
				identifierGenerator = null;
				identityDelegate = null;
			}

			#endregion

			#region GENERATE THE SQL

			// NH Different behavior : for the Insert SQL we are managing isPostInsertIdentifier (not supported in H3.2.5) 
			if (collection.CustomSQLInsert == null)
			{
				if (!IsIdentifierAssignedByInsert)
				{
					sqlInsertRowString = GenerateInsertRowString();
				}
				else
				{
					sqlInsertRowString = GenerateIdentityInsertRowString();
				}
				insertCallable = false;
				insertCheckStyle = ExecuteUpdateResultCheckStyle.Count;
			}
			else
			{
				SqlType[] parmsTypes = GenerateInsertRowString().ParameterTypes;
				sqlInsertRowString = new SqlCommandInfo(collection.CustomSQLInsert, parmsTypes);
				insertCallable = collection.IsCustomInsertCallable;
				insertCheckStyle = collection.CustomSQLInsertCheckStyle
				                   ?? ExecuteUpdateResultCheckStyle.DetermineDefault(collection.CustomSQLInsert, insertCallable);
			}

			sqlUpdateRowString = GenerateUpdateRowString();
			if (collection.CustomSQLUpdate == null)
			{
				updateCallable = false;
				updateCheckStyle = ExecuteUpdateResultCheckStyle.Count;
			}
			else
			{
				sqlUpdateRowString = new SqlCommandInfo(collection.CustomSQLUpdate, sqlUpdateRowString.ParameterTypes);
				updateCallable = collection.IsCustomUpdateCallable;
				updateCheckStyle = collection.CustomSQLUpdateCheckStyle
				                   ?? ExecuteUpdateResultCheckStyle.DetermineDefault(collection.CustomSQLUpdate, updateCallable);
			}

			sqlDeleteRowString = GenerateDeleteRowString();
			if (collection.CustomSQLDelete == null)
			{
				deleteCallable = false;
				deleteCheckStyle = ExecuteUpdateResultCheckStyle.None;
			}
			else
			{
				sqlDeleteRowString = new SqlCommandInfo(collection.CustomSQLDelete, sqlDeleteRowString.ParameterTypes);
				deleteCallable = collection.IsCustomDeleteCallable;
				deleteCheckStyle = ExecuteUpdateResultCheckStyle.None;
			}

			sqlDeleteString = GenerateDeleteString();
			if (collection.CustomSQLDeleteAll == null)
			{
				deleteAllCallable = false;
				deleteAllCheckStyle = ExecuteUpdateResultCheckStyle.None;
			}
			else
			{
				sqlDeleteString = new SqlCommandInfo(collection.CustomSQLDeleteAll, sqlDeleteString.ParameterTypes);
				deleteAllCallable = collection.IsCustomDeleteAllCallable;
				deleteAllCheckStyle = ExecuteUpdateResultCheckStyle.None;
			}

		    isCollectionIntegerIndex = collection.IsIndexed && !collection.IsMap;
			sqlDetectRowByIndexString = GenerateDetectRowByIndexString();
			sqlDetectRowByElementString = GenerateDetectRowByElementString();
			sqlSelectRowByIndexString = GenerateSelectRowByIndexString();

			LogStaticSQL();

			#endregion

			isLazy = collection.IsLazy;
			isExtraLazy = collection.ExtraLazy;
			isInverse = collection.IsInverse;

			if (collection.IsArray)
			{
				elementClass = ((Array) collection).ElementClass;
			}
			else
			{
				// for non-arrays, we don't need to know the element class
				elementClass = null;
			}

			if (elementType.IsComponentType)
			{
				elementPropertyMapping =
					new CompositeElementPropertyMapping(elementColumnNames, elementFormulaTemplates,
					                                    (IAbstractComponentType) elementType, factory);
			}
			else if (!elementType.IsEntityType)
			{
				elementPropertyMapping = new ElementPropertyMapping(elementColumnNames, elementType);
			}
			else
			{
				elementPropertyMapping = elementPersister as IPropertyMapping;
				if (elementPropertyMapping == null)
				{
					elementPropertyMapping = new ElementPropertyMapping(elementColumnNames, elementType);
				}
			}

			// Handle any filters applied to this collection
			filterHelper = new FilterHelper(collection.FilterMap, dialect, factory.SQLFunctionRegistry);

			// Handle any filters applied to this collection for many-to-many
			manyToManyFilterHelper = new FilterHelper(collection.ManyToManyFilterMap, dialect, factory.SQLFunctionRegistry);
			manyToManyWhereString = !string.IsNullOrEmpty(collection.ManyToManyWhere)
			                        	? "( " + collection.ManyToManyWhere + " )"
			                        	: null;
			manyToManyWhereTemplate = manyToManyWhereString == null
			                          	? null
			                          	: Template.RenderWhereStringTemplate(manyToManyWhereString, factory.Dialect,
			                          	                                     factory.SQLFunctionRegistry);
			manyToManyOrderByString = collection.ManyToManyOrdering;
			manyToManyOrderByTemplate = manyToManyOrderByString == null
			                            	? null
			                            	: Template.RenderOrderByStringTemplate(manyToManyOrderByString, factory.Dialect,
			                            	                                       factory.SQLFunctionRegistry);
			InitCollectionPropertyMap();
		}
Ejemplo n.º 28
0
			/// <summary>
			/// The children to whom we should cascade.
			/// </summary>
			public abstract ICollection CascadableChildrenCollection(CollectionType collectionType, object collection);
Ejemplo n.º 29
0
		/// <summary>
		/// Visit a collection. Default superclass implementation is a no-op.
		/// </summary>
		/// <param name="value"></param>
		/// <param name="collectionType"></param>
		/// <returns></returns>
		internal virtual object ProcessCollection(object value, CollectionType collectionType)
		{
			return null;
		}
Ejemplo n.º 30
0
            public Collection(CollectionType type, ICollectionPersister persister)
            {
                if (type == null) throw new ArgumentNullException("type");
                if (persister == null) throw new ArgumentNullException("persister");

                Type = type;
                Persister = persister;
            }