• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Exceptions.AdoExceptionContextInfo类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中NHibernate.Exceptions.AdoExceptionContextInfo的典型用法代码示例。如果您正苦于以下问题:C# AdoExceptionContextInfo类的具体用法?C# AdoExceptionContextInfo怎么用?C# AdoExceptionContextInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AdoExceptionContextInfo类属于NHibernate.Exceptions命名空间,在下文中一共展示了AdoExceptionContextInfo类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Convert

        public Exception Convert(AdoExceptionContextInfo exInfo)
        {
            var dbException = ADOExceptionHelper.ExtractDbException(exInfo.SqlException);

              var ns = dbException.GetType().Namespace ?? string.Empty;
              if (ns.ToLowerInvariant().StartsWith("system.data.sqlite"))
              {
            // SQLite exception
            switch (dbException.ErrorCode)
            {
              case -2147467259: // Abort due to constraint violation
            throw new ConcurrencyException();
            }
              }

              if (ns.ToLowerInvariant().StartsWith("system.data.sqlclient"))
              {
            // MS SQL Server
            switch (dbException.ErrorCode)
            {
              case -2146232060:
            throw new ConcurrencyException();
            }
              }

              return SQLStateConverter.HandledNonSpecificException(exInfo.SqlException,
              exInfo.Message, exInfo.Sql);
        }
开发者ID:jasondentler,项目名称:gregyoung-simple-cqrs,代码行数:28,代码来源:SqlExceptionConverter.cs


示例2: Convert

        public Exception Convert(AdoExceptionContextInfo adoExceptionContextInfo)
        {
            DbException sqlException = ADOExceptionHelper.ExtractDbException(adoExceptionContextInfo.SqlException);
            string message = adoExceptionContextInfo.Message;
            string sql = adoExceptionContextInfo.Sql;

            int errorCode = (int)sqlException.GetType().GetProperty("NativeError").GetValue(sqlException, null);

            if (errorCode >= 1 && errorCode <= 90)
            {
                return new SQLGrammarException(message, sqlException, sql);
            }

            if (integrityViolationCategories.Contains(errorCode))
            {
                string constraintName = extracter.ExtractConstraintName(sqlException);
                return new ConstraintViolationException(message, sqlException, sql, constraintName);
            }

            if (connectionCategories.Contains(errorCode))
            {
                return new ADOConnectionException(message, sqlException, sql);
            }

            if (dataCategories.Contains(errorCode))
            {
                return new DataException(message, sqlException, sql);
            }

            return HandledNonSpecificException(sqlException, message, sql);
        }
开发者ID:mnjstwins,项目名称:NHibernate.CacheDb,代码行数:31,代码来源:CacheSQLStateConverter.cs


示例3: Convert

            public Exception Convert(AdoExceptionContextInfo contextInfo)
            {
                Exception result = null;
                var sqle = ADOExceptionHelper.ExtractDbException(contextInfo.SqlException) as SqlException;
                if (sqle != null)
                {
                    switch (sqle.Number)
                    {
                        case 547:
                            result = new ConstraintViolationException(
                                sqle.Message,
                                sqle,
                                contextInfo.Sql,
                                null);
                            break;
                        case 208:
                            result = new SQLGrammarException(
                                contextInfo.Message,
                                sqle,
                                contextInfo.Sql);
                            break;
                        case 3960:
                            result = new StaleObjectStateException(
                                contextInfo.EntityName,
                                contextInfo.EntityId);
                            break;
                    }
                }

                return result ?? SQLStateConverter.HandledNonSpecificException(
                    contextInfo.SqlException,
                    contextInfo.Message,
                    contextInfo.Sql);
            }
开发者ID:quadio,项目名称:amss-boilerplate,代码行数:34,代码来源:MsSql2005DatabaseConfigurator.cs


