using System; using System.Globalization; using System.Runtime.Serialization; namespace SDA.DataProvider { /// /// Hibakódok /// public enum SDADataProviderError { /// /// Ismeretlen hiba /// Unknown, /// /// Egyedi kulcs megsértése /// UniqueKeyViolation, /// /// Idegen kulcs megsértése /// ForeignKeyViolation, /// /// A tábla vagy nézet nem létezik /// TableOrViewNotExists, /// /// Érvénytelen oszlopnév /// InvalidColumnName, /// /// Null érték nem beszúrható /// CannotInsertNull, /// /// Adatbázis-kapcsolati hiba /// CommunicationError, /// /// Táblaterekkel, rendelkezésre álló hellyel kapcsolatos hiba /// TableSpaceError, /// /// Deadlock történt /// DeadlockDetected, /// /// Adatbázis művelet időtúllépés történt /// CommandTimeout } /// /// Adatbázis hibát jelző kivétel. /// [Serializable] public class SDADataProviderException : Exception { const string DefaultMessage = "SQL error!"; const string DefaultCommand = ""; const int DefaultDatabaseNumber = -1; readonly string _commandText = DefaultCommand; /// /// Mező annak jelzésére, hogy a művelet végrehajtását célszerű-e /// újra megpróbálni, mielőtt a kivételt továbbdobjuk. /// internal readonly bool MustRetry = false; /// /// Hibakód. /// public SDADataProviderError Error { get; protected set; } /// /// Az eredeti - adatbázisfüggő - hibakód. /// public int DatabaseSpecificNumber { get; protected set; } /// /// Szabványos konstruktor. /// public SDADataProviderException() : base(DefaultMessage) { Error = SDADataProviderError.Unknown; DatabaseSpecificNumber = DefaultDatabaseNumber; } /// /// Szabványos konstruktor. /// public SDADataProviderException(string message) : base(message ?? DefaultMessage) { Error = SDADataProviderError.Unknown; DatabaseSpecificNumber = DefaultDatabaseNumber; } /// /// Szabványos konstruktor. /// public SDADataProviderException(string message, Exception innerException) : base(message ?? DefaultMessage, innerException) { Error = SDADataProviderError.Unknown; DatabaseSpecificNumber = DefaultDatabaseNumber; } internal SDADataProviderException(Exception innerException) : this(innerException == null ? DefaultMessage : innerException.Message, innerException) { } /// /// Szabványos konstruktor. /// protected SDADataProviderException(SerializationInfo info, StreamingContext context) : base(info, context) { if (info == null) { throw new ArgumentNullException(nameof(info)); } Error = (SDADataProviderError)info.GetValue("Error", typeof(SDADataProviderError)); DatabaseSpecificNumber = info.GetInt32("DatabaseSpecificNumber"); MustRetry = info.GetBoolean("MustRetry"); } internal SDADataProviderException(Exception innerException, SDADataProviderError error, int number, bool mustRetry, string commandText) : this(innerException == null ? DefaultMessage : innerException.Message, innerException) { Error = error; DatabaseSpecificNumber = number; MustRetry = mustRetry; _commandText = commandText ?? DefaultCommand; } internal SDADataProviderException(Exception innerException, SDADataProviderError error, string commandText) : this(innerException, error, DefaultDatabaseNumber, false, commandText) { } internal SDADataProviderException(Exception innerException, SDADataProviderError error, int number, string commandText) : this(innerException, error, number, false, commandText) { } internal SDADataProviderException(Exception innerException, SDADataProviderError error, int number, bool mustRetry) : this(innerException, error, number, mustRetry, DefaultCommand) { } /// /// A kivétel üzenete. /// public override string Message { get { if (!string.IsNullOrWhiteSpace(_commandText)) { return string.Format( CultureInfo.InvariantCulture, @"{0}: {1} {2}", DatabaseSpecificNumber, _commandText, base.Message); } return string.Format( CultureInfo.InvariantCulture, @"{0} {1}", DatabaseSpecificNumber, base.Message); } } /// /// Sorosítás. /// public override void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) { throw new ArgumentNullException(nameof(info)); } base.GetObjectData(info, context); info.AddValue("Error", Error); info.AddValue("DatabaseSpecificNumber", DatabaseSpecificNumber); info.AddValue("MustRetry", MustRetry); } } /// /// Holtpont. /// [Serializable] public sealed class DeadlockException : SDADataProviderException { /// /// Szabványos konstruktor. /// public DeadlockException() { } /// /// Szabványos konstruktor. /// public DeadlockException(string message) : base(message) { } /// /// Szabványos konstruktor. /// public DeadlockException(string message, Exception inner) : base(message, inner) { } /// /// Szabványos konstruktor. /// DeadlockException(SerializationInfo info, StreamingContext context) : base(info, context) { } internal DeadlockException(Exception innerException, int number, string commandText) : base(innerException, SDADataProviderError.DeadlockDetected, number, false, commandText) { } } /// /// Adatbázis művelet időtúllépés. /// [Serializable] public sealed class CommandTimeoutException : SDADataProviderException { /// /// Szabványos konstruktor. /// public CommandTimeoutException() { } /// /// Szabványos konstruktor. /// public CommandTimeoutException(string message) : base(message) { } /// /// Szabványos konstruktor. /// public CommandTimeoutException(string message, Exception inner) : base(message, inner) { } /// /// Szabványos konstruktor. /// CommandTimeoutException(SerializationInfo info, StreamingContext context) : base(info, context) { } internal CommandTimeoutException(Exception innerException, int number, string commandText) : base(innerException, SDADataProviderError.CommandTimeout, number, false, commandText) { } } /// /// Táblatér hiba. /// [Serializable] public sealed class TableSpaceErrorException : SDADataProviderException { /// /// Szabványos konstruktor. /// public TableSpaceErrorException() { } /// /// Szabványos konstruktor. /// public TableSpaceErrorException(string message) : base(message) { } /// /// Szabványos konstruktor. /// public TableSpaceErrorException(string message, Exception inner) : base(message, inner) { } /// /// Szabványos konstruktor. /// TableSpaceErrorException(SerializationInfo info, StreamingContext context) : base(info, context) { } internal TableSpaceErrorException(Exception innerException, int number, string commandText) : base(innerException, SDADataProviderError.TableSpaceError, number, false, commandText) { } } /// /// Egyediség megsértése. /// [Serializable] public sealed class UniqueKeyViolationException : SDADataProviderException { /// /// Szabványos konstruktor. /// public UniqueKeyViolationException() { } /// /// Szabványos konstruktor. /// public UniqueKeyViolationException(string message) : base(message) { } /// /// Szabványos konstruktor. /// public UniqueKeyViolationException(string message, Exception inner) : base(message, inner) { } /// /// Szabványos konstruktor. /// UniqueKeyViolationException(SerializationInfo info, StreamingContext context) : base(info, context) { } internal UniqueKeyViolationException(Exception innerException, int number, string commandText) : base(innerException, SDADataProviderError.UniqueKeyViolation, number, false, commandText) { } } /// /// Idegen kulcs megsértése. /// [Serializable] public sealed class ForeignKeyViolationException : SDADataProviderException { /// /// Szabványos konstruktor. /// public ForeignKeyViolationException() { } /// /// Szabványos konstruktor. /// public ForeignKeyViolationException(string message) : base(message) { } /// /// Szabványos konstruktor. /// public ForeignKeyViolationException(string message, Exception inner) : base(message, inner) { } /// /// Szabványos konstruktor. /// ForeignKeyViolationException(SerializationInfo info, StreamingContext context) : base(info, context) { } internal ForeignKeyViolationException(Exception innerException, int number, string commandText) : base(innerException, SDADataProviderError.ForeignKeyViolation, number, false, commandText) { } } /// /// Tábla vagy nézet nem létezik. /// [Serializable] public sealed class TableOrViewNotExistsException : SDADataProviderException { /// /// Szabványos konstruktor. /// public TableOrViewNotExistsException() { } /// /// Szabványos konstruktor. /// public TableOrViewNotExistsException(string message) : base(message) { } /// /// Szabványos konstruktor. /// public TableOrViewNotExistsException(string message, Exception inner) : base(message, inner) { } /// /// Szabványos konstruktor. /// TableOrViewNotExistsException(SerializationInfo info, StreamingContext context) : base(info, context) { } internal TableOrViewNotExistsException(Exception innerException, int number, string commandText) : base(innerException, SDADataProviderError.TableOrViewNotExists, number, false, commandText) { } } /// /// Oszlop nem létezik. /// [Serializable] public sealed class InvalidColumnNameException : SDADataProviderException { /// /// Szabványos konstruktor. /// public InvalidColumnNameException() { } /// /// Szabványos konstruktor. /// public InvalidColumnNameException(string message) : base(message) { } /// /// Szabványos konstruktor. /// public InvalidColumnNameException(string message, Exception inner) : base(message, inner) { } /// /// Szabványos konstruktor. /// InvalidColumnNameException(SerializationInfo info, StreamingContext context) : base(info, context) { } internal InvalidColumnNameException(Exception innerException, int number, string commandText) : base(innerException, SDADataProviderError.InvalidColumnName, number, false, commandText) { } } /// /// Kommunikációs hiba. /// [Serializable] public sealed class CommunicationErrorException : SDADataProviderException { /// /// Szabványos konstruktor. /// public CommunicationErrorException() { } /// /// Szabványos konstruktor. /// public CommunicationErrorException(string message) : base(message) { } /// /// Szabványos konstruktor. /// public CommunicationErrorException(string message, Exception inner) : base(message, inner) { } /// /// Szabványos konstruktor. /// CommunicationErrorException(SerializationInfo info, StreamingContext context) : base(info, context) { } internal CommunicationErrorException(Exception innerException, int number) : base(innerException, SDADataProviderError.CommunicationError, number, false) { } internal CommunicationErrorException(Exception innerException, int number, bool mustRetry) : base(innerException, SDADataProviderError.CommunicationError, number, mustRetry) { } } }