SPRNET-1240 - Add Non/TransientDataAccessException to DAO exception hierarchy

This commit is contained in:
markpollack
2009-07-29 02:15:10 +00:00
parent 8ea2bb4e86
commit edf9b867a7
13 changed files with 317 additions and 152 deletions

View File

@@ -44,8 +44,8 @@ namespace Spring.Dao
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Griffin Caprio (.NET)</author>
[Serializable]
public class CleanupFailureDataAccessException : DataAccessException
[Serializable]
public class CleanupFailureDataAccessException : NonTransientDataAccessException
{
/// <summary>
/// Creates a new instance of the

View File

@@ -39,8 +39,8 @@ namespace Spring.Dao
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Griffin Caprio (.NET)</author>
[Serializable]
public class DataIntegrityViolationException : DataAccessException
[Serializable]
public class DataIntegrityViolationException : NonTransientDataAccessException
{
/// <summary>
/// Creates a new instance of the

View File

@@ -39,8 +39,8 @@ namespace Spring.Dao
/// </remarks>
/// <author>Juergen Hoeller</author>
/// <author>Griffin Caprio (.NET)</author>
[Serializable]
public class DataRetrievalFailureException : DataAccessException
[Serializable]
public class DataRetrievalFailureException : NonTransientDataAccessException
{
/// <summary>
/// Creates a new instance of the

View File

@@ -39,8 +39,8 @@ namespace Spring.Dao
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Griffin Caprio (.NET)</author>
[Serializable]
public class InvalidDataAccessApiUsageException : DataAccessException
[Serializable]
public class InvalidDataAccessApiUsageException : NonTransientDataAccessException
{
/// <summary>
/// Creates a new instance of the

View File

@@ -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
{
/// <summary>
/// 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.
/// </summary>
/// <author>Thomas Risberg</author>
/// <author>Mark Pollack (.NET)</author>
[Serializable]
public abstract class NonTransientDataAccessException : DataAccessException
{
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Dao.NonTransientDataAccessException"/> class.
/// </summary>
public NonTransientDataAccessException() : base("No Exception Message") {}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Dao.NonTransientDataAccessException"/> class.
/// </summary>
/// <param name="message">
/// A message about the exception.
/// </param>
public NonTransientDataAccessException( string message ) : base( message ) {}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Dao.NonTransientDataAccessException"/> class.
/// </summary>
/// <param name="message">
/// A message about the exception.
/// </param>
/// <param name="rootCause">
/// The root exception (from the underlying data access API, such as ADO.NET).
/// </param>
public NonTransientDataAccessException( string message, Exception rootCause)
: base( message , rootCause ) {}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Dao.NonTransientDataAccessException"/> class.
/// </summary>
/// <param name="info">
/// The <see cref="System.Runtime.Serialization.SerializationInfo"/>
/// that holds the serialized object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The <see cref="System.Runtime.Serialization.StreamingContext"/>
/// that contains contextual information about the source or destination.
/// </param>
protected NonTransientDataAccessException(
SerializationInfo info, StreamingContext context ) : base( info, context ) {}
}
}

View File

@@ -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
{
/// <summary>
/// Data access exception thrown when a resource fails completely and the failure is permanent.
/// </summary>
/// <author>Thomas Risberg</author>
/// <author>Mark Pollack (.NET)</author>
[Serializable]
public abstract class NonTransientDataAccessResourceException : NonTransientDataAccessException
{
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Dao.NonTransientDataAccessResourceException"/> class.
/// </summary>
public NonTransientDataAccessResourceException() : base("No Exception Message") {}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Dao.NonTransientDataAccessResourceException"/> class.
/// </summary>
/// <param name="message">
/// A message about the exception.
/// </param>
public NonTransientDataAccessResourceException( string message ) : base( message ) {}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Dao.NonTransientDataAccessResourceException"/> class.
/// </summary>
/// <param name="message">
/// A message about the exception.
/// </param>
/// <param name="rootCause">
/// The root exception (from the underlying data access API, such as ADO.NET).
/// </param>
public NonTransientDataAccessResourceException( string message, Exception rootCause)
: base( message , rootCause ) {}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Dao.NonTransientDataAccessResourceException"/> class.
/// </summary>
/// <param name="info">
/// The <see cref="System.Runtime.Serialization.SerializationInfo"/>
/// that holds the serialized object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The <see cref="System.Runtime.Serialization.StreamingContext"/>
/// that contains contextual information about the source or destination.
/// </param>
protected NonTransientDataAccessResourceException(
SerializationInfo info, StreamingContext context ) : base( info, context ) {}
}
}

View File

@@ -33,7 +33,7 @@ namespace Spring.Dao
/// </summary>
/// <author>Mark Pollack (.NET)</author>
[Serializable]
public class ObjectRetrievalFailureException : DataRetrievalFailureException, ISerializable
public class ObjectRetrievalFailureException : DataRetrievalFailureException
{
private object persistentClass;

View File

@@ -33,8 +33,8 @@ namespace Spring.Dao
/// </summary>
/// <author>Juergen Hoeller</author>
/// <author>Mark Pollack (.NET)</author>
[Serializable]
public class PermissionDeniedDataAccessException : InvalidDataAccessResourceUsageException
[Serializable]
public class PermissionDeniedDataAccessException : NonTransientDataAccessException
{
/// <summary>
/// Creates a new instance of the

View File

@@ -34,8 +34,8 @@ namespace Spring.Dao
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Griffin Caprio (.NET)</author>
[Serializable]
public abstract class UncategorizedDataAccessException : DataAccessException
[Serializable]
public abstract class UncategorizedDataAccessException : NonTransientDataAccessException
{
/// <summary>
/// Creates a new instance of the

View File

@@ -34,7 +34,7 @@ namespace Spring.Data
/// <author>Rod Johnson</author>
/// <author>Mark Pollack (.NET)</author>
[Serializable]
public class CannotGetAdoConnectionException : InvalidDataAccessResourceUsageException, ISerializable
public class CannotGetAdoConnectionException : InvalidDataAccessResourceUsageException
{
#region Constructor (s)

View File

@@ -1,141 +1,141 @@
#region License
/*
* Copyright <20> 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
{
/// <summary>
#region License
/*
* Copyright <20> 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
{
/// <summary>
/// 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.
/// </summary>
/// <author>Thomas Risberg</author>
/// <author>Mark Pollack (.NET)</author>
[Serializable]
public class DuplicateKeyException : DataIntegrityViolationException
{
#region Fields
/// <summary>
/// SQL that led to the problem
/// </summary>
private string sql;
#endregion
#region Constructor (s)
/// <summary>
/// Initializes a new instance of the <see cref="DuplicateKeyException"/> class.
/// </summary>
public DuplicateKeyException()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DuplicateKeyException"/> class.
/// </summary>
/// <param name="message">A message about the exception.</param>
public DuplicateKeyException(string message): base(message)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DuplicateKeyException"/> class.
/// </summary>
/// <param name="message">A message about the exception.</param>
/// <param name="inner">The inner exception.</param>
public DuplicateKeyException(string message, Exception inner): base(message, inner)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DuplicateKeyException"/> class.
/// </summary>
/// <param name="task">name of the current task.</param>
/// <param name="sql">The offending SQL statment</param>
/// <param name="ex">The root cause.</param>
public DuplicateKeyException(string task, String sql, Exception ex) : base(task + "; Duplicate key for SQL [" + sql + "]; " + ex.Message, ex)
{
this.sql = sql;
}
/// <summary>
/// Creates a new instance of the
/// <see cref="DuplicateKeyException"/> class.
/// </summary>
/// <param name="info">
/// The <see cref="System.Runtime.Serialization.SerializationInfo"/>
/// that holds the serialized object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The <see cref="System.Runtime.Serialization.StreamingContext"/>
/// that contains contextual information about the source or destination.
/// <author>Thomas Risberg</author>
/// <author>Mark Pollack (.NET)</author>
[Serializable]
public class DuplicateKeyException : DataIntegrityViolationException
{
#region Fields
/// <summary>
/// SQL that led to the problem
/// </summary>
private string sql;
#endregion
#region Constructor (s)
/// <summary>
/// Initializes a new instance of the <see cref="DuplicateKeyException"/> class.
/// </summary>
public DuplicateKeyException()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DuplicateKeyException"/> class.
/// </summary>
/// <param name="message">A message about the exception.</param>
public DuplicateKeyException(string message): base(message)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DuplicateKeyException"/> class.
/// </summary>
/// <param name="message">A message about the exception.</param>
/// <param name="inner">The inner exception.</param>
public DuplicateKeyException(string message, Exception inner): base(message, inner)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DuplicateKeyException"/> class.
/// </summary>
/// <param name="task">name of the current task.</param>
/// <param name="sql">The offending SQL statment</param>
/// <param name="ex">The root cause.</param>
public DuplicateKeyException(string task, String sql, Exception ex) : base(task + "; Duplicate key for SQL [" + sql + "]; " + ex.Message, ex)
{
this.sql = sql;
}
/// <summary>
/// Creates a new instance of the
/// <see cref="DuplicateKeyException"/> class.
/// </summary>
/// <param name="info">
/// The <see cref="System.Runtime.Serialization.SerializationInfo"/>
/// that holds the serialized object data about the exception being thrown.
/// </param>
protected DuplicateKeyException(SerializationInfo info, StreamingContext context) : base(info, context) { }
#endregion
#region Properties
/// <summary>
/// Gets the SQL that caused the exception
/// </summary>
/// <value>The SQL that caused the exception.</value>
public string Sql
{
get
{
return sql;
}
}
#endregion
#region Methods
#endregion
#region ISerializable Members
/// <summary>
/// When overridden in a derived class, sets the <see cref="T:System.Runtime.Serialization.SerializationInfo"/>
/// with information about the exception.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="info"/> parameter is a null reference (<see langword="Nothing"/> in Visual Basic).</exception>
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue( "sql", sql );
base.GetObjectData( info, context );
}
#endregion
}
}
/// <param name="context">
/// The <see cref="System.Runtime.Serialization.StreamingContext"/>
/// that contains contextual information about the source or destination.
/// </param>
protected DuplicateKeyException(SerializationInfo info, StreamingContext context) : base(info, context) { }
#endregion
#region Properties
/// <summary>
/// Gets the SQL that caused the exception
/// </summary>
/// <value>The SQL that caused the exception.</value>
public string Sql
{
get
{
return sql;
}
}
#endregion
#region Methods
#endregion
#region ISerializable Members
/// <summary>
/// When overridden in a derived class, sets the <see cref="T:System.Runtime.Serialization.SerializationInfo"/>
/// with information about the exception.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="info"/> parameter is a null reference (<see langword="Nothing"/> in Visual Basic).</exception>
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue( "sql", sql );
base.GetObjectData( info, context );
}
#endregion
}
}

View File

@@ -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)
{

View File

@@ -104,6 +104,8 @@
<Compile Include="Dao\CannotSerializeTransactionException.cs" />
<Compile Include="Dao\CleanupFailureDataAccessException.cs" />
<Compile Include="Dao\ConcurrencyFailureException.cs" />
<Compile Include="Dao\NonTransientDataAccessResourceException.cs" />
<Compile Include="Dao\NonTransientDataAccessException.cs" />
<Compile Include="Dao\TransientDataAccessResourceException.cs" />
<Compile Include="Dao\TransientDataAccessException.cs" />
<Compile Include="Dao\PessimisticLockingFailureException.cs" />