Skip to content

Commit

Permalink
Commented all the builder methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jagregory committed May 21, 2010
1 parent 92ad2d8 commit b6fd4bc
Show file tree
Hide file tree
Showing 34 changed files with 1,338 additions and 561 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,22 @@ protected ModelTester<PropertyPart, PropertyMapping> Property<T>(Expression<Func

protected ModelTester<OneToManyPart<T>, ICollectionMapping> OneToMany<T>(Expression<Func<OneToManyTarget, IEnumerable<T>>> property)
{
return new ModelTester<OneToManyPart<T>, ICollectionMapping>(() => new OneToManyPart<T>(typeof(OneToManyTarget), ReflectionHelper.GetMember(property)), x => x.GetCollectionMapping());
return new ModelTester<OneToManyPart<T>, ICollectionMapping>(() => new OneToManyPart<T>(typeof(OneToManyTarget), ReflectionHelper.GetMember(property)), x => ((ICollectionMappingProvider)x).GetCollectionMapping());
}

protected ModelTester<ManyToManyPart<T>, ICollectionMapping> ManyToMany<T>(Expression<Func<ManyToManyTarget, IList<T>>> property)
{
return new ModelTester<ManyToManyPart<T>, ICollectionMapping>(() => new ManyToManyPart<T>(typeof(ManyToManyTarget), ReflectionHelper.GetMember(property)), x => x.GetCollectionMapping());
return new ModelTester<ManyToManyPart<T>, ICollectionMapping>(() => new ManyToManyPart<T>(typeof(ManyToManyTarget), ReflectionHelper.GetMember(property)), x => ((ICollectionMappingProvider)x).GetCollectionMapping());
}

protected ModelTester<ManyToManyPart<IDictionary>, ICollectionMapping> ManyToMany(Expression<Func<ManyToManyTarget, IDictionary>> property)
{
return new ModelTester<ManyToManyPart<IDictionary>, ICollectionMapping>(() => new ManyToManyPart<IDictionary>(typeof(ManyToManyTarget), ReflectionHelper.GetMember(property)), x => x.GetCollectionMapping());
return new ModelTester<ManyToManyPart<IDictionary>, ICollectionMapping>(() => new ManyToManyPart<IDictionary>(typeof(ManyToManyTarget), ReflectionHelper.GetMember(property)), x => ((ICollectionMappingProvider)x).GetCollectionMapping());
}

protected ModelTester<ManyToManyPart<IDictionary<TIndex, TValue>>, ICollectionMapping> ManyToMany<TIndex, TValue>(Expression<Func<ManyToManyTarget, IDictionary<TIndex, TValue>>> property)
{
return new ModelTester<ManyToManyPart<IDictionary<TIndex, TValue>>, ICollectionMapping>(() => new ManyToManyPart<IDictionary<TIndex, TValue>>(typeof(ManyToManyTarget), ReflectionHelper.GetMember(property)), x => x.GetCollectionMapping());
return new ModelTester<ManyToManyPart<IDictionary<TIndex, TValue>>, ICollectionMapping>(() => new ManyToManyPart<IDictionary<TIndex, TValue>>(typeof(ManyToManyTarget), ReflectionHelper.GetMember(property)), x => ((ICollectionMappingProvider)x).GetCollectionMapping());
}

protected ModelTester<ManyToOnePart<PropertyReferenceTarget>, ManyToOneMapping> ManyToOne()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Mapping.Providers;
using NUnit.Framework;
using FluentNHibernate.Mapping;
using FluentNHibernate.Testing.DomainModel.Mapping;
Expand All @@ -18,7 +19,7 @@ public void CanSetLength()
var part = new ElementPart(typeof(MappedObject));
part.Length(50);

ElementMapping elementMapping = part.GetElementMapping();
ElementMapping elementMapping = ((IElementMappingProvider)part).GetElementMapping();
elementMapping.Length.ShouldEqual(50);
}

Expand All @@ -28,7 +29,7 @@ public void CanSetFormula()
var part = new ElementPart(typeof(MappedObject));
part.Formula("formula");

ElementMapping elementMapping = part.GetElementMapping();
ElementMapping elementMapping = ((IElementMappingProvider)part).GetElementMapping();
elementMapping.Formula.ShouldEqual("formula");
}
}
Expand Down
1 change: 1 addition & 0 deletions src/FluentNHibernate/FluentNHibernate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@
<Compile Include="Mapping\Access.cs" />
<Compile Include="Mapping\Laziness.cs" />
<Compile Include="Mapping\NaturalIdPart.cs" />
<Compile Include="Mapping\Providers\IElementMappingProvider.cs" />
<Compile Include="Mapping\Providers\IExternalComponentMappingProvider.cs" />
<Compile Include="Mapping\Providers\INaturalIdMappingProvider.cs" />
<Compile Include="Mapping\Providers\INestedCompositeElementMappingProvider.cs" />
Expand Down
49 changes: 40 additions & 9 deletions src/FluentNHibernate/Mapping/CachePart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,71 +14,102 @@ public CachePart(Type entityType)
this.entityType = entityType;
}

CacheMapping ICacheMappingProvider.GetCacheMapping()
{
var mapping = new CacheMapping(attributes.CloneInner());
mapping.ContainedEntityType = entityType;

return mapping;
}

/// <summary>
/// Sets caching to read-write
/// </summary>
public CachePart ReadWrite()
{
attributes.Set(x => x.Usage, "read-write");
return this;
}

/// <summary>
/// Sets caching to non-strict read-write
/// </summary>
public CachePart NonStrictReadWrite()
{
attributes.Set(x => x.Usage, "nonstrict-read-write");
return this;
}

