Browse files

Added support for setting optimistic-lock on a many-to-one

  • Loading branch information...
1 parent 0683385 commit 0c1867cc5d6356f68b200dff72e4844c48a8fee7 @paulbatum paulbatum committed with Oct 16, 2010
View
8 src/FluentNHibernate.Testing/ConventionsTests/ApplyingToModel/ManyToOneConventionTests.cs
@@ -162,6 +162,14 @@ public void ShouldSetFormulaProperty()
VerifyModel(x => x.Formula.ShouldEqual("xxx"));
}
+ [Test]
+ public void ShouldSetOptimisticLockProperty()
+ {
+ Convention(x => x.OptimisticLock());
+
+ VerifyModel(x => x.OptimisticLock.ShouldBeTrue());
+ }
+
#region Helpers
private void Convention(Action<IManyToOneInstance> convention)
View
10 ...ntNHibernate.Testing/FluentInterfaceTests/ManyToOneMutablePropertyModelGenerationTests.cs
@@ -228,9 +228,17 @@ public void IndexShouldSetColumnIndexPropertyToValue()
[Test]
public void FormulaIsShouldSetModelFormulaPropertyToValue()
{
- Property()
+ ManyToOne()
.Mapping(m => m.Formula("form"))
.ModelShouldMatch(x => x.Formula.ShouldEqual("form"));
}
+
+ [Test]
+ public void OptimisticLockShouldSetModelOptimisticLockPropertyToValue()
+ {
+ ManyToOne()
+ .Mapping(m => m.OptimisticLock())
+ .ModelShouldMatch(x => x.OptimisticLock.ShouldBeTrue());
+ }
}
}
View
9 src/FluentNHibernate.Testing/MappingModel/Output/XmlManyToOneWriterTester.cs
@@ -148,5 +148,14 @@ public void ShouldWriteFormulaAttribute()
testHelper.VerifyAll(writer);
}
+
+ [Test]
+ public void ShouldWriteOptimisticLockAttribute()
+ {
+ var testHelper = new XmlWriterTestHelper<ManyToOneMapping>();
+ testHelper.Check(x => x.OptimisticLock, true).MapsToAttribute("optimistic-lock");
+
+ testHelper.VerifyAll(writer);
+ }
}
}
View
1 src/FluentNHibernate/Conventions/Inspections/IManyToOneInspector.cs
@@ -19,5 +19,6 @@ public interface IManyToOneInspector : IAccessInspector, IExposedThroughProperty
string PropertyRef { get; }
bool Update { get; }
bool Nullable { get; }
+ bool OptimisticLock { get; }
}
}
View
4 src/FluentNHibernate/Conventions/Inspections/ManyToOneInspector.cs
@@ -49,6 +49,10 @@ public bool Nullable
return !mapping.Columns.First().NotNull;
}
}
+ public bool OptimisticLock
+ {
+ get { return mapping.OptimisticLock; }
+ }
public Type EntityType
{
View
1 src/FluentNHibernate/Conventions/Instances/IManyToOneInstance.cs
@@ -18,6 +18,7 @@ public interface IManyToOneInstance : IManyToOneInspector
new INotFoundInstance NotFound { get; }
void Index(string index);
new void Insert();
+ new void OptimisticLock();
/// <summary>
/// Specify the lazy behaviour of this relationship.
View
7 src/FluentNHibernate/Conventions/Instances/ManyToOneInstance.cs
@@ -124,6 +124,13 @@ public new void Insert()
nextBool = true;
}
+ public new void OptimisticLock()
+ {
+ if (!mapping.IsSpecified("OptimisticLock"))
+ mapping.OptimisticLock = nextBool;
+ nextBool = true;
+ }
+
public new void LazyLoad()
{
if (!mapping.IsSpecified("Lazy"))
View
7 src/FluentNHibernate/Mapping/ManyToOnePart.cs
@@ -364,5 +364,12 @@ ColumnMapping CreateColumn(string column)
{
return new ColumnMapping(columnAttributes.CloneInner()) { Name = column };
}
+
+ public ManyToOneBuilder<TOther> OptimisticLock()
+ {
+ mapping.OptimisticLock = nextBool;
+ nextBool = true;
+ return this;
+ }
}
}
View
6 src/FluentNHibernate/MappingModel/ManyToOneMapping.cs
@@ -110,6 +110,12 @@ public string EntityName
set { attributes.Set(x => x.EntityName, value); }
}
+ public bool OptimisticLock
+ {
+ get { return attributes.Get(x => x.OptimisticLock); }
+ set { attributes.Set(x => x.OptimisticLock, value); }
+ }
+
public IDefaultableEnumerable<ColumnMapping> Columns
{
get { return columns; }
View
3 src/FluentNHibernate/MappingModel/Output/XmlManyToOneWriter.cs
@@ -65,6 +65,9 @@ public override void ProcessManyToOne(ManyToOneMapping mapping)
if (mapping.HasValue(x => x.EntityName))
element.WithAtt("entity-name", mapping.EntityName);
+
+ if (mapping.HasValue(x => x.OptimisticLock))
+ element.WithAtt("optimstic-lock", mapping.OptimisticLock);
}
public override void Visit(ColumnMapping columnMapping)

0 comments on commit 0c1867c

Please sign in to comment.