示例4: Convert

        /// <summary>
        ///     Converts the db specific exceptions to something more usable.
        /// </summary>
        /// <param name="exInfo">The exception info.</param>
        /// <returns>Exception thrown</returns>
        public System.Exception Convert(AdoExceptionContextInfo exInfo)
        {
            var sqle = ADOExceptionHelper.ExtractDbException(exInfo.SqlException) as SqlException;
            var finalException = Convert(sqle, exInfo);

            return finalException;
        }
开发者ID:phucls,项目名称:ara,代码行数:12,代码来源:SQLServerExceptionConverter.cs


示例5: Convert

        public Exception Convert(AdoExceptionContextInfo exInfo)
        {
            var sqle = ADOExceptionHelper.ExtractDbException(exInfo.SqlException) as SqlException;
            if (sqle != null)
            {
                switch (sqle.Number)
                {
                case 17:
                    // SQL Server does not exist or access denied.
                case 4060:
                    // Invalid Database
                case 18456:
                    // Login Failed
                    return new DatabaseException(sqle.Message, sqle);
                case 547:
                    // ForeignKey Violation
                    return new ConstraintException(_ParseConstraintName(sqle.Message), sqle);
                case 1205:
                    // DeadLock Victim
                    return new DatabaseException(sqle.Message, sqle);
                case 2627:
                case 2601:
                    // Unique Index/Constriant Violation
                    return new ConstraintException(_ParseConstraintName(sqle.Message), sqle);
                default:
                    // throw a general DAL Exception
                    return new DatabaseException(sqle.Message, sqle);
                }
            }

            return SQLStateConverter.HandledNonSpecificException(
                       exInfo.SqlException,
                       exInfo.Message, exInfo.Sql);
        }
开发者ID:OscarNET,项目名称:Hexa.Core,代码行数:34,代码来源:SqlExceptionHandler.cs


示例6: Convert

        public Exception Convert(AdoExceptionContextInfo exInfo)
        {
            //var dbException = ADOExceptionHelper.ExtractDbException(exInfo.SqlException);
            //var textoResource = String.Empty;


            //// SQLite exception
            //switch (dbException.ErrorCode)
            //{
            //    case 2601://Cannot insert duplicate key row in object '%.*ls' with unique index '%.*ls'. The duplicate key value is %ls.
            //        textoResource = _resource.GetString("DadoDuplicadoNaoPermitido"); //Repetição não permitida para o campo {0}.
            //        //return new BusinessException(campo, erro);//DadoDuplicadoNaoPermitido

            //    case 233:
            //        textoResource = _resource.GetString("ValorNuloNaoPermitido");
            //        //return new BusinessException(campo, erro);//DadoDuplicadoNaoPermitido


            //    default:
            //        throw new InvalidOperationException(String.Format("ExtendedError {0} não mapeado", erro));

            //}

            throw new NotImplementedException();

        }
开发者ID:TicketArchitecture,项目名称:Api-Template,代码行数:26,代码来源:SQLServerSqlExceptionConverter.cs