/// <summary>
/// Sets caching to read-only
/// </summary>
public CachePart ReadOnly()
{
attributes.Set(x => x.Usage, "read-only");
return this;
}

/// <summary>
/// Sets caching to transactional
/// </summary>
public CachePart Transactional()
{
attributes.Set(x => x.Usage, "transactional");
return this;
}

/// <summary>
/// Specifies a custom cache behaviour
/// </summary>
/// <param name="custom">Custom behaviour</param>
public CachePart CustomUsage(string custom)
{
attributes.Set(x => x.Usage, custom);
return this;
}

/// <summary>
/// Specifies the cache region
/// </summary>
/// <returns></returns>
public CachePart Region(string name)
{
attributes.Set(x => x.Region, name);
return this;
}

/// <summary>
/// Include all properties for caching
/// </summary>
/// <returns></returns>
public CachePart IncludeAll()
{
attributes.Set(x => x.Include, "all");
return this;
}

/// <summary>
/// Include only non-lazy properties for caching
/// </summary>
public CachePart IncludeNonLazy()
{
attributes.Set(x => x.Include, "non-lazy");
return this;
}

/// <summary>
/// Specify a custom property inclusion strategy
/// </summary>
/// <param name="custom">Inclusion strategy</param>
public CachePart CustomInclude(string custom)
{
attributes.Set(x => x.Include, custom);
return this;
}

public bool IsDirty
internal bool IsDirty
{
get { return attributes.IsSpecified(x => x.Region) || attributes.IsSpecified(x => x.Usage) || attributes.IsSpecified(x => x.Include); }
}

CacheMapping ICacheMappingProvider.GetCacheMapping()
{
var mapping = new CacheMapping(attributes.CloneInner());
mapping.ContainedEntityType = entityType;

return mapping;
}
}
}
12 changes: 12 additions & 0 deletions src/FluentNHibernate/Mapping/CascadeExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,36 @@ public CascadeExpression(TParent parent, Action<string> setter)
this.setter = setter;
}

/// <summary>
/// Cascade all actions
/// </summary>
public TParent All()
{
setter("all");
return parent;
}

/// <summary>
/// Cascade no actions
/// </summary>
public TParent None()
{
setter("none");
return parent;
}

/// <summary>
/// Cascade saves and updates
/// </summary>
public TParent SaveUpdate()
{
setter("save-update");
return parent;
}

/// <summary>
/// Cascade deletes
/// </summary>
public TParent Delete()
{
setter("delete");
Expand Down
1 change: 0 additions & 1 deletion src/FluentNHibernate/Mapping/CheckTypeExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public CheckTypeExpression(TParent parent, Action<string> setter)
this.setValue = setter;
}


public void None()
{
setValue("none");
Expand Down
6 changes: 6 additions & 0 deletions src/FluentNHibernate/Mapping/CollectionCascadeExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ public CollectionCascadeExpression(TParent parent, Action<string> setter)
this.setter = setter;
}

/// <summary>
/// Cascade all actions, deleting any orphaned records
/// </summary>
public TParent AllDeleteOrphan()
{
setter("all-delete-orphan");
return parent;
}

/// <summary>
/// Cascade deletes, deleting any orphaned records
/// </summary>
public TParent DeleteOrphan()
{
setter("delete-orphan");
Expand Down
30 changes: 28 additions & 2 deletions src/FluentNHibernate/Mapping/ColumnPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,44 +30,70 @@ public ColumnPart Not
}
}

/// <summary>
/// Specify the column name
/// </summary>
/// <param name="columnName">Column name</param>
public ColumnPart Name(string columnName)
{
columnMapping.Name = columnName;
return this;
}

/// <summary>
/// Specify the column length
/// </summary>
/// <param name="length">Column length</param>
public ColumnPart Length(int length)
{
columnMapping.Length = length;
return this;
}

/// <summary>
/// Specify the nullability of the column
/// </summary>
public ColumnPart Nullable()
{
columnMapping.NotNull = !nextBool;
nextBool = true;
return this;
}

/// <summary>
/// Specify the uniquness of the column
/// </summary>
public ColumnPart Unique()
{
columnMapping.Unique = nextBool;
nextBool = true;
return this;
}

public ColumnPart UniqueKey(string key1)
/// <summary>
/// Specify the unique key constraint name
/// </summary>
/// <param name="key">Constraint name</param>
public ColumnPart UniqueKey(string key)
{
columnMapping.UniqueKey = key1;
columnMapping.UniqueKey = key;
return this;
}

/// <summary>
/// Specify the SQL type for the column
/// </summary>
/// <param name="sqlType">SQL type</param>
public ColumnPart SqlType(string sqlType)
{
columnMapping.SqlType = sqlType;
return this;
}

/// <summary>
/// Specify the index name
/// </summary>
/// <param name="index">Index name</param>
public ColumnPart Index(string index)
{
columnMapping.Index = index;
Expand Down
2 changes: 1 addition & 1 deletion src/FluentNHibernate/Mapping/ComponentMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace FluentNHibernate.Mapping
/// }
/// </example>
/// <typeparam name="T">Component type to map</typeparam>
public class ComponentMap<T> : ComponentPartBase<T>, IExternalComponentMappingProvider
public class ComponentMap<T> : ComponentPartBase<T, ComponentMap<T>>, IExternalComponentMappingProvider
{
private readonly AttributeStore<ComponentMapping> attributes;

Expand Down
Loading

0 comments on commit b6fd4bc

Please sign in to comment.