forked from nhibernate/fluent-nhibernate
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimental HasMap functionality on Classlike.
- Loading branch information
Stuart Childs
committed
May 14, 2009
1 parent
d782f8c
commit 67d4a50
Showing
13 changed files
with
438 additions
and
1 deletion.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/FluentNHibernate/Conventions/Defaults/HasMapCollectionNameConvention.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using FluentNHibernate.Mapping; | ||
|
||
namespace FluentNHibernate.Conventions.Defaults | ||
{ | ||
public class HasMapCollectionNameConvention : IMapConvention | ||
{ | ||
public bool Accept(IMapCollectionPart target) | ||
{ | ||
return string.IsNullOrEmpty(target.CollectionColumnName); | ||
} | ||
|
||
public void Apply(IMapCollectionPart target) | ||
{ | ||
target.WithCollectionColumn(target.ValueType.Name + "_id"); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/FluentNHibernate/Conventions/Defaults/HasMapIndexNameConvention.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using FluentNHibernate.Mapping; | ||
|
||
namespace FluentNHibernate.Conventions.Defaults | ||
{ | ||
public class HasMapIndexNameConvention : IMapConvention | ||
{ | ||
public bool Accept(IMapCollectionPart target) | ||
{ | ||
return string.IsNullOrEmpty(target.IndexColumnName); | ||
} | ||
|
||
public void Apply(IMapCollectionPart target) | ||
{ | ||
target.WithIndexColumn(target.IndexType.Name + "_id"); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/FluentNHibernate/Conventions/Defaults/HasMapTableNameConvention.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using FluentNHibernate.Mapping; | ||
|
||
namespace FluentNHibernate.Conventions.Defaults | ||
{ | ||
class HasMapTableNameConvention : IMapConvention | ||
{ | ||
public bool Accept(IMapCollectionPart target) | ||
{ | ||
return string.IsNullOrEmpty(target.TableName); | ||
} | ||
|
||
public void Apply(IMapCollectionPart target) | ||
{ | ||
target.WithTableName(target.EntityType.Name + "To" + target.ValueType.Name); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/FluentNHibernate/Conventions/Discovery/HasMapDiscoveryConvention.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using FluentNHibernate.Mapping; | ||
|
||
namespace FluentNHibernate.Conventions.Discovery | ||
{ | ||
/// <summary> | ||
/// Discovers any <see cref="IJoinedSubclassConvention"/> implementations and applies them to | ||
/// an <see cref="IJoinedSubclass"/> instance. | ||
/// </summary> | ||
public class HasMapDiscoveryConvention : IMappingPartConvention | ||
{ | ||
private readonly IConventionFinder conventionFinder; | ||
|
||
public HasMapDiscoveryConvention(IConventionFinder conventionFinder) | ||
{ | ||
this.conventionFinder = conventionFinder; | ||
} | ||
|
||
public bool Accept(IMappingPart target) | ||
{ | ||
return (target is IMapCollectionPart); | ||
} | ||
|
||
public void Apply(IMappingPart target) | ||
{ | ||
var conventions = conventionFinder.Find<IMapConvention>(); | ||
var join = (IMapCollectionPart)target; | ||
|
||
foreach (var convention in conventions) | ||
{ | ||
if (convention.Accept(join)) | ||
convention.Apply(join); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using FluentNHibernate.Mapping; | ||
|
||
namespace FluentNHibernate.Conventions | ||
{ | ||
public interface IMapConvention : IConvention<IMapCollectionPart> | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Xml; | ||
|
||
namespace FluentNHibernate.Mapping | ||
{ | ||
public interface IIndexMapping | ||
{ | ||
IIndexMapping WithColumn(string columnName); | ||
IIndexMapping WithType<TIndex>(); | ||
IIndexMapping WithType(Type type); | ||
void WriteIndexElement(XmlElement element); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace FluentNHibernate.Mapping | ||
{ | ||
public interface IMapCollectionPart : IMappingPart | ||
{ | ||
Type EntityType { get; } | ||
Type IndexType { get; } | ||
Type ValueType { get; } | ||
string TableName { get; } | ||
string IndexColumnName { get; } | ||
string CollectionColumnName { get; } | ||
IMapCollectionPart WithTableName(string name); | ||
IMapCollectionPart WithIndexColumn(string name); | ||
IMapCollectionPart WithCollectionColumn(string name); | ||
IColumnNameCollection KeyColumnNames { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Xml; | ||
using FluentNHibernate.Utils; | ||
|
||
namespace FluentNHibernate.Mapping | ||
{ | ||
public class IndexMappingBase : IIndexMapping | ||
{ | ||
protected Cache<string, string> properties = new Cache<string, string>(); | ||
protected string indexElementName; | ||
protected string indexType; | ||
|
||
public IndexMappingBase() | ||
: this("type", "index") | ||
{ | ||
|
||
} | ||
|
||
public IndexMappingBase(string indexType, string indexElementName) | ||
{ | ||
this.indexType = indexType; | ||
this.indexElementName = indexElementName; | ||
} | ||
|
||
#region IIndexMapping Members | ||
|
||
public IIndexMapping WithColumn(string columnName) | ||
{ | ||
properties.Store("column", columnName); | ||
return this; | ||
} | ||
|
||
public IIndexMapping WithType<TIndex>() | ||
{ | ||
return WithType(typeof(TIndex)); | ||
} | ||
|
||
public IIndexMapping WithType(Type type) | ||
{ | ||
properties.Store(indexType, (indexType == "type") ? type.Name : type.AssemblyQualifiedName); | ||
return this; | ||
} | ||
|
||
public void WriteIndexElement(XmlElement collectionElement) | ||
{ | ||
var indexElement = collectionElement.AddElement(indexElementName); | ||
indexElement.WithProperties(properties); | ||
} | ||
|
||
public static IIndexMapping GetIndexMappingTypeFor<TIndex>() | ||
{ | ||
return (typeof(TIndex).IsPrimitive || typeof(TIndex) == typeof(string)) | ||
? new IndexMappingBase() | ||
: new IndexMappingBase("class", "index-many-to-many"); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
Oops, something went wrong.