示例7: Convert

		public Exception Convert(AdoExceptionContextInfo exInfo)
		{
			var sqle = ADOExceptionHelper.ExtractDbException(exInfo.SqlException) as SqlException;
			if ((sqle != null) && (sqle.Number == 3960))
			{
				return new StaleObjectStateException(exInfo.EntityName, exInfo.EntityId);
			}
			return SQLStateConverter.HandledNonSpecificException(exInfo.SqlException, exInfo.Message, exInfo.Sql);
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:9,代码来源:SQLUpdateConflictToStaleStateExceptionConverter.cs


示例8: Convert

		public Exception Convert(AdoExceptionContextInfo exceptionInfo)
		{
			/*
			 * So far I know we don't have something similar to "X/Open-compliant SQLState" in .NET
			 * This mean that each Dialect must have its own ISQLExceptionConverter, overriding BuildSQLExceptionConverter method,
			 * and its own IViolatedConstraintNameExtracter if needed.
			 * The System.Data.Common.DbException, of .NET2.0, don't give us something applicable to all dialects.
			 */
			return HandledNonSpecificException(exceptionInfo.SqlException, exceptionInfo.Message, exceptionInfo.Sql);
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:10,代码来源:SQLStateConverter.cs


示例9: Convert

		public static Exception Convert(ISQLExceptionConverter converter, AdoExceptionContextInfo exceptionContextInfo)
		{
			if(exceptionContextInfo == null)
			{
				throw new AssertionFailure("The argument exceptionContextInfo is null.");
			}
			var sql = TryGetActualSqlQuery(exceptionContextInfo.SqlException, exceptionContextInfo.Sql);
			ADOExceptionReporter.LogExceptions(exceptionContextInfo.SqlException,
			                                   ExtendMessage(exceptionContextInfo.Message, sql, null, null));
			return converter.Convert(exceptionContextInfo);
		}
开发者ID:khaliyo,项目名称:Spring.net-NHibernate.net-Asp.net-MVC-DWZ-,代码行数:11,代码来源:ADOExceptionHelper.cs


示例10: Convert

		public Exception Convert(AdoExceptionContextInfo exInfo)
		{
			SqlException sqle = ADOExceptionHelper.ExtractDbException(exInfo.SqlException) as SqlException;
			if(sqle != null)
			{
				if (sqle.Number == 547)
					return new ConstraintViolationException(exInfo.Message, sqle.InnerException, exInfo.Sql, null);
				if (sqle.Number == 208)
					return new SQLGrammarException(exInfo.Message, sqle.InnerException, exInfo.Sql);
			}
			return SQLStateConverter.HandledNonSpecificException(exInfo.SqlException, exInfo.Message, exInfo.Sql);
		}
开发者ID:hoangduc007,项目名称:nhibernate-core,代码行数:12,代码来源:MSSQLExceptionConverterExample.cs


示例11: Convert

		public Exception Convert(AdoExceptionContextInfo exInfo)
		{
			var sqle = ADOExceptionHelper.ExtractDbException(exInfo.SqlException) as OracleException;
			if (sqle != null)
			{
				if (sqle.Code == 1036)
				{
					return new ConstraintViolationException(exInfo.Message, sqle.InnerException, exInfo.Sql, null);
				}
				if (sqle.Code == 942)
				{
					return new SQLGrammarException(exInfo.Message, sqle.InnerException, exInfo.Sql);
				}
			}
			return SQLStateConverter.HandledNonSpecificException(exInfo.SqlException, exInfo.Message, exInfo.Sql);
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:16,代码来源:OracleClientExceptionConverterExample.cs


示例12: Convert

		public Exception Convert(AdoExceptionContextInfo adoExceptionContextInfo)
		{
			var sqle = ADOExceptionHelper.ExtractDbException(adoExceptionContextInfo.SqlException) as DbException;
			if (sqle != null)
			{
				if (sqle.ErrorCode == 335544466)
				{
					return new ConstraintViolationException(adoExceptionContextInfo.Message, sqle.InnerException, adoExceptionContextInfo.Sql, null);
				}
				if (sqle.ErrorCode == 335544569)
				{
					return new SQLGrammarException(adoExceptionContextInfo.Message, sqle.InnerException, adoExceptionContextInfo.Sql);
				}
			}
			return SQLStateConverter.HandledNonSpecificException(adoExceptionContextInfo.SqlException, adoExceptionContextInfo.Message, adoExceptionContextInfo.Sql);
		}
开发者ID:rosieks,项目名称:nhibernate-core,代码行数:16,代码来源:FbExceptionConverterExample.cs


示例13: Convert

		public Exception Convert(AdoExceptionContextInfo exInfo)
		{
			var sqle = ADOExceptionHelper.ExtractDbException(exInfo.SqlException) as DbException;
			if (sqle != null)
			{
				string code = (string)sqle.GetType().GetProperty("Code").GetValue(sqle, null);

				if (code == "23503")
				{
					return new ConstraintViolationException(exInfo.Message, sqle.InnerException, exInfo.Sql, null);
				}
				if (code == "42P01")
				{
					return new SQLGrammarException(exInfo.Message, sqle.InnerException, exInfo.Sql);
				}
			}
			return SQLStateConverter.HandledNonSpecificException(exInfo.SqlException, exInfo.Message, exInfo.Sql);
		}
开发者ID:hoangduc007,项目名称:nhibernate-core,代码行数:18,代码来源:PostgresExceptionConverterExample.cs


示例14: Convert

 /// <summary>
 /// 转换
 /// </summary>
 /// <param name="adoExceptionContextInfo"></param>
 /// <returns></returns>
 public Exception Convert(AdoExceptionContextInfo adoExceptionContextInfo)
 {
     var sqle = ADOExceptionHelper.ExtractDbException(adoExceptionContextInfo.SqlException) as SqlException;
     if (sqle != null)
     {
         switch (sqle.Number)
         {
             case 547:
             case 2627:
                 return new ConstraintViolationException(adoExceptionContextInfo.SqlException.Message,
                     null, adoExceptionContextInfo.Sql, null);
             case 208:
                 return new SQLGrammarException(adoExceptionContextInfo.SqlException.Message,
                     null, adoExceptionContextInfo.Sql);
             case 3960:
                 return new StaleObjectStateException(adoExceptionContextInfo.EntityName, adoExceptionContextInfo.EntityId);
         }
     }
     return SQLStateConverter.HandledNonSpecificException(adoExceptionContextInfo.SqlException,
         adoExceptionContextInfo.SqlException.Message, adoExceptionContextInfo.Sql);
 }
开发者ID:urmilaNominate,项目名称:mERP-framework,代码行数:26,代码来源:MsSqlExceptionConverter.cs


示例15: Convert

        public Exception Convert(AdoExceptionContextInfo exInfo)
        {
            var dbException = ADOExceptionHelper.ExtractDbException(exInfo.SqlException);


            var erro = ErrorDescription(dbException.Message);
            var campo = SQLiteErrorField(dbException.Message);


            // SQLite exception
            switch (dbException.ErrorCode)
            {
                case 19: // violação de constraint
                    return WorkOnExtendedError(erro, campo);

                default:
                    throw new InvalidOperationException(String.Format("Error code {0} não mapeado", dbException.ErrorCode));
                    //return SQLStateConverter.HandledNonSpecificException(exInfo.SqlException,
                    //exInfo.Message, exInfo.Sql);

            }


        }
开发者ID:TicketArchitecture,项目名称:Api-Template,代码行数:24,代码来源:SQLiteSqlExceptionConverter.cs


示例16: Convert

        public Exception Convert(AdoExceptionContextInfo exInfo)
        {
            var sqle = ADOExceptionHelper.ExtractDbException(exInfo.SqlException) as SqlException;
            if (sqle != null)
            {
                switch (sqle.Number)
                {
                    case -2: // timeout
                    case -2147217871: // timeout
                    case 11: // network error
                    case 1205: // deadlock
                        return new TransientErrorException("Temporary db error occured. Try again later.", sqle);

                    // case 208: // sql grammar
                    // case 547: // constraint violation
                    // case 3960: // stale object state (does not occur with ReadCommitted isolation level). Should trigger reload on client side
                    default:
                        return new ApplicationException("DB error", sqle);

                }
            }
            return SQLStateConverter.HandledNonSpecificException(exInfo.SqlException,
                exInfo.Message, exInfo.Sql);
        }
开发者ID:ristokyburz,项目名称:ServiceArchitecture,代码行数:24,代码来源:MsSqlExceptionConverter.cs


示例17: ProcessGeneratedProperties

		private void ProcessGeneratedProperties(object id, object entity, object[] state,
				ISessionImplementor session, SqlString selectionSQL, ValueInclusion[] includeds)
		{
			session.Batcher.ExecuteBatch(); //force immediate execution of the insert

			using (new SessionIdLoggingContext(session.SessionId)) 
			try
			{
				IDbCommand cmd =
					session.Batcher.PrepareQueryCommand(CommandType.Text, selectionSQL, IdentifierType.SqlTypes(Factory));
				IDataReader rs = null;
				try
				{
					IdentifierType.NullSafeSet(cmd, id, 0, session);
					rs = session.Batcher.ExecuteReader(cmd);
					if (!rs.Read())
					{
						throw new HibernateException("Unable to locate row for retrieval of generated properties: "
																				 + MessageHelper.InfoString(this, id, Factory));
					}
					for (int i = 0; i < PropertySpan; i++)
					{
						if (includeds[i] != ValueInclusion.None)
						{
							object hydratedState = PropertyTypes[i].Hydrate(rs, GetPropertyAliases(string.Empty, i), session, entity);
							state[i] = PropertyTypes[i].ResolveIdentifier(hydratedState, session, entity);
							SetPropertyValue(entity, i, state[i], session.EntityMode);
						}
					}
				}
				finally
				{
					session.Batcher.CloseCommand(cmd, rs);
				}
			}
			catch (DbException sqle)
			{
				var exceptionContext = new AdoExceptionContextInfo
				                       	{
				                       		SqlException = sqle,
				                       		Message = "unable to select generated column values",
				                       		Sql = selectionSQL.ToString(),
				                       		EntityName = EntityName,
				                       		EntityId = id
				                       	};
				throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, exceptionContext);
			}
		}
开发者ID:rbirkby,项目名称:nhibernate-core,代码行数:48,代码来源:AbstractEntityPersister.cs


示例18: GetNaturalIdentifierSnapshot

		public virtual object[] GetNaturalIdentifierSnapshot(object id, ISessionImplementor session)
		{
			if (!HasNaturalIdentifier)
			{
				throw new MappingException("persistent class did not define a natural-id : " + MessageHelper.InfoString(this));
			}
			if (log.IsDebugEnabled)
			{
				log.Debug("Getting current natural-id snapshot state for: " + MessageHelper.InfoString(this, id, Factory));
			}

			int[] naturalIdPropertyIndexes = NaturalIdentifierProperties;
			int naturalIdPropertyCount = naturalIdPropertyIndexes.Length;
			bool[] naturalIdMarkers = new bool[PropertySpan];
			IType[] extractionTypes = new IType[naturalIdPropertyCount];
			for (int i = 0; i < naturalIdPropertyCount; i++)
			{
				extractionTypes[i] = PropertyTypes[naturalIdPropertyIndexes[i]];
				naturalIdMarkers[naturalIdPropertyIndexes[i]] = true;
			}

			///////////////////////////////////////////////////////////////////////
			// TODO : look at perhaps caching this...
			SqlSelectBuilder select = new SqlSelectBuilder(Factory);
			if (Factory.Settings.IsCommentsEnabled)
			{
				select.SetComment("get current natural-id state " + EntityName);
			}
			select.SetSelectClause(ConcretePropertySelectFragmentSansLeadingComma(RootAlias, naturalIdMarkers));
			select.SetFromClause(FromTableFragment(RootAlias) + FromJoinFragment(RootAlias, true, false));

			string[] aliasedIdColumns = StringHelper.Qualify(RootAlias, IdentifierColumnNames);
			SqlString whereClause = new SqlStringBuilder()
				.Add(StringHelper.Join(new SqlString("=", Parameter.Placeholder, " and "), aliasedIdColumns))
				.Add("=").AddParameter()
				.Add(WhereJoinFragment(RootAlias, true, false))
				.ToSqlString();

			SqlString sql = select.SetOuterJoins(SqlString.Empty, SqlString.Empty).SetWhereClause(whereClause).ToStatementString();
			///////////////////////////////////////////////////////////////////////

			object[] snapshot = new object[naturalIdPropertyCount];
			using (new SessionIdLoggingContext(session.SessionId)) 
			try
			{
				IDbCommand ps = session.Batcher.PrepareCommand(CommandType.Text, sql, IdentifierType.SqlTypes(factory));
				IDataReader rs = null;
				try
				{
					IdentifierType.NullSafeSet(ps, id, 0, session);
					rs = session.Batcher.ExecuteReader(ps);
					//if there is no resulting row, return null
					if (!rs.Read())
					{
						return null;
					}

					for (int i = 0; i < naturalIdPropertyCount; i++)
					{
						snapshot[i] =
							extractionTypes[i].Hydrate(rs, GetPropertyAliases(string.Empty, naturalIdPropertyIndexes[i]), session, null);
						if (extractionTypes[i].IsEntityType)
						{
							snapshot[i] = extractionTypes[i].ResolveIdentifier(snapshot[i], session, null);
						}
					}
					return snapshot;
				}
				finally
				{
					session.Batcher.CloseCommand(ps, rs);
				}
			}
			catch (DbException sqle)
			{
				var exceptionContext = new AdoExceptionContextInfo
				                       	{
				                       		SqlException = sqle,
				                       		Message = "could not retrieve snapshot: " + MessageHelper.InfoString(this, id, Factory),
				                       		Sql = sql.ToString(),
				                       		EntityName = EntityName,
				                       		EntityId = id
				                       	};
				throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, exceptionContext);
			}
		}
开发者ID:rbirkby,项目名称:nhibernate-core,代码行数:86,代码来源:AbstractEntityPersister.cs


示例19: Update

		protected bool Update(object id, object[] fields, object[] oldFields, object rowId, bool[] includeProperty, int j,
			object oldVersion, object obj, SqlCommandInfo sql, ISessionImplementor session)
		{
			bool useVersion = j == 0 && IsVersioned;
			IExpectation expectation = Expectations.AppropriateExpectation(updateResultCheckStyles[j]);
			//bool callable = IsUpdateCallable(j);
			bool useBatch = j == 0 && expectation.CanBeBatched && IsBatchable; //note: updates to joined tables can't be batched...

			if (log.IsDebugEnabled)
			{
				log.Debug("Updating entity: " + MessageHelper.InfoString(this, id, Factory));
				if (useVersion)
				{
					log.Debug("Existing version: " + oldVersion + " -> New Version: " + fields[VersionProperty]);
				}
			}

			try
			{
				int index = 0;
				IDbCommand statement = useBatch
																? session.Batcher.PrepareBatchCommand(sql.CommandType, sql.Text, sql.ParameterTypes)
																: session.Batcher.PrepareCommand(sql.CommandType, sql.Text, sql.ParameterTypes);
				try
				{
					//index += expectation.Prepare(statement, factory.ConnectionProvider.Driver);

					//Now write the values of fields onto the prepared statement
					index = Dehydrate(id, fields, rowId, includeProperty, propertyColumnUpdateable, j, statement, session, index);

					// Write any appropriate versioning conditional parameters
					if (useVersion && Versioning.OptimisticLock.Version == entityMetamodel.OptimisticLockMode)
					{
						if (CheckVersion(includeProperty))
							VersionType.NullSafeSet(statement, oldVersion, index, session);
					}
					else if (entityMetamodel.OptimisticLockMode > Versioning.OptimisticLock.Version && oldFields != null)
					{
						bool[] versionability = PropertyVersionability;
						bool[] includeOldField = OptimisticLockMode == Versioning.OptimisticLock.All
																			? PropertyUpdateability
																			: includeProperty;
						IType[] types = PropertyTypes;

						for (int i = 0; i < entityMetamodel.PropertySpan; i++)
						{
							bool include = includeOldField[i] &&
														 IsPropertyOfTable(i, j) &&
														 versionability[i];
							if (include)
							{
								bool[] settable = types[i].ToColumnNullness(oldFields[i], Factory);
								types[i].NullSafeSet(statement, oldFields[i], index, settable, session);
								index += ArrayHelper.CountTrue(settable);
							}
						}
					}

					if (useBatch)
					{
						session.Batcher.AddToBatch(expectation);
						return true;
					}
					else
					{
						return Check(session.Batcher.ExecuteNonQuery(statement), id, j, expectation, statement);
					}
				}
				catch (StaleStateException e)
				{
					if (useBatch)
					{
						session.Batcher.AbortBatch(e);
					}

					throw new StaleObjectStateException(EntityName, id);
				}
				catch (Exception e)
				{
					if (useBatch)
					{
						session.Batcher.AbortBatch(e);
					}

					throw;
				}
				finally
				{
					if (!useBatch)
					{
						session.Batcher.CloseCommand(statement, null);
					}
				}
			}
			catch (DbException sqle)
			{
				var exceptionContext = new AdoExceptionContextInfo
				                       	{
				                       		SqlException = sqle,
				                       		Message = "could not update: " + MessageHelper.InfoString(this, id, Factory),
//.........这里部分代码省略.........
开发者ID:rbirkby,项目名称:nhibernate-core,代码行数:101,代码来源:AbstractEntityPersister.cs


示例20: Delete


//.........这里部分代码省略.........
			{
				log.Debug("Deleting entity: " + MessageHelper.InfoString(this, id, Factory));
				if (useVersion)
				{
					log.Debug("Version: " + version);
				}
			}

			if (IsTableCascadeDeleteEnabled(j))
			{
				if (log.IsDebugEnabled)
				{
					log.Debug("delete handled by foreign key constraint: " + GetTableName(j));
				}
				return; //EARLY EXIT!
			}

			try
			{
				int index = 0;
				IDbCommand statement;
				if (useBatch)
				{
					statement = session.Batcher.PrepareBatchCommand(sql.CommandType, sql.Text, sql.ParameterTypes);
				}
				else
				{
					statement = session.Batcher.PrepareCommand(sql.CommandType, sql.Text, sql.ParameterTypes);
				}

				try
				{
					//index += expectation.Prepare(statement, factory.ConnectionProvider.Driver);

					// Do the key. The key is immutable so we can use the _current_ object state - not necessarily
					// the state at the time the delete was issued
					IdentifierType.NullSafeSet(statement, id, index, session);
					index += IdentifierColumnSpan;

					// We should use the _current_ object state (ie. after any updates that occurred during flush)
					if (useVersion)
					{
						VersionType.NullSafeSet(statement, version, index, session);
					}
					else if (entityMetamodel.OptimisticLockMode > Versioning.OptimisticLock.Version && loadedState != null)
					{
						bool[] versionability = PropertyVersionability;
						IType[] types = PropertyTypes;
						for (int i = 0; i < entityMetamodel.PropertySpan; i++)
						{
							if (IsPropertyOfTable(i, j) && versionability[i])
							{
								// this property belongs to the table and it is not specifically
								// excluded from optimistic locking by optimistic-lock="false"
								bool[] settable = types[i].ToColumnNullness(loadedState[i], Factory);

								types[i].NullSafeSet(statement, loadedState[i], index, settable, session);
								index += ArrayHelper.CountTrue(settable);
							}
						}
					}

					if (useBatch)
					{
						session.Batcher.AddToBatch(expectation);
					}
					else
					{
						Check(session.Batcher.ExecuteNonQuery(statement), id, j, expectation, statement);
					}
				}
				catch (Exception e)
				{
					if (useBatch)
					{
						session.Batcher.AbortBatch(e);
					}
					throw;
				}
				finally
				{
					if (!useBatch)
					{
						session.Batcher.CloseCommand(statement, null);
					}
				}
			}
			catch (DbException sqle)
			{
				var exceptionContext = new AdoExceptionContextInfo
				                       	{
				                       		SqlException = sqle,
				                       		Message = "could not delete: " + MessageHelper.InfoString(this, id, Factory),
				                       		Sql = sql.Text.ToString(),
				                       		EntityName = EntityName,
				                       		EntityId = id
				                       	};
				throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, exceptionContext);
			}
		}
开发者ID:rbirkby,项目名称:nhibernate-core,代码行数:101,代码来源:AbstractEntityPersister.cs



注:本文中的NHibernate.Exceptions.AdoExceptionContextInfo类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Ast.HqlExpression类代码示例发布时间:2022-05-26
下一篇:
C# Engine.RowSelection类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap