|
From: <fab...@us...> - 2009-03-04 18:47:07
|
Revision: 4110
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4110&view=rev
Author: fabiomaulo
Date: 2009-03-04 18:47:03 +0000 (Wed, 04 Mar 2009)
Log Message:
-----------
Fix of NH-1687 and NH-1685
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs
trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs
trunk/nhibernate/src/NHibernate.Test/VersionTest/Db/MsSQL/GeneratedBinaryVersionFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2009-03-04 16:45:01 UTC (rev 4109)
+++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2009-03-04 18:47:03 UTC (rev 4110)
@@ -1297,8 +1297,10 @@
}
}
- protected static void BindColumn(HbmColumn columnSchema, Column column, bool isNullable)
+ protected void BindColumn(HbmColumn columnSchema, Column column, bool isNullable)
{
+ column.Name = mappings.NamingStrategy.ColumnName(columnSchema.name);
+
if (columnSchema.length != null)
column.Length = int.Parse(columnSchema.length);
if (columnSchema.scale != null)
Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs 2009-03-04 16:45:01 UTC (rev 4109)
+++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs 2009-03-04 18:47:03 UTC (rev 4110)
@@ -213,11 +213,9 @@
private void BindColumns(HbmVersion versionSchema, SimpleValue model, bool isNullable, string propertyPath)
{
Table table = model.Table;
-
if (versionSchema.column1 != null)
{
- Column col = new Column();
- col.Value = model;
+ var col = new Column {Value = model};
BindColumn(col, isNullable);
col.Name = mappings.NamingStrategy.ColumnName(versionSchema.column1);
@@ -226,11 +224,22 @@
model.AddColumn(col);
}
+ else if (versionSchema.column != null)
+ {
+ foreach (HbmColumn hbmColumn in versionSchema.column)
+ {
+ var col = new Column {Value = model};
+ BindColumn(hbmColumn, col, isNullable);
+ if (table != null)
+ table.AddColumn(col);
+ model.AddColumn(col);
+ }
+ }
+
if (model.ColumnSpan == 0)
{
- Column col = new Column();
- col.Value = model;
+ var col = new Column {Value = model};
BindColumn(col, isNullable);
col.Name = mappings.NamingStrategy.PropertyToColumnName(propertyPath);
model.Table.AddColumn(col);
Modified: trunk/nhibernate/src/NHibernate.Test/VersionTest/Db/MsSQL/GeneratedBinaryVersionFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/VersionTest/Db/MsSQL/GeneratedBinaryVersionFixture.cs 2009-03-04 16:45:01 UTC (rev 4109)
+++ trunk/nhibernate/src/NHibernate.Test/VersionTest/Db/MsSQL/GeneratedBinaryVersionFixture.cs 2009-03-04 18:47:03 UTC (rev 4110)
@@ -7,7 +7,7 @@
{
// related issues NH-1687, NH-1685
- [TestFixture, Ignore("Not fixed yet.")]
+ [TestFixture]
public class GeneratedBinaryVersionFixture : TestCase
{
protected override IList Mappings
@@ -28,6 +28,8 @@
[Test]
public void ShouldRetrieveVersionAfterFlush()
{
+ // Note : if you are using identity-style strategy the value of version
+ // is available inmediately after save.
var e = new SimpleVersioned {Something = "something"};
using (ISession s = OpenSession())
{
@@ -42,5 +44,78 @@
}
}
}
+
+ [Test]
+ public void ShouldChangeAfterUpdate()
+ {
+ object savedId = PersistANewSomething();
+ using (ISession s = OpenSession())
+ {
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ var fetched = s.Get<SimpleVersioned>(savedId);
+ var freshVersion = fetched.LastModified;
+ fetched.Something = "make it dirty";
+ s.Update(fetched);
+ s.Flush(); // force flush to hit DB
+ Assert.That(fetched.LastModified, Is.Not.SameAs(freshVersion));
+ s.Delete(fetched);
+ tx.Commit();
+ }
+ }
+ }
+
+ private object PersistANewSomething()
+ {
+ object savedId;
+ using (ISession s = OpenSession())
+ {
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ var e = new SimpleVersioned {Something = "something"};
+ savedId = s.Save(e);
+ tx.Commit();
+ }
+ }
+ return savedId;
+ }
+
+ [Test]
+ public void ShouldCheckStaleState()
+ {
+ var versioned = new SimpleVersioned {Something = "original string"};
+
+ try
+ {
+ using (ISession session = OpenSession())
+ {
+ session.Save(versioned);
+ session.Flush();
+
+ using (ISession concurrentSession = OpenSession())
+ {
+ var sameVersioned = concurrentSession.Get<SimpleVersioned>(versioned.Id);
+ sameVersioned.Something = "another string";
+ concurrentSession.Flush();
+ }
+
+ versioned.Something = "new string";
+ session.Flush();
+ }
+ Assert.Fail("Expected exception was not thrown");
+ }
+ catch (StaleObjectStateException)
+ {
+ // as expected
+ }
+ finally
+ {
+ using (ISession session = OpenSession())
+ {
+ session.Delete("from SimpleVersioned");
+ session.Flush();
+ }
+ }
+ }
}
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|