From edf9b867a7080aed2323b661e681bc4580b1791f Mon Sep 17 00:00:00 2001 From: markpollack Date: Wed, 29 Jul 2009 02:15:10 +0000 Subject: [PATCH] SPRNET-1240 - Add Non/TransientDataAccessException to DAO exception hierarchy --- .../Dao/CleanupFailureDataAccessException.cs | 4 +- .../Dao/DataIntegrityViolationException.cs | 4 +- .../Dao/DataRetrievalFailureException.cs | 4 +- .../Dao/InvalidDataAccessApiUsageException.cs | 4 +- .../Dao/NonTransientDataAccessException.cs | 83 ++++++ ...NonTransientDataAccessResourceException.cs | 81 ++++++ .../Dao/ObjectRetrievalFailureException.cs | 2 +- .../PermissionDeniedDataAccessException.cs | 4 +- .../Dao/UncategorizedDataAccessException.cs | 4 +- .../Data/CannotGetAdoConnectionException.cs | 2 +- .../Spring.Data/Data/DuplicateKeyException.cs | 272 +++++++++--------- .../Data/Support/ConnectionUtils.cs | 3 +- .../Spring.Data/Spring.Data.2008.csproj | 2 + 13 files changed, 317 insertions(+), 152 deletions(-) create mode 100644 src/Spring/Spring.Data/Dao/NonTransientDataAccessException.cs create mode 100644 src/Spring/Spring.Data/Dao/NonTransientDataAccessResourceException.cs diff --git a/src/Spring/Spring.Data/Dao/CleanupFailureDataAccessException.cs b/src/Spring/Spring.Data/Dao/CleanupFailureDataAccessException.cs index de9ea026..1f88f3a9 100644 --- a/src/Spring/Spring.Data/Dao/CleanupFailureDataAccessException.cs +++ b/src/Spring/Spring.Data/Dao/CleanupFailureDataAccessException.cs @@ -44,8 +44,8 @@ namespace Spring.Dao /// /// Rod Johnson /// Griffin Caprio (.NET) - [Serializable] - public class CleanupFailureDataAccessException : DataAccessException + [Serializable] + public class CleanupFailureDataAccessException : NonTransientDataAccessException { /// /// Creates a new instance of the diff --git a/src/Spring/Spring.Data/Dao/DataIntegrityViolationException.cs b/src/Spring/Spring.Data/Dao/DataIntegrityViolationException.cs index 7a1f3d2d..0caa689f 100644 --- a/src/Spring/Spring.Data/Dao/DataIntegrityViolationException.cs +++ b/src/Spring/Spring.Data/Dao/DataIntegrityViolationException.cs @@ -39,8 +39,8 @@ namespace Spring.Dao /// /// Rod Johnson /// Griffin Caprio (.NET) - [Serializable] - public class DataIntegrityViolationException : DataAccessException + [Serializable] + public class DataIntegrityViolationException : NonTransientDataAccessException { /// /// Creates a new instance of the diff --git a/src/Spring/Spring.Data/Dao/DataRetrievalFailureException.cs b/src/Spring/Spring.Data/Dao/DataRetrievalFailureException.cs index e84ea780..fa808ec2 100644 --- a/src/Spring/Spring.Data/Dao/DataRetrievalFailureException.cs +++ b/src/Spring/Spring.Data/Dao/DataRetrievalFailureException.cs @@ -39,8 +39,8 @@ namespace Spring.Dao /// /// Juergen Hoeller /// Griffin Caprio (.NET) - [Serializable] - public class DataRetrievalFailureException : DataAccessException + [Serializable] + public class DataRetrievalFailureException : NonTransientDataAccessException { /// /// Creates a new instance of the diff --git a/src/Spring/Spring.Data/Dao/InvalidDataAccessApiUsageException.cs b/src/Spring/Spring.Data/Dao/InvalidDataAccessApiUsageException.cs index eb4c1714..9d98590b 100644 --- a/src/Spring/Spring.Data/Dao/InvalidDataAccessApiUsageException.cs +++ b/src/Spring/Spring.Data/Dao/InvalidDataAccessApiUsageException.cs @@ -39,8 +39,8 @@ namespace Spring.Dao /// /// Rod Johnson /// Griffin Caprio (.NET) - [Serializable] - public class InvalidDataAccessApiUsageException : DataAccessException + [Serializable] + public class InvalidDataAccessApiUsageException : NonTransientDataAccessException { /// /// Creates a new instance of the diff --git a/src/Spring/Spring.Data/Dao/NonTransientDataAccessException.cs b/src/Spring/Spring.Data/Dao/NonTransientDataAccessException.cs new file mode 100644 index 00000000..7f42144d --- /dev/null +++ b/src/Spring/Spring.Data/Dao/NonTransientDataAccessException.cs @@ -0,0 +1,83 @@ +#region License + +/* + * Copyright 2002-2004 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#endregion + +#region Imports + +using System; +using System.Runtime.Serialization; + +#endregion + +namespace Spring.Dao +{ + /// + /// Root of the hierarchy of data access exception that are considered non-transient - + /// where a retry of the same operation would fail unless the cause of the Exception is + /// corrected. + /// + /// Thomas Risberg + /// Mark Pollack (.NET) + [Serializable] + public abstract class NonTransientDataAccessException : DataAccessException + { + /// + /// Creates a new instance of the + /// class. + /// + public NonTransientDataAccessException() : base("No Exception Message") {} + + /// + /// Creates a new instance of the + /// class. + /// + /// + /// A message about the exception. + /// + public NonTransientDataAccessException( string message ) : base( message ) {} + + /// + /// Creates a new instance of the + /// class. + /// + /// + /// A message about the exception. + /// + /// + /// The root exception (from the underlying data access API, such as ADO.NET). + /// + public NonTransientDataAccessException( string message, Exception rootCause) + : base( message , rootCause ) {} + + /// + /// Creates a new instance of the + /// class. + /// + /// + /// The + /// that holds the serialized object data about the exception being thrown. + /// + /// + /// The + /// that contains contextual information about the source or destination. + /// + protected NonTransientDataAccessException( + SerializationInfo info, StreamingContext context ) : base( info, context ) {} + } +} \ No newline at end of file diff --git a/src/Spring/Spring.Data/Dao/NonTransientDataAccessResourceException.cs b/src/Spring/Spring.Data/Dao/NonTransientDataAccessResourceException.cs new file mode 100644 index 00000000..9cb264d6 --- /dev/null +++ b/src/Spring/Spring.Data/Dao/NonTransientDataAccessResourceException.cs @@ -0,0 +1,81 @@ +#region License + +/* + * Copyright 2002-2004 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#endregion + +#region Imports + +using System; +using System.Runtime.Serialization; + +#endregion + +namespace Spring.Dao +{ + /// + /// Data access exception thrown when a resource fails completely and the failure is permanent. + /// + /// Thomas Risberg + /// Mark Pollack (.NET) + [Serializable] + public abstract class NonTransientDataAccessResourceException : NonTransientDataAccessException + { + /// + /// Creates a new instance of the + /// class. + /// + public NonTransientDataAccessResourceException() : base("No Exception Message") {} + + /// + /// Creates a new instance of the + /// class. + /// + /// + /// A message about the exception. + /// + public NonTransientDataAccessResourceException( string message ) : base( message ) {} + + /// + /// Creates a new instance of the + /// class. + /// + /// + /// A message about the exception. + /// + /// + /// The root exception (from the underlying data access API, such as ADO.NET). + /// + public NonTransientDataAccessResourceException( string message, Exception rootCause) + : base( message , rootCause ) {} + + /// + /// Creates a new instance of the + /// class. + /// + /// + /// The + /// that holds the serialized object data about the exception being thrown. + /// + /// + /// The + /// that contains contextual information about the source or destination. + /// + protected NonTransientDataAccessResourceException( + SerializationInfo info, StreamingContext context ) : base( info, context ) {} + } +} \ No newline at end of file diff --git a/src/Spring/Spring.Data/Dao/ObjectRetrievalFailureException.cs b/src/Spring/Spring.Data/Dao/ObjectRetrievalFailureException.cs index 15d326e2..393b7481 100644 --- a/src/Spring/Spring.Data/Dao/ObjectRetrievalFailureException.cs +++ b/src/Spring/Spring.Data/Dao/ObjectRetrievalFailureException.cs @@ -33,7 +33,7 @@ namespace Spring.Dao /// /// Mark Pollack (.NET) [Serializable] - public class ObjectRetrievalFailureException : DataRetrievalFailureException, ISerializable + public class ObjectRetrievalFailureException : DataRetrievalFailureException { private object persistentClass; diff --git a/src/Spring/Spring.Data/Dao/PermissionDeniedDataAccessException.cs b/src/Spring/Spring.Data/Dao/PermissionDeniedDataAccessException.cs index f505d31a..a3353f17 100644 --- a/src/Spring/Spring.Data/Dao/PermissionDeniedDataAccessException.cs +++ b/src/Spring/Spring.Data/Dao/PermissionDeniedDataAccessException.cs @@ -33,8 +33,8 @@ namespace Spring.Dao /// /// Juergen Hoeller /// Mark Pollack (.NET) - [Serializable] - public class PermissionDeniedDataAccessException : InvalidDataAccessResourceUsageException + [Serializable] + public class PermissionDeniedDataAccessException : NonTransientDataAccessException { /// /// Creates a new instance of the diff --git a/src/Spring/Spring.Data/Dao/UncategorizedDataAccessException.cs b/src/Spring/Spring.Data/Dao/UncategorizedDataAccessException.cs index 9b9169de..d418f9fd 100644 --- a/src/Spring/Spring.Data/Dao/UncategorizedDataAccessException.cs +++ b/src/Spring/Spring.Data/Dao/UncategorizedDataAccessException.cs @@ -34,8 +34,8 @@ namespace Spring.Dao /// /// Rod Johnson /// Griffin Caprio (.NET) - [Serializable] - public abstract class UncategorizedDataAccessException : DataAccessException + [Serializable] + public abstract class UncategorizedDataAccessException : NonTransientDataAccessException { /// /// Creates a new instance of the diff --git a/src/Spring/Spring.Data/Data/CannotGetAdoConnectionException.cs b/src/Spring/Spring.Data/Data/CannotGetAdoConnectionException.cs index 93308924..52a06aa1 100644 --- a/src/Spring/Spring.Data/Data/CannotGetAdoConnectionException.cs +++ b/src/Spring/Spring.Data/Data/CannotGetAdoConnectionException.cs @@ -34,7 +34,7 @@ namespace Spring.Data /// Rod Johnson /// Mark Pollack (.NET) [Serializable] - public class CannotGetAdoConnectionException : InvalidDataAccessResourceUsageException, ISerializable + public class CannotGetAdoConnectionException : InvalidDataAccessResourceUsageException { #region Constructor (s) diff --git a/src/Spring/Spring.Data/Data/DuplicateKeyException.cs b/src/Spring/Spring.Data/Data/DuplicateKeyException.cs index 1b4f92c3..846c4e09 100644 --- a/src/Spring/Spring.Data/Data/DuplicateKeyException.cs +++ b/src/Spring/Spring.Data/Data/DuplicateKeyException.cs @@ -1,141 +1,141 @@ -#region License - -/* - * Copyright © 2002-2005 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#endregion - -#region Imports - -using System; -using System.Runtime.Serialization; -using Spring.Dao; - -#endregion - -namespace Spring.Data -{ - /// +#region License + +/* + * Copyright © 2002-2005 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#endregion + +#region Imports + +using System; +using System.Runtime.Serialization; +using Spring.Dao; + +#endregion + +namespace Spring.Data +{ + /// /// Exception thrown when an attempt to insert or update data /// results in violation of an primary key or unique constraint. /// Note that this is not necessarily a purely relational concept; - /// unique primary keys are required by most database types. + /// unique primary keys are required by most database types. /// - /// Thomas Risberg - /// Mark Pollack (.NET) - [Serializable] - public class DuplicateKeyException : DataIntegrityViolationException - { - #region Fields - - /// - /// SQL that led to the problem - /// - private string sql; - - #endregion - - #region Constructor (s) - /// - /// Initializes a new instance of the class. - /// - public DuplicateKeyException() - { - } - - /// - /// Initializes a new instance of the class. - /// - /// A message about the exception. - public DuplicateKeyException(string message): base(message) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// A message about the exception. - /// The inner exception. - public DuplicateKeyException(string message, Exception inner): base(message, inner) - { - } - - - /// - /// Initializes a new instance of the class. - /// - /// name of the current task. - /// The offending SQL statment - /// The root cause. - public DuplicateKeyException(string task, String sql, Exception ex) : base(task + "; Duplicate key for SQL [" + sql + "]; " + ex.Message, ex) - { - this.sql = sql; - } - /// - /// Creates a new instance of the - /// class. - /// - /// - /// The - /// that holds the serialized object data about the exception being thrown. - /// - /// - /// The - /// that contains contextual information about the source or destination. + /// Thomas Risberg + /// Mark Pollack (.NET) + [Serializable] + public class DuplicateKeyException : DataIntegrityViolationException + { + #region Fields + + /// + /// SQL that led to the problem + /// + private string sql; + + #endregion + + #region Constructor (s) + /// + /// Initializes a new instance of the class. + /// + public DuplicateKeyException() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// A message about the exception. + public DuplicateKeyException(string message): base(message) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// A message about the exception. + /// The inner exception. + public DuplicateKeyException(string message, Exception inner): base(message, inner) + { + } + + + /// + /// Initializes a new instance of the class. + /// + /// name of the current task. + /// The offending SQL statment + /// The root cause. + public DuplicateKeyException(string task, String sql, Exception ex) : base(task + "; Duplicate key for SQL [" + sql + "]; " + ex.Message, ex) + { + this.sql = sql; + } + /// + /// Creates a new instance of the + /// class. + /// + /// + /// The + /// that holds the serialized object data about the exception being thrown. /// - protected DuplicateKeyException(SerializationInfo info, StreamingContext context) : base(info, context) { } - - - - #endregion - - #region Properties - - /// - /// Gets the SQL that caused the exception - /// - /// The SQL that caused the exception. - public string Sql - { - get - { - return sql; - } - } - #endregion - - #region Methods - - #endregion - - #region ISerializable Members - - /// - /// When overridden in a derived class, sets the - /// with information about the exception. - /// - /// The that holds the serialized object data about the exception being thrown. - /// The that contains contextual information about the source or destination. - /// The parameter is a null reference ( in Visual Basic). - public override void GetObjectData(SerializationInfo info, StreamingContext context) - { - info.AddValue( "sql", sql ); - base.GetObjectData( info, context ); - } - - #endregion - } -} + /// + /// The + /// that contains contextual information about the source or destination. + /// + protected DuplicateKeyException(SerializationInfo info, StreamingContext context) : base(info, context) { } + + + + #endregion + + #region Properties + + /// + /// Gets the SQL that caused the exception + /// + /// The SQL that caused the exception. + public string Sql + { + get + { + return sql; + } + } + #endregion + + #region Methods + + #endregion + + #region ISerializable Members + + /// + /// When overridden in a derived class, sets the + /// with information about the exception. + /// + /// The that holds the serialized object data about the exception being thrown. + /// The that contains contextual information about the source or destination. + /// The parameter is a null reference ( in Visual Basic). + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + info.AddValue( "sql", sql ); + base.GetObjectData( info, context ); + } + + #endregion + } +} diff --git a/src/Spring/Spring.Data/Data/Support/ConnectionUtils.cs b/src/Spring/Spring.Data/Data/Support/ConnectionUtils.cs index 604fed1d..510e0287 100644 --- a/src/Spring/Spring.Data/Data/Support/ConnectionUtils.cs +++ b/src/Spring/Spring.Data/Data/Support/ConnectionUtils.cs @@ -151,8 +151,7 @@ namespace Spring.Data.Support LOG.Debug("Registering transaction synchronization for IDbConnection"); //Use same connection for further ADO.NET actions with the transaction. //Thread-bound object will get removed by manager at transaction completion. - - //TODO investigate creating tx object... + ConnectionHolder holderToUse = conHolder; if (holderToUse == null) { diff --git a/src/Spring/Spring.Data/Spring.Data.2008.csproj b/src/Spring/Spring.Data/Spring.Data.2008.csproj index ce985839..31ccbaf3 100644 --- a/src/Spring/Spring.Data/Spring.Data.2008.csproj +++ b/src/Spring/Spring.Data/Spring.Data.2008.csproj @@ -104,6 +104,8 @@ + +