SPRNET-1422: HibernateTemplate should support Merge
This commit is contained in:
@@ -677,8 +677,28 @@ namespace Spring.Data.NHibernate
|
||||
public object SaveOrUpdateCopy(object entity)
|
||||
{
|
||||
return Execute(new SaveOrUpdateCopyHibernateCallback(this, entity),true);
|
||||
}
|
||||
|
||||
#if !NH_1_2
|
||||
/// <summary>
|
||||
/// Copy the state of the given object onto the persistent object with the same identifier.
|
||||
/// If there is no persistent instance currently associated with the session, it will be loaded.
|
||||
/// Return the persistent instance. If the given instance is unsaved,
|
||||
/// save a copy of and return it as a newly persistent instance.
|
||||
/// The given instance does not become associated with the session.
|
||||
/// This operation cascades to associated instances if the association is mapped with cascade="merge".
|
||||
/// The semantics of this method are defined by JSR-220.
|
||||
/// </summary>
|
||||
/// <param name="entity">The persistent object to merge.
|
||||
/// (<i>not</i> necessarily to be associated with the Hibernate Session)
|
||||
/// </param>
|
||||
/// <returns>An updated persistent instance</returns>
|
||||
/// <exception cref="DataAccessException">In case of Hibernate errors</exception>
|
||||
public object Merge(object entity)
|
||||
{
|
||||
return Execute(new MergeHibernateCallback(this, entity), true);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Remove all objects from the Session cache, and cancel all pending saves,
|
||||
@@ -2226,10 +2246,41 @@ namespace Spring.Data.NHibernate
|
||||
public object DoInHibernate(ISession session)
|
||||
{
|
||||
outer.CheckWriteOperationAllowed(session);
|
||||
return session.SaveOrUpdateCopy(entity);
|
||||
return session.SaveOrUpdateCopy(entity);
|
||||
}
|
||||
}
|
||||
|
||||
#if !NH_1_2
|
||||
internal class MergeHibernateCallback : IHibernateCallback
|
||||
{
|
||||
private HibernateTemplate outer;
|
||||
private object entity;
|
||||
|
||||
public MergeHibernateCallback(HibernateTemplate template, object entity)
|
||||
{
|
||||
this.outer = template;
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets called by HibernateTemplate with an active
|
||||
/// Hibernate Session. Does not need to care about activating or closing
|
||||
/// the Session, or handling transactions.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <p>
|
||||
/// Allows for returning a result object created within the callback, i.e.
|
||||
/// a domain object or a collection of domain objects. Note that there's
|
||||
/// special support for single step actions: see HibernateTemplate.find etc.
|
||||
/// </p>
|
||||
/// </remarks>
|
||||
public object DoInHibernate(ISession session)
|
||||
{
|
||||
outer.CheckWriteOperationAllowed(session);
|
||||
return session.Merge(entity);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -234,11 +234,26 @@ namespace Spring.Data.NHibernate
|
||||
/// <returns>The actually associated persistent object.
|
||||
/// (either an already loaded instance with the same id, or the given object)</returns>
|
||||
/// <exception cref="DataAccessException">In case of Hibernate errors</exception>
|
||||
object SaveOrUpdateCopy(object entity);
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
object SaveOrUpdateCopy(object entity);
|
||||
|
||||
#if !NH_1_2
|
||||
/// <summary>
|
||||
/// Copy the state of the given object onto the persistent object with the same identifier.
|
||||
/// If there is no persistent instance currently associated with the session, it will be loaded.
|
||||
/// Return the persistent instance. If the given instance is unsaved,
|
||||
/// save a copy of and return it as a newly persistent instance.
|
||||
/// The given instance does not become associated with the session.
|
||||
/// This operation cascades to associated instances if the association is mapped with cascade="merge".
|
||||
/// The semantics of this method are defined by JSR-220.
|
||||
/// </summary>
|
||||
/// <param name="entity">The persistent object to merge.
|
||||
/// (<i>not</i> necessarily to be associated with the Hibernate Session)
|
||||
/// </param>
|
||||
/// <returns>An updated persistent instance</returns>
|
||||
/// <exception cref="DataAccessException">In case of Hibernate errors</exception>
|
||||
object Merge(object entity);
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -603,6 +603,27 @@ namespace Spring.Data.NHibernate.Generic
|
||||
return classicHibernateTemplate.SaveOrUpdateCopy(entity);
|
||||
}
|
||||
|
||||
#if !NH_1_2
|
||||
/// <summary>
|
||||
/// Copy the state of the given object onto the persistent object with the same identifier.
|
||||
/// If there is no persistent instance currently associated with the session, it will be loaded.
|
||||
/// Return the persistent instance. If the given instance is unsaved,
|
||||
/// save a copy of and return it as a newly persistent instance.
|
||||
/// The given instance does not become associated with the session.
|
||||
/// This operation cascades to associated instances if the association is mapped with cascade="merge".
|
||||
/// The semantics of this method are defined by JSR-220.
|
||||
/// </summary>
|
||||
/// <param name="entity">The persistent object to merge.
|
||||
/// (<i>not</i> necessarily to be associated with the Hibernate Session)
|
||||
/// </param>
|
||||
/// <returns>An updated persistent instance</returns>
|
||||
/// <exception cref="DataAccessException">In case of Hibernate errors</exception>
|
||||
public object Merge(object entity)
|
||||
{
|
||||
return classicHibernateTemplate.Merge(entity);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
#region IHibernateOperations Gets
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
BaseAddress = "285212672"
|
||||
CheckForOverflowUnderflow = "false"
|
||||
ConfigurationOverrideFile = ""
|
||||
DefineConstants = "DEBUG;TRACE;NET_1_1"
|
||||
DefineConstants = "DEBUG;TRACE;NET_1_1,NH_1_2"
|
||||
DocumentationFile = ""
|
||||
DebugSymbols = "true"
|
||||
FileAlignment = "4096"
|
||||
@@ -48,7 +48,7 @@
|
||||
BaseAddress = "285212672"
|
||||
CheckForOverflowUnderflow = "false"
|
||||
ConfigurationOverrideFile = ""
|
||||
DefineConstants = "TRACE"
|
||||
DefineConstants = "TRACE,NH_1_2"
|
||||
DocumentationFile = ""
|
||||
DebugSymbols = "false"
|
||||
FileAlignment = "4096"
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\..\..\build\VS.Net.2005\Spring.Data.NHibernate12\Debug\</OutputPath>
|
||||
<DefineConstants>TRACE;DEBUG;NET_2_0</DefineConstants>
|
||||
<DefineConstants>TRACE;DEBUG;NET_2_0,NH_1_2</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>Spring.Data.NHibernate12.xml</DocumentationFile>
|
||||
@@ -24,7 +24,7 @@
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\..\..\build\VS.Net.2005\Spring.Data.NHibernate12\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NET_2_0</DefineConstants>
|
||||
<DefineConstants>TRACE;NET_2_0,NH_1_2</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\..\..\build\VS.Net.2008\Spring.Data.NHibernate12\Debug\</OutputPath>
|
||||
<DefineConstants>TRACE;DEBUG;NET_2_0</DefineConstants>
|
||||
<DefineConstants>TRACE;DEBUG;NET_2_0,NH_1_2</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>Spring.Data.NHibernate12.xml</DocumentationFile>
|
||||
@@ -25,7 +25,7 @@
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\..\..\build\VS.Net.2008\Spring.Data.NHibernate12\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NET_2_0</DefineConstants>
|
||||
<DefineConstants>TRACE;NET_2_0,NH_1_2</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\..\..\build\VS.Net.2010\Spring.Data.NHibernate12\Debug\</OutputPath>
|
||||
<DefineConstants>TRACE;DEBUG;NET_2_0</DefineConstants>
|
||||
<DefineConstants>TRACE;DEBUG;NET_2_0,NH_1_2</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>Spring.Data.NHibernate12.xml</DocumentationFile>
|
||||
@@ -30,7 +30,7 @@
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\..\..\build\VS.Net.2010\Spring.Data.NHibernate12\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NET_2_0</DefineConstants>
|
||||
<DefineConstants>TRACE;NET_2_0,NH_1_2</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
</copy>
|
||||
|
||||
<!-- build Spring.Data.NHibernate12 -->
|
||||
<csc target="library" define="${current.build.defines.csc}"
|
||||
<csc target="library" define="${current.build.defines.csc},NH_1_2"
|
||||
warnaserror="true"
|
||||
optimize="${build.optimize}"
|
||||
debug="${current.build.debug}"
|
||||
|
||||
Reference in New Issue
Block a user