⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractcollectionpersister.cs

📁 NHibernate NET开发者所需的
💻 CS
📖 第 1 页 / 共 4 页
字号:

		public void InitCollectionPropertyMap()
		{
			InitCollectionPropertyMap("key", keyType, keyColumnAliases, keyColumnNames);
			InitCollectionPropertyMap("element", elementType, elementColumnAliases, elementColumnNames);

			if (hasIndex)
				InitCollectionPropertyMap("index", indexType, indexColumnAliases, indexColumnNames);

			if (hasIdentifier)
			{
				InitCollectionPropertyMap("id", identifierType, new string[] {identifierColumnAlias},
				                          new string[] {identifierColumnName});
			}
		}

		private void InitCollectionPropertyMap(string aliasName, IType type, string[] columnAliases, string[] columnNames)
		{
			collectionPropertyColumnAliases[aliasName] = columnAliases;
			collectionPropertyColumnNames[aliasName] = columnNames;

			if (type.IsComponentType)
			{
				IAbstractComponentType ct = (IAbstractComponentType)type;
				string[] propertyNames = ct.PropertyNames;
				for (int i = 0; i < propertyNames.Length; i++)
				{
					string name = propertyNames[i];
					collectionPropertyColumnAliases[aliasName + "." + name] = columnAliases[i];
					collectionPropertyColumnNames[aliasName + "." + name] = columnNames[i];
				}
			}
		}

		public int GetSize(object key, ISessionImplementor session)
		{
			try
			{
				IDbCommand st = session.Batcher.PrepareCommand(CommandType.Text, sqlSelectSizeString, KeyType.SqlTypes(factory));
				IDataReader rs = null;
				try
				{
					KeyType.NullSafeSet(st, key, 1, session);
					rs = session.Batcher.ExecuteReader(st);
					return rs.Read() ? rs.GetInt32(0) - baseIndex : 0;
				}
				finally
				{
					session.Batcher.CloseCommand(st, rs);
				}
			}
			catch (DbException sqle)
			{
				throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, sqle,
																					"could not retrieve collection size: "
																					+ MessageHelper.InfoString(this, key, Factory), sqlSelectSizeString);
			}
		}

		public bool IndexExists(object key, object index, ISessionImplementor session)
		{
			return Exists(key, IncrementIndexByBase(index), IndexType, sqlDetectRowByIndexString, session);
		}

		public bool ElementExists(object key, object element, ISessionImplementor session)
		{
			return Exists(key, element, ElementType, sqlDetectRowByElementString, session);
		}

		private bool Exists(object key, object indexOrElement, IType indexOrElementType, SqlString sql, ISessionImplementor session)
		{
			try
			{
				List<SqlType> sqlTl = new List<SqlType>(KeyType.SqlTypes(factory));
				sqlTl.AddRange(indexOrElementType.SqlTypes(factory));
				IDbCommand st = session.Batcher.PrepareCommand(CommandType.Text, sql, sqlTl.ToArray());
				IDataReader rs= null;
				try
				{
					KeyType.NullSafeSet(st, key, 1, session);
					indexOrElementType.NullSafeSet(st, indexOrElement, keyColumnNames.Length + 1, session);
					rs = session.Batcher.ExecuteReader(st);
					try
					{
						return rs.Read();
					}
					finally
					{
						rs.Close();
					}
				}
				catch (TransientObjectException)
				{
					return false;
				}
				finally
				{
					session.Batcher.CloseCommand(st, rs);
				}
			}
			catch (DbException sqle)
			{
				throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, sqle, "could not check row existence: " + MessageHelper.InfoString(this, key, Factory), sqlSelectSizeString);
			}
		}

		public virtual object GetElementByIndex(object key, object index, ISessionImplementor session, object owner)
		{
			try
			{
				List<SqlType> sqlTl = new List<SqlType>(KeyType.SqlTypes(factory));
				sqlTl.AddRange(IndexType.SqlTypes(factory));
				IDbCommand st = session.Batcher.PrepareCommand(CommandType.Text, sqlSelectRowByIndexString, sqlTl.ToArray());
				IDataReader rs= null;
				try
				{
					KeyType.NullSafeSet(st, key, 1, session);
					IndexType.NullSafeSet(st, IncrementIndexByBase(index), keyColumnNames.Length + 1, session);
					rs = session.Batcher.ExecuteReader(st);
					try
					{
						if (rs.Read())
							return ElementType.NullSafeGet(rs, elementColumnAliases, session, owner);
						else
							return null;
					}
					finally
					{
						rs.Close();
					}
				}
				finally
				{
					session.Batcher.CloseCommand(st, rs);
				}
			}
			catch (DbException sqle)
			{
				throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, sqle, "could not read row: " + MessageHelper.InfoString(this, key, Factory), sqlSelectSizeString);
			}
		}

		public abstract bool ConsumesEntityAlias();

		public abstract SqlString FromJoinFragment(string alias, bool innerJoin, bool includeSubclasses);

		public abstract SqlString WhereJoinFragment(string alias, bool innerJoin, bool includeSubclasses);

		public abstract string SelectFragment(IJoinable rhs, string rhsAlias, string lhsAlias, string currentEntitySuffix,
																					string currentCollectionSuffix, bool includeCollectionColumns);

		public abstract bool ConsumesCollectionAlias();

		private void CheckColumnDuplication(ISet distinctColumns, IEnumerable<ISelectable> columns)
		{
			foreach (ISelectable sel in columns)
			{
				Column col = sel as Column;
				if (col == null)
				{
					// Ignore formulas
					continue;
				}
				if (distinctColumns.Contains(col.Name))
				{
					throw new MappingException(
						"Repeated column in mapping for collection: " +
						role +
						" column: " +
						col.Name
						);
				}
				else
				{
					distinctColumns.Add(col.Name);
				}
			}
		}

		public ICacheConcurrencyStrategy Cache
		{
			get { return cache; }
		}

		public CollectionType CollectionType
		{
			get { return collectionType; }
		}

		public FetchMode FetchMode
		{
			get { return fetchMode; }
		}

		protected SqlCommandInfo SqlDeleteString
		{
			get { return sqlDeleteString; }
		}

		protected SqlCommandInfo SqlInsertRowString
		{
			get { return sqlInsertRowString; }
		}

		protected SqlCommandInfo SqlUpdateRowString
		{
			get { return sqlUpdateRowString; }
		}

		protected SqlCommandInfo SqlDeleteRowString
		{
			get { return sqlDeleteRowString; }
		}

		public IType KeyType
		{
			get { return keyType; }
		}

		public IType IndexType
		{
			get { return indexType; }
		}

		public IType ElementType
		{
			get { return elementType; }
		}

		/// <summary>
		/// Return the element class of an array, or null otherwise
		/// </summary>
		public System.Type ElementClass
		{
			// needed by arrays
			get { return elementClass; }
		}

		public bool IsPrimitiveArray
		{
			get { return isPrimitiveArray; }
		}

		public bool IsArray
		{
			get { return isArray; }
		}

		public string IdentifierColumnName
		{
			get
			{
				if (hasIdentifier)
					return identifierColumnName;
				else
					return null;
			}
		}

		public string[] IndexFormulas
		{
			get { return indexFormulas; }
		}

		public string[] KeyColumnNames
		{
			get { return keyColumnNames; }
		}

		public bool IsLazy
		{
			get { return isLazy; }
		}

		public bool IsInverse
		{
			get { return isInverse; }
		}
		protected virtual bool RowDeleteEnabled
		{
			get { return true; }
		}

		protected virtual bool RowInsertEnabled
		{
			get { return true; }
		}

		/// <summary>
		/// Get the name of this collection role (the fully qualified class name,
		/// extended by a "property path")
		/// </summary>
		public string Role
		{
			get { return role; }
		}

		public virtual string OwnerEntityName
		{
			get { return entityName; }
		}

		public IEntityPersister OwnerEntityPersister
		{
			get { return ownerPersister; }
		}

		public IIdentifierGenerator IdentifierGenerator
		{
			get { return identifierGenerator; }
		}

		public IType IdentifierType
		{
			get { return identifierType; }
		}

		public abstract bool IsManyToMany { get; }

		public IType Type
		{
			get { return elementPropertyMapping.Type; }
		}

		public string Name
		{
			get { return Role; }
		}

		public IEntityPersister ElementPersister
		{
			get
			{
				if (elementPersister == null)
					throw new AssertionFailure("Not an association");

				return elementPersister;
			}
		}

		public bool IsCollection
		{
			get { return true; }
		}

		public string[] CollectionSpaces
		{
			get { return spaces; }
		}

		public ICollectionMetadata CollectionMetadata
		{
			get { return this; }
		}

		public ISessionFactoryImplementor Factory
		{
			get { return factory; }
		}

		protected virtual bool InsertCallable
		{
			get { return insertCallable; }
		}

		protected ExecuteUpdateResultCheckStyle InsertCheckStyle
		{
			get { return insertCheckStyle; }
		}

		protected virtual bool UpdateCallable
		{
			get { return updateCallable; }
		}

		protected ExecuteUpdateResultCheckStyle UpdateCheckStyle
		{
			get { return updateCheckStyle; }
		}

		protected virtual bool DeleteCallable
		{
			get { return deleteCallable; }
		}

		protected ExecuteUpdateResultCheckStyle DeleteCheckStyle
		{
			get { return deleteCheckStyle; }
		}

		protected virtual bool DeleteAllCallable
		{
			get { return deleteAllCallable; }
		}

		protected ExecuteUpdateResultCheckStyle DeleteAllCheckStyle
		{
			get { return deleteAllCheckStyle; }
		}

		public bool IsVersioned
		{
			get { return isVersioned && OwnerEntityPersister.IsVersioned; }
		}

		public string NodeName
		{
			get { return nodeName; }
		}

		public string ElementNodeName
		{
			get { return elementNodeName; }
		}

		public string IndexNodeName
		{
			get { return indexNodeName; }
		}

		protected virtual ISQLExceptionConverter SQLExceptionConverter
		{
			get { return sqlExceptionConverter; }
		}

		public ICacheEntryStructure CacheEntryStructure
		{
			get { return cacheEntryStructure; }
		}

		public bool IsSubselectLoadable
		{
			get { return subselectLoadable; }
		}

		public bool IsMutable
		{
			get { return isMutable; }
		}

		public bool IsExtraLazy
		{
			get { return isExtraLazy; }
		}

		protected Dialect.Dialect Dialect
		{
			get { return dialect; }
		}

		public abstract bool CascadeDeleteEnabled { get;}
		public abstract bool IsOneToMany { get; }
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -