|
From: <pa...@us...> - 2011-04-08 17:52:59
|
Revision: 5645
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5645&view=rev
Author: patearl
Date: 2011-04-08 17:52:52 +0000 (Fri, 08 Apr 2011)
Log Message:
-----------
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Linq/Visitors/GroupByKeySelectorVisitor.cs
trunk/nhibernate/src/NHibernate/Linq/Visitors/NhExpressionTreeVisitor.cs
trunk/nhibernate/src/NHibernate/Linq/Visitors/SelectClauseVisitor.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Linq/Visitors/ExpressionTreeVisitor.cs
Added: trunk/nhibernate/src/NHibernate/Linq/Visitors/ExpressionTreeVisitor.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Visitors/ExpressionTreeVisitor.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Linq/Visitors/ExpressionTreeVisitor.cs 2011-04-08 17:52:52 UTC (rev 5645)
@@ -0,0 +1,160 @@
+using System;
+using System.Collections.ObjectModel;
+using System.Linq.Expressions;
+using Remotion.Data.Linq.Clauses.Expressions;
+
+namespace NHibernate.Linq.Visitors
+{
+ /// <summary>
+ /// This class is used to expose the members from the base class that get internalized when the other class is ilmerged.
+ /// We do this instead of exposing the base class directly by name, since we don't want it to be part of our public API.
+ /// </summary>
+ public class ExpressionTreeVisitor : Remotion.Data.Linq.Parsing.ExpressionTreeVisitor
+ {
+ public override ReadOnlyCollection<T> VisitAndConvert<T>(ReadOnlyCollection<T> expressions, string callerName)
+ {
+ return base.VisitAndConvert<T>(expressions, callerName);
+ }
+
+ public override T VisitAndConvert<T>(T expression, string methodName)
+ {
+ return base.VisitAndConvert<T>(expression, methodName);
+ }
+
+ protected override Expression VisitBinaryExpression(BinaryExpression expression)
+ {
+ return base.VisitBinaryExpression(expression);
+ }
+
+ protected override Expression VisitConditionalExpression(ConditionalExpression expression)
+ {
+ return base.VisitConditionalExpression(expression);
+ }
+
+ protected override Expression VisitConstantExpression(ConstantExpression expression)
+ {
+ return base.VisitConstantExpression(expression);
+ }
+
+ protected override ElementInit VisitElementInit(ElementInit elementInit)
+ {
+ return base.VisitElementInit(elementInit);
+ }
+
+ protected override ReadOnlyCollection<ElementInit> VisitElementInitList(ReadOnlyCollection<ElementInit> expressions)
+ {
+ return base.VisitElementInitList(expressions);
+ }
+
+ public override Expression VisitExpression(Expression expression)
+ {
+ return base.VisitExpression(expression);
+ }
+
+ protected override Expression VisitExtensionExpression(ExtensionExpression expression)
+ {
+ return base.VisitExtensionExpression(expression);
+ }
+
+ protected override Expression VisitInvocationExpression(InvocationExpression expression)
+ {
+ return base.VisitInvocationExpression(expression);
+ }
+
+ protected override Expression VisitLambdaExpression(LambdaExpression expression)
+ {
+ return base.VisitLambdaExpression(expression);
+ }
+
+ protected override Expression VisitListInitExpression(ListInitExpression expression)
+ {
+ return base.VisitListInitExpression(expression);
+ }
+
+ protected override MemberBinding VisitMemberAssignment(MemberAssignment memberAssigment)
+ {
+ return base.VisitMemberAssignment(memberAssigment);
+ }
+
+ protected override MemberBinding VisitMemberBinding(MemberBinding memberBinding)
+ {
+ return base.VisitMemberBinding(memberBinding);
+ }
+
+ protected override ReadOnlyCollection<MemberBinding> VisitMemberBindingList(ReadOnlyCollection<MemberBinding> expressions)
+ {
+ return base.VisitMemberBindingList(expressions);
+ }
+
+ protected override Expression VisitMemberExpression(MemberExpression expression)
+ {
+ return base.VisitMemberExpression(expression);
+ }
+
+ protected override Expression VisitMemberInitExpression(MemberInitExpression expression)
+ {
+ return base.VisitMemberInitExpression(expression);
+ }
+
+ protected override MemberBinding VisitMemberListBinding(MemberListBinding listBinding)
+ {
+ return base.VisitMemberListBinding(listBinding);
+ }
+
+ protected override MemberBinding VisitMemberMemberBinding(MemberMemberBinding binding)
+ {
+ return base.VisitMemberMemberBinding(binding);
+ }
+
+ protected override Expression VisitMethodCallExpression(MethodCallExpression expression)
+ {
+ return base.VisitMethodCallExpression(expression);
+ }
+
+ protected override Expression VisitNewArrayExpression(NewArrayExpression expression)
+ {
+ return base.VisitNewArrayExpression(expression);
+ }
+
+ protected override Expression VisitNewExpression(NewExpression expression)
+ {
+ return base.VisitNewExpression(expression);
+ }
+
+ protected override Expression VisitParameterExpression(ParameterExpression expression)
+ {
+ return base.VisitParameterExpression(expression);
+ }
+
+ protected override Expression VisitQuerySourceReferenceExpression(Remotion.Data.Linq.Clauses.Expressions.QuerySourceReferenceExpression expression)
+ {
+ return base.VisitQuerySourceReferenceExpression(expression);
+ }
+
+ protected override Expression VisitSubQueryExpression(Remotion.Data.Linq.Clauses.Expressions.SubQueryExpression expression)
+ {
+ return base.VisitSubQueryExpression(expression);
+ }
+
+ protected override Expression VisitTypeBinaryExpression(TypeBinaryExpression expression)
+ {
+ return base.VisitTypeBinaryExpression(expression);
+ }
+
+ protected override Expression VisitUnaryExpression(UnaryExpression expression)
+ {
+ return base.VisitUnaryExpression(expression);
+ }
+
+ [Obsolete]
+ protected override Expression VisitUnknownExpression(Expression expression)
+ {
+ return base.VisitUnknownExpression(expression);
+ }
+
+ protected override Expression VisitUnknownNonExtensionExpression(Expression expression)
+ {
+ return base.VisitUnknownNonExtensionExpression(expression);
+ }
+ }
+}
Modified: trunk/nhibernate/src/NHibernate/Linq/Visitors/GroupByKeySelectorVisitor.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Visitors/GroupByKeySelectorVisitor.cs 2011-04-08 17:19:14 UTC (rev 5644)
+++ trunk/nhibernate/src/NHibernate/Linq/Visitors/GroupByKeySelectorVisitor.cs 2011-04-08 17:52:52 UTC (rev 5645)
@@ -1,6 +1,5 @@
using System.Linq.Expressions;
using Remotion.Data.Linq.Clauses.Expressions;
-using Remotion.Data.Linq.Parsing;
namespace NHibernate.Linq.Visitors
{
Modified: trunk/nhibernate/src/NHibernate/Linq/Visitors/NhExpressionTreeVisitor.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Visitors/NhExpressionTreeVisitor.cs 2011-04-08 17:19:14 UTC (rev 5644)
+++ trunk/nhibernate/src/NHibernate/Linq/Visitors/NhExpressionTreeVisitor.cs 2011-04-08 17:52:52 UTC (rev 5645)
@@ -1,7 +1,6 @@
using System;
using System.Linq.Expressions;
using NHibernate.Linq.Expressions;
-using Remotion.Data.Linq.Parsing;
namespace NHibernate.Linq.Visitors
{
Modified: trunk/nhibernate/src/NHibernate/Linq/Visitors/SelectClauseVisitor.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Visitors/SelectClauseVisitor.cs 2011-04-08 17:19:14 UTC (rev 5644)
+++ trunk/nhibernate/src/NHibernate/Linq/Visitors/SelectClauseVisitor.cs 2011-04-08 17:52:52 UTC (rev 5645)
@@ -4,7 +4,6 @@
using NHibernate.Hql.Ast;
using NHibernate.Linq.Expressions;
using NHibernate.Linq.Functions;
-using Remotion.Data.Linq.Parsing;
namespace NHibernate.Linq.Visitors
{
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-08 17:19:14 UTC (rev 5644)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-08 17:52:52 UTC (rev 5645)
@@ -266,6 +266,7 @@
<Compile Include="Linq\ReWriters\MoveOrderByToEndRewriter.cs" />
<Compile Include="Linq\ReWriters\ResultOperatorRewriter.cs" />
<Compile Include="Linq\ReWriters\ResultOperatorRewriterResult.cs" />
+ <Compile Include="Linq\Visitors\ExpressionTreeVisitor.cs" />
<Compile Include="Linq\Visitors\ResultOperatorProcessors\ProcessAggregateFromSeed.cs" />
<Compile Include="Loader\Loader.cs" />
<Compile Include="Loader\OuterJoinLoader.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2011-04-08 17:57:11
|
Revision: 5646
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5646&view=rev
Author: fabiomaulo
Date: 2011-04-08 17:57:05 +0000 (Fri, 08 Apr 2011)
Log Message:
-----------
Multi type registration auto filter valid conformist mappings classes
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs
trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ClassMappingRegistrationTest.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs 2011-04-08 17:52:52 UTC (rev 5645)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs 2011-04-08 17:57:05 UTC (rev 5646)
@@ -1645,7 +1645,7 @@
{
throw new ArgumentNullException("types");
}
- foreach (var type in types)
+ foreach (var type in types.Where(x=> typeof(IConformistHoldersProvider).IsAssignableFrom(x)))
{
AddMapping(type);
}
Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ClassMappingRegistrationTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ClassMappingRegistrationTest.cs 2011-04-08 17:52:52 UTC (rev 5645)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ClassMappingRegistrationTest.cs 2011-04-08 17:57:05 UTC (rev 5646)
@@ -59,6 +59,16 @@
}
[Test]
+ public void WhenRegisterClassMappingThroughCollectionOfTypeThenFilterValidMappings()
+ {
+ var mapper = new ModelMapper();
+ mapper.Executing(x=> x.AddMappings(new[] { typeof(object), typeof(MyClassMap), typeof(MyClass) })).NotThrows();
+ var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
+
+ ModelIsWellFormed(hbmMapping);
+ }
+
+ [Test]
public void WhenRegisterClassMappingThroughTypeThenGetMapping()
{
var mapper = new ModelMapper();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jul...@us...> - 2011-04-10 16:12:32
|
Revision: 5649
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5649&view=rev
Author: julian-maughan
Date: 2011-04-10 16:12:26 +0000 (Sun, 10 Apr 2011)
Log Message:
-----------
Added Sybase ASE 15 support (NH-2526). Predominantly a port from Hibernate, with some refinements.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/NHibernate.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Dialect/SybaseASE15Dialect.cs
trunk/nhibernate/src/NHibernate/Driver/SybaseAseClientDriver.cs
trunk/nhibernate/src/NHibernate.Config.Templates/SybaseASE.cfg.xml
Added: trunk/nhibernate/src/NHibernate/Dialect/SybaseASE15Dialect.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Dialect/SybaseASE15Dialect.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Dialect/SybaseASE15Dialect.cs 2011-04-10 16:12:26 UTC (rev 5649)
@@ -0,0 +1,331 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Data.Common;
+using System.Text;
+using Environment = NHibernate.Cfg.Environment;
+using NHibernate.Dialect.Function;
+using NHibernate.SqlCommand;
+
+namespace NHibernate.Dialect
+{
+ /// <summary>
+ /// An SQL dialect targeting Sybase Adaptive Server Enterprise (ASE) 15 and higher.
+ /// </summary>
+ /// <remarks>
+ /// The dialect defaults the following configuration properties:
+ /// <list type="table">
+ /// <listheader>
+ /// <term>Property</term>
+ /// <description>Default Value</description>
+ /// </listheader>
+ /// <item>
+ /// <term>connection.driver_class</term>
+ /// <description><see cref="NHibernate.Driver.SybaseAseClientDriver" /></description>
+ /// </item>
+ /// </list>
+ /// </remarks>
+ public class SybaseASE15Dialect : Dialect
+ {
+ public SybaseASE15Dialect()
+ {
+ DefaultProperties[Environment.ConnectionDriver] = "NHibernate.Driver.SybaseAseClientDriver";
+
+ RegisterColumnType(DbType.Boolean, "tinyint"); // Sybase BIT type does not support null values
+ RegisterColumnType(DbType.Int16, "smallint");
+ RegisterColumnType(DbType.Int16, 255, "tinyint");
+ RegisterColumnType(DbType.Int32, "int");
+ RegisterColumnType(DbType.Int64, "bigint");
+ RegisterColumnType(DbType.Decimal, "numeric(18,0)");
+ RegisterColumnType(DbType.Single, "real");
+ RegisterColumnType(DbType.Double, "float");
+ RegisterColumnType(DbType.AnsiStringFixedLength, "char(1)");
+ RegisterColumnType(DbType.AnsiStringFixedLength, 255, "char($l)");
+ RegisterColumnType(DbType.StringFixedLength, "nchar(1)");
+ RegisterColumnType(DbType.StringFixedLength, 255, "nchar($l)");
+ RegisterColumnType(DbType.AnsiString, "varchar(255)");
+ RegisterColumnType(DbType.AnsiString, 16384, "varchar($l)");
+ RegisterColumnType(DbType.String, "nvarchar(255)");
+ RegisterColumnType(DbType.String, 16384, "nvarchar($l)");
+ RegisterColumnType(DbType.String, int.MaxValue, "text");
+ RegisterColumnType(DbType.DateTime, "datetime");
+ RegisterColumnType(DbType.Time, "time");
+ RegisterColumnType(DbType.Date, "date");
+ RegisterColumnType(DbType.Binary, 8000, "varbinary($l)");
+ RegisterColumnType(DbType.Binary, "varbinary");
+
+ RegisterFunction("abs", new StandardSQLFunction("abs"));
+ RegisterFunction("acos", new StandardSQLFunction("acos", NHibernateUtil.Double));
+ RegisterFunction("ascii", new StandardSQLFunction("ascii", NHibernateUtil.Int32));
+ RegisterFunction("asin", new StandardSQLFunction("asin", NHibernateUtil.Double));
+ RegisterFunction("atan", new StandardSQLFunction("atan", NHibernateUtil.Double));
+ RegisterFunction("bit_length", new SQLFunctionTemplate(NHibernateUtil.Int32, "datalength(?1) * 8"));
+ RegisterFunction("ceiling", new StandardSQLFunction("ceiling"));
+ RegisterFunction("char", new StandardSQLFunction("char", NHibernateUtil.String));
+ RegisterFunction("concat", new VarArgsSQLFunction(NHibernateUtil.String, "(","+",")"));
+ RegisterFunction("cos", new StandardSQLFunction("cos", NHibernateUtil.Double));
+ RegisterFunction("cot", new StandardSQLFunction("cot", NHibernateUtil.Double));
+ RegisterFunction("current_date", new NoArgSQLFunction("getdate", NHibernateUtil.Date));
+ RegisterFunction("current_time", new NoArgSQLFunction("getdate", NHibernateUtil.Time));
+ RegisterFunction("current_timestamp", new NoArgSQLFunction("getdate", NHibernateUtil.Timestamp));
+ RegisterFunction("datename", new StandardSQLFunction("datename", NHibernateUtil.String));
+ RegisterFunction("day", new StandardSQLFunction("day", NHibernateUtil.Int32));
+ RegisterFunction("degrees", new StandardSQLFunction("degrees", NHibernateUtil.Double));
+ RegisterFunction("exp", new StandardSQLFunction("exp", NHibernateUtil.Double));
+ RegisterFunction("extract", new SQLFunctionTemplate(NHibernateUtil.Int32, "datepart(?1, ?3)"));
+ RegisterFunction("floor", new StandardSQLFunction("floor"));
+ RegisterFunction("getdate", new NoArgSQLFunction("getdate", NHibernateUtil.Timestamp));
+ RegisterFunction("getutcdate", new NoArgSQLFunction("getutcdate", NHibernateUtil.Timestamp));
+ RegisterFunction("hour", new SQLFunctionTemplate(NHibernateUtil.Int32, "datepart(hour, ?1)"));
+ RegisterFunction("isnull", new StandardSQLFunction("isnull"));
+ RegisterFunction("len", new StandardSQLFunction("len", NHibernateUtil.Int64));
+ RegisterFunction("length", new StandardSQLFunction("len", NHibernateUtil.Int32));
+ RegisterFunction("locate", new CharIndexFunction());
+ RegisterFunction("log", new StandardSQLFunction("log", NHibernateUtil.Double));
+ RegisterFunction("log10", new StandardSQLFunction("log10", NHibernateUtil.Double));
+ RegisterFunction("lower", new StandardSQLFunction("lower"));
+ RegisterFunction("ltrim", new StandardSQLFunction("ltrim"));
+ RegisterFunction("minute", new SQLFunctionTemplate(NHibernateUtil.Int32, "datepart(minute, ?1)"));
+ RegisterFunction("mod", new SQLFunctionTemplate(NHibernateUtil.Int32, "?1 % ?2"));
+ RegisterFunction("month", new StandardSQLFunction("month", NHibernateUtil.Int32));
+ RegisterFunction("pi", new NoArgSQLFunction("pi", NHibernateUtil.Double));
+ RegisterFunction("radians", new StandardSQLFunction("radians", NHibernateUtil.Double));
+ RegisterFunction("rand", new StandardSQLFunction("rand", NHibernateUtil.Double));
+ RegisterFunction("reverse", new StandardSQLFunction("reverse"));
+ RegisterFunction("round", new StandardSQLFunction("round"));
+ RegisterFunction("rtrim", new StandardSQLFunction("rtrim"));
+ RegisterFunction("second", new SQLFunctionTemplate(NHibernateUtil.Int32, "datepart(second, ?1)"));
+ RegisterFunction("sign", new StandardSQLFunction("sign", NHibernateUtil.Int32));
+ RegisterFunction("sin", new StandardSQLFunction("sin", NHibernateUtil.Double));
+ RegisterFunction("space", new StandardSQLFunction("space", NHibernateUtil.String));
+ RegisterFunction("sqrt", new StandardSQLFunction("sqrt", NHibernateUtil.Double));
+ RegisterFunction("square", new StandardSQLFunction("square"));
+ RegisterFunction("str", new StandardSQLFunction("str", NHibernateUtil.String));
+ RegisterFunction("tan", new StandardSQLFunction("tan", NHibernateUtil.Double));
+ // TODO RegisterFunction("trim", new SQLFunctionTemplate(NHibernateUtil.String, "ltrim(rtrim(?1))"));
+ RegisterFunction("upper", new StandardSQLFunction("upper"));
+ RegisterFunction("user", new NoArgSQLFunction("user", NHibernateUtil.String));
+ RegisterFunction("year", new StandardSQLFunction("year", NHibernateUtil.Int32));
+ }
+
+ public override string AddColumnString
+ {
+ get { return "add"; }
+ }
+
+ public override string NullColumnString
+ {
+ get { return " null"; }
+ }
+
+ public override bool QualifyIndexName
+ {
+ get { return false; }
+ }
+
+ public override bool SupportsIdentityColumns
+ {
+ get { return true; }
+ }
+
+ public override string IdentitySelectString
+ {
+ get { return "select @@identity"; }
+ }
+
+ public override string IdentityColumnString
+ {
+ get { return "identity not null"; } // starts with 1, implicitly
+ }
+
+ public override bool SupportsInsertSelectIdentity
+ {
+ get { return true; }
+ }
+
+ public override bool SupportsCurrentTimestampSelection
+ {
+ get { return true; }
+ }
+
+ public override bool IsCurrentTimestampSelectStringCallable
+ {
+ get { return false; }
+ }
+
+ public override string CurrentTimestampSelectString
+ {
+ get { return "select getdate()"; }
+ }
+
+ /// <summary>
+ /// Sybase ASE 15 temporary tables are not supported
+ /// </summary>
+ /// <remarks>
+ /// By default, temporary tables in Sybase ASE 15 can only be created outside a transaction.
+ /// This is not supported by NHibernate. Temporary tables (and other DDL) statements can only
+ /// be run in a transaction if the 'ddl in tran' database option on tempdb is set to 'true'.
+ /// However, Sybase does not recommend this setting due to the performance impact arising from
+ /// locking and contention on tempdb system tables.
+ /// </remarks>
+ public override bool SupportsTemporaryTables
+ {
+ get { return false; }
+ }
+
+ public override string SelectGUIDString
+ {
+ get { return "select newid()"; }
+ }
+
+ public override bool SupportsEmptyInList
+ {
+ get { return false; }
+ }
+
+ public override bool SupportsUnionAll
+ {
+ get { return true; }
+ }
+
+ public override bool SupportsExistsInSelect
+ {
+ get { return false; }
+ }
+
+ public override bool DoesReadCommittedCauseWritersToBlockReaders
+ {
+ get { return true; }
+ }
+
+ public override bool DoesRepeatableReadCauseReadersToBlockWriters
+ {
+ get { return true; }
+ }
+
+ public override bool SupportsCascadeDelete
+ {
+ get { return false; }
+ }
+
+ public override int MaxAliasLength
+ {
+ get { return 30; }
+ }
+
+ /// <summary>
+ /// This is false only by default. The database can be configured to be
+ /// case-insensitive.
+ /// </summary>
+ public override bool AreStringComparisonsCaseInsensitive
+ {
+ get { return false; }
+ }
+
+ public override string CurrentTimestampSQLFunctionName
+ {
+ get { return "getdate()"; }
+ }
+
+ public override bool SupportsExpectedLobUsagePattern
+ {
+ get { return false; }
+ }
+
+ public override char OpenQuote
+ {
+ get { return '['; }
+ }
+
+ public override char CloseQuote
+ {
+ get { return ']'; }
+ }
+
+ public override string ForUpdateString
+ {
+ get { return String.Empty; }
+ }
+
+ public override string GenerateTemporaryTableName(string baseTableName)
+ {
+ return "#" + baseTableName;
+ }
+
+ public override bool DropTemporaryTableAfterUse()
+ {
+ return true;
+ }
+
+ public override SqlString AppendIdentitySelectToInsert(SqlString insertString)
+ {
+ return insertString.Append("\nselect @@identity");
+ }
+
+ public override string AppendLockHint(LockMode lockMode, string tableName)
+ {
+ if (lockMode.GreaterThan(LockMode.Read))
+ return tableName + " holdlock";
+
+ return tableName;
+ }
+
+ public override SqlString ApplyLocksToSql(SqlString sql, IDictionary<string, LockMode> aliasedLockModes, IDictionary<string, string[]> keyColumnNames)
+ {
+ // TODO: merge additional lockoptions support in Dialect.applyLocksToSql
+
+ var buffer = new StringBuilder(sql.ToString());
+ int correction = 0;
+
+ foreach (KeyValuePair<string, LockMode> entry in aliasedLockModes)
+ {
+ LockMode mode = entry.Value;
+
+ if (mode.GreaterThan(LockMode.Read))
+ {
+ string alias = entry.Key;
+ int start = -1;
+ int end = -1;
+
+ if (sql.EndsWith(" " + alias))
+ {
+ start = (sql.Length - alias.Length) + correction;
+ end = start + alias.Length;
+ }
+ else
+ {
+ int position = sql.IndexOfCaseInsensitive(" " + alias + " ");
+
+ if (position <= -1)
+ position = sql.IndexOfCaseInsensitive(" " + alias + ",");
+
+ if (position > -1)
+ {
+ start = position + correction + 1;
+ end = start + alias.Length;
+ }
+ }
+
+ if (start > -1)
+ {
+ string lockHint = AppendLockHint(mode, alias);
+ buffer.Remove(start, end - start + 1);
+ buffer.Insert(start, lockHint);
+ correction += (lockHint.Length - alias.Length);
+ }
+ }
+ }
+ return new SqlString(buffer.ToString());
+ }
+
+ public override int RegisterResultSetOutParameter(DbCommand statement, int position)
+ {
+ return position;
+ }
+
+ public override DbDataReader GetResultSet(DbCommand statement)
+ {
+ return statement.ExecuteReader();
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate/Driver/SybaseAseClientDriver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Driver/SybaseAseClientDriver.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Driver/SybaseAseClientDriver.cs 2011-04-10 16:12:26 UTC (rev 5649)
@@ -0,0 +1,36 @@
+using System;
+
+namespace NHibernate.Driver
+{
+ /// <summary>
+ /// This provides a driver for Sybase ASE 15 using the ADO.NET driver.
+ /// </summary>
+ /// <remarks>
+ /// You will need the following libraries available to your application:
+ /// <ul>
+ /// <li>Sybase.AdoNet2.AseClient.dll</li>
+ /// <li>sybdrvado20.dll</li>
+ /// </ul>
+ /// </remarks>
+ public class SybaseAseClientDriver : ReflectionBasedDriver
+ {
+ public SybaseAseClientDriver() : base("Sybase.AdoNet2.AseClient", "Sybase.Data.AseClient.AseConnection", "Sybase.Data.AseClient.AseCommand")
+ {
+ }
+
+ public override string NamedPrefix
+ {
+ get { return "@"; }
+ }
+
+ public override bool UseNamedPrefixInParameter
+ {
+ get { return true; }
+ }
+
+ public override bool UseNamedPrefixInSql
+ {
+ get { return true; }
+ }
+ }
+}
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-09 16:01:06 UTC (rev 5648)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-10 16:12:26 UTC (rev 5649)
@@ -140,6 +140,7 @@
<Compile Include="Dialect\PostgreSQLDialect.cs" />
<Compile Include="Dialect\Schema\PostgreSQLMetadata.cs" />
<Compile Include="Dialect\SQLiteDialect.cs" />
+ <Compile Include="Dialect\SybaseASE15Dialect.cs" />
<Compile Include="Dialect\SybaseSQLAnywhere10Dialect.cs" />
<Compile Include="Dialect\SybaseSQLAnywhere11Dialect.cs" />
<Compile Include="Dialect\TypeNames.cs" />
@@ -159,6 +160,7 @@
<Compile Include="Driver\SqlClientDriver.cs" />
<Compile Include="Driver\BasicResultSetsCommand.cs" />
<Compile Include="Driver\SQLiteDriver.cs" />
+ <Compile Include="Driver\SybaseAseClientDriver.cs" />
<Compile Include="Engine\Cascade.cs" />
<Compile Include="Engine\IBatcher.cs" />
<Compile Include="Engine\IMapping.cs" />
Added: trunk/nhibernate/src/NHibernate.Config.Templates/SybaseASE.cfg.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Config.Templates/SybaseASE.cfg.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Config.Templates/SybaseASE.cfg.xml 2011-04-10 16:12:26 UTC (rev 5649)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+This template was written to work with NHibernate.Test.
+Copy the template to your NHibernate.Test project folder and rename it hibernate.cfg.xml. Change it
+for your own use before compiling tests in Visual Studio.
+-->
+<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
+ <session-factory name="NHibernate.Test">
+ <property name="connection.driver_class">NHibernate.Driver.SybaseAseClientDriver</property>
+ <property name="connection.connection_string">
+ Data Source=10.0.0.1;Port=5000;Database=nhibernate;User ID=nhibernate;Password=password
+ </property>
+ <property name="dialect">NHibernate.Dialect.SybaseASE15Dialect</property>
+ <property name="query.substitutions">true=1;false=0</property>
+ </session-factory>
+</hibernate-configuration>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jul...@us...> - 2011-04-10 16:38:32
|
Revision: 5650
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5650&view=rev
Author: julian-maughan
Date: 2011-04-10 16:38:24 +0000 (Sun, 10 Apr 2011)
Log Message:
-----------
Deprecated badly-named Sybase ASA/SQLAnywhere drivers. Updated dialects to use non-deprecated drivers.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Dialect/SybaseASA9Dialect.cs
trunk/nhibernate/src/NHibernate/Dialect/SybaseSQLAnywhere10Dialect.cs
trunk/nhibernate/src/NHibernate/Dialect/SybaseSQLAnywhere11Dialect.cs
trunk/nhibernate/src/NHibernate/Driver/ASA10ClientDriver.cs
trunk/nhibernate/src/NHibernate/Driver/ASAClientDriver.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Driver/SybaseAsaClientDriver.cs
trunk/nhibernate/src/NHibernate/Driver/SybaseSQLAnywhereDriver.cs
Modified: trunk/nhibernate/src/NHibernate/Dialect/SybaseASA9Dialect.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Dialect/SybaseASA9Dialect.cs 2011-04-10 16:12:26 UTC (rev 5649)
+++ trunk/nhibernate/src/NHibernate/Dialect/SybaseASA9Dialect.cs 2011-04-10 16:38:24 UTC (rev 5650)
@@ -24,7 +24,7 @@
/// </listheader>
/// <item>
/// <term>connection.driver_class</term>
- /// <description><see cref="NHibernate.Driver.ASAClientDriver" /></description>
+ /// <description><see cref="NHibernate.Driver.SybaseAsaClientDriver" /></description>
/// </item>
/// <item>
/// <term>prepare_sql</term>
@@ -36,7 +36,7 @@
{
public SybaseASA9Dialect()
{
- DefaultProperties[Environment.ConnectionDriver] = "NHibernate.Driver.ASAClientDriver";
+ DefaultProperties[Environment.ConnectionDriver] = "NHibernate.Driver.SybaseAsaClientDriver";
DefaultProperties[Environment.PrepareSql] = "false";
RegisterColumnType(DbType.AnsiStringFixedLength, 255, "CHAR($l)");
@@ -77,7 +77,6 @@
RegisterFunction("nullif", new StandardSafeSQLFunction("nullif", 2));
RegisterFunction("lower", new StandardSafeSQLFunction("lower", NHibernateUtil.String, 1));
RegisterFunction("upper", new StandardSafeSQLFunction("upper", NHibernateUtil.String, 1));
-
RegisterFunction("now", new StandardSQLFunction("now"));
RegisterKeyword("top");
@@ -96,7 +95,7 @@
public override SqlString GetLimitString(SqlString querySqlString, int offset, int limit)
{
int intSelectInsertPoint = GetAfterSelectInsertPoint(querySqlString);
- string strLimit = string.Format(" TOP {0} START AT {1}", limit, offset + 1);
+ string strLimit = string.Format(" top {0} start at {1}", limit, offset + 1);
return querySqlString.Insert(intSelectInsertPoint, strLimit);
}
@@ -135,16 +134,14 @@
get { return "select @@identity"; }
}
- /// <summary></summary>
public override string IdentityColumnString
{
- get { return "IDENTITY NOT NULL"; }
+ get { return "identity not null"; }
}
- /// <summary></summary>
public override string NoColumnsInsertString
{
- get { return "DEFAULT VALUES"; }
+ get { return "default values"; }
}
/// <summary>
Modified: trunk/nhibernate/src/NHibernate/Dialect/SybaseSQLAnywhere10Dialect.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Dialect/SybaseSQLAnywhere10Dialect.cs 2011-04-10 16:12:26 UTC (rev 5649)
+++ trunk/nhibernate/src/NHibernate/Dialect/SybaseSQLAnywhere10Dialect.cs 2011-04-10 16:38:24 UTC (rev 5650)
@@ -38,30 +38,29 @@
/// You should have received a copy of the GNU Lesser General Public
/// License along with this library; if not, write to the Free Software
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- ///
/// </summary>
/// <remarks>
/// The dialect defaults the following configuration properties:
/// <list type="table">
- /// <listheader>
- /// <term>Property</term>
- /// <description>Default Value</description>
- /// </listheader>
- /// <item>
- /// <term>connection.driver_class</term>
- /// <description><see cref="NHibernate.Driver.ASA10ClientDriver" /></description>
- /// </item>
- /// <item>
- /// <term>prepare_sql</term>
- /// <description><see langword="false" /></description>
- /// </item>
+ /// <listheader>
+ /// <term>Property</term>
+ /// <description>Default Value</description>
+ /// </listheader>
+ /// <item>
+ /// <term>connection.driver_class</term>
+ /// <description><see cref="NHibernate.Driver.SybaseSQLAnywhereDriver" /></description>
+ /// </item>
+ /// <item>
+ /// <term>prepare_sql</term>
+ /// <description><see langword="false" /></description>
+ /// </item>
/// </list>
/// </remarks>
public class SybaseSQLAnywhere10Dialect : Dialect
{
public SybaseSQLAnywhere10Dialect()
{
- DefaultProperties[Environment.ConnectionDriver] = "NHibernate.Driver.ASA10ClientDriver";
+ DefaultProperties[Environment.ConnectionDriver] = "NHibernate.Driver.SybaseSQLAnywhereDriver";
DefaultProperties[Environment.PrepareSql] = "false";
RegisterCharacterTypeMappings();
@@ -72,298 +71,298 @@
RegisterKeywords();
}
- protected void RegisterCharacterTypeMappings()
+ protected virtual void RegisterCharacterTypeMappings()
{
- RegisterColumnType( DbType.AnsiStringFixedLength, "CHAR(1)" );
- RegisterColumnType( DbType.AnsiStringFixedLength, 32767, "CHAR($l)" );
- RegisterColumnType( DbType.AnsiString, "VARCHAR(1)" );
- RegisterColumnType( DbType.AnsiString, 32767, "VARCHAR($l)" );
- RegisterColumnType( DbType.AnsiString, 2147483647, "LONG VARCHAR" );
- RegisterColumnType( DbType.StringFixedLength, "NCHAR(1)" );
- RegisterColumnType( DbType.StringFixedLength, 32767, "NCHAR($l)" );
- RegisterColumnType( DbType.String, "NVARCHAR(1)" );
- RegisterColumnType( DbType.String, 32767, "NVARCHAR($l)" );
- RegisterColumnType( DbType.String, 2147483647, "LONG NVARCHAR" );
- RegisterColumnType( DbType.Binary, "BINARY(1)" );
- RegisterColumnType( DbType.Binary, 32767, "VARBINARY($l)" );
- RegisterColumnType( DbType.Binary, 2147483647, "LONG VARBINARY" );
- RegisterColumnType( DbType.Guid, "UNIQUEIDENTIFIER");
+ RegisterColumnType(DbType.AnsiStringFixedLength, "CHAR(1)");
+ RegisterColumnType(DbType.AnsiStringFixedLength, 32767, "CHAR($l)");
+ RegisterColumnType(DbType.AnsiString, "VARCHAR(1)");
+ RegisterColumnType(DbType.AnsiString, 32767, "VARCHAR($l)");
+ RegisterColumnType(DbType.AnsiString, 2147483647, "LONG VARCHAR");
+ RegisterColumnType(DbType.StringFixedLength, "NCHAR(1)");
+ RegisterColumnType(DbType.StringFixedLength, 32767, "NCHAR($l)");
+ RegisterColumnType(DbType.String, "NVARCHAR(1)");
+ RegisterColumnType(DbType.String, 32767, "NVARCHAR($l)");
+ RegisterColumnType(DbType.String, 2147483647, "LONG NVARCHAR");
+ RegisterColumnType(DbType.Binary, "BINARY(1)");
+ RegisterColumnType(DbType.Binary, 32767, "VARBINARY($l)");
+ RegisterColumnType(DbType.Binary, 2147483647, "LONG VARBINARY");
+ RegisterColumnType(DbType.Guid, "UNIQUEIDENTIFIER");
}
- protected void RegisterNumericTypeMappings()
+ protected virtual void RegisterNumericTypeMappings()
{
- RegisterColumnType( DbType.Boolean, "BIT" ); // BIT type is NOT NULL by default
- RegisterColumnType( DbType.Int64, "BIGINT" );
- RegisterColumnType( DbType.UInt64, "UNSIGNED BIGINT");
- RegisterColumnType( DbType.Int16, "SMALLINT" );
- RegisterColumnType( DbType.UInt16,"UNSIGNED SMALLINT");
- RegisterColumnType( DbType.Int32, "INTEGER" );
- RegisterColumnType( DbType.UInt32, "UNSIGNED INTEGER");
- RegisterColumnType( DbType.Single, "REAL" );
- RegisterColumnType( DbType.Double, "DOUBLE" );
- RegisterColumnType( DbType.Decimal, "NUMERIC(19,$l)" ); // Precision ranges from 0-127
+ RegisterColumnType(DbType.Boolean, "BIT"); // BIT type is NOT NULL by default
+ RegisterColumnType(DbType.Int64, "BIGINT");
+ RegisterColumnType(DbType.UInt64, "UNSIGNED BIGINT");
+ RegisterColumnType(DbType.Int16, "SMALLINT");
+ RegisterColumnType(DbType.UInt16,"UNSIGNED SMALLINT");
+ RegisterColumnType(DbType.Int32, "INTEGER");
+ RegisterColumnType(DbType.UInt32, "UNSIGNED INTEGER");
+ RegisterColumnType(DbType.Single, "REAL");
+ RegisterColumnType(DbType.Double, "DOUBLE");
+ RegisterColumnType(DbType.Decimal, "NUMERIC(19,$l)"); // Precision ranges from 0-127
}
- protected void RegisterDateTimeTypeMappings()
+ protected virtual void RegisterDateTimeTypeMappings()
{
- RegisterColumnType( DbType.Date, "DATE" );
- RegisterColumnType( DbType.Time, "TIME" );
- RegisterColumnType( DbType.DateTime, "TIMESTAMP" );
+ RegisterColumnType(DbType.Date, "DATE");
+ RegisterColumnType(DbType.Time, "TIME");
+ RegisterColumnType(DbType.DateTime, "TIMESTAMP");
}
- protected void RegisterReverseNHibernateTypeMappings() {}
+ protected virtual void RegisterReverseNHibernateTypeMappings() {}
- protected void RegisterFunctions()
+ protected virtual void RegisterFunctions()
{
RegisterMathFunctions();
- RegisterXMLFunctions();
+ RegisterXmlFunctions();
RegisterAggregationFunctions();
RegisterBitFunctions();
RegisterDateFunctions();
RegisterStringFunctions();
- RegisterSOAPFunctions();
+ RegisterSoapFunctions();
RegisterMiscellaneousFunctions();
}
- protected void RegisterMathFunctions()
+ protected virtual void RegisterMathFunctions()
{
// mathematical functions
- RegisterFunction( "abs", new StandardSQLFunction("abs") );
- RegisterFunction( "acos", new StandardSQLFunction("acos", NHibernateUtil.Double) );
- RegisterFunction( "asin", new StandardSQLFunction("asin", NHibernateUtil.Double) );
- RegisterFunction( "atan", new StandardSQLFunction("atan", NHibernateUtil.Double) );
- RegisterFunction( "atan2", new StandardSQLFunction("atan2", NHibernateUtil.Double) );
- RegisterFunction( "ceiling", new StandardSQLFunction("ceiling", NHibernateUtil.Double) );
- RegisterFunction( "cos", new StandardSQLFunction("cos", NHibernateUtil.Double) );
- RegisterFunction( "cot", new StandardSQLFunction("cot", NHibernateUtil.Double) );
- RegisterFunction( "degrees", new StandardSQLFunction("degrees", NHibernateUtil.Double) );
- RegisterFunction( "exp", new StandardSQLFunction("exp", NHibernateUtil.Double) );
- RegisterFunction( "floor", new StandardSQLFunction("floor", NHibernateUtil.Double) );
- RegisterFunction( "log", new StandardSQLFunction("log", NHibernateUtil.Double) );
- RegisterFunction( "log10", new StandardSQLFunction("log10", NHibernateUtil.Double) );
- RegisterFunction( "mod", new StandardSQLFunction("mod") );
- RegisterFunction( "pi", new NoArgSQLFunction("pi", NHibernateUtil.Double, true ) );
- RegisterFunction( "power", new StandardSQLFunction("power", NHibernateUtil.Double) );
- RegisterFunction( "radians", new StandardSQLFunction("radians", NHibernateUtil.Double) );
- RegisterFunction( "rand", new StandardSQLFunction("rand", NHibernateUtil.Double) );
- RegisterFunction( "remainder", new StandardSQLFunction("remainder") );
- RegisterFunction( "round", new StandardSQLFunction("round") );
- RegisterFunction( "sign", new StandardSQLFunction("sign", NHibernateUtil.Int32) );
- RegisterFunction( "sin", new StandardSQLFunction("sin", NHibernateUtil.Double) );
- RegisterFunction( "sqrt", new StandardSQLFunction("sqrt", NHibernateUtil.Double) );
- RegisterFunction( "tan", new StandardSQLFunction("tan", NHibernateUtil.Double) );
- RegisterFunction( "truncate", new StandardSQLFunction("truncate") );
+ RegisterFunction("abs", new StandardSQLFunction("abs"));
+ RegisterFunction("acos", new StandardSQLFunction("acos", NHibernateUtil.Double));
+ RegisterFunction("asin", new StandardSQLFunction("asin", NHibernateUtil.Double));
+ RegisterFunction("atan", new StandardSQLFunction("atan", NHibernateUtil.Double));
+ RegisterFunction("atan2", new StandardSQLFunction("atan2", NHibernateUtil.Double));
+ RegisterFunction("ceiling", new StandardSQLFunction("ceiling", NHibernateUtil.Double));
+ RegisterFunction("cos", new StandardSQLFunction("cos", NHibernateUtil.Double));
+ RegisterFunction("cot", new StandardSQLFunction("cot", NHibernateUtil.Double));
+ RegisterFunction("degrees", new StandardSQLFunction("degrees", NHibernateUtil.Double));
+ RegisterFunction("exp", new StandardSQLFunction("exp", NHibernateUtil.Double));
+ RegisterFunction("floor", new StandardSQLFunction("floor", NHibernateUtil.Double));
+ RegisterFunction("log", new StandardSQLFunction("log", NHibernateUtil.Double));
+ RegisterFunction("log10", new StandardSQLFunction("log10", NHibernateUtil.Double));
+ RegisterFunction("mod", new StandardSQLFunction("mod"));
+ RegisterFunction("pi", new NoArgSQLFunction("pi", NHibernateUtil.Double, true ));
+ RegisterFunction("power", new StandardSQLFunction("power", NHibernateUtil.Double));
+ RegisterFunction("radians", new StandardSQLFunction("radians", NHibernateUtil.Double));
+ RegisterFunction("rand", new StandardSQLFunction("rand", NHibernateUtil.Double));
+ RegisterFunction("remainder", new StandardSQLFunction("remainder"));
+ RegisterFunction("round", new StandardSQLFunction("round"));
+ RegisterFunction("sign", new StandardSQLFunction("sign", NHibernateUtil.Int32));
+ RegisterFunction("sin", new StandardSQLFunction("sin", NHibernateUtil.Double));
+ RegisterFunction("sqrt", new StandardSQLFunction("sqrt", NHibernateUtil.Double));
+ RegisterFunction("tan", new StandardSQLFunction("tan", NHibernateUtil.Double));
+ RegisterFunction("truncate", new StandardSQLFunction("truncate"));
}
- protected void RegisterXMLFunctions()
+ protected virtual void RegisterXmlFunctions()
{
// XML scalar functions only
- RegisterFunction( "xmlconcat", new VarArgsSQLFunction( NHibernateUtil.String, "xmlconcat(", ",", ")" ) );
- RegisterFunction( "xmlelement", new VarArgsSQLFunction( NHibernateUtil.String, "xmlelement(", ",", ")" ) );
- RegisterFunction( "xmlgen", new VarArgsSQLFunction( NHibernateUtil.String, "xmlgen(", ",", ")" ) );
+ RegisterFunction("xmlconcat", new VarArgsSQLFunction( NHibernateUtil.String, "xmlconcat(", ",", ")"));
+ RegisterFunction("xmlelement", new VarArgsSQLFunction( NHibernateUtil.String, "xmlelement(", ",", ")"));
+ RegisterFunction("xmlgen", new VarArgsSQLFunction( NHibernateUtil.String, "xmlgen(", ",", ")"));
// missing: XMLForest().
}
- protected void RegisterAggregationFunctions()
+ protected virtual void RegisterAggregationFunctions()
{
// basic aggregate, linear regression OLAP, and window functions
- RegisterFunction( "bit_or", new StandardSQLFunction("bit_or") );
- RegisterFunction( "bit_and", new StandardSQLFunction("bit_and") );
- RegisterFunction( "bit_xor", new StandardSQLFunction("bit_xor") );
- RegisterFunction( "covar_pop", new StandardSQLFunction("covar_pop", NHibernateUtil.Double) );
- RegisterFunction( "covar_samp", new StandardSQLFunction("covar_samp", NHibernateUtil.Double) );
- RegisterFunction( "corr", new StandardSQLFunction("corr", NHibernateUtil.Double) );
- RegisterFunction( "first_value", new VarArgsSQLFunction(NHibernateUtil.Double, "first_value(", ",", ")" ));
- RegisterFunction( "grouping", new StandardSQLFunction("grouping", NHibernateUtil.Int32) );
- RegisterFunction( "last_value", new VarArgsSQLFunction(NHibernateUtil.Double, "last_value(", ",", ")" ));
- RegisterFunction( "list", new VarArgsSQLFunction("list(", ",", ")" ));
- RegisterFunction( "regr_avgx", new StandardSQLFunction("regr_avgx", NHibernateUtil.Double) );
- RegisterFunction( "regr_avgy", new StandardSQLFunction("regr_avgy", NHibernateUtil.Double) );
- RegisterFunction( "regr_count", new StandardSQLFunction("regr_count", NHibernateUtil.Double) );
- RegisterFunction( "regr_intercept", new StandardSQLFunction("regr_intercept", NHibernateUtil.Double) );
- RegisterFunction( "regr_r2", new StandardSQLFunction("regr_r2", NHibernateUtil.Double) );
- RegisterFunction( "regr_slope", new StandardSQLFunction("regr_slope", NHibernateUtil.Double) );
- RegisterFunction( "regr_sxx", new StandardSQLFunction("regr_sxx", NHibernateUtil.Double) );
- RegisterFunction( "regr_sxy", new StandardSQLFunction("regr_sxy", NHibernateUtil.Double) );
- RegisterFunction( "regr_syy", new StandardSQLFunction("regr_syy", NHibernateUtil.Double) );
- RegisterFunction( "set_bits", new StandardSQLFunction("set_bits") );
- RegisterFunction( "stddev", new StandardSQLFunction("stddev", NHibernateUtil.Double) );
- RegisterFunction( "stddev_pop", new StandardSQLFunction("stddev_pop", NHibernateUtil.Double) );
- RegisterFunction( "stddev_samp", new StandardSQLFunction("stddev_samp", NHibernateUtil.Double) );
- RegisterFunction( "variance", new StandardSQLFunction("variance", NHibernateUtil.Double) );
- RegisterFunction( "var_pop", new StandardSQLFunction("var_pop", NHibernateUtil.Double) );
- RegisterFunction( "var_samp", new StandardSQLFunction("var_samp", NHibernateUtil.Double) );
- RegisterFunction( "xmlagg", new StandardSQLFunction("xmlagg") );
+ RegisterFunction("bit_or", new StandardSQLFunction("bit_or"));
+ RegisterFunction("bit_and", new StandardSQLFunction("bit_and"));
+ RegisterFunction("bit_xor", new StandardSQLFunction("bit_xor"));
+ RegisterFunction("covar_pop", new StandardSQLFunction("covar_pop", NHibernateUtil.Double));
+ RegisterFunction("covar_samp", new StandardSQLFunction("covar_samp", NHibernateUtil.Double));
+ RegisterFunction("corr", new StandardSQLFunction("corr", NHibernateUtil.Double));
+ RegisterFunction("first_value", new VarArgsSQLFunction(NHibernateUtil.Double, "first_value(", ",", ")"));
+ RegisterFunction("grouping", new StandardSQLFunction("grouping", NHibernateUtil.Int32));
+ RegisterFunction("last_value", new VarArgsSQLFunction(NHibernateUtil.Double, "last_value(", ",", ")"));
+ RegisterFunction("list", new VarArgsSQLFunction("list(", ",", ")"));
+ RegisterFunction("regr_avgx", new StandardSQLFunction("regr_avgx", NHibernateUtil.Double));
+ RegisterFunction("regr_avgy", new StandardSQLFunction("regr_avgy", NHibernateUtil.Double));
+ RegisterFunction("regr_count", new StandardSQLFunction("regr_count", NHibernateUtil.Double));
+ RegisterFunction("regr_intercept", new StandardSQLFunction("regr_intercept", NHibernateUtil.Double));
+ RegisterFunction("regr_r2", new StandardSQLFunction("regr_r2", NHibernateUtil.Double));
+ RegisterFunction("regr_slope", new StandardSQLFunction("regr_slope", NHibernateUtil.Double));
+ RegisterFunction("regr_sxx", new StandardSQLFunction("regr_sxx", NHibernateUtil.Double));
+ RegisterFunction("regr_sxy", new StandardSQLFunction("regr_sxy", NHibernateUtil.Double));
+ RegisterFunction("regr_syy", new StandardSQLFunction("regr_syy", NHibernateUtil.Double));
+ RegisterFunction("set_bits", new StandardSQLFunction("set_bits"));
+ RegisterFunction("stddev", new StandardSQLFunction("stddev", NHibernateUtil.Double));
+ RegisterFunction("stddev_pop", new StandardSQLFunction("stddev_pop", NHibernateUtil.Double));
+ RegisterFunction("stddev_samp", new StandardSQLFunction("stddev_samp", NHibernateUtil.Double));
+ RegisterFunction("variance", new StandardSQLFunction("variance", NHibernateUtil.Double));
+ RegisterFunction("var_pop", new StandardSQLFunction("var_pop", NHibernateUtil.Double));
+ RegisterFunction("var_samp", new StandardSQLFunction("var_samp", NHibernateUtil.Double));
+ RegisterFunction("xmlagg", new StandardSQLFunction("xmlagg"));
}
- protected void RegisterBitFunctions()
+ protected virtual void RegisterBitFunctions()
{
- RegisterFunction( "bit_length", new StandardSQLFunction("bit_length", NHibernateUtil.Int32) );
- RegisterFunction( "bit_substr", new StandardSQLFunction("bit_substr") );
- RegisterFunction( "get_bit", new StandardSQLFunction("get_bit", NHibernateUtil.Boolean) );
- RegisterFunction( "set_bit", new VarArgsSQLFunction("set_bit(", ",", ")" ));
+ RegisterFunction("bit_length", new StandardSQLFunction("bit_length", NHibernateUtil.Int32));
+ RegisterFunction("bit_substr", new StandardSQLFunction("bit_substr"));
+ RegisterFunction("get_bit", new StandardSQLFunction("get_bit", NHibernateUtil.Boolean));
+ RegisterFunction("set_bit", new VarArgsSQLFunction("set_bit(", ",", ")"));
}
- protected void RegisterDateFunctions()
+ protected virtual void RegisterDateFunctions()
{
- RegisterFunction( "date", new StandardSQLFunction("date", NHibernateUtil.Date) );
- RegisterFunction( "dateadd", new StandardSQLFunction("dateadd", NHibernateUtil.Timestamp) );
- RegisterFunction( "datediff", new StandardSQLFunction("datediff", NHibernateUtil.Int32) );
- RegisterFunction( "dateformat", new StandardSQLFunction("dateformat", NHibernateUtil.String) );
- RegisterFunction( "datename", new StandardSQLFunction("datename", NHibernateUtil.String) );
- RegisterFunction( "datepart", new StandardSQLFunction("datepart", NHibernateUtil.Int32) );
- RegisterFunction( "datetime", new StandardSQLFunction("datetime", NHibernateUtil.Timestamp) );
- RegisterFunction( "day", new StandardSQLFunction("day", NHibernateUtil.Int32) );
- RegisterFunction( "dayname", new StandardSQLFunction("dayname", NHibernateUtil.String) );
- RegisterFunction( "days", new StandardSQLFunction("days") );
- RegisterFunction( "dow", new StandardSQLFunction("dow", NHibernateUtil.Int32) );
- RegisterFunction( "getdate", new StandardSQLFunction("getdate", NHibernateUtil.Timestamp) );
- RegisterFunction( "hour", new StandardSQLFunction("hour", NHibernateUtil.Int32) );
- RegisterFunction( "hours", new StandardSQLFunction("hours") );
- RegisterFunction( "minute", new StandardSQLFunction("minute", NHibernateUtil.Int32) );
- RegisterFunction( "minutes", new StandardSQLFunction("minutes") );
- RegisterFunction( "month", new StandardSQLFunction("month", NHibernateUtil.Int32) );
- RegisterFunction( "monthname", new StandardSQLFunction("monthname", NHibernateUtil.String) );
- RegisterFunction( "months", new StandardSQLFunction("months") );
- RegisterFunction( "now", new NoArgSQLFunction("now", NHibernateUtil.Timestamp) );
- RegisterFunction( "quarter", new StandardSQLFunction("quarter", NHibernateUtil.Int32) );
- RegisterFunction( "second", new StandardSQLFunction("second", NHibernateUtil.Int32) );
- RegisterFunction( "seconds", new StandardSQLFunction("seconds") );
- RegisterFunction( "today", new NoArgSQLFunction("now", NHibernateUtil.Date) );
- RegisterFunction( "weeks", new StandardSQLFunction("weeks") );
- RegisterFunction( "year", new StandardSQLFunction("year", NHibernateUtil.Int32) );
- RegisterFunction( "years", new StandardSQLFunction("years") );
- RegisterFunction( "ymd", new StandardSQLFunction("ymd", NHibernateUtil.Date) );
+ RegisterFunction("date", new StandardSQLFunction("date", NHibernateUtil.Date));
+ RegisterFunction("dateadd", new StandardSQLFunction("dateadd", NHibernateUtil.Timestamp));
+ RegisterFunction("datediff", new StandardSQLFunction("datediff", NHibernateUtil.Int32));
+ RegisterFunction("dateformat", new StandardSQLFunction("dateformat", NHibernateUtil.String));
+ RegisterFunction("datename", new StandardSQLFunction("datename", NHibernateUtil.String));
+ RegisterFunction("datepart", new StandardSQLFunction("datepart", NHibernateUtil.Int32));
+ RegisterFunction("datetime", new StandardSQLFunction("datetime", NHibernateUtil.Timestamp));
+ RegisterFunction("day", new StandardSQLFunction("day", NHibernateUtil.Int32));
+ RegisterFunction("dayname", new StandardSQLFunction("dayname", NHibernateUtil.String));
+ RegisterFunction("days", new StandardSQLFunction("days"));
+ RegisterFunction("dow", new StandardSQLFunction("dow", NHibernateUtil.Int32));
+ RegisterFunction("getdate", new StandardSQLFunction("getdate", NHibernateUtil.Timestamp));
+ RegisterFunction("hour", new StandardSQLFunction("hour", NHibernateUtil.Int32));
+ RegisterFunction("hours", new StandardSQLFunction("hours"));
+ RegisterFunction("minute", new StandardSQLFunction("minute", NHibernateUtil.Int32));
+ RegisterFunction("minutes", new StandardSQLFunction("minutes"));
+ RegisterFunction("month", new StandardSQLFunction("month", NHibernateUtil.Int32));
+ RegisterFunction("monthname", new StandardSQLFunction("monthname", NHibernateUtil.String));
+ RegisterFunction("months", new StandardSQLFunction("months"));
+ RegisterFunction("now", new NoArgSQLFunction("now", NHibernateUtil.Timestamp));
+ RegisterFunction("quarter", new StandardSQLFunction("quarter", NHibernateUtil.Int32));
+ RegisterFunction("second", new StandardSQLFunction("second", NHibernateUtil.Int32));
+ RegisterFunction("seconds", new StandardSQLFunction("seconds"));
+ RegisterFunction("today", new NoArgSQLFunction("now", NHibernateUtil.Date));
+ RegisterFunction("weeks", new StandardSQLFunction("weeks"));
+ RegisterFunction("year", new StandardSQLFunction("year", NHibernateUtil.Int32));
+ RegisterFunction("years", new StandardSQLFunction("years"));
+ RegisterFunction("ymd", new StandardSQLFunction("ymd", NHibernateUtil.Date));
// compatibility functions
- RegisterFunction( "current_timestamp", new NoArgSQLFunction("getdate", NHibernateUtil.Timestamp, true ) );
- RegisterFunction( "current_time", new NoArgSQLFunction("getdate", NHibernateUtil.Time, true ) );
- RegisterFunction( "current_date", new NoArgSQLFunction("getdate", NHibernateUtil.Date, true ) );
+ RegisterFunction("current_timestamp", new NoArgSQLFunction("getdate", NHibernateUtil.Timestamp, true ));
+ RegisterFunction("current_time", new NoArgSQLFunction("getdate", NHibernateUtil.Time, true ));
+ RegisterFunction("current_date", new NoArgSQLFunction("getdate", NHibernateUtil.Date, true ));
}
- protected void RegisterStringFunctions()
+ protected virtual void RegisterStringFunctions()
{
- RegisterFunction( "ascii", new StandardSQLFunction("ascii", NHibernateUtil.Int32) );
- RegisterFunction( "byte64_decode", new StandardSQLFunction("byte64_decode", NHibernateUtil.StringClob ) );
- RegisterFunction( "byte64_encode", new StandardSQLFunction("byte64_encode", NHibernateUtil.StringClob ) );
- RegisterFunction( "byte_length", new StandardSQLFunction("byte_length", NHibernateUtil.Int32) );
- RegisterFunction( "byte_substr", new VarArgsSQLFunction( NHibernateUtil.String, "byte_substr(",",",")" ) );
- RegisterFunction( "char", new StandardSQLFunction("char", NHibernateUtil.String ) );
- RegisterFunction( "charindex", new StandardSQLFunction("charindex", NHibernateUtil.Int32) );
- RegisterFunction( "char_length", new StandardSQLFunction("char_length", NHibernateUtil.Int32) );
- RegisterFunction( "compare", new VarArgsSQLFunction( NHibernateUtil.Int32, "compare(",",",")" ) );
- RegisterFunction( "compress", new VarArgsSQLFunction( NHibernateUtil.BinaryBlob, "compress(",",",")" ) );
- RegisterFunction( "concat", new VarArgsSQLFunction( NHibernateUtil.String, "(","+",")" ) );
- RegisterFunction( "csconvert", new VarArgsSQLFunction( NHibernateUtil.StringClob, "csconvert(",",",")" ) );
- RegisterFunction( "decompress", new VarArgsSQLFunction( NHibernateUtil.BinaryBlob, "decompress(",",",")" ) );
- RegisterFunction( "decrypt", new VarArgsSQLFunction( NHibernateUtil.BinaryBlob, "decrypt(",",",")" ) );
- RegisterFunction( "difference", new StandardSQLFunction("difference", NHibernateUtil.Int32) );
- RegisterFunction( "encrypt", new VarArgsSQLFunction( NHibernateUtil.BinaryBlob, "encrypt(",",",")" ) );
- RegisterFunction( "hash", new VarArgsSQLFunction( NHibernateUtil.String, "hash(",",",")" ) );
- RegisterFunction( "insertstr", new StandardSQLFunction("insertstr", NHibernateUtil.String) );
- RegisterFunction( "lcase", new StandardSQLFunction("lcase", NHibernateUtil.String) );
- RegisterFunction( "left", new StandardSQLFunction("left", NHibernateUtil.String) );
- RegisterFunction( "length", new StandardSQLFunction("length", NHibernateUtil.Int32) );
- RegisterFunction( "locate", new VarArgsSQLFunction( NHibernateUtil.Int32, "locate(",",",")" ) );
- RegisterFunction( "lower", new StandardSQLFunction("lower", NHibernateUtil.String) );
- RegisterFunction( "ltrim", new StandardSQLFunction("ltrim", NHibernateUtil.String) );
- RegisterFunction( "patindex", new StandardSQLFunction("patindex", NHibernateUtil.Int32) );
- RegisterFunction( "repeat", new StandardSQLFunction("repeat", NHibernateUtil.String) );
- RegisterFunction( "replace", new StandardSQLFunction("replace", NHibernateUtil.String) );
- RegisterFunction( "replicate", new StandardSQLFunction("replicate", NHibernateUtil.String) );
- RegisterFunction( "reverse", new StandardSQLFunction("reverse", NHibernateUtil.String) );
- RegisterFunction( "right", new StandardSQLFunction("right", NHibernateUtil.String) );
- RegisterFunction( "rtrim", new StandardSQLFunction("rtrim", NHibernateUtil.String) );
- RegisterFunction( "similar", new StandardSQLFunction("rtrim", NHibernateUtil.Int32) );
- RegisterFunction( "sortkey", new VarArgsSQLFunction( NHibernateUtil.Binary, "sortkey(",",",")" ) );
- RegisterFunction( "soundex", new StandardSQLFunction("soundex", NHibernateUtil.Int32) );
- RegisterFunction( "space", new StandardSQLFunction("space", NHibernateUtil.String) );
- RegisterFunction( "str", new VarArgsSQLFunction( NHibernateUtil.String, "str(",",",")" ) );
- RegisterFunction( "string", new VarArgsSQLFunction( NHibernateUtil.String, "string(",",",")" ) );
- RegisterFunction( "strtouuid", new StandardSQLFunction("strtouuid") );
- RegisterFunction( "stuff", new StandardSQLFunction("stuff", NHibernateUtil.String) );
+ RegisterFunction("ascii", new StandardSQLFunction("ascii", NHibernateUtil.Int32));
+ RegisterFunction("byte64_decode", new StandardSQLFunction("byte64_decode", NHibernateUtil.StringClob ));
+ RegisterFunction("byte64_encode", new StandardSQLFunction("byte64_encode", NHibernateUtil.StringClob ));
+ RegisterFunction("byte_length", new StandardSQLFunction("byte_length", NHibernateUtil.Int32));
+ RegisterFunction("byte_substr", new VarArgsSQLFunction( NHibernateUtil.String, "byte_substr(",",",")"));
+ RegisterFunction("char", new StandardSQLFunction("char...
[truncated message content] |
|
From: <fab...@us...> - 2011-04-10 17:55:11
|
Revision: 5651
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5651&view=rev
Author: fabiomaulo
Date: 2011-04-10 17:55:04 +0000 (Sun, 10 Apr 2011)
Log Message:
-----------
SimpleModelInspector (only as forward to explicit declaration) with minor refactoring
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs
trunk/nhibernate/src/NHibernate/Mapping/ByCode/FakeModelExplicitDeclarationsHolder.cs
trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelExplicitDeclarationsHolder.cs
trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinCustomizer.cs
trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ExplicitDeclarationsHolder.cs
trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelExplicitDeclarationsHolderExtensions.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/SplitPropertiesRegistrationTests.cs
trunk/nhibernate/src/NHibernate.Test/MappingByCode/ModelExplicitDeclarationsHolderMergeTest.cs
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs 2011-04-10 16:38:24 UTC (rev 5650)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs 2011-04-10 17:55:04 UTC (rev 5651)
@@ -382,11 +382,17 @@
persistentMembers.Add(member);
}
- public void AddAsPropertySplit(System.Type propertyContainer, string splitGroupId, MemberInfo member)
+ public void AddAsPropertySplit(SplitDefinition definition)
{
+ if (definition == null)
+ {
+ return;
+ }
/* Note: if the user "jump/exclude" a class and then map the property in two subclasses the usage of GetMemberFromDeclaringType() may cause a problem
for a legal usage... we will see when the case happen */
-
+ System.Type propertyContainer = definition.On;
+ string splitGroupId = definition.GroupId;
+ MemberInfo member = definition.Member;
var memberKey = member.GetMemberFromDeclaringType();
string splitGroup;
if (!memberSplitGroup.TryGetValue(memberKey, out splitGroup))
@@ -395,7 +401,7 @@
memberSplitGroup[memberKey] = splitGroupId;
}
- splitDefinitions.Add(new SplitDefinition(propertyContainer, splitGroup, member));
+ splitDefinitions.Add(definition);
}
private void AddTypeSplits(System.Type propertyContainer, string splitGroupId)
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/FakeModelExplicitDeclarationsHolder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/FakeModelExplicitDeclarationsHolder.cs 2011-04-10 16:38:24 UTC (rev 5650)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/FakeModelExplicitDeclarationsHolder.cs 2011-04-10 17:55:04 UTC (rev 5651)
@@ -200,9 +200,8 @@
public void AddAsProperty(MemberInfo member) {}
public void AddAsPersistentMember(MemberInfo member){}
+ public void AddAsPropertySplit(SplitDefinition definition) {}
- public void AddAsPropertySplit(System.Type propertyContainer, string splitGroupId, MemberInfo member) {}
-
#endregion
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelExplicitDeclarationsHolder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelExplicitDeclarationsHolder.cs 2011-04-10 16:38:24 UTC (rev 5650)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelExplicitDeclarationsHolder.cs 2011-04-10 17:55:04 UTC (rev 5651)
@@ -72,6 +72,6 @@
void AddAsMap(MemberInfo member);
void AddAsProperty(MemberInfo member);
void AddAsPersistentMember(MemberInfo member);
- void AddAsPropertySplit(System.Type propertyContainer, string splitGroupId, MemberInfo member);
+ void AddAsPropertySplit(SplitDefinition definition);
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinCustomizer.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinCustomizer.cs 2011-04-10 16:38:24 UTC (rev 5650)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinCustomizer.cs 2011-04-10 17:55:04 UTC (rev 5651)
@@ -85,90 +85,90 @@
public override void Set<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property, Action<ISetPropertiesMapper<TEntity, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping)
{
MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property);
- ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member);
+ ExplicitDeclarationsHolder.AddAsPropertySplit(new SplitDefinition(typeof (TEntity), splitGroupId, member));
base.Set(property, collectionMapping, mapping);
}
public override void Bag<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property, Action<IBagPropertiesMapper<TEntity, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping)
{
MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property);
- ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member);
+ ExplicitDeclarationsHolder.AddAsPropertySplit(new SplitDefinition(typeof(TEntity), splitGroupId, member));
base.Bag(property, collectionMapping, mapping);
}
public override void List<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property, Action<IListPropertiesMapper<TEntity, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping)
{
MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property);
- ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member);
+ ExplicitDeclarationsHolder.AddAsPropertySplit(new SplitDefinition(typeof(TEntity), splitGroupId, member));
base.List(property, collectionMapping, mapping);
}
public override void Map<TKey, TElement>(Expression<Func<TEntity, IDictionary<TKey, TElement>>> property, Action<IMapPropertiesMapper<TEntity, TKey, TElement>> collectionMapping, Action<IMapKeyRelation<TKey>> keyMapping, Action<ICollectionElementRelation<TElement>> mapping)
{
MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property);
- ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member);
+ ExplicitDeclarationsHolder.AddAsPropertySplit(new SplitDefinition(typeof(TEntity), splitGroupId, member));
base.Map(property, collectionMapping, keyMapping, mapping);
}
public override void Map<TKey, TElement>(Expression<Func<TEntity, IDictionary<TKey, TElement>>> property, Action<IMapPropertiesMapper<TEntity, TKey, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping)
{
MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property);
- ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member);
+ ExplicitDeclarationsHolder.AddAsPropertySplit(new SplitDefinition(typeof(TEntity), splitGroupId, member));
base.Map(property, collectionMapping, mapping);
}
public override void Property<TProperty>(Expression<Func<TEntity, TProperty>> property)
{
MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property);
- ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member);
+ ExplicitDeclarationsHolder.AddAsPropertySplit(new SplitDefinition(typeof(TEntity), splitGroupId, member));
base.Property(property);
}
public override void Property<TProperty>(Expression<Func<TEntity, TProperty>> property, Action<IPropertyMapper> mapping)
{
MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property);
- ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member);
+ ExplicitDeclarationsHolder.AddAsPropertySplit(new SplitDefinition(typeof(TEntity), splitGroupId, member));
base.Property(property, mapping);
}
public override void Property(FieldInfo member, Action<IPropertyMapper> mapping)
{
- ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member);
+ ExplicitDeclarationsHolder.AddAsPropertySplit(new SplitDefinition(typeof(TEntity), splitGroupId, member));
base.Property(member, mapping);
}
public override void Component<TComponent>(Expression<Func<TEntity, TComponent>> property, Action<IComponentMapper<TComponent>> mapping)
{
MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property);
- ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member);
+ ExplicitDeclarationsHolder.AddAsPropertySplit(new SplitDefinition(typeof(TEntity), splitGroupId, member));
base.Component(property, mapping);
}
public override void ManyToOne<TProperty>(Expression<Func<TEntity, TProperty>> property, Action<IManyToOneMapper> mapping)
{
MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property);
- ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member);
+ ExplicitDeclarationsHolder.AddAsPropertySplit(new SplitDefinition(typeof(TEntity), splitGroupId, member));
base.ManyToOne(property, mapping);
}
public override void ManyToOne<TProperty>(Expression<Func<TEntity, TProperty>> property)
{
MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property);
- ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member);
+ ExplicitDeclarationsHolder.AddAsPropertySplit(new SplitDefinition(typeof(TEntity), splitGroupId, member));
base.ManyToOne(property);
}
public override void Any<TProperty>(Expression<Func<TEntity, TProperty>> property, System.Type idTypeOfMetaType, Action<IAnyMapper> mapping)
{
MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property);
- ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member);
+ ExplicitDeclarationsHolder.AddAsPropertySplit(new SplitDefinition(typeof(TEntity), splitGroupId, member));
base.Any(property, idTypeOfMetaType, mapping);
}
public override void IdBag<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property, Action<IIdBagPropertiesMapper<TEntity, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping)
{
MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property);
- ExplicitDeclarationsHolder.AddAsPropertySplit(typeof(TEntity), splitGroupId, member);
+ ExplicitDeclarationsHolder.AddAsPropertySplit(new SplitDefinition(typeof(TEntity), splitGroupId, member));
base.IdBag(property, collectionMapping, mapping);
}
}
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ExplicitDeclarationsHolder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ExplicitDeclarationsHolder.cs 2011-04-10 16:38:24 UTC (rev 5650)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ExplicitDeclarationsHolder.cs 2011-04-10 17:55:04 UTC (rev 5651)
@@ -257,9 +257,9 @@
persistentMembers.Add(member);
}
- public void AddAsPropertySplit(System.Type propertyContainer, string splitGroupId, MemberInfo member)
+ public void AddAsPropertySplit(SplitDefinition definition)
{
- splitDefinitions.Add(new SplitDefinition(propertyContainer, splitGroupId, member));
+ splitDefinitions.Add(definition);
}
#endregion
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelExplicitDeclarationsHolderExtensions.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelExplicitDeclarationsHolderExtensions.cs 2011-04-10 16:38:24 UTC (rev 5650)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelExplicitDeclarationsHolderExtensions.cs 2011-04-10 17:55:04 UTC (rev 5651)
@@ -35,7 +35,7 @@
System.Array.ForEach(source.Dictionaries.ToArray(), destination.AddAsMap);
System.Array.ForEach(source.Properties.ToArray(), destination.AddAsProperty);
System.Array.ForEach(source.PersistentMembers.ToArray(), destination.AddAsPersistentMember);
- System.Array.ForEach(source.SplitDefinitions.ToArray(), x => destination.AddAsPropertySplit(x.On, x.GroupId, x.Member));
+ System.Array.ForEach(source.SplitDefinitions.ToArray(), destination.AddAsPropertySplit);
}
}
}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-10 17:55:04 UTC (rev 5651)
@@ -0,0 +1,640 @@
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+
+namespace NHibernate.Mapping.ByCode
+{
+ /// <summary>
+ /// A <see cref="IModelInspector"/> which allows customization of conditions with explicitly declared members.
+ /// </summary>
+ public class SimpleModelInspector : IModelInspector, IModelExplicitDeclarationsHolder
+ {
+ private readonly ExplicitlyDeclaredModel declaredModel = new ExplicitlyDeclaredModel();
+
+ private Func<System.Type, bool, bool> isEntity = (t, declared) => declared;
+ private Func<System.Type, bool, bool> isRootEntity = (t, declared) => declared;
+ private Func<System.Type, bool, bool> isTablePerClass = (t, declared) => declared;
+ private Func<SplitDefinition, bool, bool> isTablePerClassSplit = (sd, declared) => declared;
+ private Func<System.Type, bool, bool> isTablePerClassHierarchy = (t, declared) => declared;
+ private Func<System.Type, bool, bool> isTablePerConcreteClass = (t, declared) => declared;
+ private Func<System.Type, IEnumerable<string>, IEnumerable<string>> splitsForType = (t, declared) => declared;
+ private Func<System.Type, bool, bool> isComponent = (t, declared) => declared;
+
+ private Func<MemberInfo, bool, bool> isPersistentId = (m, declared) => declared;
+ private Func<MemberInfo, bool, bool> isPersistentProperty = (m, declared) => declared;
+ private Func<MemberInfo, bool, bool> isVersion = (m, declared) => declared;
+
+ private Func<MemberInfo, bool, bool> isProperty = (m, declared) => declared;
+ private Func<MemberInfo, bool, bool> isAny = (m, declared) => declared;
+ private Func<MemberInfo, bool, bool> isManyToMany = (m, declared) => declared;
+ private Func<MemberInfo, bool, bool> isManyToOne = (m, declared) => declared;
+ private Func<MemberInfo, bool, bool> isMemberOfNaturalId = (m, declared) => declared;
+ private Func<MemberInfo, bool, bool> isOneToMany = (m, declared) => declared;
+ private Func<MemberInfo, bool, bool> isOneToOne = (m, declared) => declared;
+
+ private Func<MemberInfo, bool, bool> isSet = (m, declared) => declared;
+ private Func<MemberInfo, bool, bool> isArray = (m, declared) => declared;
+ private Func<MemberInfo, bool, bool> isBag = (m, declared) => declared;
+ private Func<MemberInfo, bool, bool> isDictionary = (m, declared) => declared;
+ private Func<MemberInfo, bool, bool> isIdBag = (m, declared) => declared;
+ private Func<MemberInfo, bool, bool> isList = (m, declared) => declared;
+
+ #region IModelExplicitDeclarationsHolder Members
+
+ IEnumerable<System.Type> IModelExplicitDeclarationsHolder.RootEntities
+ {
+ get { return declaredModel.RootEntities; }
+ }
+
+ IEnumerable<System.Type> IModelExplicitDeclarationsHolder.Components
+ {
+ get { return declaredModel.Components; }
+ }
+
+ IEnumerable<System.Type> IModelExplicitDeclarationsHolder.TablePerClassEntities
+ {
+ get { return declaredModel.TablePerClassEntities; }
+ }
+
+ IEnumerable<System.Type> IModelExplicitDeclarationsHolder.TablePerClassHierarchyEntities
+ {
+ get { return declaredModel.TablePerClassHierarchyEntities; }
+ }
+
+ IEnumerable<System.Type> IModelExplicitDeclarationsHolder.TablePerConcreteClassEntities
+ {
+ get { return declaredModel.TablePerConcreteClassEntities; }
+ }
+
+ IEnumerable<MemberInfo> IModelExplicitDeclarationsHolder.OneToOneRelations
+ {
+ get { return declaredModel.OneToOneRelations; }
+ }
+
+ IEnumerable<MemberInfo> IModelExplicitDeclarationsHolder.ManyToOneRelations
+ {
+ get { return declaredModel.ManyToManyRelations; }
+ }
+
+ IEnumerable<MemberInfo> IModelExplicitDeclarationsHolder.ManyToManyRelations
+ {
+ get { return declaredModel.ManyToManyRelations; }
+ }
+
+ IEnumerable<MemberInfo> IModelExplicitDeclarationsHolder.OneToManyRelations
+ {
+ get { return declaredModel.OneToManyRelations; }
+ }
+
+ IEnumerable<MemberInfo> IModelExplicitDeclarationsHolder.Any
+ {
+ get { return declaredModel.Any; }
+ }
+
+ IEnumerable<MemberInfo> IModelExplicitDeclarationsHolder.Poids
+ {
+ get { return declaredModel.Poids; }
+ }
+
+ IEnumerable<MemberInfo> IModelExplicitDeclarationsHolder.VersionProperties
+ {
+ get { return declaredModel.VersionProperties; }
+ }
+
+ IEnumerable<MemberInfo> IModelExplicitDeclarationsHolder.NaturalIds
+ {
+ get { return declaredModel.NaturalIds; }
+ }
+
+ IEnumerable<MemberInfo> IModelExplicitDeclarationsHolder.Sets
+ {
+ get { return declaredModel.Sets; }
+ }
+
+ IEnumerable<MemberInfo> IModelExplicitDeclarationsHolder.Bags
+ {
+ get { return declaredModel.Bags; }
+ }
+
+ IEnumerable<MemberInfo> IModelExplicitDeclarationsHolder.IdBags
+ {
+ get { return declaredModel.IdBags; }
+ }
+
+ IEnumerable<MemberInfo> IModelExplicitDeclarationsHolder.Lists
+ {
+ get { return declaredModel.Lists; }
+ }
+
+ IEnumerable<MemberInfo> IModelExplicitDeclarationsHolder.Arrays
+ {
+ get { return declaredModel.Arrays; }
+ }
+
+ IEnumerable<MemberInfo> IModelExplicitDeclarationsHolder.Dictionaries
+ {
+ get { return declaredModel.Dictionaries; }
+ }
+
+ IEnumerable<MemberInfo> IModelExplicitDeclarationsHolder.Properties
+ {
+ get { return declaredModel.Properties; }
+ }
+
+ IEnumerable<MemberInfo> IModelExplicitDeclarationsHolder.PersistentMembers
+ {
+ get { return declaredModel.PersistentMembers; }
+ }
+
+ IEnumerable<SplitDefinition> IModelExplicitDeclarationsHolder.SplitDefinitions
+ {
+ get { return declaredModel.SplitDefinitions; }
+ }
+
+ IEnumerable<string> IModelExplicitDeclarationsHolder.GetSplitGroupsFor(System.Type type)
+ {
+ return declaredModel.GetSplitGroupsFor(type);
+ }
+
+ string IModelExplicitDeclarationsHolder.GetSplitGroupFor(MemberInfo member)
+ {
+ return declaredModel.GetSplitGroupFor(member);
+ }
+
+ void IModelExplicitDeclarationsHolder.AddAsRootEntity(System.Type type)
+ {
+ declaredModel.AddAsRootEntity(type);
+ }
+
+ void IModelExplicitDeclarationsHolder.AddAsComponent(System.Type type)
+ {
+ declaredModel.AddAsComponent(type);
+ }
+
+ void IModelExplicitDeclarationsHolder.AddAsTablePerClassEntity(System.Type type)
+ {
+ declaredModel.AddAsTablePerClassEntity(type);
+ }
+
+ void IModelExplicitDeclarationsHolder.AddAsTablePerClassHierarchyEntity(System.Type type)
+ {
+ declaredModel.AddAsTablePerClassHierarchyEntity(type);
+ }
+
+ void IModelExplicitDeclarationsHolder.AddAsTablePerConcreteClassEntity(System.Type type)
+ {
+ declaredModel.AddAsTablePerConcreteClassEntity(type);
+ }
+
+ void IModelExplicitDeclarationsHolder.AddAsOneToOneRelation(MemberInfo member)
+ {
+ declaredModel.AddAsOneToOneRelation(member);
+ }
+
+ void IModelExplicitDeclarationsHolder.AddAsManyToOneRelation(MemberInfo member)
+ {
+ declaredModel.AddAsManyToOneRelation(member);
+ }
+
+ void IModelExplicitDeclarationsHolder.AddAsManyToManyRelation(MemberInfo member)
+ {
+ declaredModel.AddAsManyToManyRelation(member);
+ }
+
+ void IModelExplicitDeclarationsHolder.AddAsOneToManyRelation(MemberInfo member)
+ {
+ declaredModel.AddAsOneToManyRelation(member);
+ }
+
+ void IModelExplicitDeclarationsHolder.AddAsAny(MemberInfo member)
+ {
+ declaredModel.AddAsAny(member);
+ }
+
+ void IModelExplicitDeclarationsHolder.AddAsPoid(MemberInfo member)
+ {
+ declaredModel.AddAsPoid(member);
+ }
+
+ void IModelExplicitDeclarationsHolder.AddAsVersionProperty(MemberInfo member)
+ {
+ declaredModel.AddAsVersionProperty(member);
+ }
+
+ void IModelExplicitDeclarationsHolder.AddAsNaturalId(MemberInfo member)
+ {
+ declaredModel.AddAsNaturalId(member);
+ }
+
+ void IModelExplicitDeclarationsHolder.AddAsSet(MemberInfo member)
+ {
+ declaredModel.AddAsSet(member);
+ }
+
+ void IModelExplicitDeclarationsHolder.AddAsBag(MemberInfo member)
+ {
+ declaredModel.AddAsBag(member);
+ }
+
+ void IModelExplicitDeclarationsHolder.AddAsIdBag(MemberInfo member)
+ {
+ declaredModel.AddAsIdBag(member);
+ }
+
+ void IModelExplicitDeclarationsHolder.AddAsList(MemberInfo member)
+ {
+ declaredModel.AddAsList(member);
+ }
+
+ void IModelExplicitDeclarationsHolder.AddAsArray(MemberInfo member)
+ {
+ declaredModel.AddAsArray(member);
+ }
+
+ void IModelExplicitDeclarationsHolder.AddAsMap(MemberInfo member)
+ {
+ declaredModel.AddAsMap(member);
+ }
+
+ void IModelExplicitDeclarationsHolder.AddAsProperty(MemberInfo member)
+ {
+ declaredModel.AddAsProperty(member);
+ }
+
+ void IModelExplicitDeclarationsHolder.AddAsPersistentMember(MemberInfo member)
+ {
+ declaredModel.AddAsPersistentMember(member);
+ }
+
+ void IModelExplicitDeclarationsHolder.AddAsPropertySplit(SplitDefinition definition)
+ {
+ declaredModel.AddAsPropertySplit(definition);
+ }
+
+ #endregion
+
+ #region Implementation of IModelInspector
+
+ bool IModelInspector.IsRootEntity(System.Type type)
+ {
+ bool declaredResult = declaredModel.IsRootEntity(type);
+ return isRootEntity(type, declaredResult);
+ }
+
+ bool IModelInspector.IsComponent(System.Type type)
+ {
+ bool declaredResult = declaredModel.IsComponent(type);
+ return isComponent(type, declaredResult);
+ }
+
+ bool IModelInspector.IsEntity(System.Type type)
+ {
+ bool declaredResult = declaredModel.IsEntity(type);
+ return isEntity(type, declaredResult);
+ }
+
+ bool IModelInspector.IsTablePerClass(System.Type type)
+ {
+ bool declaredResult = declaredModel.IsTablePerClass(type);
+ return isTablePerClass(type, declaredResult);
+ }
+
+ bool IModelInspector.IsTablePerClassSplit(System.Type type, object splitGroupId, MemberInfo member)
+ {
+ bool declaredResult = declaredModel.IsTablePerClassSplit(type, splitGroupId, member);
+ return isTablePerClassSplit(new SplitDefinition(type, splitGroupId.ToString(), member), declaredResult);
+ }
+
+ bool IModelInspector.IsTablePerClassHierarchy(System.Type type)
+ {
+ bool declaredResult = declaredModel.IsTablePerClassHierarchy(type);
+ return isTablePerClassHierarchy(type, declaredResult);
+ }
+
+ bool IModelInspector.IsTablePerConcreteClass(System.Type type)
+ {
+ bool declaredResult = declaredModel.IsTablePerConcreteClass(type);
+ return isTablePerConcreteClass(type, declaredResult);
+ }
+
+ bool IModelInspector.IsOneToOne(MemberInfo member)
+ {
+ bool declaredResult = declaredModel.IsOneToOne(member);
+ return isOneToOne(member, declaredResult);
+ }
+
+ bool IModelInspector.IsManyToOne(MemberInfo member)
+ {
+ bool declaredResult = declaredModel.IsManyToOne(member);
+ return isManyToOne(member, declaredResult);
+ }
+
+ bool IModelInspector.IsManyToMany(MemberInfo member)
+ {
+ bool declaredResult = declaredModel.IsManyToMany(member);
+ return isManyToMany(member, declaredResult);
+ }
+
+ bool IModelInspector.IsOneToMany(MemberInfo member)
+ {
+ bool declaredResult = declaredModel.IsOneToMany(member);
+ return isOneToMany(member, declaredResult);
+ }
+
+ bool IModelInspector.IsAny(MemberInfo member)
+ {
+ bool declaredResult = declaredModel.IsAny(member);
+ return isAny(member, declaredResult);
+ }
+
+ bool IModelInspector.IsPersistentId(MemberInfo member)
+ {
+ bool declaredResult = declaredModel.IsPersistentId(member);
+ return isPersistentId(member, declaredResult);
+ }
+
+ bool IModelInspector.IsVersion(MemberInfo member)
+ {
+ bool declaredResult = declaredModel.IsVersion(member);
+ return isVersion(member, declaredResult);
+ }
+
+ bool IModelInspector.IsMemberOfNaturalId(MemberInfo member)
+ {
+ bool declaredResult = declaredModel.IsMemberOfNaturalId(member);
+ return isMemberOfNaturalId(member, declaredResult);
+ }
+
+ bool IModelInspector.IsPersistentProperty(MemberInfo member)
+ {
+ bool declaredResult = declaredModel.IsPersistentProperty(member);
+ return isPersistentProperty(member, declaredResult);
+ }
+
+ bool IModelInspector.IsSet(MemberInfo role)
+ {
+ bool declaredResult = declaredModel.IsSet(role);
+ return isSet(role, declaredResult);
+ }
+
+ bool IModelInspector.IsBag(MemberInfo role)
+ {
+ bool declaredResult = declaredModel.IsBag(role);
+ return isBag(role, declaredResult);
+ }
+
+ bool IModelInspector.IsIdBag(MemberInfo role)
+ {
+ bool declaredResult = declaredModel.IsIdBag(role);
+ return isIdBag(role, declaredResult);
+ }
+
+ bool IModelInspector.IsList(MemberInfo role)
+ {
+ bool declaredResult = declaredModel.IsList(role);
+ return isList(role, declaredResult);
+ }
+
+ bool IModelInspector.IsArray(MemberInfo role)
+ {
+ bool declaredResult = declaredModel.IsArray(role);
+ return isArray(role, declaredResult);
+ }
+
+ bool IModelInspector.IsDictionary(MemberInfo role)
+ {
+ bool declaredResult = declaredModel.IsDictionary(role);
+ return isDictionary(role, declaredResult);
+ }
+
+ bool IModelInspector.IsProperty(MemberInfo member)
+ {
+ bool declaredResult = declaredModel.IsProperty(member);
+ return isProperty(member, declaredResult);
+ }
+
+ IEnumerable<string> IModelInspector.GetPropertiesSplits(System.Type type)
+ {
+ IEnumerable<string> declaredResult = declaredModel.GetPropertiesSplits(type);
+ return splitsForType(type, declaredResult);
+ }
+
+ #endregion
+
+ public void IsRootEntity(Func<System.Type, bool, bool> match)
+ {
+ if (match == null)
+ {
+ return;
+ }
+ isRootEntity = match;
+ }
+
+ public void IsComponent(Func<System.Type, bool, bool> match)
+ {
+ if (match == null)
+ {
+ return;
+ }
+ isComponent = match;
+ }
+
+ public void IsEntity(Func<System.Type, bool, bool> match)
+ {
+ if (match == null)
+ {
+ return;
+ }
+ isEntity = match;
+ }
+
+ public void IsTablePerClass(Func<System.Type, bool, bool> match)
+ {
+ if (match == null)
+ {
+ return;
+ }
+ isTablePerClass = match;
+ }
+
+ public void IsTablePerClassHierarchy(Func<System.Type, bool, bool> match)
+ {
+ if (match == null)
+ {
+ return;
+ }
+ isTablePerClassHierarchy = match;
+ }
+
+ public void IsTablePerConcreteClass(Func<System.Type, bool, bool> match)
+ {
+ if (match == null)
+ {
+ return;
+ }
+ isTablePerConcreteClass = match;
+ }
+
+ public void IsOneToOne(Func<MemberInfo, bool, bool> match)
+ {
+ if (match == null)
+ {
+ return;
+ }
+ isOneToOne = match;
+ }
+
+ public void IsManyToOne(Func<MemberInfo, bool, bool> match)
+ {
+ if (match == null)
+ {
+ return;
+ }
+ isManyToOne = match;
+ }
+
+ public void IsManyToMany(Func<MemberInfo, bool, bool> match)
+ {
+ if (match == null)
+ {
+ return;
+ }
+ isManyToMany = match;
+ }
+
+ public void IsOneToMany(Func<MemberInfo, bool, bool> match)
+ {
+ if (match == null)
+ {
+ return;
+ }
+ isOneToMany = match;
+ }
+
+ public void IsAny(Func<MemberInfo, bool, bool> match)
+ {
+ if (match == null)
+ {
+ return;
+ }
+ isAny = match;
+ }
+
+ public void IsPersistentId(Func<MemberInfo, bool, bool> match)
+ {
+ if (match == null)
+ {
+ return;
+ }
+ isPersistentId = match;
+ }
+
+ public void IsVersion(Func<MemberInfo, bool, bool> match)
+ {
+ if (match == null)
+ {
+ return;
+ }
+ isVersion = match;
+ }
+
+ public void IsMemberOfNaturalId(Func<MemberInfo, bool, bool> match)
+ {
+ if (match == null)
+ {
+ return;
+ }
+ isMemberOfNaturalId = match;
+ }
+
+ public void IsPersistentProperty(Func<MemberInfo, bool, bool> match)
+ {
+ if (match == null)
+ {
+ return;
+ }
+ isPersistentProperty = match;
+ }
+
+ public void IsSet(Func<MemberInfo, bool, bool> match)
+ {
+ if (match == null)
+ {
+ return;
+ }
+ isSet = match;
+ }
+
+ public void IsBag(Func<MemberInfo, bool, bool> match)
+ {
+ if (match == null)
+ {
+ return;
+ }
+ isBag = match;
+ }
+
+ public void IsIdBag(Func<MemberInfo, bool, bool> match)
+ {
+ if (match == null)
+ {
+ return;
+ }
+ isIdBag = match;
+ }
+
+ public void IsList(Func<MemberInfo, bool, bool> match)
+ {
+ if (match == null)
+ {
+ return;
+ }
+ isList = match;
+ }
+
+ public void IsArray(Func<MemberInfo, bool, bool> match)
+ {
+ if (match == null)
+ {
+ return;
+ }
+ isArray = match;
+ }
+
+ public void IsDictionary(Func<MemberInfo, bool, bool> match)
+ {
+ if (match == null)
+ {
+ return;
+ }
+ isDictionary = match;
+ }
+
+ public void IsProperty(Func<MemberInfo, bool, bool> match)
+ {
+ if (match == null)
+ {
+ return;
+ }
+ isProperty = match;
+ }
+
+ public void SplitsFor(Func<System.Type, IEnumerable<string>, IEnumerable<string>> getPropertiesSplitsId)
+ {
+ if (getPropertiesSplitsId == null)
+ {
+ return;
+ }
+ splitsForType = getPropertiesSplitsId;
+ }
+
+ public void IsTablePerClassSplit(Func<SplitDefinition, bool, bool> match)
+ {
+ if (match == null)
+ {
+ return;
+ }
+ isTablePerClassSplit = match;
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate....
[truncated message content] |
|
From: <fab...@us...> - 2011-04-10 18:15:32
|
Revision: 5652
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5652&view=rev
Author: fabiomaulo
Date: 2011-04-10 18:15:26 +0000 (Sun, 10 Apr 2011)
Log Message:
-----------
SimpleModelInspector with default pattern to discover POID
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/
trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/PoidTests.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-10 17:55:04 UTC (rev 5651)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-10 18:15:26 UTC (rev 5652)
@@ -20,7 +20,7 @@
private Func<System.Type, IEnumerable<string>, IEnumerable<string>> splitsForType = (t, declared) => declared;
private Func<System.Type, bool, bool> isComponent = (t, declared) => declared;
- private Func<MemberInfo, bool, bool> isPersistentId = (m, declared) => declared;
+ private Func<MemberInfo, bool, bool> isPersistentId;
private Func<MemberInfo, bool, bool> isPersistentProperty = (m, declared) => declared;
private Func<MemberInfo, bool, bool> isVersion = (m, declared) => declared;
@@ -39,6 +39,20 @@
private Func<MemberInfo, bool, bool> isIdBag = (m, declared) => declared;
private Func<MemberInfo, bool, bool> isList = (m, declared) => declared;
+ public SimpleModelInspector()
+ {
+ isPersistentId = (m, declared) => declared || MatchPoIdPattern(m);
+ }
+
+ protected bool MatchPoIdPattern(MemberInfo subject)
+ {
+ var name = subject.Name;
+ return name.Equals("id", StringComparison.InvariantCultureIgnoreCase)
+ || name.Equals("poid", StringComparison.InvariantCultureIgnoreCase)
+ || name.Equals("oid", StringComparison.InvariantCultureIgnoreCase)
+ || (name.StartsWith(subject.DeclaringType.Name) && name.Equals(subject.DeclaringType.Name + "id", StringComparison.InvariantCultureIgnoreCase));
+ }
+
#region IModelExplicitDeclarationsHolder Members
IEnumerable<System.Type> IModelExplicitDeclarationsHolder.RootEntities
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/PoidTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/PoidTests.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/PoidTests.cs 2011-04-10 18:15:26 UTC (rev 5652)
@@ -0,0 +1,60 @@
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.MixAutomapping
+{
+ public class PoidTests
+ {
+ private class MyClass
+ {
+ public int EntityIdentificator { get; set; }
+ }
+ private class TestEntity
+ {
+ public int Id { get; set; }
+ public int id { get; set; }
+ public int PoId { get; set; }
+ public int POID { get; set; }
+ public int OId { get; set; }
+ public int TestEntityId { get; set; }
+ public int testEntityId { get; set; }
+ public int Something { get; set; }
+ }
+
+ [Test]
+ public void WhenExplicitDeclaredThenMatch()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var mapper = new ModelMapper(autoinspector);
+ mapper.Class<MyClass>(map => map.Id(x => x.EntityIdentificator));
+
+ var inspector = (IModelInspector)autoinspector;
+ inspector.IsPersistentId(typeof(MyClass).GetProperty("EntityIdentificator")).Should().Be.True();
+ }
+
+ [Test]
+ public void WhenNotExplicitlyDeclaredMatchDefaultDelegate()
+ {
+ var autoinspector = new SimpleModelInspector();
+
+ var inspector = (IModelInspector)autoinspector;
+ inspector.IsPersistentId(typeof(TestEntity).GetProperty("Id")).Should().Be.True();
+ inspector.IsPersistentId(typeof(TestEntity).GetProperty("id")).Should().Be.True();
+ inspector.IsPersistentId(typeof(TestEntity).GetProperty("PoId")).Should().Be.True();
+ inspector.IsPersistentId(typeof(TestEntity).GetProperty("POID")).Should().Be.True();
+ inspector.IsPersistentId(typeof(TestEntity).GetProperty("OId")).Should().Be.True();
+ inspector.IsPersistentId(typeof(TestEntity).GetProperty("TestEntityId")).Should().Be.True();
+ }
+
+ [Test]
+ public void WhenNotExplicitlyDeclaredThenNoMatchPropertiesOutOfDefaultDelegate()
+ {
+ var autoinspector = new SimpleModelInspector();
+
+ var inspector = (IModelInspector)autoinspector;
+ inspector.IsPersistentId(typeof(TestEntity).GetProperty("testEntityId")).Should().Be.False();
+ inspector.IsPersistentId(typeof(TestEntity).GetProperty("Something")).Should().Be.False();
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-10 17:55:04 UTC (rev 5651)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-10 18:15:26 UTC (rev 5652)
@@ -541,6 +541,7 @@
<Compile Include="MappingByCode\MappersTests\IdBagMapperTest.cs" />
<Compile Include="MappingByCode\MappersTests\JoinMapperTests.cs" />
<Compile Include="MappingByCode\MappersTests\SubclassMapperWithJoinPropertiesTest.cs" />
+ <Compile Include="MappingByCode\MixAutomapping\PoidTests.cs" />
<Compile Include="MappingByCode\ModelExplicitDeclarationsHolderMergeTest.cs" />
<Compile Include="MappingByCode\NatureDemo\Naturalness\Address.cs" />
<Compile Include="MappingByCode\NatureDemo\Naturalness\Animal.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2011-04-10 18:32:41
|
Revision: 5653
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5653&view=rev
Author: fabiomaulo
Date: 2011-04-10 18:32:35 +0000 (Sun, 10 Apr 2011)
Log Message:
-----------
SimpleModelInspector with default pattern to discover Components
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/ComponentsTests.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-10 18:15:26 UTC (rev 5652)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-10 18:32:35 UTC (rev 5653)
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Reflection;
namespace NHibernate.Mapping.ByCode
@@ -18,7 +19,7 @@
private Func<System.Type, bool, bool> isTablePerClassHierarchy = (t, declared) => declared;
private Func<System.Type, bool, bool> isTablePerConcreteClass = (t, declared) => declared;
private Func<System.Type, IEnumerable<string>, IEnumerable<string>> splitsForType = (t, declared) => declared;
- private Func<System.Type, bool, bool> isComponent = (t, declared) => declared;
+ private Func<System.Type, bool, bool> isComponent;
private Func<MemberInfo, bool, bool> isPersistentId;
private Func<MemberInfo, bool, bool> isPersistentProperty = (m, declared) => declared;
@@ -42,6 +43,7 @@
public SimpleModelInspector()
{
isPersistentId = (m, declared) => declared || MatchPoIdPattern(m);
+ isComponent = (t, declared) => declared || MatchComponentPattern(t);
}
protected bool MatchPoIdPattern(MemberInfo subject)
@@ -53,6 +55,18 @@
|| (name.StartsWith(subject.DeclaringType.Name) && name.Equals(subject.DeclaringType.Name + "id", StringComparison.InvariantCultureIgnoreCase));
}
+ protected bool MatchComponentPattern(System.Type subject)
+ {
+ const BindingFlags flattenHierarchyMembers =
+ BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
+
+ var modelInspector = (IModelInspector) this;
+ return !subject.IsEnum && !subject.Namespace.StartsWith("System") /* hack */&& !modelInspector.IsEntity(subject)
+ &&
+ !subject.GetProperties(flattenHierarchyMembers).Cast<MemberInfo>().Concat(
+ subject.GetFields(flattenHierarchyMembers)).Any(m => modelInspector.IsPersistentId(m));
+ }
+
#region IModelExplicitDeclarationsHolder Members
IEnumerable<System.Type> IModelExplicitDeclarationsHolder.RootEntities
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/ComponentsTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/ComponentsTests.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/ComponentsTests.cs 2011-04-10 18:32:35 UTC (rev 5653)
@@ -0,0 +1,79 @@
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.MixAutomapping
+{
+ public class ComponentsTests
+ {
+ // a class without Poid is a Component
+ private class AComponent
+ {
+ public string S { get; set; }
+ }
+ private class AEntity
+ {
+ public int Id { get; set; }
+ }
+ private class Entity
+ {
+ private int id;
+ }
+
+ private enum Something
+ {
+
+ }
+
+ [Test]
+ public void WhenAClassIsExplicitlyDeclaredAsComponentThenIsComponent()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var mapper = new ModelMapper(autoinspector);
+ mapper.Component<AEntity>(map => { });
+
+ var inspector = (IModelInspector)autoinspector;
+ inspector.IsComponent(typeof(AEntity)).Should().Be.True();
+ }
+
+ [Test]
+ public void ClassWithoutPoidIsComponent()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+ inspector.IsComponent(typeof(AComponent)).Should().Be.True();
+ }
+
+ [Test]
+ public void ClassWithPoidIsNotComponent()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+ inspector.IsComponent(typeof(AEntity)).Should().Be.False();
+ }
+
+ [Test]
+ public void ClassWithPoidFieldIsNotComponent()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+ inspector.IsComponent(typeof(Entity)).Should().Be.False();
+ }
+
+ [Test]
+ public void EnumIsNotComponent()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+ inspector.IsComponent(typeof(Something)).Should().Be.False();
+ }
+
+ [Test]
+ public void StringIsNotComponent()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+ inspector.IsComponent(typeof(string)).Should().Be.False();
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-10 18:15:26 UTC (rev 5652)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-10 18:32:35 UTC (rev 5653)
@@ -541,6 +541,7 @@
<Compile Include="MappingByCode\MappersTests\IdBagMapperTest.cs" />
<Compile Include="MappingByCode\MappersTests\JoinMapperTests.cs" />
<Compile Include="MappingByCode\MappersTests\SubclassMapperWithJoinPropertiesTest.cs" />
+ <Compile Include="MappingByCode\MixAutomapping\ComponentsTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\PoidTests.cs" />
<Compile Include="MappingByCode\ModelExplicitDeclarationsHolderMergeTest.cs" />
<Compile Include="MappingByCode\NatureDemo\Naturalness\Address.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2011-04-10 19:27:43
|
Revision: 5654
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5654&view=rev
Author: fabiomaulo
Date: 2011-04-10 19:27:37 +0000 (Sun, 10 Apr 2011)
Log Message:
-----------
SimpleModelInspector with default pattern to discover Persistent properties
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/AccessorPropertyMapper.cs
trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/PropertyToField.cs
trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/PropertiesExclusionTests.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/AccessorPropertyMapper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/AccessorPropertyMapper.cs 2011-04-10 18:32:35 UTC (rev 5653)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/AccessorPropertyMapper.cs 2011-04-10 19:27:37 UTC (rev 5654)
@@ -15,16 +15,7 @@
private readonly System.Type declaringType;
- private readonly Dictionary<string, IFieldNamingStrategy> fieldNamningStrategies =
- new Dictionary<string, IFieldNamingStrategy>
- {
- {"camelcase", new CamelCaseStrategy()},
- {"camelcase-underscore", new CamelCaseUnderscoreStrategy()},
- {"lowercase", new LowerCaseStrategy()},
- {"lowercase-underscore", new LowerCaseUnderscoreStrategy()},
- {"pascalcase-underscore", new PascalCaseUnderscoreStrategy()},
- {"pascalcase-m-underscore", new PascalCaseMUnderscoreStrategy()},
- };
+ private readonly IDictionary<string, IFieldNamingStrategy> fieldNamningStrategies = PropertyToField.DefaultStrategies;
private readonly string propertyName;
private readonly Action<string> setAccessor;
Added: trunk/nhibernate/src/NHibernate/Mapping/ByCode/PropertyToField.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/PropertyToField.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/PropertyToField.cs 2011-04-10 19:27:37 UTC (rev 5654)
@@ -0,0 +1,32 @@
+using System.Collections.Generic;
+using NHibernate.Properties;
+
+namespace NHibernate.Mapping.ByCode
+{
+ public class PropertyToField
+ {
+ private static readonly Dictionary<string, IFieldNamingStrategy> FieldNamningStrategies = new Dictionary<string, IFieldNamingStrategy>
+ {
+ {"camelcase", new CamelCaseStrategy()},
+ {"camelcase-underscore", new CamelCaseUnderscoreStrategy()},
+ {"lowercase", new LowerCaseStrategy()},
+ {"lowercase-underscore", new LowerCaseUnderscoreStrategy()},
+ {"pascalcase-underscore", new PascalCaseUnderscoreStrategy()},
+ {"pascalcase-m-underscore", new PascalCaseMUnderscoreStrategy()},
+ };
+
+ /// <summary>
+ /// Dictionary containing the embedded strategies to find a field giving a property name.
+ /// The key is the "partial-name" of the strategy used in XML mapping.
+ /// The value is an instance of the strategy.
+ /// </summary>
+ public static IDictionary<string, IFieldNamingStrategy> DefaultStrategies
+ {
+ get
+ {
+ // please leave it as no read-only; the user may need to add his strategies or remove existing if he no want his people use it.
+ return FieldNamningStrategies;
+ }
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-10 18:32:35 UTC (rev 5653)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-10 19:27:37 UTC (rev 5654)
@@ -22,7 +22,7 @@
private Func<System.Type, bool, bool> isComponent;
private Func<MemberInfo, bool, bool> isPersistentId;
- private Func<MemberInfo, bool, bool> isPersistentProperty = (m, declared) => declared;
+ private Func<MemberInfo, bool, bool> isPersistentProperty;
private Func<MemberInfo, bool, bool> isVersion = (m, declared) => declared;
private Func<MemberInfo, bool, bool> isProperty = (m, declared) => declared;
@@ -44,8 +44,53 @@
{
isPersistentId = (m, declared) => declared || MatchPoIdPattern(m);
isComponent = (t, declared) => declared || MatchComponentPattern(t);
+ isPersistentProperty = (m, declared) => declared || MatchNoReadOnlyPropertyPattern(m);
}
+ protected bool MatchNoReadOnlyPropertyPattern(MemberInfo subject)
+ {
+ var isReadOnlyProperty = IsReadOnlyProperty(subject);
+ return !isReadOnlyProperty;
+ }
+
+ protected bool IsReadOnlyProperty(MemberInfo subject)
+ {
+ const BindingFlags defaultBinding = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;
+
+ var property = subject as PropertyInfo;
+ if (property == null)
+ {
+ return false;
+ }
+ if (CanReadCantWriteInsideType(property) || CanReadCantWriteInBaseType(property))
+ {
+ return !PropertyToField.DefaultStrategies.Values.Any(s => subject.DeclaringType.GetField(s.GetFieldName(property.Name), defaultBinding) != null) || IsAutoproperty(property);
+ }
+ return false;
+ }
+
+ protected bool IsAutoproperty(PropertyInfo property)
+ {
+ return property.ReflectedType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance
+ | BindingFlags.DeclaredOnly).Any(pi => pi.Name == string.Concat("<", property.Name, ">k__BackingField"));
+ }
+
+ protected bool CanReadCantWriteInsideType(PropertyInfo property)
+ {
+ return !property.CanWrite && property.CanRead && property.DeclaringType == property.ReflectedType;
+ }
+
+ protected bool CanReadCantWriteInBaseType(PropertyInfo property)
+ {
+ if (property.DeclaringType == property.ReflectedType)
+ {
+ return false;
+ }
+ var rfprop = property.DeclaringType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance
+ | BindingFlags.DeclaredOnly).SingleOrDefault(pi => pi.Name == property.Name);
+ return rfprop != null && !rfprop.CanWrite && rfprop.CanRead;
+ }
+
protected bool MatchPoIdPattern(MemberInfo subject)
{
var name = subject.Name;
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-10 18:32:35 UTC (rev 5653)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-10 19:27:37 UTC (rev 5654)
@@ -290,6 +290,7 @@
<Compile Include="Mapping\ByCode\Conformist\JoinedSubclassMapping.cs" />
<Compile Include="Mapping\ByCode\Conformist\SubclassMapping.cs" />
<Compile Include="Mapping\ByCode\Conformist\UnionSubclassMapping.cs" />
+ <Compile Include="Mapping\ByCode\PropertyToField.cs" />
<Compile Include="Mapping\ByCode\SimpleModelInspector.cs" />
<Compile Include="Mapping\ByCode\ExplicitlyDeclaredModel.cs" />
<Compile Include="Mapping\ByCode\FakeModelExplicitDeclarationsHolder.cs" />
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/PropertiesExclusionTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/PropertiesExclusionTests.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/PropertiesExclusionTests.cs 2011-04-10 19:27:37 UTC (rev 5654)
@@ -0,0 +1,103 @@
+using System.Reflection;
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.MixAutomapping
+{
+ public class PropertiesExclusionTests
+ {
+ public class MyEntity
+ {
+ private string noReadOnlyWithField;
+ private string pizza;
+
+ public string ReadOnly
+ {
+ get { return ""; }
+ }
+
+ public string NoReadOnlyWithField
+ {
+ get { return noReadOnlyWithField; }
+ }
+
+ public string NoReadOnly
+ {
+ get { return ""; }
+ set { }
+ }
+
+ public string WriteOnly
+ {
+ set { }
+ }
+
+ public string AutoPropWithPrivateSet { get; private set; }
+ }
+
+ [Test]
+ public void WhenReadonlyDeclaredThenIsPersistentProperty()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var mapper = new ModelMapper(autoinspector);
+ mapper.Class<MyEntity>(map => map.Property(x => x.ReadOnly));
+
+ var inspector = (IModelInspector)autoinspector;
+ inspector.IsPersistentProperty(typeof(MyEntity).GetProperty("ReadOnly")).Should().Be.True();
+ }
+
+ [Test]
+ public void WhenReadonlyNotDeclaredThenIsNotPersistentProperty()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsPersistentProperty(typeof(MyEntity).GetProperty("ReadOnly")).Should().Be.False();
+ }
+
+ [Test]
+ public void IncludesReadOnlyWithField()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ PropertyInfo pi = typeof(MyEntity).GetProperty("NoReadOnlyWithField");
+ inspector.IsPersistentProperty(pi).Should().Be.True();
+ }
+
+ [Test]
+ public void IncludesNoReadOnly()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ PropertyInfo pi = typeof(MyEntity).GetProperty("NoReadOnly");
+ inspector.IsPersistentProperty(pi).Should().Be.True();
+
+ pi = typeof(MyEntity).GetProperty("WriteOnly");
+ inspector.IsPersistentProperty(pi).Should().Be.True();
+ }
+
+ [Test]
+ public void IncludesFields()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ var pi = typeof(MyEntity).GetField("pizza", BindingFlags.Instance | BindingFlags.NonPublic);
+ inspector.IsPersistentProperty(pi).Should().Be.True();
+ }
+
+ [Test]
+ public void IncludesAutoprop()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ var pi = typeof(MyEntity).GetProperty("AutoPropWithPrivateSet");
+ inspector.IsPersistentProperty(pi).Should().Be.True();
+ }
+
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-10 18:32:35 UTC (rev 5653)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-10 19:27:37 UTC (rev 5654)
@@ -543,6 +543,7 @@
<Compile Include="MappingByCode\MappersTests\SubclassMapperWithJoinPropertiesTest.cs" />
<Compile Include="MappingByCode\MixAutomapping\ComponentsTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\PoidTests.cs" />
+ <Compile Include="MappingByCode\MixAutomapping\PropertiesExclusionTests.cs" />
<Compile Include="MappingByCode\ModelExplicitDeclarationsHolderMergeTest.cs" />
<Compile Include="MappingByCode\NatureDemo\Naturalness\Address.cs" />
<Compile Include="MappingByCode\NatureDemo\Naturalness\Animal.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2011-04-10 20:04:32
|
Revision: 5655
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5655&view=rev
Author: fabiomaulo
Date: 2011-04-10 20:04:25 +0000 (Sun, 10 Apr 2011)
Log Message:
-----------
SimpleModelInspector with default pattern to discover Sets properties
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/SetCollectionTests.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-10 19:27:37 UTC (rev 5654)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-10 20:04:25 UTC (rev 5655)
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
+using Iesi.Collections;
namespace NHibernate.Mapping.ByCode
{
@@ -33,20 +34,60 @@
private Func<MemberInfo, bool, bool> isOneToMany = (m, declared) => declared;
private Func<MemberInfo, bool, bool> isOneToOne = (m, declared) => declared;
- private Func<MemberInfo, bool, bool> isSet = (m, declared) => declared;
- private Func<MemberInfo, bool, bool> isArray = (m, declared) => declared;
- private Func<MemberInfo, bool, bool> isBag = (m, declared) => declared;
- private Func<MemberInfo, bool, bool> isDictionary = (m, declared) => declared;
+ private Func<MemberInfo, bool, bool> isSet;
+ private Func<MemberInfo, bool, bool> isArray;
+ private Func<MemberInfo, bool, bool> isBag;
+ private Func<MemberInfo, bool, bool> isDictionary;
private Func<MemberInfo, bool, bool> isIdBag = (m, declared) => declared;
- private Func<MemberInfo, bool, bool> isList = (m, declared) => declared;
+ private Func<MemberInfo, bool, bool> isList;
public SimpleModelInspector()
{
isPersistentId = (m, declared) => declared || MatchPoIdPattern(m);
isComponent = (t, declared) => declared || MatchComponentPattern(t);
isPersistentProperty = (m, declared) => declared || MatchNoReadOnlyPropertyPattern(m);
+ isSet = (m, declared) => declared || MatchCollection(m, MatchSetMember);
+ isArray = (m, declared) => declared;
+ isBag = (m, declared) => declared;
+ isDictionary = (m, declared) => declared;
+ isList = (m, declared) => declared;
}
+ public bool MatchCollection(MemberInfo subject, Predicate<MemberInfo> specificCollectionPredicate)
+ {
+ const BindingFlags defaultBinding = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;
+
+ if (specificCollectionPredicate(subject)) return true;
+ var pi = subject as PropertyInfo;
+ if (pi != null)
+ {
+ var fieldInfo = (from ps in PropertyToField.DefaultStrategies.Values
+ let fi = subject.DeclaringType.GetField(ps.GetFieldName(pi.Name), defaultBinding)
+ where fi != null
+ select fi).FirstOrDefault();
+
+ if (fieldInfo != null)
+ {
+ return specificCollectionPredicate(fieldInfo);
+ }
+ }
+ return false;
+ }
+
+ protected bool MatchSetMember(MemberInfo subject)
+ {
+ var memberType = subject.GetPropertyOrFieldType();
+ if (typeof(ISet).IsAssignableFrom(memberType))
+ {
+ return true;
+ }
+ if (memberType.IsGenericType)
+ {
+ return memberType.GetGenericIntercafesTypeDefinitions().Contains(typeof(Iesi.Collections.Generic.ISet<>));
+ }
+ return false;
+ }
+
protected bool MatchNoReadOnlyPropertyPattern(MemberInfo subject)
{
var isReadOnlyProperty = IsReadOnlyProperty(subject);
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/SetCollectionTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/SetCollectionTests.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/SetCollectionTests.cs 2011-04-10 20:04:25 UTC (rev 5655)
@@ -0,0 +1,91 @@
+using System.Collections.Generic;
+using System.Reflection;
+using Iesi.Collections.Generic;
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.MixAutomapping
+{
+ public class SetCollectionTests
+ {
+ private class EntityWithSets
+ {
+ private ICollection<string> others;
+ private ISet<string> emails;
+ public ISet<string> NickNames { get; set; }
+
+ public ICollection<string> Emails
+ {
+ get { return emails; }
+ }
+
+ public ICollection<string> Others
+ {
+ get { return others; }
+ }
+ }
+
+ [Test]
+ public void MatchWithSetProperty()
+ {
+ var mi = typeof(EntityWithSets).GetProperty("NickNames");
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsSet(mi).Should().Be.True();
+ }
+
+ [Test]
+ public void MatchWithSetField()
+ {
+ var mi = typeof(EntityWithSets).GetField("emails", BindingFlags.NonPublic | BindingFlags.Instance);
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsSet(mi).Should().Be.True();
+ }
+
+ [Test]
+ public void MatchWithCollectionPropertyAndSetField()
+ {
+ var mi = typeof(EntityWithSets).GetProperty("Emails");
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsSet(mi).Should().Be.True();
+ }
+
+ [Test]
+ public void NotMatchWithCollectionField()
+ {
+ var mi = typeof(EntityWithSets).GetField("others", BindingFlags.NonPublic | BindingFlags.Instance);
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsSet(mi).Should().Be.False();
+ }
+
+ [Test]
+ public void NotMatchWithCollectionProperty()
+ {
+ var mi = typeof(EntityWithSets).GetProperty("Others");
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsSet(mi).Should().Be.False();
+ }
+
+ [Test]
+ public void WhenExplicitDeclaredThenMatchWithCollectionProperty()
+ {
+ var mi = typeof(EntityWithSets).GetProperty("Others");
+ var autoinspector = new SimpleModelInspector();
+ var mapper = new ModelMapper(autoinspector);
+ mapper.Class<EntityWithSets>(map => map.Set(x => x.Others, x => { }, y=> {}));
+
+ var inspector = (IModelInspector)autoinspector;
+ inspector.IsSet(mi).Should().Be.True();
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-10 19:27:37 UTC (rev 5654)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-10 20:04:25 UTC (rev 5655)
@@ -544,6 +544,7 @@
<Compile Include="MappingByCode\MixAutomapping\ComponentsTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\PoidTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\PropertiesExclusionTests.cs" />
+ <Compile Include="MappingByCode\MixAutomapping\SetCollectionTests.cs" />
<Compile Include="MappingByCode\ModelExplicitDeclarationsHolderMergeTest.cs" />
<Compile Include="MappingByCode\NatureDemo\Naturalness\Address.cs" />
<Compile Include="MappingByCode\NatureDemo\Naturalness\Animal.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2011-04-10 20:35:51
|
Revision: 5656
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5656&view=rev
Author: fabiomaulo
Date: 2011-04-10 20:35:45 +0000 (Sun, 10 Apr 2011)
Log Message:
-----------
SimpleModelInspector with default pattern to discover Bags properties
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/BagCollectionTests.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-10 20:04:25 UTC (rev 5655)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-10 20:35:45 UTC (rev 5656)
@@ -48,13 +48,19 @@
isPersistentProperty = (m, declared) => declared || MatchNoReadOnlyPropertyPattern(m);
isSet = (m, declared) => declared || MatchCollection(m, MatchSetMember);
isArray = (m, declared) => declared;
- isBag = (m, declared) => declared;
+ isBag = (m, declared) => declared || MatchCollection(m, MatchBagMember);
isDictionary = (m, declared) => declared;
isList = (m, declared) => declared;
}
- public bool MatchCollection(MemberInfo subject, Predicate<MemberInfo> specificCollectionPredicate)
+ protected bool MatchBagMember(MemberInfo subject)
{
+ System.Type memberType = subject.GetPropertyOrFieldType();
+ return typeof(System.Collections.IEnumerable).IsAssignableFrom(memberType) && !(memberType == typeof(string) || memberType == typeof(byte[]));
+ }
+
+ protected bool MatchCollection(MemberInfo subject, Predicate<MemberInfo> specificCollectionPredicate)
+ {
const BindingFlags defaultBinding = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;
if (specificCollectionPredicate(subject)) return true;
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/BagCollectionTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/BagCollectionTests.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/BagCollectionTests.cs 2011-04-10 20:35:45 UTC (rev 5656)
@@ -0,0 +1,75 @@
+using System.Collections.Generic;
+using System.Reflection;
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.MixAutomapping
+{
+ public class BagCollectionTests
+ {
+ // match any IEnumerable
+ private class Entity
+ {
+ private ICollection<string> emails;
+ public IEnumerable<string> NickNames { get; set; }
+ public byte[] Bytes { get; set; }
+ public object Emails
+ {
+ get { return emails; }
+ }
+
+ public string Simple { get; set; }
+ }
+
+ [Test]
+ public void MatchWithEnumerableProperty()
+ {
+ var mi = typeof(Entity).GetProperty("NickNames");
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsBag(mi).Should().Be.True();
+ }
+
+ [Test]
+ public void MatchWithEnumerableField()
+ {
+ var mi = typeof(Entity).GetField("emails", BindingFlags.NonPublic | BindingFlags.Instance);
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsBag(mi).Should().Be.True();
+ }
+
+ [Test]
+ public void MatchWithObjectPropertyAndEnumerableField()
+ {
+ var mi = typeof(Entity).GetProperty("Emails");
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsBag(mi).Should().Be.True();
+ }
+
+ [Test]
+ public void NotMatchWithStringProperty()
+ {
+ var mi = typeof(Entity).GetProperty("Simple");
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsBag(mi).Should().Be.False();
+ }
+
+ [Test]
+ public void NotMatchWithByteArrayProperty()
+ {
+ var mi = typeof(Entity).GetProperty("Bytes");
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsBag(mi).Should().Be.False();
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-10 20:04:25 UTC (rev 5655)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-10 20:35:45 UTC (rev 5656)
@@ -541,6 +541,7 @@
<Compile Include="MappingByCode\MappersTests\IdBagMapperTest.cs" />
<Compile Include="MappingByCode\MappersTests\JoinMapperTests.cs" />
<Compile Include="MappingByCode\MappersTests\SubclassMapperWithJoinPropertiesTest.cs" />
+ <Compile Include="MappingByCode\MixAutomapping\BagCollectionTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\ComponentsTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\PoidTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\PropertiesExclusionTests.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2011-04-10 20:43:19
|
Revision: 5657
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5657&view=rev
Author: fabiomaulo
Date: 2011-04-10 20:43:13 +0000 (Sun, 10 Apr 2011)
Log Message:
-----------
SimpleModelInspector with default pattern to discover Dictionaries properties
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/DictionaryCollectionTests.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-10 20:35:45 UTC (rev 5656)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-10 20:43:13 UTC (rev 5657)
@@ -49,10 +49,24 @@
isSet = (m, declared) => declared || MatchCollection(m, MatchSetMember);
isArray = (m, declared) => declared;
isBag = (m, declared) => declared || MatchCollection(m, MatchBagMember);
- isDictionary = (m, declared) => declared;
+ isDictionary = (m, declared) => declared || MatchCollection(m, MatchDictionaryMember);
isList = (m, declared) => declared;
}
+ protected bool MatchDictionaryMember(MemberInfo subject)
+ {
+ System.Type memberType = subject.GetPropertyOrFieldType();
+ if (typeof(System.Collections.IDictionary).IsAssignableFrom(memberType))
+ {
+ return true;
+ }
+ if (memberType.IsGenericType)
+ {
+ return memberType.GetGenericIntercafesTypeDefinitions().Contains(typeof(IDictionary<,>));
+ }
+ return false;
+ }
+
protected bool MatchBagMember(MemberInfo subject)
{
System.Type memberType = subject.GetPropertyOrFieldType();
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/DictionaryCollectionTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/DictionaryCollectionTests.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/DictionaryCollectionTests.cs 2011-04-10 20:43:13 UTC (rev 5657)
@@ -0,0 +1,78 @@
+using System.Collections.Generic;
+using System.Reflection;
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.MixAutomapping
+{
+ public class DictionaryCollectionTests
+ {
+ private class Entity
+ {
+ private ICollection<string> others;
+ private IDictionary<string, string> emails;
+ public IDictionary<string, string> NickNames { get; set; }
+
+ public ICollection<KeyValuePair<string, string>> Emails
+ {
+ get { return emails; }
+ }
+
+ public ICollection<string> Others
+ {
+ get { return others; }
+ }
+ }
+
+ [Test]
+ public void MatchWithDictionaryProperty()
+ {
+ var mi = typeof(Entity).GetProperty("NickNames");
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsDictionary(mi).Should().Be.True();
+ }
+
+ [Test]
+ public void MatchWithDictionaryField()
+ {
+ var mi = typeof(Entity).GetField("emails", BindingFlags.NonPublic | BindingFlags.Instance);
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsDictionary(mi).Should().Be.True();
+ }
+
+ [Test]
+ public void MatchWithCollectionPropertyAndDictionaryField()
+ {
+ var mi = typeof(Entity).GetProperty("Emails");
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsDictionary(mi).Should().Be.True();
+ }
+
+ [Test]
+ public void NotMatchWithCollectionField()
+ {
+ var mi = typeof(Entity).GetField("others", BindingFlags.NonPublic | BindingFlags.Instance);
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsDictionary(mi).Should().Be.False();
+ }
+
+ [Test]
+ public void NotMatchWithCollectionProperty()
+ {
+ var mi = typeof(Entity).GetProperty("Others");
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsDictionary(mi).Should().Be.False();
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-10 20:35:45 UTC (rev 5656)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-10 20:43:13 UTC (rev 5657)
@@ -543,6 +543,7 @@
<Compile Include="MappingByCode\MappersTests\SubclassMapperWithJoinPropertiesTest.cs" />
<Compile Include="MappingByCode\MixAutomapping\BagCollectionTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\ComponentsTests.cs" />
+ <Compile Include="MappingByCode\MixAutomapping\DictionaryCollectionTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\PoidTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\PropertiesExclusionTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\SetCollectionTests.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2011-04-10 20:48:44
|
Revision: 5658
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5658&view=rev
Author: fabiomaulo
Date: 2011-04-10 20:48:38 +0000 (Sun, 10 Apr 2011)
Log Message:
-----------
SimpleModelInspector with default pattern to discover Arrays properties
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/ArrayCollectionTests.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-10 20:43:13 UTC (rev 5657)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-10 20:48:38 UTC (rev 5658)
@@ -39,7 +39,7 @@
private Func<MemberInfo, bool, bool> isBag;
private Func<MemberInfo, bool, bool> isDictionary;
private Func<MemberInfo, bool, bool> isIdBag = (m, declared) => declared;
- private Func<MemberInfo, bool, bool> isList;
+ private Func<MemberInfo, bool, bool> isList = (m, declared) => declared;
public SimpleModelInspector()
{
@@ -47,12 +47,17 @@
isComponent = (t, declared) => declared || MatchComponentPattern(t);
isPersistentProperty = (m, declared) => declared || MatchNoReadOnlyPropertyPattern(m);
isSet = (m, declared) => declared || MatchCollection(m, MatchSetMember);
- isArray = (m, declared) => declared;
+ isArray = (m, declared) => declared || MatchCollection(m, MatchArrayMember);
isBag = (m, declared) => declared || MatchCollection(m, MatchBagMember);
isDictionary = (m, declared) => declared || MatchCollection(m, MatchDictionaryMember);
- isList = (m, declared) => declared;
}
+ protected bool MatchArrayMember(MemberInfo subject)
+ {
+ System.Type memberType = subject.GetPropertyOrFieldType();
+ return memberType.IsArray && memberType.GetElementType() != typeof(byte);
+ }
+
protected bool MatchDictionaryMember(MemberInfo subject)
{
System.Type memberType = subject.GetPropertyOrFieldType();
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/ArrayCollectionTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/ArrayCollectionTests.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/ArrayCollectionTests.cs 2011-04-10 20:48:38 UTC (rev 5658)
@@ -0,0 +1,114 @@
+using System.Collections.Generic;
+using System.Reflection;
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.MixAutomapping
+{
+ public class ArrayCollectionTests
+ {
+ private class Entity
+ {
+ private ICollection<string> others;
+ private string[] emails;
+ public string[] NickNames { get; set; }
+ public byte[] Photo { get; set; }
+
+ public ICollection<string> Emails
+ {
+ get { return emails; }
+ }
+
+ public ICollection<string> Others
+ {
+ get { return others; }
+ }
+ public IList<string> NoArray
+ {
+ get { return null; }
+ }
+ public string Simple { get; set; }
+ }
+
+ [Test]
+ public void MatchWithArrayProperty()
+ {
+ var mi = typeof(Entity).GetProperty("NickNames");
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsArray(mi).Should().Be.True();
+ }
+
+ [Test]
+ public void MatchWithArrayField()
+ {
+ var mi = typeof(Entity).GetField("emails", BindingFlags.NonPublic | BindingFlags.Instance);
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsArray(mi).Should().Be.True();
+ }
+
+ [Test]
+ public void MatchWithCollectionPropertyAndArrayField()
+ {
+ var mi = typeof(Entity).GetProperty("Emails");
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsArray(mi).Should().Be.True();
+ }
+
+ [Test]
+ public void NotMatchWithCollectionField()
+ {
+ var mi = typeof(Entity).GetField("others", BindingFlags.NonPublic | BindingFlags.Instance);
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsArray(mi).Should().Be.False();
+ }
+
+ [Test]
+ public void NotMatchWithCollectionProperty()
+ {
+ var mi = typeof(Entity).GetProperty("Others");
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsArray(mi).Should().Be.False();
+ }
+
+ [Test]
+ public void NotMatchWithNoArrayCollectionProperty()
+ {
+ var mi = typeof(Entity).GetProperty("NoArray");
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsArray(mi).Should().Be.False();
+ }
+
+ [Test]
+ public void NotMatchWithStringProperty()
+ {
+ var mi = typeof(Entity).GetProperty("Simple");
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsArray(mi).Should().Be.False();
+ }
+
+ [Test]
+ public void NotMatchWithByteArrayProperty()
+ {
+ var mi = typeof(Entity).GetProperty("Photo");
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsArray(mi).Should().Be.False();
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-10 20:43:13 UTC (rev 5657)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-10 20:48:38 UTC (rev 5658)
@@ -541,6 +541,7 @@
<Compile Include="MappingByCode\MappersTests\IdBagMapperTest.cs" />
<Compile Include="MappingByCode\MappersTests\JoinMapperTests.cs" />
<Compile Include="MappingByCode\MappersTests\SubclassMapperWithJoinPropertiesTest.cs" />
+ <Compile Include="MappingByCode\MixAutomapping\ArrayCollectionTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\BagCollectionTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\ComponentsTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\DictionaryCollectionTests.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2011-04-10 21:14:36
|
Revision: 5659
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5659&view=rev
Author: fabiomaulo
Date: 2011-04-10 21:14:30 +0000 (Sun, 10 Apr 2011)
Log Message:
-----------
SimpleModelInspector with default pattern to discover ManyToOne properties
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/ManyToOneTest.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-10 20:48:38 UTC (rev 5658)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-10 21:14:30 UTC (rev 5659)
@@ -29,7 +29,7 @@
private Func<MemberInfo, bool, bool> isProperty = (m, declared) => declared;
private Func<MemberInfo, bool, bool> isAny = (m, declared) => declared;
private Func<MemberInfo, bool, bool> isManyToMany = (m, declared) => declared;
- private Func<MemberInfo, bool, bool> isManyToOne = (m, declared) => declared;
+ private Func<MemberInfo, bool, bool> isManyToOne;
private Func<MemberInfo, bool, bool> isMemberOfNaturalId = (m, declared) => declared;
private Func<MemberInfo, bool, bool> isOneToMany = (m, declared) => declared;
private Func<MemberInfo, bool, bool> isOneToOne = (m, declared) => declared;
@@ -50,8 +50,20 @@
isArray = (m, declared) => declared || MatchCollection(m, MatchArrayMember);
isBag = (m, declared) => declared || MatchCollection(m, MatchBagMember);
isDictionary = (m, declared) => declared || MatchCollection(m, MatchDictionaryMember);
+ isManyToOne = (m, declared) => declared || MatchManyToOne(m);
}
+ private bool MatchManyToOne(MemberInfo memberInfo)
+ {
+ var modelInspector = (IModelInspector)this;
+ System.Type from = memberInfo.ReflectedType;
+ System.Type to = memberInfo.GetPropertyOrFieldType();
+
+ bool areEntities = modelInspector.IsEntity(from) && modelInspector.IsEntity(to);
+ bool isFromComponentToEntity = modelInspector.IsComponent(from) && modelInspector.IsEntity(to);
+ return isFromComponentToEntity || (areEntities && !modelInspector.IsOneToOne(memberInfo));
+ }
+
protected bool MatchArrayMember(MemberInfo subject)
{
System.Type memberType = subject.GetPropertyOrFieldType();
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/ManyToOneTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/ManyToOneTest.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/ManyToOneTest.cs 2011-04-10 21:14:30 UTC (rev 5659)
@@ -0,0 +1,63 @@
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.MixAutomapping
+{
+ public class ManyToOneTest
+ {
+ private class AEntity
+ {
+ public int Id { get; set; }
+ public BEntity B { get; set; }
+ public string Name { get; set; }
+ }
+
+ private class BEntity
+ {
+ public int Id { get; set; }
+ }
+
+ [Test]
+ public void WhenRelationWithTwoEntityThenIsManyToOne()
+ {
+ var autoinspector = new SimpleModelInspector();
+ autoinspector.IsEntity((t, declared) => typeof(AEntity).Equals(t) || typeof(BEntity).Equals(t));
+
+ var inspector = (IModelInspector)autoinspector;
+ inspector.IsManyToOne(typeof(AEntity).GetProperty("B")).Should().Be.True();
+ }
+
+ [Test]
+ public void WhenSimplePropertyThenIsNotManyToOne()
+ {
+ var autoinspector = new SimpleModelInspector();
+ autoinspector.IsEntity((t, declared) => typeof(AEntity).Equals(t) || typeof(BEntity).Equals(t));
+
+ var inspector = (IModelInspector)autoinspector;
+ inspector.IsManyToOne(typeof(AEntity).GetProperty("Name")).Should().Be.False();
+ }
+
+ [Test]
+ public void WhenRelatedMatchComponentThenIsNotManyToOne()
+ {
+ var autoinspector = new SimpleModelInspector();
+ autoinspector.IsEntity((t, declared) => typeof(AEntity).Equals(t));
+ autoinspector.IsComponent((t, declared) => typeof(BEntity).Equals(t));
+
+ var inspector = (IModelInspector)autoinspector;
+ inspector.IsManyToOne(typeof(AEntity).GetProperty("B")).Should().Be.False();
+ }
+
+ [Test]
+ public void WhenRelatedDeclaredAsOneToOneThenIsNotManyToOne()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var mapper = new ModelMapper(autoinspector);
+ mapper.Class<AEntity>(map => map.OneToOne(a => a.B, x => { }));
+ mapper.Class<BEntity>(x=> { });
+ var inspector = (IModelInspector)autoinspector;
+ inspector.IsManyToOne(typeof(AEntity).GetProperty("B")).Should().Be.False();
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-10 20:48:38 UTC (rev 5658)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-10 21:14:30 UTC (rev 5659)
@@ -545,6 +545,7 @@
<Compile Include="MappingByCode\MixAutomapping\BagCollectionTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\ComponentsTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\DictionaryCollectionTests.cs" />
+ <Compile Include="MappingByCode\MixAutomapping\ManyToOneTest.cs" />
<Compile Include="MappingByCode\MixAutomapping\PoidTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\PropertiesExclusionTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\SetCollectionTests.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2011-04-10 21:56:04
|
Revision: 5660
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5660&view=rev
Author: fabiomaulo
Date: 2011-04-10 21:55:57 +0000 (Sun, 10 Apr 2011)
Log Message:
-----------
SimpleModelInspector with default pattern to discover OneToMany properties
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/OneToManyTests.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-10 21:14:30 UTC (rev 5659)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-10 21:55:57 UTC (rev 5660)
@@ -31,7 +31,7 @@
private Func<MemberInfo, bool, bool> isManyToMany = (m, declared) => declared;
private Func<MemberInfo, bool, bool> isManyToOne;
private Func<MemberInfo, bool, bool> isMemberOfNaturalId = (m, declared) => declared;
- private Func<MemberInfo, bool, bool> isOneToMany = (m, declared) => declared;
+ private Func<MemberInfo, bool, bool> isOneToMany;
private Func<MemberInfo, bool, bool> isOneToOne = (m, declared) => declared;
private Func<MemberInfo, bool, bool> isSet;
@@ -51,8 +51,24 @@
isBag = (m, declared) => declared || MatchCollection(m, MatchBagMember);
isDictionary = (m, declared) => declared || MatchCollection(m, MatchDictionaryMember);
isManyToOne = (m, declared) => declared || MatchManyToOne(m);
+ isOneToMany = (m, declared) => declared || MatchOneToMany(m);
}
+ private bool MatchOneToMany(MemberInfo memberInfo)
+ {
+ var modelInspector = (IModelInspector) this;
+ System.Type from = memberInfo.ReflectedType;
+ System.Type to = memberInfo.GetPropertyOrFieldType().DetermineCollectionElementOrDictionaryValueType();
+ if(to == null)
+ {
+ // no generic collection or simple property
+ return false;
+ }
+ bool areEntities = modelInspector.IsEntity(from) && modelInspector.IsEntity(to);
+ bool isFromComponentToEntity = modelInspector.IsComponent(from) && modelInspector.IsEntity(to);
+ return !declaredModel.IsManyToMany(memberInfo) && (areEntities || isFromComponentToEntity);
+ }
+
private bool MatchManyToOne(MemberInfo memberInfo)
{
var modelInspector = (IModelInspector)this;
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/OneToManyTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/OneToManyTests.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/OneToManyTests.cs 2011-04-10 21:55:57 UTC (rev 5660)
@@ -0,0 +1,138 @@
+using System.Collections.Generic;
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.MixAutomapping
+{
+ public class OneToManyTests
+ {
+ private class MyClass
+ {
+ public string Something { get; set; }
+ public IEnumerable<Related> Relateds { get; set; }
+ public IEnumerable<Bidirectional> Children { get; set; }
+ public IEnumerable<Component> Components { get; set; }
+ public IEnumerable<string> Elements { get; set; }
+ public IDictionary<string, Related> DicRelateds { get; set; }
+ public IDictionary<string, Bidirectional> DicChildren { get; set; }
+ }
+
+ private class Related
+ {
+
+ }
+
+ private class Bidirectional
+ {
+ public MyClass MyClass { get; set; }
+ }
+
+ private class Component
+ {
+ }
+
+ private IModelInspector GetConfiguredInspector()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var mapper = new ModelMapper(autoinspector);
+ mapper.Class<MyClass>(x => { });
+ mapper.Class<Related>(x => { });
+ mapper.Class<Bidirectional>(x => { });
+ return autoinspector;
+ }
+
+ [Test]
+ public void WhenNoCollectionPropertyThenNoMatch()
+ {
+ var pi = Mapping.ByCode.TypeExtensions.DecodeMemberAccessExpression<MyClass>(x => x.Something);
+
+ var inspector = GetConfiguredInspector();
+ inspector.IsOneToMany(pi).Should().Be.False();
+ }
+
+ [Test]
+ public void WhenCollectionOfComponentsThenNoMatch()
+ {
+ var pi = Mapping.ByCode.TypeExtensions.DecodeMemberAccessExpression<MyClass>(x => x.Components);
+
+ var inspector = GetConfiguredInspector();
+ inspector.IsOneToMany(pi).Should().Be.False();
+ }
+
+ [Test]
+ public void WhenCollectionBidirectionalThenMatch()
+ {
+ var pi = Mapping.ByCode.TypeExtensions.DecodeMemberAccessExpression<MyClass>(x => x.Children);
+
+ var inspector = GetConfiguredInspector();
+ inspector.IsOneToMany(pi).Should().Be.True();
+ }
+
+ [Test]
+ public void WhenCollectionOfElementsThenNoMatch()
+ {
+ var pi = Mapping.ByCode.TypeExtensions.DecodeMemberAccessExpression<MyClass>(x => x.Elements);
+
+ var inspector = GetConfiguredInspector();
+ inspector.IsOneToMany(pi).Should().Be.False();
+ }
+
+ [Test]
+ public void WhenCollectionUnidirectionalThenMatch()
+ {
+ var pi = Mapping.ByCode.TypeExtensions.DecodeMemberAccessExpression<MyClass>(x => x.Relateds);
+
+ var inspector = GetConfiguredInspector();
+ inspector.IsOneToMany(pi).Should().Be.True();
+ }
+
+ [Test]
+ public void WhenDictionaryBidirectionalThenMatch()
+ {
+ var pi = Mapping.ByCode.TypeExtensions.DecodeMemberAccessExpression<MyClass>(x => x.DicChildren);
+
+ var inspector = GetConfiguredInspector();
+ inspector.IsOneToMany(pi).Should().Be.True();
+ }
+
+ [Test]
+ public void WhenDictionaryUnidirectionalThenMatch()
+ {
+ var pi = Mapping.ByCode.TypeExtensions.DecodeMemberAccessExpression<MyClass>(x => x.DicRelateds);
+
+ var inspector = GetConfiguredInspector();
+ inspector.IsOneToMany(pi).Should().Be.True();
+ }
+
+ [Test]
+ public void WhenCollectionUnidirectionalDeclaredManyToManyThenNoMatch()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var mapper = new ModelMapper(autoinspector);
+ mapper.Class<MyClass>(map => map.Bag(x => x.Relateds, cm => { }, relMap => relMap.ManyToMany()));
+ mapper.Class<Related>(x => { });
+ mapper.Class<Bidirectional>(x => { });
+ var inspector = (IModelInspector) autoinspector;
+
+ var pi = Mapping.ByCode.TypeExtensions.DecodeMemberAccessExpression<MyClass>(x => x.Relateds);
+
+ inspector.IsOneToMany(pi).Should().Be.False();
+ }
+
+ [Test]
+ public void WhenDictionaryUnidirectionalDeclaredManyToManyThenNoMatch()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var mapper = new ModelMapper(autoinspector);
+ mapper.Class<MyClass>(map => map.Bag(x => x.DicRelateds, cm => { }, relMap => relMap.ManyToMany()));
+ mapper.Class<Related>(x => { });
+ mapper.Class<Bidirectional>(x => { });
+ var inspector = (IModelInspector)autoinspector;
+
+ var pi = Mapping.ByCode.TypeExtensions.DecodeMemberAccessExpression<MyClass>(x => x.DicRelateds);
+
+ inspector.IsOneToMany(pi).Should().Be.False();
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-10 21:14:30 UTC (rev 5659)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-10 21:55:57 UTC (rev 5660)
@@ -546,6 +546,7 @@
<Compile Include="MappingByCode\MixAutomapping\ComponentsTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\DictionaryCollectionTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\ManyToOneTest.cs" />
+ <Compile Include="MappingByCode\MixAutomapping\OneToManyTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\PoidTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\PropertiesExclusionTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\SetCollectionTests.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2011-04-10 22:20:24
|
Revision: 5661
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5661&view=rev
Author: fabiomaulo
Date: 2011-04-10 22:20:17 +0000 (Sun, 10 Apr 2011)
Log Message:
-----------
SimpleModelInspector with default pattern to discover Entities
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/EntityTests.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-10 21:55:57 UTC (rev 5660)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-10 22:20:17 UTC (rev 5661)
@@ -43,6 +43,7 @@
public SimpleModelInspector()
{
+ isEntity = (t, declared) => declared || MatchEntity(t);
isPersistentId = (m, declared) => declared || MatchPoIdPattern(m);
isComponent = (t, declared) => declared || MatchComponentPattern(t);
isPersistentProperty = (m, declared) => declared || MatchNoReadOnlyPropertyPattern(m);
@@ -206,6 +207,16 @@
subject.GetFields(flattenHierarchyMembers)).Any(m => modelInspector.IsPersistentId(m));
}
+ protected bool MatchEntity(System.Type subject)
+ {
+ const BindingFlags flattenHierarchyMembers =
+ BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
+
+ var modelInspector = (IModelInspector) this;
+ return subject.IsClass &&
+ subject.GetProperties(flattenHierarchyMembers).Cast<MemberInfo>().Concat(subject.GetFields(flattenHierarchyMembers)).Any(m => modelInspector.IsPersistentId(m));
+ }
+
#region IModelExplicitDeclarationsHolder Members
IEnumerable<System.Type> IModelExplicitDeclarationsHolder.RootEntities
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/EntityTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/EntityTests.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/EntityTests.cs 2011-04-10 22:20:17 UTC (rev 5661)
@@ -0,0 +1,78 @@
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.MixAutomapping
+{
+ public class EntityTests
+ {
+ private class AComponent
+ {
+ public string S { get; set; }
+ }
+ private class AEntity
+ {
+ public int Id { get; set; }
+ }
+ private class Entity
+ {
+ private int id;
+ }
+
+ private enum Something
+ {
+
+ }
+
+ [Test]
+ public void WhenAClassIsExplicitlyDeclaredAsEntityThenIsEntity()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var mapper = new ModelMapper(autoinspector);
+ mapper.Class<AComponent>(map => { });
+
+ var inspector = (IModelInspector)autoinspector;
+ inspector.IsEntity(typeof(AComponent)).Should().Be.True();
+ }
+
+ [Test]
+ public void ClassWithPoidIsEntity()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+ inspector.IsEntity(typeof(AEntity)).Should().Be.True();
+ }
+
+ [Test]
+ public void ClassWithoutPoidIsNotEntity()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+ inspector.IsEntity(typeof(AComponent)).Should().Be.False();
+ }
+
+ [Test]
+ public void ClassWithPoidFieldIsEntity()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+ inspector.IsEntity(typeof(Entity)).Should().Be.True();
+ }
+
+ [Test]
+ public void EnumIsNotEntity()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+ inspector.IsEntity(typeof(Something)).Should().Be.False();
+ }
+
+ [Test]
+ public void StringIsNotEntity()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+ inspector.IsEntity(typeof(string)).Should().Be.False();
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-10 21:55:57 UTC (rev 5660)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-10 22:20:17 UTC (rev 5661)
@@ -545,6 +545,7 @@
<Compile Include="MappingByCode\MixAutomapping\BagCollectionTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\ComponentsTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\DictionaryCollectionTests.cs" />
+ <Compile Include="MappingByCode\MixAutomapping\EntityTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\ManyToOneTest.cs" />
<Compile Include="MappingByCode\MixAutomapping\OneToManyTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\PoidTests.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2011-04-10 22:50:12
|
Revision: 5662
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5662&view=rev
Author: fabiomaulo
Date: 2011-04-10 22:50:06 +0000 (Sun, 10 Apr 2011)
Log Message:
-----------
SimpleModelInspector with default pattern to discover TablePerClass entities
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/DefaultClassHierarchyRepresentationTests.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-10 22:20:17 UTC (rev 5661)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-10 22:50:06 UTC (rev 5662)
@@ -15,7 +15,7 @@
private Func<System.Type, bool, bool> isEntity = (t, declared) => declared;
private Func<System.Type, bool, bool> isRootEntity = (t, declared) => declared;
- private Func<System.Type, bool, bool> isTablePerClass = (t, declared) => declared;
+ private Func<System.Type, bool, bool> isTablePerClass;
private Func<SplitDefinition, bool, bool> isTablePerClassSplit = (sd, declared) => declared;
private Func<System.Type, bool, bool> isTablePerClassHierarchy = (t, declared) => declared;
private Func<System.Type, bool, bool> isTablePerConcreteClass = (t, declared) => declared;
@@ -44,6 +44,7 @@
public SimpleModelInspector()
{
isEntity = (t, declared) => declared || MatchEntity(t);
+ isTablePerClass = (t, declared) => declared || MatchTablePerClass(t);
isPersistentId = (m, declared) => declared || MatchPoIdPattern(m);
isComponent = (t, declared) => declared || MatchComponentPattern(t);
isPersistentProperty = (m, declared) => declared || MatchNoReadOnlyPropertyPattern(m);
@@ -55,6 +56,11 @@
isOneToMany = (m, declared) => declared || MatchOneToMany(m);
}
+ private bool MatchTablePerClass(System.Type type)
+ {
+ return !declaredModel.IsTablePerClassHierarchy(type) && !declaredModel.IsTablePerConcreteClass(type);
+ }
+
private bool MatchOneToMany(MemberInfo memberInfo)
{
var modelInspector = (IModelInspector) this;
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/DefaultClassHierarchyRepresentationTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/DefaultClassHierarchyRepresentationTests.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/DefaultClassHierarchyRepresentationTests.cs 2011-04-10 22:50:06 UTC (rev 5662)
@@ -0,0 +1,58 @@
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.MixAutomapping
+{
+ public class DefaultClassHierarchyRepresentationTests
+ {
+ private class MyClass
+ {
+ public int Id { get; set; }
+ }
+
+ private class Inherited: MyClass
+ {
+ }
+
+ [Test]
+ public void WhenNotExplicitlyDeclaredThenIsTablePerClass()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var mapper = new ModelMapper(autoinspector);
+ mapper.Class<MyClass>(x => { });
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsTablePerClass(typeof(MyClass)).Should().Be.True();
+ inspector.IsTablePerClass(typeof(Inherited)).Should().Be.True();
+ }
+
+ [Test]
+ public void WhenExplicitlyDeclaredAsSubclassThenIsNotTablePerClass()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var mapper = new ModelMapper(autoinspector);
+ mapper.Class<MyClass>(x => { });
+ mapper.Subclass<Inherited>(x => { });
+
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsTablePerClass(typeof(MyClass)).Should().Be.False();
+ inspector.IsTablePerClass(typeof(Inherited)).Should().Be.False();
+ }
+
+ [Test]
+ public void WhenExplicitlyDeclaredAsUnionSubclassThenIsNotTablePerClass()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var mapper = new ModelMapper(autoinspector);
+ mapper.Class<MyClass>(x => { });
+ mapper.UnionSubclass<Inherited>(x => { });
+
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsTablePerClass(typeof(MyClass)).Should().Be.False();
+ inspector.IsTablePerClass(typeof(Inherited)).Should().Be.False();
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-10 22:20:17 UTC (rev 5661)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-10 22:50:06 UTC (rev 5662)
@@ -544,6 +544,7 @@
<Compile Include="MappingByCode\MixAutomapping\ArrayCollectionTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\BagCollectionTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\ComponentsTests.cs" />
+ <Compile Include="MappingByCode\MixAutomapping\DefaultClassHierarchyRepresentationTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\DictionaryCollectionTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\EntityTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\ManyToOneTest.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pa...@us...> - 2011-04-11 17:42:06
|
Revision: 5668
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5668&view=rev
Author: patearl
Date: 2011-04-11 17:41:57 +0000 (Mon, 11 Apr 2011)
Log Message:
-----------
HQL: Support SKIP and TAKE. Support having clause without group by. Throw exception on unexpected trailing input.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Dialect/MsSql2005Dialect.cs
trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlLexer.cs
trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlParser.cs
trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlSqlWalker.cs
trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Generated/SqlGenerator.cs
trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Hql.g
trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.g
trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/SqlGenerator.cs
trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/SqlGenerator.g
trunk/nhibernate/src/NHibernate.Test/DialectTest/MsSql2005DialectFixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1990/Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/Hql/Ast/LimitClauseFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Dialect/MsSql2005Dialect.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Dialect/MsSql2005Dialect.cs 2011-04-11 17:04:42 UTC (rev 5667)
+++ trunk/nhibernate/src/NHibernate/Dialect/MsSql2005Dialect.cs 2011-04-11 17:41:57 UTC (rev 5668)
@@ -29,6 +29,13 @@
RegisterKeyword("xml");
}
+ public override SqlString GetLimitString(SqlString querySqlString, int offset, int limit)
+ {
+ return GetLimitString(querySqlString,
+ offset == 0 ? null : new SqlString(offset.ToString()),
+ limit == int.MaxValue ? null : new SqlString(limit.ToString()));
+ }
+
/// <summary>
/// Add a <c>LIMIT</c> clause to the given SQL <c>SELECT</c>
/// </summary>
@@ -43,17 +50,29 @@
/// </remarks>
public override SqlString GetLimitString(SqlString querySqlString, int offset, int limit, int? offsetParameterIndex, int? limitParameterIndex)
{
+ object limitObject = limitParameterIndex == null ? Parameter.Placeholder : Parameter.WithIndex(limitParameterIndex.Value);
+ object offsetObject = null;
+ if (offset != 0)
+ offsetObject = offsetParameterIndex == null ? Parameter.Placeholder : Parameter.WithIndex(offsetParameterIndex.Value);
+ return GetLimitString(querySqlString, offsetObject, limitObject);
+ }
+
+ private SqlString GetLimitString(SqlString querySqlString, object offset, object limit)
+ {
+ if (offset == null && limit == null)
+ return querySqlString;
+
SqlStringBuilder result = new SqlStringBuilder();
- if (offset == 0)
+ if (offset == null)
{
int insertPoint = this.GetAfterSelectInsertPoint(querySqlString);
return result
.Add(querySqlString.Substring(0, insertPoint))
.Add(" TOP (")
- .Add(limitParameterIndex == null ? Parameter.Placeholder : Parameter.WithIndex(limitParameterIndex.Value))
- .Add(")")
+ .AddObject(limit)
+ .Add(") ")
.Add(querySqlString.Substring(insertPoint))
.ToSqlString();
}
@@ -84,10 +103,12 @@
sortExpressions = new[] {new SqlString("CURRENT_TIMESTAMP"),};
}
- result
- .Add("SELECT TOP (")
- .Add(limitParameterIndex == null ? Parameter.Placeholder : Parameter.WithIndex(limitParameterIndex.Value))
- .Add(") ")
+ result.Add("SELECT ");
+
+ if (limit != null)
+ result.Add("TOP (").AddObject(limit).Add(") ");
+
+ result
.Add(StringHelper.Join(", ", columnsOrAliases))
.Add(" FROM (")
.Add(select)
@@ -99,7 +120,7 @@
.Add(") as __hibernate_sort_row ")
.Add(fromAndWhere)
.Add(") as query WHERE query.__hibernate_sort_row > ")
- .Add(offsetParameterIndex == null ? Parameter.Placeholder : Parameter.WithIndex(offsetParameterIndex.Value))
+ .AddObject(offset)
.Add(" ORDER BY query.__hibernate_sort_row");
return result.ToSqlString();
Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlLexer.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlLexer.cs 2011-04-11 17:04:42 UTC (rev 5667)
+++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlLexer.cs 2011-04-11 17:41:57 UTC (rev 5668)
@@ -1,4 +1,4 @@
-// $ANTLR 3.2 Sep 23, 2009 12:02:23 Hql.g 2011-01-13 10:47:55
+// $ANTLR 3.2 Sep 23, 2009 12:02:23 Hql.g 2011-04-11 10:19:40
// The variable 'variable' is assigned but its value is never used.
#pragma warning disable 168, 219
@@ -17,136 +17,138 @@
namespace NHibernate.Hql.Ast.ANTLR
{
public partial class HqlLexer : Lexer {
- public const int LT = 105;
- public const int EXPONENT = 128;
- public const int STAR = 116;
- public const int FLOAT_SUFFIX = 129;
- public const int LITERAL_by = 54;
- public const int CASE = 55;
+ public const int LT = 107;
+ public const int EXPONENT = 130;
+ public const int STAR = 118;
+ public const int FLOAT_SUFFIX = 131;
+ public const int LITERAL_by = 56;
+ public const int CASE = 57;
public const int NEW = 37;
- public const int FILTER_ENTITY = 74;
- public const int PARAM = 121;
+ public const int FILTER_ENTITY = 76;
+ public const int PARAM = 123;
public const int COUNT = 12;
public const int NOT = 38;
public const int EOF = -1;
- public const int UNARY_PLUS = 89;
- public const int QUOTED_String = 122;
- public const int ESCqs = 126;
- public const int WEIRD_IDENT = 91;
- public const int OPEN_BRACKET = 118;
+ public const int UNARY_PLUS = 91;
+ public const int QUOTED_String = 124;
+ public const int ESCqs = 128;
+ public const int WEIRD_IDENT = 93;
+ public const int OPEN_BRACKET = 120;
public const int FULL = 23;
- public const int ORDER_ELEMENT = 83;
- public const int IS_NULL = 78;
+ public const int ORDER_ELEMENT = 85;
+ public const int IS_NULL = 80;
public const int ESCAPE = 18;
public const int INSERT = 29;
- public const int BOTH = 62;
- public const int NUM_DECIMAL = 95;
- public const int VERSIONED = 52;
- public const int EQ = 100;
+ public const int BOTH = 64;
+ public const int NUM_DECIMAL = 97;
+ public const int VERSIONED = 54;
+ public const int EQ = 102;
public const int SELECT = 45;
public const int INTO = 30;
- public const int NE = 103;
- public const int GE = 108;
- public const int CONCAT = 109;
- public const int ID_LETTER = 125;
+ public const int NE = 105;
+ public const int GE = 110;
+ public const int TAKE = 50;
+ public const int CONCAT = 111;
+ public const int ID_LETTER = 127;
public const int NULL = 39;
- public const int ELSE = 57;
- public const int SELECT_FROM = 87;
- public const int TRAILING = 68;
- public const int ON = 60;
- public const int NUM_LONG = 97;
- public const int NUM_DOUBLE = 94;
- public const int UNARY_MINUS = 88;
+ public const int ELSE = 59;
+ public const int SELECT_FROM = 89;
+ public const int TRAILING = 70;
+ public const int ON = 62;
+ public const int NUM_LONG = 99;
+ public const int NUM_DOUBLE = 96;
+ public const int UNARY_MINUS = 90;
public const int DELETE = 13;
public const int INDICES = 27;
- public const int OF = 67;
- public const int METHOD_CALL = 79;
- public const int LEADING = 64;
- public const int EMPTY = 63;
+ public const int OF = 69;
+ public const int METHOD_CALL = 81;
+ public const int LEADING = 66;
+ public const int SKIP = 47;
+ public const int EMPTY = 65;
public const int GROUP = 24;
- public const int WS = 127;
+ public const int WS = 129;
public const int FETCH = 21;
- public const int VECTOR_EXPR = 90;
- public const int NOT_IN = 81;
- public const int NUM_INT = 93;
+ public const int VECTOR_EXPR = 92;
+ public const int NOT_IN = 83;
+ public const int NUM_INT = 95;
public const int OR = 40;
- public const int ALIAS = 70;
- public const int JAVA_CONSTANT = 98;
- public const int CONSTANT = 92;
- public const int GT = 106;
- public const int QUERY = 84;
- public const int BNOT = 110;
- public const int INDEX_OP = 76;
- public const int NUM_FLOAT = 96;
+ public const int ALIAS = 72;
+ public const int JAVA_CONSTANT = 100;
+ public const int CONSTANT = 94;
+ public const int GT = 108;
+ public const int QUERY = 86;
+ public const int BNOT = 112;
+ public const int INDEX_OP = 78;
+ public const int NUM_FLOAT = 98;
public const int FROM = 22;
- public const int END = 56;
+ public const int END = 58;
public const int FALSE = 20;
public const int DISTINCT = 16;
- public const int T__131 = 131;
- public const int CONSTRUCTOR = 71;
- public const int T__132 = 132;
- public const int CLOSE_BRACKET = 119;
- public const int WHERE = 53;
+ public const int CONSTRUCTOR = 73;
+ public const int T__133 = 133;
+ public const int T__134 = 134;
+ public const int CLOSE_BRACKET = 121;
+ public const int WHERE = 55;
public const int CLASS = 11;
- public const int MEMBER = 65;
+ public const int MEMBER = 67;
public const int INNER = 28;
public const int PROPERTIES = 43;
public const int ORDER = 41;
public const int MAX = 35;
- public const int UPDATE = 51;
- public const int SQL_NE = 104;
+ public const int UPDATE = 53;
+ public const int SQL_NE = 106;
public const int AND = 6;
- public const int SUM = 48;
+ public const int SUM = 49;
public const int ASCENDING = 8;
- public const int EXPR_LIST = 73;
+ public const int EXPR_LIST = 75;
public const int AS = 7;
public const int IN = 26;
- public const int THEN = 58;
- public const int OBJECT = 66;
- public const int COMMA = 99;
+ public const int THEN = 60;
+ public const int OBJECT = 68;
+ public const int COMMA = 101;
public const int IS = 31;
public const int AVG = 9;
public const int LEFT = 33;
- public const int SOME = 47;
+ public const int SOME = 48;
public const int ALL = 4;
- public const int BOR = 111;
- public const int IDENT = 123;
- public const int CASE2 = 72;
- public const int BXOR = 112;
- public const int PLUS = 114;
+ public const int BOR = 113;
+ public const int IDENT = 125;
+ public const int CASE2 = 74;
+ public const int BXOR = 114;
+ public const int PLUS = 116;
public const int EXISTS = 19;
public const int DOT = 15;
- public const int WITH = 61;
+ public const int WITH = 63;
public const int LIKE = 34;
public const int OUTER = 42;
- public const int ID_START_LETTER = 124;
- public const int ROW_STAR = 86;
- public const int NOT_LIKE = 82;
- public const int RANGE = 85;
- public const int NOT_BETWEEN = 80;
- public const int HEX_DIGIT = 130;
+ public const int ID_START_LETTER = 126;
+ public const int ROW_STAR = 88;
+ public const int NOT_LIKE = 84;
+ public const int RANGE = 87;
+ public const int NOT_BETWEEN = 82;
+ public const int HEX_DIGIT = 132;
public const int SET = 46;
public const int RIGHT = 44;
public const int HAVING = 25;
public const int MIN = 36;
- public const int IS_NOT_NULL = 77;
- public const int MINUS = 115;
+ public const int IS_NOT_NULL = 79;
+ public const int MINUS = 117;
public const int ELEMENTS = 17;
- public const int BAND = 113;
- public const int TRUE = 49;
+ public const int BAND = 115;
+ public const int TRUE = 51;
public const int JOIN = 32;
- public const int IN_LIST = 75;
- public const int UNION = 50;
- public const int OPEN = 101;
- public const int COLON = 120;
+ public const int IN_LIST = 77;
+ public const int UNION = 52;
+ public const int OPEN = 103;
+ public const int COLON = 122;
public const int ANY = 5;
- public const int CLOSE = 102;
- public const int WHEN = 59;
- public const int DIV = 117;
+ public const int CLOSE = 104;
+ public const int WHEN = 61;
+ public const int DIV = 119;
public const int DESCENDING = 14;
- public const int AGGREGATE = 69;
+ public const int AGGREGATE = 71;
public const int BETWEEN = 10;
- public const int LE = 107;
+ public const int LE = 109;
// delegates
// delegators
@@ -1177,6 +1179,30 @@
}
// $ANTLR end "SET"
+ // $ANTLR start "SKIP"
+ public void mSKIP() // throws RecognitionException [2]
+ {
+ try
+ {
+ int _type = SKIP;
+ int _channel = DEFAULT_TOKEN_CHANNEL;
+ // Hql.g:51:6: ( 'skip' )
+ // Hql.g:51:8: 'skip'
+ {
+ Match("skip"); if (state.failed) return ;
+
+
+ }
+
+ state.type = _type;
+ state.channel = _channel;
+ }
+ finally
+ {
+ }
+ }
+ // $ANTLR end "SKIP"
+
// $ANTLR start "SOME"
public void mSOME() // throws RecognitionException [2]
{
@@ -1184,8 +1210,8 @@
{
int _type = SOME;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:51:6: ( 'some' )
- // Hql.g:51:8: 'some'
+ // Hql.g:52:6: ( 'some' )
+ // Hql.g:52:8: 'some'
{
Match("some"); if (state.failed) return ;
@@ -1208,8 +1234,8 @@
{
int _type = SUM;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:52:5: ( 'sum' )
- // Hql.g:52:7: 'sum'
+ // Hql.g:53:5: ( 'sum' )
+ // Hql.g:53:7: 'sum'
{
Match("sum"); if (state.failed) return ;
@@ -1225,6 +1251,30 @@
}
// $ANTLR end "SUM"
+ // $ANTLR start "TAKE"
+ public void mTAKE() // throws RecognitionException [2]
+ {
+ try
+ {
+ int _type = TAKE;
+ int _channel = DEFAULT_TOKEN_CHANNEL;
+ // Hql.g:54:6: ( 'take' )
+ // Hql.g:54:8: 'take'
+ {
+ Match("take"); if (state.failed) return ;
+
+
+ }
+
+ state.type = _type;
+ state.channel = _channel;
+ }
+ finally
+ {
+ }
+ }
+ // $ANTLR end "TAKE"
+
// $ANTLR start "TRUE"
public void mTRUE() // throws RecognitionException [2]
{
@@ -1232,8 +1282,8 @@
{
int _type = TRUE;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:53:6: ( 'true' )
- // Hql.g:53:8: 'true'
+ // Hql.g:55:6: ( 'true' )
+ // Hql.g:55:8: 'true'
{
Match("true"); if (state.failed) return ;
@@ -1256,8 +1306,8 @@
{
int _type = UNION;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:54:7: ( 'union' )
- // Hql.g:54:9: 'union'
+ // Hql.g:56:7: ( 'union' )
+ // Hql.g:56:9: 'union'
{
Match("union"); if (state.failed) return ;
@@ -1280,8 +1330,8 @@
{
int _type = UPDATE;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:55:8: ( 'update' )
- // Hql.g:55:10: 'update'
+ // Hql.g:57:8: ( 'update' )
+ // Hql.g:57:10: 'update'
{
Match("update"); if (state.failed) return ;
@@ -1304,8 +1354,8 @@
{
int _type = VERSIONED;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:56:11: ( 'versioned' )
- // Hql.g:56:13: 'versioned'
+ // Hql.g:58:11: ( 'versioned' )
+ // Hql.g:58:13: 'versioned'
{
Match("versioned"); if (state.failed) return ;
@@ -1328,8 +1378,8 @@
{
int _type = WHERE;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:57:7: ( 'where' )
- // Hql.g:57:9: 'where'
+ // Hql.g:59:7: ( 'where' )
+ // Hql.g:59:9: 'where'
{
Match("where"); if (state.failed) return ;
@@ -1352,8 +1402,8 @@
{
int _type = LITERAL_by;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:58:12: ( 'by' )
- // Hql.g:58:14: 'by'
+ // Hql.g:60:12: ( 'by' )
+ // Hql.g:60:14: 'by'
{
Match("by"); if (state.failed) return ;
@@ -1376,8 +1426,8 @@
{
int _type = CASE;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:59:6: ( 'case' )
- // Hql.g:59:8: 'case'
+ // Hql.g:61:6: ( 'case' )
+ // Hql.g:61:8: 'case'
{
Match("case"); if (state.failed) return ;
@@ -1400,8 +1450,8 @@
{
int _type = END;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:60:5: ( 'end' )
- // Hql.g:60:7: 'end'
+ // Hql.g:62:5: ( 'end' )
+ // Hql.g:62:7: 'end'
{
Match("end"); if (state.failed) return ;
@@ -1424,8 +1474,8 @@
{
int _type = ELSE;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:61:6: ( 'else' )
- // Hql.g:61:8: 'else'
+ // Hql.g:63:6: ( 'else' )
+ // Hql.g:63:8: 'else'
{
Match("else"); if (state.failed) return ;
@@ -1448,8 +1498,8 @@
{
int _type = THEN;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:62:6: ( 'then' )
- // Hql.g:62:8: 'then'
+ // Hql.g:64:6: ( 'then' )
+ // Hql.g:64:8: 'then'
{
Match("then"); if (state.failed) return ;
@@ -1472,8 +1522,8 @@
{
int _type = WHEN;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:63:6: ( 'when' )
- // Hql.g:63:8: 'when'
+ // Hql.g:65:6: ( 'when' )
+ // Hql.g:65:8: 'when'
{
Match("when"); if (state.failed) return ;
@@ -1496,8 +1546,8 @@
{
int _type = ON;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:64:4: ( 'on' )
- // Hql.g:64:6: 'on'
+ // Hql.g:66:4: ( 'on' )
+ // Hql.g:66:6: 'on'
{
Match("on"); if (state.failed) return ;
@@ -1520,8 +1570,8 @@
{
int _type = WITH;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:65:6: ( 'with' )
- // Hql.g:65:8: 'with'
+ // Hql.g:67:6: ( 'with' )
+ // Hql.g:67:8: 'with'
{
Match("with"); if (state.failed) return ;
@@ -1544,8 +1594,8 @@
{
int _type = BOTH;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:66:6: ( 'both' )
- // Hql.g:66:8: 'both'
+ // Hql.g:68:6: ( 'both' )
+ // Hql.g:68:8: 'both'
{
Match("both"); if (state.failed) return ;
@@ -1568,8 +1618,8 @@
{
int _type = EMPTY;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:67:7: ( 'empty' )
- // Hql.g:67:9: 'empty'
+ // Hql.g:69:7: ( 'empty' )
+ // Hql.g:69:9: 'empty'
{
Match("empty"); if (state.failed) return ;
@@ -1592,8 +1642,8 @@
{
int _type = LEADING;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:68:9: ( 'leading' )
- // Hql.g:68:11: 'leading'
+ // Hql.g:70:9: ( 'leading' )
+ // Hql.g:70:11: 'leading'
{
Match("leading"); if (state.failed) return ;
@@ -1616,8 +1666,8 @@
{
int _type = MEMBER;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:69:8: ( 'member' )
- // Hql.g:69:10: 'member'
+ // Hql.g:71:8: ( 'member' )
+ // Hql.g:71:10: 'member'
{
Match("member"); if (state.failed) return ;
@@ -1640,8 +1690,8 @@
{
int _type = OBJECT;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:70:8: ( 'object' )
- // Hql.g:70:10: 'object'
+ // Hql.g:72:8: ( 'object' )
+ // Hql.g:72:10: 'object'
{
Match("object"); if (state.failed) return ;
@@ -1664,8 +1714,8 @@
{
int _type = OF;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:71:4: ( 'of' )
- // Hql.g:71:6: 'of'
+ // Hql.g:73:4: ( 'of' )
+ // Hql.g:73:6: 'of'
{
Match("of"); if (state.failed) return ;
@@ -1688,8 +1738,8 @@
{
int _type = TRAILING;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:72:10: ( 'trailing' )
- // Hql.g:72:12: 'trailing'
+ // Hql.g:74:10: ( 'trailing' )
+ // Hql.g:74:12: 'trailing'
{
Match("trailing"); if (state.failed) return ;
@@ -1705,15 +1755,15 @@
}
// $ANTLR end "TRAILING"
- // $ANTLR start "T__131"
- public void mT__131() // throws RecognitionException [2]
+ // $ANTLR start "T__133"
+ public void mT__133() // throws RecognitionException [2]
{
try
{
- int _type = T__131;
+ int _type = T__133;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:73:8: ( 'ascending' )
- // Hql.g:73:10: 'ascending'
+ // Hql.g:75:8: ( 'ascending' )
+ // Hql.g:75:10: 'ascending'
{
Match("ascending"); if (state.failed) return ;
@@ -1727,17 +1777,17 @@
{
}
}
- // $ANTLR end "T__131"
+ // $ANTLR end "T__133"
- // $ANTLR start "T__132"
- public void mT__132() // throws RecognitionException [2]
+ // $ANTLR start "T__134"
+ public void mT__134() // throws RecognitionException [2]
{
try
{
- int _type = T__132;
+ int _type = T__134;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:74:8: ( 'descending' )
- // Hql.g:74:10: 'descending'
+ // Hql.g:76:8: ( 'descending' )
+ // Hql.g:76:10: 'descending'
{
Match("descending"); if (state.failed) return ;
@@ -1751,7 +1801,7 @@
{
}
}
- // $ANTLR end "T__132"
+ // $ANTLR end "T__134"
// $ANTLR start "EQ"
public void mEQ() // throws RecognitionException [2]
@@ -1760,8 +1810,8 @@
{
int _type = EQ;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:672:3: ( '=' )
- // Hql.g:672:5: '='
+ // Hql.g:684:3: ( '=' )
+ // Hql.g:684:5: '='
{
Match('='); if (state.failed) return ;
@@ -1783,8 +1833,8 @@
{
int _type = LT;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:673:3: ( '<' )
- // Hql.g:673:5: '<'
+ // Hql.g:685:3: ( '<' )
+ // Hql.g:685:5: '<'
{
Match('<'); if (state.failed) return ;
@@ -1806,8 +1856,8 @@
{
int _type = GT;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:674:3: ( '>' )
- // Hql.g:674:5: '>'
+ // Hql.g:686:3: ( '>' )
+ // Hql.g:686:5: '>'
{
Match('>'); if (state.failed) return ;
@@ -1829,8 +1879,8 @@
{
int _type = SQL_NE;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:675:7: ( '<>' )
- // Hql.g:675:9: '<>'
+ // Hql.g:687:7: ( '<>' )
+ // Hql.g:687:9: '<>'
{
Match("<>"); if (state.failed) return ;
@@ -1853,7 +1903,7 @@
{
int _type = NE;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:676:3: ( '!=' | '^=' )
+ // Hql.g:688:3: ( '!=' | '^=' )
int alt1 = 2;
int LA1_0 = input.LA(1);
@@ -1876,7 +1926,7 @@
switch (alt1)
{
case 1 :
- // Hql.g:676:5: '!='
+ // Hql.g:688:5: '!='
{
Match("!="); if (state.failed) return ;
@@ -1884,7 +1934,7 @@
}
break;
case 2 :
- // Hql.g:676:12: '^='
+ // Hql.g:688:12: '^='
{
Match("^="); if (state.failed) return ;
@@ -1909,8 +1959,8 @@
{
int _type = LE;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:677:3: ( '<=' )
- // Hql.g:677:5: '<='
+ // Hql.g:689:3: ( '<=' )
+ // Hql.g:689:5: '<='
{
Match("<="); if (state.failed) return ;
@@ -1933,8 +1983,8 @@
{
int _type = GE;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:678:3: ( '>=' )
- // Hql.g:678:5: '>='
+ // Hql.g:690:3: ( '>=' )
+ // Hql.g:690:5: '>='
{
Match(">="); if (state.failed) return ;
@@ -1957,8 +2007,8 @@
{
int _type = BOR;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:680:5: ( '|' )
- // Hql.g:680:8: '|'
+ // Hql.g:692:5: ( '|' )
+ // Hql.g:692:8: '|'
{
Match('|'); if (state.failed) return ;
@@ -1980,8 +2030,8 @@
{
int _type = BXOR;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:681:6: ( '^' )
- // Hql.g:681:8: '^'
+ // Hql.g:693:6: ( '^' )
+ // Hql.g:693:8: '^'
{
Match('^'); if (state.failed) return ;
@@ -2003,8 +2053,8 @@
{
int _type = BAND;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:682:6: ( '&' )
- // Hql.g:682:8: '&'
+ // Hql.g:694:6: ( '&' )
+ // Hql.g:694:8: '&'
{
Match('&'); if (state.failed) return ;
@@ -2026,8 +2076,8 @@
{
int _type = BNOT;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:683:6: ( '!' )
- // Hql.g:683:8: '!'
+ // Hql.g:695:6: ( '!' )
+ // Hql.g:695:8: '!'
{
Match('!'); if (state.failed) return ;
@@ -2049,8 +2099,8 @@
{
int _type = COMMA;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:685:6: ( ',' )
- // Hql.g:685:8: ','
+ // Hql.g:697:6: ( ',' )
+ // Hql.g:697:8: ','
{
Match(','); if (state.failed) return ;
@@ -2072,8 +2122,8 @@
{
int _type = OPEN;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:687:5: ( '(' )
- // Hql.g:687:7: '('
+ // Hql.g:699:5: ( '(' )
+ // Hql.g:699:7: '('
{
Match('('); if (state.failed) return ;
@@ -2095,8 +2145,8 @@
{
int _type = CLOSE;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:688:6: ( ')' )
- // Hql.g:688:8: ')'
+ // Hql.g:700:6: ( ')' )
+ // Hql.g:700:8: ')'
{
Match(')'); if (state.failed) return ;
@@ -2118,8 +2168,8 @@
{
int _type = OPEN_BRACKET;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:689:13: ( '[' )
- // Hql.g:689:15: '['
+ // Hql.g:701:13: ( '[' )
+ // Hql.g:701:15: '['
{
Match('['); if (state.failed) return ;
@@ -2141,8 +2191,8 @@
{
int _type = CLOSE_BRACKET;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:690:14: ( ']' )
- // Hql.g:690:16: ']'
+ // Hql.g:702:14: ( ']' )
+ // Hql.g:702:16: ']'
{
Match(']'); if (state.failed) return ;
@@ -2164,8 +2214,8 @@
{
int _type = CONCAT;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:692:7: ( '||' )
- // Hql.g:692:9: '||'
+ // Hql.g:704:7: ( '||' )
+ // Hql.g:704:9: '||'
{
Match("||"); if (state.failed) return ;
@@ -2188,8 +2238,8 @@
{
int _type = PLUS;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:693:5: ( '+' )
- // Hql.g:693:7: '+'
+ // Hql.g:705:5: ( '+' )
+ // Hql.g:705:7: '+'
{
Match('+'); if (state.failed) return ;
@@ -2211,8 +2261,8 @@
{
int _type = MINUS;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:694:6: ( '-' )
- // Hql.g:694:8: '-'
+ // Hql.g:706:6: ( '-' )
+ // Hql.g:706:8: '-'
{
Match('-'); if (state.failed) return ;
@@ -2234,8 +2284,8 @@
{
int _type = STAR;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:695:5: ( '*' )
- // Hql.g:695:7: '*'
+ // Hql.g:707:5: ( '*' )
+ // Hql.g:707:7: '*'
{
Match('*'); if (state.failed) return ;
@@ -2257,8 +2307,8 @@
{
int _type = DIV;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:696:4: ( '/' )
- // Hql.g:696:6: '/'
+ // Hql.g:708:4: ( '/' )
+ // Hql.g:708:6: '/'
{
Match('/'); if (state.failed) return ;
@@ -2280,8 +2330,8 @@
{
int _type = COLON;
int _channel = DEFAULT_TOKEN_CHANNEL;
- // Hql.g:697:6: ( ':' )
- // Hql.g:697:8: ':'
+ // Hql.g:709:6: ( ':' )
+ // Hql.g:709:8: ':'
{
...
[truncated message content] |
|
From: <fab...@us...> - 2011-04-12 12:19:40
|
Revision: 5675
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5675&view=rev
Author: fabiomaulo
Date: 2011-04-12 12:19:33 +0000 (Tue, 12 Apr 2011)
Log Message:
-----------
SimpleModelInspector with default pattern to discover RootEntities entities
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/RootEntityTests.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-12 11:08:59 UTC (rev 5674)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-12 12:19:33 UTC (rev 5675)
@@ -44,6 +44,7 @@
public SimpleModelInspector()
{
isEntity = (t, declared) => declared || MatchEntity(t);
+ isRootEntity = (t, declared) => declared || MatchRootEntity(t);
isTablePerClass = (t, declared) => declared || MatchTablePerClass(t);
isPersistentId = (m, declared) => declared || MatchPoIdPattern(m);
isComponent = (t, declared) => declared || MatchComponentPattern(t);
@@ -56,6 +57,11 @@
isOneToMany = (m, declared) => declared || MatchOneToMany(m);
}
+ private bool MatchRootEntity(System.Type type)
+ {
+ return type.IsClass && typeof(object).Equals(type.BaseType);
+ }
+
private bool MatchTablePerClass(System.Type type)
{
return !declaredModel.IsTablePerClassHierarchy(type) && !declaredModel.IsTablePerConcreteClass(type);
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/RootEntityTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/RootEntityTests.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/RootEntityTests.cs 2011-04-12 12:19:33 UTC (rev 5675)
@@ -0,0 +1,45 @@
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.MixAutomapping
+{
+ public class RootEntityTests
+ {
+ private class Person
+ {
+ public int Id { get; set; }
+ }
+
+ private class BaseEntity
+ {
+ public int Id { get; set; }
+ }
+
+ private class Product: BaseEntity
+ {
+ }
+
+ [Test]
+ public void ByDefaultInheritedFromObject()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsRootEntity(typeof(Person)).Should().Be.True();
+ inspector.IsRootEntity(typeof(Product)).Should().Be.False();
+ }
+
+ [Test]
+ public void WhenCustomizedThenUseCustomizedPredicate()
+ {
+ var autoinspector = new SimpleModelInspector();
+ autoinspector.IsRootEntity((t, declared) => typeof(BaseEntity).Equals(t.BaseType));
+
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsRootEntity(typeof(Person)).Should().Be.False();
+ inspector.IsRootEntity(typeof(Product)).Should().Be.True();
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-12 11:08:59 UTC (rev 5674)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-12 12:19:33 UTC (rev 5675)
@@ -552,6 +552,7 @@
<Compile Include="MappingByCode\MixAutomapping\OneToManyTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\PoidTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\PropertiesExclusionTests.cs" />
+ <Compile Include="MappingByCode\MixAutomapping\RootEntityTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\SetCollectionTests.cs" />
<Compile Include="MappingByCode\ModelExplicitDeclarationsHolderMergeTest.cs" />
<Compile Include="MappingByCode\NatureDemo\Naturalness\Address.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2011-04-12 17:50:40
|
Revision: 5678
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5678&view=rev
Author: fabiomaulo
Date: 2011-04-12 17:50:33 +0000 (Tue, 12 Apr 2011)
Log Message:
-----------
ConventionModelMapper with convention for joined-subclass key column
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/ConventionModelMapper.cs
trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/
trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/JoinedSubclassKeyAsRootIdColumnTest.cs
Added: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ConventionModelMapper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ConventionModelMapper.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ConventionModelMapper.cs 2011-04-12 17:50:33 UTC (rev 5678)
@@ -0,0 +1,155 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+
+namespace NHibernate.Mapping.ByCode
+{
+ public class ConventionModelMapper : ModelMapper
+ {
+ public ConventionModelMapper()
+ : base(new SimpleModelInspector())
+ {
+ AppendDefaultEvents();
+ }
+
+ protected virtual void AppendDefaultEvents()
+ {
+ BeforeMapJoinedSubclass += JoinedSubclassKeyAsRootIdColumn;
+ }
+
+ protected void JoinedSubclassKeyAsRootIdColumn(IModelInspector modelInspector, System.Type type, IJoinedSubclassAttributesMapper joinedSubclassCustomizer)
+ {
+ var idMember = type.GetProperties().Cast<MemberInfo>().Concat(type.GetFields()).FirstOrDefault(mi => ModelInspector.IsPersistentId(mi.GetMemberFromDeclaringType()));
+ if (idMember != null)
+ {
+ joinedSubclassCustomizer.Key(km => km.Column(idMember.Name));
+ }
+ }
+
+ protected SimpleModelInspector SimpleModelInspector
+ {
+ get { return (SimpleModelInspector) base.ModelInspector; }
+ }
+
+ public void IsRootEntity(Func<System.Type, bool, bool> match)
+ {
+ SimpleModelInspector.IsRootEntity(match);
+ }
+
+ public void IsComponent(Func<System.Type, bool, bool> match)
+ {
+ SimpleModelInspector.IsComponent(match);
+ }
+
+ public void IsEntity(Func<System.Type, bool, bool> match)
+ {
+ SimpleModelInspector.IsEntity(match);
+ }
+
+ public void IsTablePerClass(Func<System.Type, bool, bool> match)
+ {
+ SimpleModelInspector.IsTablePerClass(match);
+ }
+
+ public void IsTablePerClassHierarchy(Func<System.Type, bool, bool> match)
+ {
+ SimpleModelInspector.IsTablePerClassHierarchy(match);
+ }
+
+ public void IsTablePerConcreteClass(Func<System.Type, bool, bool> match)
+ {
+ SimpleModelInspector.IsTablePerConcreteClass(match);
+ }
+
+ public void IsOneToOne(Func<MemberInfo, bool, bool> match)
+ {
+ SimpleModelInspector.IsOneToOne(match);
+ }
+
+ public void IsManyToOne(Func<MemberInfo, bool, bool> match)
+ {
+ SimpleModelInspector.IsManyToOne(match);
+ }
+
+ public void IsManyToMany(Func<MemberInfo, bool, bool> match)
+ {
+ SimpleModelInspector.IsManyToMany(match);
+ }
+
+ public void IsOneToMany(Func<MemberInfo, bool, bool> match)
+ {
+ SimpleModelInspector.IsOneToMany(match);
+ }
+
+ public void IsAny(Func<MemberInfo, bool, bool> match)
+ {
+ SimpleModelInspector.IsAny(match);
+ }
+
+ public void IsPersistentId(Func<MemberInfo, bool, bool> match)
+ {
+ SimpleModelInspector.IsPersistentId(match);
+ }
+
+ public void IsVersion(Func<MemberInfo, bool, bool> match)
+ {
+ SimpleModelInspector.IsVersion(match);
+ }
+
+ public void IsMemberOfNaturalId(Func<MemberInfo, bool, bool> match)
+ {
+ SimpleModelInspector.IsMemberOfNaturalId(match);
+ }
+
+ public void IsPersistentProperty(Func<MemberInfo, bool, bool> match)
+ {
+ SimpleModelInspector.IsPersistentProperty(match);
+ }
+
+ public void IsSet(Func<MemberInfo, bool, bool> match)
+ {
+ SimpleModelInspector.IsSet(match);
+ }
+
+ public void IsBag(Func<MemberInfo, bool, bool> match)
+ {
+ SimpleModelInspector.IsBag(match);
+ }
+
+ public void IsIdBag(Func<MemberInfo, bool, bool> match)
+ {
+ SimpleModelInspector.IsIdBag(match);
+ }
+
+ public void IsList(Func<MemberInfo, bool, bool> match)
+ {
+ SimpleModelInspector.IsList(match);
+ }
+
+ public void IsArray(Func<MemberInfo, bool, bool> match)
+ {
+ SimpleModelInspector.IsArray(match);
+ }
+
+ public void IsDictionary(Func<MemberInfo, bool, bool> match)
+ {
+ SimpleModelInspector.IsDictionary(match);
+ }
+
+ public void IsProperty(Func<MemberInfo, bool, bool> match)
+ {
+ SimpleModelInspector.IsProperty(match);
+ }
+
+ public void SplitsFor(Func<System.Type, IEnumerable<string>, IEnumerable<string>> getPropertiesSplitsId)
+ {
+ SimpleModelInspector.SplitsFor(getPropertiesSplitsId);
+ }
+
+ public void IsTablePerClassSplit(Func<SplitDefinition, bool, bool> match)
+ {
+ SimpleModelInspector.IsTablePerClassSplit(match);
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-12 14:27:47 UTC (rev 5677)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-12 17:50:33 UTC (rev 5678)
@@ -438,6 +438,7 @@
<Compile Include="Mapping\Column.cs" />
<Compile Include="Mapping\Component.cs" />
<Compile Include="Mapping\Constraint.cs" />
+ <Compile Include="Mapping\ByCode\ConventionModelMapper.cs" />
<Compile Include="Mapping\ForeignKey.cs" />
<Compile Include="Mapping\Formula.cs" />
<Compile Include="Mapping\IdentifierBag.cs" />
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/JoinedSubclassKeyAsRootIdColumnTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/JoinedSubclassKeyAsRootIdColumnTest.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/JoinedSubclassKeyAsRootIdColumnTest.cs 2011-04-12 17:50:33 UTC (rev 5678)
@@ -0,0 +1,53 @@
+using System.Linq;
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.ConventionModelMapperTests
+{
+ public class JoinedSubclassKeyAsRootIdColumnTest
+ {
+ private class MyClass
+ {
+ public int MyId { get; set; }
+ public int HisId { get; set; }
+ }
+
+ private class Inherited : MyClass
+ {
+ }
+
+ [Test]
+ public void WhenBaseIsIdThenUseId()
+ {
+ var mapper = new ConventionModelMapper();
+ mapper.Class<MyClass>(map=> map.Id(x=> x.MyId));
+ var mapping = mapper.CompileMappingFor(new[] { typeof(Inherited), typeof(MyClass) });
+ var hbmJoinedClass = mapping.JoinedSubclasses[0];
+
+ hbmJoinedClass.key.Columns.Single().name.Should().Be("MyId");
+ }
+
+ [Test]
+ public void WhenBaseIsPoIdThenUsePoId()
+ {
+ var mapper = new ConventionModelMapper();
+ mapper.Class<MyClass>(map => map.Id(x => x.HisId));
+ var mapping = mapper.CompileMappingFor(new[] { typeof(Inherited), typeof(MyClass) });
+ var hbmJoinedClass = mapping.JoinedSubclasses[0];
+
+ hbmJoinedClass.key.Columns.Single().name.Should().Be("HisId");
+ }
+
+ [Test]
+ public void WhenNoPoidMemberThenDoesNotSet()
+ {
+ var mapper = new ConventionModelMapper();
+ mapper.Class<MyClass>(map => { });
+ var mapping = mapper.CompileMappingFor(new[] { typeof(Inherited), typeof(MyClass) });
+ var hbmJoinedClass = mapping.JoinedSubclasses[0];
+
+ hbmJoinedClass.key.Columns.Single().name.Should().Not.Be("MyId").And.Not.Be("HisId");
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-12 14:27:47 UTC (rev 5677)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-12 17:50:33 UTC (rev 5678)
@@ -511,6 +511,7 @@
<Compile Include="Linq\ByMethod\SumTests.cs" />
<Compile Include="Logging\Log4NetLoggerTest.cs" />
<Compile Include="Logging\LoggerProviderTest.cs" />
+ <Compile Include="MappingByCode\ConventionModelMapperTests\JoinedSubclassKeyAsRootIdColumnTest.cs" />
<Compile Include="MappingByCode\ExpliticMappingTests\BagOfNestedComponentsWithParentTest.cs" />
<Compile Include="MappingByCode\ExpliticMappingTests\ClassWithComponentsTest.cs" />
<Compile Include="MappingByCode\ExpliticMappingTests\ConformistMappingRegistrationTests\ClassMappingRegistrationTest.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2011-04-12 17:55:31
|
Revision: 5679
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5679&view=rev
Author: fabiomaulo
Date: 2011-04-12 17:55:24 +0000 (Tue, 12 Apr 2011)
Log Message:
-----------
Moved classes to the "public" namespace
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/NHibernate.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/PropertyPath.cs
trunk/nhibernate/src/NHibernate/Mapping/ByCode/PropertyPathExtensions.cs
Removed Paths:
-------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/PropertyPath.cs
trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/PropertyPathExtensions.cs
Deleted: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/PropertyPath.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/PropertyPath.cs 2011-04-12 17:50:33 UTC (rev 5678)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/PropertyPath.cs 2011-04-12 17:55:24 UTC (rev 5679)
@@ -1,84 +0,0 @@
-using System;
-using System.Reflection;
-
-namespace NHibernate.Mapping.ByCode.Impl
-{
- public class PropertyPath
- {
- private readonly int hashCode;
- private readonly MemberInfo localMember;
- private readonly PropertyPath previousPath;
-
- public PropertyPath(PropertyPath previousPath, MemberInfo localMember)
- {
- if (localMember == null)
- {
- throw new ArgumentNullException("localMember");
- }
- this.previousPath = previousPath;
- this.localMember = localMember;
- hashCode = localMember.GetHashCode() ^ (previousPath != null ? previousPath.GetHashCode() : 41);
- }
-
- public PropertyPath PreviousPath
- {
- get { return previousPath; }
- }
-
- public MemberInfo LocalMember
- {
- get { return localMember; }
- }
-
- public MemberInfo GetRootMember()
- {
- PropertyPath analizing = this;
- while (analizing.previousPath != null)
- {
- analizing = analizing.previousPath;
- }
- return analizing.localMember;
- }
-
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj))
- {
- return false;
- }
- if (ReferenceEquals(this, obj))
- {
- return true;
- }
- return Equals(obj as PropertyPath);
- }
-
- public bool Equals(PropertyPath other)
- {
- if (ReferenceEquals(null, other))
- {
- return false;
- }
- if (ReferenceEquals(this, other))
- {
- return true;
- }
- return hashCode == other.GetHashCode();
- }
-
- public override int GetHashCode()
- {
- return hashCode;
- }
-
- public string ToColumnName()
- {
- return PreviousPath == null ? LocalMember.Name : PreviousPath.ToColumnName() + LocalMember.Name;
- }
-
- public override string ToString()
- {
- return PreviousPath == null ? LocalMember.Name : PreviousPath + "." + LocalMember.Name;
- }
- }
-}
\ No newline at end of file
Deleted: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/PropertyPathExtensions.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/PropertyPathExtensions.cs 2011-04-12 17:50:33 UTC (rev 5678)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/PropertyPathExtensions.cs 2011-04-12 17:55:24 UTC (rev 5679)
@@ -1,47 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-
-namespace NHibernate.Mapping.ByCode.Impl
-{
- public static class PropertyPathExtensions
- {
- public static string ToColumnName(this PropertyPath propertyPath, string pathSeparator)
- {
- return propertyPath.ToString().Replace(".", pathSeparator);
- }
-
- /// <summary>
- /// Provide the list of progressive-paths
- /// </summary>
- /// <param name="source"></param>
- /// <returns>
- /// Given a path as : Pl1.Pl2.Pl3.Pl4.Pl5 returns paths-sequence as:
- /// Pl5
- /// Pl4.Pl5
- /// Pl3.Pl4.Pl5
- /// Pl2.Pl3.Pl4.Pl5
- /// Pl1.Pl2.Pl3.Pl4.Pl5
- /// </returns>
- public static IEnumerable<PropertyPath> InverseProgressivePath(this PropertyPath source)
- {
- if (source == null)
- {
- throw new ArgumentNullException("source");
- }
- PropertyPath analizing = source;
- var returnLocalMembers = new List<MemberInfo>(10);
- do
- {
- returnLocalMembers.Add(analizing.LocalMember);
- PropertyPath progressivePath = null;
- for (int i = returnLocalMembers.Count - 1; i >= 0; i--)
- {
- progressivePath = new PropertyPath(progressivePath, returnLocalMembers[i]);
- }
- yield return progressivePath;
- analizing = analizing.PreviousPath;
- } while (analizing != null);
- }
- }
-}
\ No newline at end of file
Copied: trunk/nhibernate/src/NHibernate/Mapping/ByCode/PropertyPath.cs (from rev 5676, trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/PropertyPath.cs)
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/PropertyPath.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/PropertyPath.cs 2011-04-12 17:55:24 UTC (rev 5679)
@@ -0,0 +1,84 @@
+using System;
+using System.Reflection;
+
+namespace NHibernate.Mapping.ByCode
+{
+ public class PropertyPath
+ {
+ private readonly int hashCode;
+ private readonly MemberInfo localMember;
+ private readonly PropertyPath previousPath;
+
+ public PropertyPath(PropertyPath previousPath, MemberInfo localMember)
+ {
+ if (localMember == null)
+ {
+ throw new ArgumentNullException("localMember");
+ }
+ this.previousPath = previousPath;
+ this.localMember = localMember;
+ hashCode = localMember.GetHashCode() ^ (previousPath != null ? previousPath.GetHashCode() : 41);
+ }
+
+ public PropertyPath PreviousPath
+ {
+ get { return previousPath; }
+ }
+
+ public MemberInfo LocalMember
+ {
+ get { return localMember; }
+ }
+
+ public MemberInfo GetRootMember()
+ {
+ PropertyPath analizing = this;
+ while (analizing.previousPath != null)
+ {
+ analizing = analizing.previousPath;
+ }
+ return analizing.localMember;
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj))
+ {
+ return false;
+ }
+ if (ReferenceEquals(this, obj))
+ {
+ return true;
+ }
+ return Equals(obj as PropertyPath);
+ }
+
+ public bool Equals(PropertyPath other)
+ {
+ if (ReferenceEquals(null, other))
+ {
+ return false;
+ }
+ if (ReferenceEquals(this, other))
+ {
+ return true;
+ }
+ return hashCode == other.GetHashCode();
+ }
+
+ public override int GetHashCode()
+ {
+ return hashCode;
+ }
+
+ public string ToColumnName()
+ {
+ return PreviousPath == null ? LocalMember.Name : PreviousPath.ToColumnName() + LocalMember.Name;
+ }
+
+ public override string ToString()
+ {
+ return PreviousPath == null ? LocalMember.Name : PreviousPath + "." + LocalMember.Name;
+ }
+ }
+}
\ No newline at end of file
Copied: trunk/nhibernate/src/NHibernate/Mapping/ByCode/PropertyPathExtensions.cs (from rev 5676, trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/PropertyPathExtensions.cs)
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/PropertyPathExtensions.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/PropertyPathExtensions.cs 2011-04-12 17:55:24 UTC (rev 5679)
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+
+namespace NHibernate.Mapping.ByCode
+{
+ public static class PropertyPathExtensions
+ {
+ public static string ToColumnName(this PropertyPath propertyPath, string pathSeparator)
+ {
+ return propertyPath.ToString().Replace(".", pathSeparator);
+ }
+
+ /// <summary>
+ /// Provide the list of progressive-paths
+ /// </summary>
+ /// <param name="source"></param>
+ /// <returns>
+ /// Given a path as : Pl1.Pl2.Pl3.Pl4.Pl5 returns paths-sequence as:
+ /// Pl5
+ /// Pl4.Pl5
+ /// Pl3.Pl4.Pl5
+ /// Pl2.Pl3.Pl4.Pl5
+ /// Pl1.Pl2.Pl3.Pl4.Pl5
+ /// </returns>
+ public static IEnumerable<PropertyPath> InverseProgressivePath(this PropertyPath source)
+ {
+ if (source == null)
+ {
+ throw new ArgumentNullException("source");
+ }
+ PropertyPath analizing = source;
+ var returnLocalMembers = new List<MemberInfo>(10);
+ do
+ {
+ returnLocalMembers.Add(analizing.LocalMember);
+ PropertyPath progressivePath = null;
+ for (int i = returnLocalMembers.Count - 1; i >= 0; i--)
+ {
+ progressivePath = new PropertyPath(progressivePath, returnLocalMembers[i]);
+ }
+ yield return progressivePath;
+ analizing = analizing.PreviousPath;
+ } while (analizing != null);
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-12 17:50:33 UTC (rev 5678)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-12 17:55:24 UTC (rev 5679)
@@ -409,8 +409,8 @@
<Compile Include="Mapping\ByCode\Impl\OneToManyMapper.cs" />
<Compile Include="Mapping\ByCode\Impl\OneToOneMapper.cs" />
<Compile Include="Mapping\ByCode\Impl\PropertyMapper.cs" />
- <Compile Include="Mapping\ByCode\Impl\PropertyPath.cs" />
- <Compile Include="Mapping\ByCode\Impl\PropertyPathExtensions.cs" />
+ <Compile Include="Mapping\ByCode\PropertyPath.cs" />
+ <Compile Include="Mapping\ByCode\PropertyPathExtensions.cs" />
<Compile Include="Mapping\ByCode\Impl\SetMapper.cs" />
<Compile Include="Mapping\ByCode\Impl\SubclassMapper.cs" />
<Compile Include="Mapping\ByCode\Impl\TypeNameUtil.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2011-04-12 18:38:03
|
Revision: 5680
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5680&view=rev
Author: fabiomaulo
Date: 2011-04-12 18:37:57 +0000 (Tue, 12 Apr 2011)
Log Message:
-----------
ConventionModelMapper with convention for property column
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/ConventionModelMapper.cs
trunk/nhibernate/src/NHibernate/Mapping/ByCode/PropertyPathExtensions.cs
trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/PropertyColumnNameTests.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ConventionModelMapper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ConventionModelMapper.cs 2011-04-12 17:55:24 UTC (rev 5679)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ConventionModelMapper.cs 2011-04-12 18:37:57 UTC (rev 5680)
@@ -16,8 +16,24 @@
protected virtual void AppendDefaultEvents()
{
BeforeMapJoinedSubclass += JoinedSubclassKeyAsRootIdColumn;
+ BeforeMapProperty += PropertyColumnName;
}
+ protected void PropertyColumnName(IModelInspector modelInspector, PropertyPath member, IPropertyMapper propertyCustomizer)
+ {
+ if (member.PreviousPath == null || member.LocalMember == null)
+ {
+ return;
+ }
+ if (member.PreviousPath.LocalMember.GetPropertyOrFieldType().IsGenericCollection())
+ {
+ return;
+ }
+
+ var pathToMap = member.DepureFirstLevelIfCollection();
+ propertyCustomizer.Column(pathToMap.ToColumnName());
+ }
+
protected void JoinedSubclassKeyAsRootIdColumn(IModelInspector modelInspector, System.Type type, IJoinedSubclassAttributesMapper joinedSubclassCustomizer)
{
var idMember = type.GetProperties().Cast<MemberInfo>().Concat(type.GetFields()).FirstOrDefault(mi => ModelInspector.IsPersistentId(mi.GetMemberFromDeclaringType()));
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/PropertyPathExtensions.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/PropertyPathExtensions.cs 2011-04-12 17:55:24 UTC (rev 5679)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/PropertyPathExtensions.cs 2011-04-12 18:37:57 UTC (rev 5680)
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Reflection;
namespace NHibernate.Mapping.ByCode
@@ -43,5 +44,19 @@
analizing = analizing.PreviousPath;
} while (analizing != null);
}
+
+ public static PropertyPath DepureFirstLevelIfCollection(this PropertyPath source)
+ {
+ // when the component is used as elements of a collection, the name of the property representing
+ // the collection itself may be ignored since each collection will have its own table.
+ // Note: In some cases may be a problem.
+ const int penultimateOffset = 2;
+ if (!source.GetRootMember().GetPropertyOrFieldType().IsGenericCollection())
+ {
+ return source;
+ }
+ var paths = source.InverseProgressivePath().ToArray();
+ return paths[paths.Length - penultimateOffset];
+ }
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-12 17:55:24 UTC (rev 5679)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-12 18:37:57 UTC (rev 5680)
@@ -48,7 +48,7 @@
isTablePerClass = (t, declared) => declared || MatchTablePerClass(t);
isPersistentId = (m, declared) => declared || MatchPoIdPattern(m);
isComponent = (t, declared) => declared || MatchComponentPattern(t);
- isPersistentProperty = (m, declared) => declared || MatchNoReadOnlyPropertyPattern(m);
+ isPersistentProperty = (m, declared) => declared || ((m is PropertyInfo) && MatchNoReadOnlyPropertyPattern(m));
isSet = (m, declared) => declared || MatchCollection(m, MatchSetMember);
isArray = (m, declared) => declared || MatchCollection(m, MatchArrayMember);
isBag = (m, declared) => declared || MatchCollection(m, MatchBagMember);
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/PropertyColumnNameTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/PropertyColumnNameTests.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/PropertyColumnNameTests.cs 2011-04-12 18:37:57 UTC (rev 5680)
@@ -0,0 +1,63 @@
+using System.Collections.Generic;
+using System.Linq;
+using NHibernate.Cfg.MappingSchema;
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.ConventionModelMapperTests
+{
+ public class PropertyColumnNameTests
+ {
+ private class MyClass
+ {
+ public int Id { get; set; }
+ public string Fake1 { get; set; }
+ }
+
+ private class MyClassWithComponent
+ {
+ public int Id { get; set; }
+ public MyComponent Component1 { get; set; }
+ public IEnumerable<MyComponent> Components { get; set; }
+ }
+
+ private class MyComponent
+ {
+ public string Fake0 { get; set; }
+ }
+
+ [Test]
+ public void WhenAtClassLevelThenNoMatch()
+ {
+ var mapper = new ConventionModelMapper();
+ var mapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
+ var hbmClass = mapping.RootClasses[0];
+ var hbmProperty = hbmClass.Properties.OfType<HbmProperty>().Single(x => x.Name == "Fake1");
+ hbmProperty.Columns.Should().Be.Empty();
+ }
+
+ [Test]
+ public void WhenFirstLevelIsCollectionThenNoMatch()
+ {
+ var mapper = new ConventionModelMapper();
+ var mapping = mapper.CompileMappingFor(new[] { typeof(MyClassWithComponent) });
+ var hbmClass = mapping.RootClasses[0];
+ var hbmBag = hbmClass.Properties.OfType<HbmBag>().Single(x => x.Name == "Components");
+ var hbmCompositeElement = (HbmCompositeElement) hbmBag.ElementRelationship;
+ var hbmProperty = hbmCompositeElement.Properties.OfType<HbmProperty>().Single(x => x.Name == "Fake0");
+ hbmProperty.Columns.Should().Be.Empty();
+ }
+
+ [Test]
+ public void WhenAtComponentLevelThenMatch()
+ {
+ var mapper = new ConventionModelMapper();
+ var mapping = mapper.CompileMappingFor(new[] { typeof(MyClassWithComponent) });
+ var hbmClass = mapping.RootClasses[0];
+ var hbmComponent = hbmClass.Properties.OfType<HbmComponent>().Single();
+ var hbmProperty = hbmComponent.Properties.OfType<HbmProperty>().Single(x => x.Name == "Fake0");
+ hbmProperty.Columns.Single().name.Should().Be("Component1Fake0");
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-12 17:55:24 UTC (rev 5679)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-12 18:37:57 UTC (rev 5680)
@@ -512,6 +512,7 @@
<Compile Include="Logging\Log4NetLoggerTest.cs" />
<Compile Include="Logging\LoggerProviderTest.cs" />
<Compile Include="MappingByCode\ConventionModelMapperTests\JoinedSubclassKeyAsRootIdColumnTest.cs" />
+ <Compile Include="MappingByCode\ConventionModelMapperTests\PropertyColumnNameTests.cs" />
<Compile Include="MappingByCode\ExpliticMappingTests\BagOfNestedComponentsWithParentTest.cs" />
<Compile Include="MappingByCode\ExpliticMappingTests\ClassWithComponentsTest.cs" />
<Compile Include="MappingByCode\ExpliticMappingTests\ConformistMappingRegistrationTests\ClassMappingRegistrationTest.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2011-04-12 22:59:32
|
Revision: 5682
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5682&view=rev
Author: fabiomaulo
Date: 2011-04-12 22:59:26 +0000 (Tue, 12 Apr 2011)
Log Message:
-----------
ConventionModelMapper with convention for many-to-many table
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/ConventionModelMapper.cs
trunk/nhibernate/src/NHibernate/Mapping/ByCode/PropertyPathExtensions.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ManyToManyInCollectionTableTests.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ConventionModelMapper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ConventionModelMapper.cs 2011-04-12 19:16:13 UTC (rev 5681)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ConventionModelMapper.cs 2011-04-12 22:59:26 UTC (rev 5682)
@@ -17,8 +17,30 @@
{
BeforeMapJoinedSubclass += JoinedSubclassKeyAsRootIdColumn;
BeforeMapProperty += PropertyColumnName;
+ BeforeMapList += ManyToManyInCollectionTable;
+ BeforeMapBag += ManyToManyInCollectionTable;
+ BeforeMapSet += ManyToManyInCollectionTable;
+ BeforeMapMap += ManyToManyInCollectionTable;
}
+ protected void ManyToManyInCollectionTable(IModelInspector modelInspector, PropertyPath member, ICollectionPropertiesMapper collectionCustomizer)
+ {
+ System.Type propertyType = member.LocalMember.GetPropertyOrFieldType();
+
+ System.Type fromMany = member.GetContainerEntity(modelInspector);
+ System.Type toMany = propertyType.DetermineCollectionElementOrDictionaryValueType();
+ if(!modelInspector.IsEntity(toMany))
+ {
+ // does not apply when the relation is on the key of the dictionary
+ // Note: a dictionary may have relation with 3 entities; in this handler we are covering only relations on values
+ return;
+ }
+ var relation = new[] { fromMany, toMany };
+ var twoEntitiesNames = (from relationOn in relation orderby relationOn.Name select relationOn.Name).ToArray();
+
+ collectionCustomizer.Table(string.Format("{0}To{1}", twoEntitiesNames[0], twoEntitiesNames[1]));
+ }
+
protected void PropertyColumnName(IModelInspector modelInspector, PropertyPath member, IPropertyMapper propertyCustomizer)
{
if (member.PreviousPath == null || member.LocalMember == null)
@@ -36,7 +58,7 @@
protected void JoinedSubclassKeyAsRootIdColumn(IModelInspector modelInspector, System.Type type, IJoinedSubclassAttributesMapper joinedSubclassCustomizer)
{
- var idMember = type.GetProperties().Cast<MemberInfo>().Concat(type.GetFields()).FirstOrDefault(mi => ModelInspector.IsPersistentId(mi.GetMemberFromDeclaringType()));
+ var idMember = type.GetProperties().Cast<MemberInfo>().Concat(type.GetFields()).FirstOrDefault(mi => modelInspector.IsPersistentId(mi.GetMemberFromDeclaringType()));
if (idMember != null)
{
joinedSubclassCustomizer.Key(km => km.Column(idMember.Name));
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/PropertyPathExtensions.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/PropertyPathExtensions.cs 2011-04-12 19:16:13 UTC (rev 5681)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/PropertyPathExtensions.cs 2011-04-12 22:59:26 UTC (rev 5682)
@@ -7,6 +7,16 @@
{
public static class PropertyPathExtensions
{
+ public static System.Type GetContainerEntity(this PropertyPath propertyPath, IModelInspector domainInspector)
+ {
+ PropertyPath analizing = propertyPath;
+ while (analizing.PreviousPath != null && !domainInspector.IsEntity(analizing.LocalMember.ReflectedType))
+ {
+ analizing = analizing.PreviousPath;
+ }
+ return analizing.LocalMember.ReflectedType;
+ }
+
public static string ToColumnName(this PropertyPath propertyPath, string pathSeparator)
{
return propertyPath.ToString().Replace(".", pathSeparator);
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ManyToManyInCollectionTableTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ManyToManyInCollectionTableTests.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ManyToManyInCollectionTableTests.cs 2011-04-12 22:59:26 UTC (rev 5682)
@@ -0,0 +1,101 @@
+using System.Collections.Generic;
+using System.Linq;
+using NHibernate.Cfg.MappingSchema;
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.ConventionModelMapperTests
+{
+ public class ManyToManyInCollectionTableTests
+ {
+ private class MyClass
+ {
+ public int Id { get; set; }
+ public ICollection<MyBidirect> MyBidirects { get; set; }
+ public IDictionary<MyBidirect, string> MapKey { get; set; }
+ public IDictionary<string, MyBidirect> MapValue { get; set; }
+ public MyComponent MyComponent { get; set; }
+ }
+
+ private class MyComponent
+ {
+ public ICollection<MyBidirect> MyBidirects { get; set; }
+ }
+
+ private class MyBidirect
+ {
+ public int Id { get; set; }
+ public ICollection<MyClass> MyClasses { get; set; }
+ }
+
+ private HbmMapping GetModelMapping()
+ {
+ var mapper = new ConventionModelMapper();
+ mapper.Class<MyClass>(map =>
+ {
+ map.Bag(mc => mc.MyBidirects, c => { }, rel => rel.ManyToMany());
+ map.Map(mc => mc.MapKey, c => { }, mk => mk.ManyToMany(), mv => { });
+ map.Map(mc => mc.MapValue, c => { }, mk => { }, mv => mv.ManyToMany());
+ });
+ mapper.Class<MyBidirect>(map =>
+ {
+ map.Bag(mc => mc.MyClasses, c => { }, rel => rel.ManyToMany());
+ });
+ mapper.Component<MyComponent>(map =>
+ {
+ map.Bag(mc => mc.MyBidirects, c => { }, rel => rel.ManyToMany());
+ });
+ return mapper.CompileMappingFor(new[] {typeof (MyClass), typeof (MyBidirect)});
+ }
+
+ [Test]
+ public void WhenManyToManyCollectionThenApplyTableAlphabetical()
+ {
+ HbmMapping mapping = GetModelMapping();
+
+ var hbmMyClass = mapping.RootClasses.Where(x => x.Name.Contains("MyClass")).Single();
+ var hbmMyBidirect = mapping.RootClasses.Where(x => x.Name.Contains("MyBidirect")).Single();
+
+ var hbmBagMyClass = hbmMyClass.Properties.Where(p => p.Name == "MyBidirects").OfType<HbmBag>().Single();
+ var hbmBagMyBidirect = hbmMyBidirect.Properties.Where(p => p.Name == "MyClasses").OfType<HbmBag>().Single();
+
+ hbmBagMyClass.Table.Should().Be("MyBidirectToMyClass");
+ hbmBagMyBidirect.Table.Should().Be(hbmBagMyClass.Table);
+ }
+
+ [Test]
+ public void WhenRelationDeclaredAsManyToManyForDictionaryKeyThenNoMatch()
+ {
+ HbmMapping mapping = GetModelMapping();
+
+ var hbmMyClass = mapping.RootClasses.Where(x => x.Name.Contains("MyClass")).Single();
+ var hbmMapKey = hbmMyClass.Properties.Where(p => p.Name == "MapKey").OfType<HbmMap>().Single();
+
+ hbmMapKey.Table.Should().Be.Null();
+ }
+
+ [Test]
+ public void WhenRelationDeclaredAsManyToManyForDictionaryValueThenMatch()
+ {
+ HbmMapping mapping = GetModelMapping();
+
+ var hbmMyClass = mapping.RootClasses.Where(x => x.Name.Contains("MyClass")).Single();
+ var hbmMapValue = hbmMyClass.Properties.Where(p => p.Name == "MapValue").OfType<HbmMap>().Single();
+
+ hbmMapValue.Table.Should().Be("MyBidirectToMyClass");
+ }
+
+ [Test]
+ public void WhenManyToManyCollectionInsideComponentThenApplyFromEntityToEntity()
+ {
+ HbmMapping mapping = GetModelMapping();
+
+ var hbmMyClass = mapping.RootClasses.Where(x => x.Name.Contains("MyClass")).Single();
+ var hbmMyComponent = hbmMyClass.Properties.Where(p => p.Name == "MyComponent").OfType<HbmComponent>().Single();
+ var hbmBagMyClass = hbmMyComponent.Properties.Where(p => p.Name == "MyBidirects").OfType<HbmBag>().Single();
+
+ hbmBagMyClass.Table.Should().Be("MyBidirectToMyClass");
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-12 19:16:13 UTC (rev 5681)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-12 22:59:26 UTC (rev 5682)
@@ -512,6 +512,7 @@
<Compile Include="Logging\Log4NetLoggerTest.cs" />
<Compile Include="Logging\LoggerProviderTest.cs" />
<Compile Include="MappingByCode\ConventionModelMapperTests\JoinedSubclassKeyAsRootIdColumnTest.cs" />
+ <Compile Include="MappingByCode\ConventionModelMapperTests\ManyToManyInCollectionTableTests.cs" />
<Compile Include="MappingByCode\ConventionModelMapperTests\PropertyColumnNameTests.cs" />
<Compile Include="MappingByCode\ExpliticMappingTests\BagOfNestedComponentsWithParentTest.cs" />
<Compile Include="MappingByCode\ExpliticMappingTests\ClassWithComponentsTest.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2011-04-13 11:48:19
|
Revision: 5684
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5684&view=rev
Author: fabiomaulo
Date: 2011-04-13 11:48:08 +0000 (Wed, 13 Apr 2011)
Log Message:
-----------
ConventionModelMapper with convention for many-to-many key
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/ConventionModelMapper.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ManyToManyKeyIdColumnTests.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ConventionModelMapper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ConventionModelMapper.cs 2011-04-13 04:15:56 UTC (rev 5683)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ConventionModelMapper.cs 2011-04-13 11:48:08 UTC (rev 5684)
@@ -19,10 +19,32 @@
BeforeMapProperty += PropertyColumnName;
BeforeMapList += ManyToManyInCollectionTable;
BeforeMapBag += ManyToManyInCollectionTable;
+ BeforeMapIdBag += ManyToManyInCollectionTable;
BeforeMapSet += ManyToManyInCollectionTable;
BeforeMapMap += ManyToManyInCollectionTable;
+
+ BeforeMapList += ManyToManyKeyIdColumn;
+ BeforeMapBag += ManyToManyKeyIdColumn;
+ BeforeMapIdBag += ManyToManyKeyIdColumn;
+ BeforeMapSet += ManyToManyKeyIdColumn;
+ BeforeMapMap += ManyToManyKeyIdColumn;
}
+ protected void ManyToManyKeyIdColumn(IModelInspector modelInspector, PropertyPath member, ICollectionPropertiesMapper collectionCustomizer)
+ {
+ System.Type propertyType = member.LocalMember.GetPropertyOrFieldType();
+
+ System.Type fromMany = member.GetContainerEntity(modelInspector);
+ System.Type toMany = propertyType.DetermineCollectionElementOrDictionaryValueType();
+ if (!modelInspector.IsEntity(toMany))
+ {
+ // does not apply when the relation is on the key of the dictionary
+ return;
+ }
+
+ collectionCustomizer.Key(km => km.Column(fromMany.Name + "Id"));
+ }
+
protected void ManyToManyInCollectionTable(IModelInspector modelInspector, PropertyPath member, ICollectionPropertiesMapper collectionCustomizer)
{
System.Type propertyType = member.LocalMember.GetPropertyOrFieldType();
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ManyToManyKeyIdColumnTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ManyToManyKeyIdColumnTests.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ManyToManyKeyIdColumnTests.cs 2011-04-13 11:48:08 UTC (rev 5684)
@@ -0,0 +1,101 @@
+using System.Collections.Generic;
+using System.Linq;
+using NHibernate.Cfg.MappingSchema;
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.ConventionModelMapperTests
+{
+ public class ManyToManyKeyIdColumnTests
+ {
+ private class MyClass
+ {
+ public int Id { get; set; }
+ public ICollection<MyBidirect> MyBidirects { get; set; }
+ public IDictionary<MyBidirect, string> MapKey { get; set; }
+ public IDictionary<string, MyBidirect> MapValue { get; set; }
+ public MyComponent MyComponent { get; set; }
+ }
+
+ private class MyComponent
+ {
+ public ICollection<MyBidirect> MyBidirects { get; set; }
+ }
+
+ private class MyBidirect
+ {
+ public int Id { get; set; }
+ public ICollection<MyClass> MyClasses { get; set; }
+ }
+
+ private HbmMapping GetModelMapping()
+ {
+ var mapper = new ConventionModelMapper();
+ mapper.Class<MyClass>(map =>
+ {
+ map.Bag(mc => mc.MyBidirects, c => { }, rel => rel.ManyToMany());
+ map.Map(mc => mc.MapKey, c => { }, mk => mk.ManyToMany(), mv => { });
+ map.Map(mc => mc.MapValue, c => { }, mk => { }, mv => mv.ManyToMany());
+ });
+ mapper.Class<MyBidirect>(map =>
+ {
+ map.Bag(mc => mc.MyClasses, c => { }, rel => rel.ManyToMany());
+ });
+ mapper.Component<MyComponent>(map =>
+ {
+ map.Bag(mc => mc.MyBidirects, c => { }, rel => rel.ManyToMany());
+ });
+ return mapper.CompileMappingFor(new[] { typeof(MyClass), typeof(MyBidirect) });
+ }
+
+ [Test]
+ public void WhenManyToManyCollectionThenApplyTableAlphabetical()
+ {
+ HbmMapping mapping = GetModelMapping();
+
+ var hbmMyClass = mapping.RootClasses.Where(x => x.Name.Contains("MyClass")).Single();
+ var hbmMyBidirect = mapping.RootClasses.Where(x => x.Name.Contains("MyBidirect")).Single();
+
+ var hbmBagMyClass = hbmMyClass.Properties.Where(p => p.Name == "MyBidirects").OfType<HbmBag>().Single();
+ var hbmBagMyBidirect = hbmMyBidirect.Properties.Where(p => p.Name == "MyClasses").OfType<HbmBag>().Single();
+
+ hbmBagMyClass.Key.column1.Should().Be("MyClassId");
+ hbmBagMyBidirect.Key.column1.Should().Be("MyBidirectId");
+ }
+
+ [Test]
+ public void WhenRelationDeclaredAsManyToManyForDictionaryKeyThenNoMatch()
+ {
+ HbmMapping mapping = GetModelMapping();
+
+ var hbmMyClass = mapping.RootClasses.Where(x => x.Name.Contains("MyClass")).Single();
+ var hbmMapKey = hbmMyClass.Properties.Where(p => p.Name == "MapKey").OfType<HbmMap>().Single();
+
+ hbmMapKey.Key.Columns.Single().name.Should().Not.Be("MyClassId");
+ }
+
+ [Test]
+ public void WhenRelationDeclaredAsManyToManyForDictionaryValueThenMatch()
+ {
+ HbmMapping mapping = GetModelMapping();
+
+ var hbmMyClass = mapping.RootClasses.Where(x => x.Name.Contains("MyClass")).Single();
+ var hbmMapValue = hbmMyClass.Properties.Where(p => p.Name == "MapValue").OfType<HbmMap>().Single();
+
+ hbmMapValue.Key.column1.Should().Be("MyClassId");
+ }
+
+ [Test]
+ public void WhenManyToManyCollectionInsideComponentThenApplyFromEntityToEntity()
+ {
+ HbmMapping mapping = GetModelMapping();
+
+ var hbmMyClass = mapping.RootClasses.Where(x => x.Name.Contains("MyClass")).Single();
+ var hbmMyComponent = hbmMyClass.Properties.Where(p => p.Name == "MyComponent").OfType<HbmComponent>().Single();
+ var hbmBagMyClass = hbmMyComponent.Properties.Where(p => p.Name == "MyBidirects").OfType<HbmBag>().Single();
+
+ hbmBagMyClass.Key.column1.Should().Be("MyClassId");
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-13 04:15:56 UTC (rev 5683)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-13 11:48:08 UTC (rev 5684)
@@ -513,6 +513,7 @@
<Compile Include="Logging\LoggerProviderTest.cs" />
<Compile Include="MappingByCode\ConventionModelMapperTests\JoinedSubclassKeyAsRootIdColumnTest.cs" />
<Compile Include="MappingByCode\ConventionModelMapperTests\ManyToManyInCollectionTableTests.cs" />
+ <Compile Include="MappingByCode\ConventionModelMapperTests\ManyToManyKeyIdColumnTests.cs" />
<Compile Include="MappingByCode\ConventionModelMapperTests\PropertyColumnNameTests.cs" />
<Compile Include="MappingByCode\ExpliticMappingTests\BagOfNestedComponentsWithParentTest.cs" />
<Compile Include="MappingByCode\ExpliticMappingTests\ClassWithComponentsTest.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2011-04-13 17:02:49
|
Revision: 5685
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5685&view=rev
Author: fabiomaulo
Date: 2011-04-13 17:02:42 +0000 (Wed, 13 Apr 2011)
Log Message:
-----------
Reverted naming conventions (perhaps we should be far away to do it)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/ConventionModelMapper.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Removed Paths:
-------------
trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/JoinedSubclassKeyAsRootIdColumnTest.cs
trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ManyToManyInCollectionTableTests.cs
trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ManyToManyKeyIdColumnTests.cs
trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/PropertyColumnNameTests.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ConventionModelMapper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ConventionModelMapper.cs 2011-04-13 11:48:08 UTC (rev 5684)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ConventionModelMapper.cs 2011-04-13 17:02:42 UTC (rev 5685)
@@ -15,78 +15,8 @@
protected virtual void AppendDefaultEvents()
{
- BeforeMapJoinedSubclass += JoinedSubclassKeyAsRootIdColumn;
- BeforeMapProperty += PropertyColumnName;
- BeforeMapList += ManyToManyInCollectionTable;
- BeforeMapBag += ManyToManyInCollectionTable;
- BeforeMapIdBag += ManyToManyInCollectionTable;
- BeforeMapSet += ManyToManyInCollectionTable;
- BeforeMapMap += ManyToManyInCollectionTable;
-
- BeforeMapList += ManyToManyKeyIdColumn;
- BeforeMapBag += ManyToManyKeyIdColumn;
- BeforeMapIdBag += ManyToManyKeyIdColumn;
- BeforeMapSet += ManyToManyKeyIdColumn;
- BeforeMapMap += ManyToManyKeyIdColumn;
}
- protected void ManyToManyKeyIdColumn(IModelInspector modelInspector, PropertyPath member, ICollectionPropertiesMapper collectionCustomizer)
- {
- System.Type propertyType = member.LocalMember.GetPropertyOrFieldType();
-
- System.Type fromMany = member.GetContainerEntity(modelInspector);
- System.Type toMany = propertyType.DetermineCollectionElementOrDictionaryValueType();
- if (!modelInspector.IsEntity(toMany))
- {
- // does not apply when the relation is on the key of the dictionary
- return;
- }
-
- collectionCustomizer.Key(km => km.Column(fromMany.Name + "Id"));
- }
-
- protected void ManyToManyInCollectionTable(IModelInspector modelInspector, PropertyPath member, ICollectionPropertiesMapper collectionCustomizer)
- {
- System.Type propertyType = member.LocalMember.GetPropertyOrFieldType();
-
- System.Type fromMany = member.GetContainerEntity(modelInspector);
- System.Type toMany = propertyType.DetermineCollectionElementOrDictionaryValueType();
- if(!modelInspector.IsEntity(toMany))
- {
- // does not apply when the relation is on the key of the dictionary
- // Note: a dictionary may have relation with 3 entities; in this handler we are covering only relations on values
- return;
- }
- var relation = new[] { fromMany, toMany };
- var twoEntitiesNames = (from relationOn in relation orderby relationOn.Name select relationOn.Name).ToArray();
-
- collectionCustomizer.Table(string.Format("{0}To{1}", twoEntitiesNames[0], twoEntitiesNames[1]));
- }
-
- protected void PropertyColumnName(IModelInspector modelInspector, PropertyPath member, IPropertyMapper propertyCustomizer)
- {
- if (member.PreviousPath == null || member.LocalMember == null)
- {
- return;
- }
- if (member.PreviousPath.LocalMember.GetPropertyOrFieldType().IsGenericCollection())
- {
- return;
- }
-
- var pathToMap = member.DepureFirstLevelIfCollection();
- propertyCustomizer.Column(pathToMap.ToColumnName());
- }
-
- protected void JoinedSubclassKeyAsRootIdColumn(IModelInspector modelInspector, System.Type type, IJoinedSubclassAttributesMapper joinedSubclassCustomizer)
- {
- var idMember = type.GetProperties().Cast<MemberInfo>().Concat(type.GetFields()).FirstOrDefault(mi => modelInspector.IsPersistentId(mi.GetMemberFromDeclaringType()));
- if (idMember != null)
- {
- joinedSubclassCustomizer.Key(km => km.Column(idMember.Name));
- }
- }
-
protected SimpleModelInspector SimpleModelInspector
{
get { return (SimpleModelInspector) base.ModelInspector; }
Deleted: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/JoinedSubclassKeyAsRootIdColumnTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/JoinedSubclassKeyAsRootIdColumnTest.cs 2011-04-13 11:48:08 UTC (rev 5684)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/JoinedSubclassKeyAsRootIdColumnTest.cs 2011-04-13 17:02:42 UTC (rev 5685)
@@ -1,53 +0,0 @@
-using System.Linq;
-using NHibernate.Mapping.ByCode;
-using NUnit.Framework;
-using SharpTestsEx;
-
-namespace NHibernate.Test.MappingByCode.ConventionModelMapperTests
-{
- public class JoinedSubclassKeyAsRootIdColumnTest
- {
- private class MyClass
- {
- public int MyId { get; set; }
- public int HisId { get; set; }
- }
-
- private class Inherited : MyClass
- {
- }
-
- [Test]
- public void WhenBaseIsIdThenUseId()
- {
- var mapper = new ConventionModelMapper();
- mapper.Class<MyClass>(map=> map.Id(x=> x.MyId));
- var mapping = mapper.CompileMappingFor(new[] { typeof(Inherited), typeof(MyClass) });
- var hbmJoinedClass = mapping.JoinedSubclasses[0];
-
- hbmJoinedClass.key.Columns.Single().name.Should().Be("MyId");
- }
-
- [Test]
- public void WhenBaseIsPoIdThenUsePoId()
- {
- var mapper = new ConventionModelMapper();
- mapper.Class<MyClass>(map => map.Id(x => x.HisId));
- var mapping = mapper.CompileMappingFor(new[] { typeof(Inherited), typeof(MyClass) });
- var hbmJoinedClass = mapping.JoinedSubclasses[0];
-
- hbmJoinedClass.key.Columns.Single().name.Should().Be("HisId");
- }
-
- [Test]
- public void WhenNoPoidMemberThenDoesNotSet()
- {
- var mapper = new ConventionModelMapper();
- mapper.Class<MyClass>(map => { });
- var mapping = mapper.CompileMappingFor(new[] { typeof(Inherited), typeof(MyClass) });
- var hbmJoinedClass = mapping.JoinedSubclasses[0];
-
- hbmJoinedClass.key.Columns.Single().name.Should().Not.Be("MyId").And.Not.Be("HisId");
- }
- }
-}
\ No newline at end of file
Deleted: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ManyToManyInCollectionTableTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ManyToManyInCollectionTableTests.cs 2011-04-13 11:48:08 UTC (rev 5684)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ManyToManyInCollectionTableTests.cs 2011-04-13 17:02:42 UTC (rev 5685)
@@ -1,101 +0,0 @@
-using System.Collections.Generic;
-using System.Linq;
-using NHibernate.Cfg.MappingSchema;
-using NHibernate.Mapping.ByCode;
-using NUnit.Framework;
-using SharpTestsEx;
-
-namespace NHibernate.Test.MappingByCode.ConventionModelMapperTests
-{
- public class ManyToManyInCollectionTableTests
- {
- private class MyClass
- {
- public int Id { get; set; }
- public ICollection<MyBidirect> MyBidirects { get; set; }
- public IDictionary<MyBidirect, string> MapKey { get; set; }
- public IDictionary<string, MyBidirect> MapValue { get; set; }
- public MyComponent MyComponent { get; set; }
- }
-
- private class MyComponent
- {
- public ICollection<MyBidirect> MyBidirects { get; set; }
- }
-
- private class MyBidirect
- {
- public int Id { get; set; }
- public ICollection<MyClass> MyClasses { get; set; }
- }
-
- private HbmMapping GetModelMapping()
- {
- var mapper = new ConventionModelMapper();
- mapper.Class<MyClass>(map =>
- {
- map.Bag(mc => mc.MyBidirects, c => { }, rel => rel.ManyToMany());
- map.Map(mc => mc.MapKey, c => { }, mk => mk.ManyToMany(), mv => { });
- map.Map(mc => mc.MapValue, c => { }, mk => { }, mv => mv.ManyToMany());
- });
- mapper.Class<MyBidirect>(map =>
- {
- map.Bag(mc => mc.MyClasses, c => { }, rel => rel.ManyToMany());
- });
- mapper.Component<MyComponent>(map =>
- {
- map.Bag(mc => mc.MyBidirects, c => { }, rel => rel.ManyToMany());
- });
- return mapper.CompileMappingFor(new[] {typeof (MyClass), typeof (MyBidirect)});
- }
-
- [Test]
- public void WhenManyToManyCollectionThenApplyTableAlphabetical()
- {
- HbmMapping mapping = GetModelMapping();
-
- var hbmMyClass = mapping.RootClasses.Where(x => x.Name.Contains("MyClass")).Single();
- var hbmMyBidirect = mapping.RootClasses.Where(x => x.Name.Contains("MyBidirect")).Single();
-
- var hbmBagMyClass = hbmMyClass.Properties.Where(p => p.Name == "MyBidirects").OfType<HbmBag>().Single();
- var hbmBagMyBidirect = hbmMyBidirect.Properties.Where(p => p.Name == "MyClasses").OfType<HbmBag>().Single();
-
- hbmBagMyClass.Table.Should().Be("MyBidirectToMyClass");
- hbmBagMyBidirect.Table.Should().Be(hbmBagMyClass.Table);
- }
-
- [Test]
- public void WhenRelationDeclaredAsManyToManyForDictionaryKeyThenNoMatch()
- {
- HbmMapping mapping = GetModelMapping();
-
- var hbmMyClass = mapping.RootClasses.Where(x => x.Name.Contains("MyClass")).Single();
- var hbmMapKey = hbmMyClass.Properties.Where(p => p.Name == "MapKey").OfType<HbmMap>().Single();
-
- hbmMapKey.Table.Should().Be.Null();
- }
-
- [Test]
- public void WhenRelationDeclaredAsManyToManyForDictionaryValueThenMatch()
- {
- HbmMapping mapping = GetModelMapping();
-
- var hbmMyClass = mapping.RootClasses.Where(x => x.Name.Contains("MyClass")).Single();
- var hbmMapValue = hbmMyClass.Properties.Where(p => p.Name == "MapValue").OfType<HbmMap>().Single();
-
- hbmMapValue.Table.Should().Be("MyBidirectToMyClass");
- }
-
- [Test]
- public void WhenManyToManyCollectionInsideComponentThenApplyFromEntityToEntity()
- {
- HbmMapping mapping = GetModelMapping();
-
- var hbmMyClass = mapping.RootClasses.Where(x => x.Name.Contains("MyClass")).Single();
- var hbmMyComponent = hbmMyClass.Properties.Where(p => p.Name == "MyComponent").OfType<HbmComponent>().Single();
- var hbmBagMyClass = hbmMyComponent.Properties.Where(p => p.Name == "MyBidirects").OfType<HbmBag>().Single();
-
- hbmBagMyClass.Table.Should().Be("MyBidirectToMyClass");
- }
- }
-}
\ No newline at end of file
Deleted: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ManyToManyKeyIdColumnTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ManyToManyKeyIdColumnTests.cs 2011-04-13 11:48:08 UTC (rev 5684)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ManyToManyKeyIdColumnTests.cs 2011-04-13 17:02:42 UTC (rev 5685)
@@ -1,101 +0,0 @@
-using System.Collections.Generic;
-using System.Linq;
-using NHibernate.Cfg.MappingSchema;
-using NHibernate.Mapping.ByCode;
-using NUnit.Framework;
-using SharpTestsEx;
-
-namespace NHibernate.Test.MappingByCode.ConventionModelMapperTests
-{
- public class ManyToManyKeyIdColumnTests
- {
- private class MyClass
- {
- public int Id { get; set; }
- public ICollection<MyBidirect> MyBidirects { get; set; }
- public IDictionary<MyBidirect, string> MapKey { get; set; }
- public IDictionary<string, MyBidirect> MapValue { get; set; }
- public MyComponent MyComponent { get; set; }
- }
-
- private class MyComponent
- {
- public ICollection<MyBidirect> MyBidirects { get; set; }
- }
-
- private class MyBidirect
- {
- public int Id { get; set; }
- public ICollection<MyClass> MyClasses { get; set; }
- }
-
- private HbmMapping GetModelMapping()
- {
- var mapper = new ConventionModelMapper();
- mapper.Class<MyClass>(map =>
- {
- map.Bag(mc => mc.MyBidirects, c => { }, rel => rel.ManyToMany());
- map.Map(mc => mc.MapKey, c => { }, mk => mk.ManyToMany(), mv => { });
- map.Map(mc => mc.MapValue, c => { }, mk => { }, mv => mv.ManyToMany());
- });
- mapper.Class<MyBidirect>(map =>
- {
- map.Bag(mc => mc.MyClasses, c => { }, rel => rel.ManyToMany());
- });
- mapper.Component<MyComponent>(map =>
- {
- map.Bag(mc => mc.MyBidirects, c => { }, rel => rel.ManyToMany());
- });
- return mapper.CompileMappingFor(new[] { typeof(MyClass), typeof(MyBidirect) });
- }
-
- [Test]
- public void WhenManyToManyCollectionThenApplyTableAlphabetical()
- {
- HbmMapping mapping = GetModelMapping();
-
- var hbmMyClass = mapping.RootClasses.Where(x => x.Name.Contains("MyClass")).Single();
- var hbmMyBidirect = mapping.RootClasses.Where(x => x.Name.Contains("MyBidirect")).Single();
-
- var hbmBagMyClass = hbmMyClass.Properties.Where(p => p.Name == "MyBidirects").OfType<HbmBag>().Single();
- var hbmBagMyBidirect = hbmMyBidirect.Properties.Where(p => p.Name == "MyClasses").OfType<HbmBag>().Single();
-
- hbmBagMyClass.Key.column1.Should().Be("MyClassId");
- hbmBagMyBidirect.Key.column1.Should().Be("MyBidirectId");
- }
-
- [Test]
- public void WhenRelationDeclaredAsManyToManyForDictionaryKeyThenNoMatch()
- {
- HbmMapping mapping = GetModelMapping();
-
- var hbmMyClass = mapping.RootClasses.Where(x => x.Name.Contains("MyClass")).Single();
- var hbmMapKey = hbmMyClass.Properties.Where(p => p.Name == "MapKey").OfType<HbmMap>().Single();
-
- hbmMapKey.Key.Columns.Single().name.Should().Not.Be("MyClassId");
- }
-
- [Test]
- public void WhenRelationDeclaredAsManyToManyForDictionaryValueThenMatch()
- {
- HbmMapping mapping = GetModelMapping();
-
- var hbmMyClass = mapping.RootClasses.Where(x => x.Name.Contains("MyClass")).Single();
- var hbmMapValue = hbmMyClass.Properties.Where(p => p.Name == "MapValue").OfType<HbmMap>().Single();
-
- hbmMapValue.Key.column1.Should().Be("MyClassId");
- }
-
- [Test]
- public void WhenManyToManyCollectionInsideComponentThenApplyFromEntityToEntity()
- {
- HbmMapping mapping = GetModelMapping();
-
- var hbmMyClass = mapping.RootClasses.Where(x => x.Name.Contains("MyClass")).Single();
- var hbmMyComponent = hbmMyClass.Properties.Where(p => p.Name == "MyComponent").OfType<HbmComponent>().Single();
- var hbmBagMyClass = hbmMyComponent.Properties.Where(p => p.Name == "MyBidirects").OfType<HbmBag>().Single();
-
- hbmBagMyClass.Key.column1.Should().Be("MyClassId");
- }
- }
-}
\ No newline at end of file
Deleted: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/PropertyColumnNameTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/PropertyColumnNameTests.cs 2011-04-13 11:48:08 UTC (rev 5684)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/PropertyColumnNameTests.cs 2011-04-13 17:02:42 UTC (rev 5685)
@@ -1,63 +0,0 @@
-using System.Collections.Generic;
-using System.Linq;
-using NHibernate.Cfg.MappingSchema;
-using NHibernate.Mapping.ByCode;
-using NUnit.Framework;
-using SharpTestsEx;
-
-namespace NHibernate.Test.MappingByCode.ConventionModelMapperTests
-{
- public class PropertyColumnNameTests
- {
- private class MyClass
- {
- public int Id { get; set; }
- public string Fake1 { get; set; }
- }
-
- private class MyClassWithComponent
- {
- public int Id { get; set; }
- public MyComponent Component1 { get; set; }
- public IEnumerable<MyComponent> Components { get; set; }
- }
-
- private class MyComponent
- {
- public string Fake0 { get; set; }
- }
-
- [Test]
- public void WhenAtClassLevelThenNoMatch()
- {
- var mapper = new ConventionModelMapper();
- var mapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
- var hbmClass = mapping.RootClasses[0];
- var hbmProperty = hbmClass.Properties.OfType<HbmProperty>().Single(x => x.Name == "Fake1");
- hbmProperty.Columns.Should().Be.Empty();
- }
-
- [Test]
- public void WhenFirstLevelIsCollectionThenNoMatch()
- {
- var mapper = new ConventionModelMapper();
- var mapping = mapper.CompileMappingFor(new[] { typeof(MyClassWithComponent) });
- var hbmClass = mapping.RootClasses[0];
- var hbmBag = hbmClass.Properties.OfType<HbmBag>().Single(x => x.Name == "Components");
- var hbmCompositeElement = (HbmCompositeElement) hbmBag.ElementRelationship;
- var hbmProperty = hbmCompositeElement.Properties.OfType<HbmProperty>().Single(x => x.Name == "Fake0");
- hbmProperty.Columns.Should().Be.Empty();
- }
-
- [Test]
- public void WhenAtComponentLevelThenMatch()
- {
- var mapper = new ConventionModelMapper();
- var mapping = mapper.CompileMappingFor(new[] { typeof(MyClassWithComponent) });
- var hbmClass = mapping.RootClasses[0];
- var hbmComponent = hbmClass.Properties.OfType<HbmComponent>().Single();
- var hbmProperty = hbmComponent.Properties.OfType<HbmProperty>().Single(x => x.Name == "Fake0");
- hbmProperty.Columns.Single().name.Should().Be("Component1Fake0");
- }
- }
-}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-13 11:48:08 UTC (rev 5684)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-13 17:02:42 UTC (rev 5685)
@@ -511,10 +511,6 @@
<Compile Include="Linq\ByMethod\SumTests.cs" />
<Compile Include="Logging\Log4NetLoggerTest.cs" />
<Compile Include="Logging\LoggerProviderTest.cs" />
- <Compile Include="MappingByCode\ConventionModelMapperTests\JoinedSubclassKeyAsRootIdColumnTest.cs" />
- <Compile Include="MappingByCode\ConventionModelMapperTests\ManyToManyInCollectionTableTests.cs" />
- <Compile Include="MappingByCode\ConventionModelMapperTests\ManyToManyKeyIdColumnTests.cs" />
- <Compile Include="MappingByCode\ConventionModelMapperTests\PropertyColumnNameTests.cs" />
<Compile Include="MappingByCode\ExpliticMappingTests\BagOfNestedComponentsWithParentTest.cs" />
<Compile Include="MappingByCode\ExpliticMappingTests\ClassWithComponentsTest.cs" />
<Compile Include="MappingByCode\ExpliticMappingTests\ConformistMappingRegistrationTests\ClassMappingRegistrationTest.cs" />
@@ -2976,6 +2972,7 @@
<EmbeddedResource Include="DynamicEntity\Tuplizer\Customer.hbm.xml" />
</ItemGroup>
<ItemGroup>
+ <Folder Include="MappingByCode\ConventionModelMapperTests\" />
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2011-04-13 17:12:59
|
Revision: 5686
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5686&view=rev
Author: fabiomaulo
Date: 2011-04-13 17:12:52 +0000 (Wed, 13 Apr 2011)
Log Message:
-----------
Fix NH-2642 (thanks to Roger)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Driver/BasicResultSetsCommand.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DataReaderWrapperTest/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DataReaderWrapperTest/Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DataReaderWrapperTest/Mappings.hbm.xml
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DataReaderWrapperTest/Model.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DataReaderWrapperTest/TheUserType.cs
Modified: trunk/nhibernate/src/NHibernate/Driver/BasicResultSetsCommand.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Driver/BasicResultSetsCommand.cs 2011-04-13 17:02:42 UTC (rev 5685)
+++ trunk/nhibernate/src/NHibernate/Driver/BasicResultSetsCommand.cs 2011-04-13 17:12:52 UTC (rev 5686)
@@ -149,7 +149,7 @@
public object GetValue(int i)
{
- return reader.GetDecimal(i);
+ return reader.GetValue(i);
}
public int GetValues(object[] values)
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DataReaderWrapperTest/Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DataReaderWrapperTest/Fixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DataReaderWrapperTest/Fixture.cs 2011-04-13 17:12:52 UTC (rev 5686)
@@ -0,0 +1,54 @@
+using System.Collections;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.NHSpecificTest.DataReaderWrapperTest
+{
+ [TestFixture]
+ public class Fixture : BugTestCase
+ {
+ private const int id = 1333;
+
+ protected override void OnSetUp()
+ {
+ var ent = new TheEntity { TheValue = "Hola", Id = id };
+ using (var s = OpenSession())
+ {
+ using (var tx = s.BeginTransaction())
+ {
+ s.Save(ent);
+ tx.Commit();
+ }
+ }
+ }
+
+ protected override void OnTearDown()
+ {
+ using (var s = OpenSession())
+ {
+ using (var tx = s.BeginTransaction())
+ {
+ s.Delete(s.Get<TheEntity>(id));
+ tx.Commit();
+ }
+ }
+ }
+
+ [Test]
+ public void CanUseDatareadersGetValue()
+ {
+ using (var s = OpenSession())
+ {
+ using (s.BeginTransaction())
+ {
+ var crit = s.CreateCriteria(typeof (TheEntity));
+ var multi = s.CreateMultiCriteria();
+ multi.Add(crit);
+ var res = (IList)multi.List()[0];
+ res.Count
+ .Should().Be.EqualTo(1);
+ }
+ }
+ }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DataReaderWrapperTest/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DataReaderWrapperTest/Mappings.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DataReaderWrapperTest/Mappings.hbm.xml 2011-04-13 17:12:52 UTC (rev 5686)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Test.NHSpecificTest.DataReaderWrapperTest"
+ assembly="NHibernate.Test">
+
+ <class name="TheEntity">
+ <id name="Id" type="Int32">
+ <generator class="assigned" />
+ </id>
+ <property name="TheValue" type="NHibernate.Test.NHSpecificTest.DataReaderWrapperTest.TheUserType, NHibernate.Test" />
+ </class>
+</hibernate-mapping>
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DataReaderWrapperTest/Model.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DataReaderWrapperTest/Model.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DataReaderWrapperTest/Model.cs 2011-04-13 17:12:52 UTC (rev 5686)
@@ -0,0 +1,8 @@
+namespace NHibernate.Test.NHSpecificTest.DataReaderWrapperTest
+{
+ public class TheEntity
+ {
+ public virtual int Id { get; set; }
+ public virtual string TheValue { get; set; }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DataReaderWrapperTest/TheUserType.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DataReaderWrapperTest/TheUserType.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DataReaderWrapperTest/TheUserType.cs 2011-04-13 17:12:52 UTC (rev 5686)
@@ -0,0 +1,65 @@
+using System;
+using System.Data;
+using NHibernate.SqlTypes;
+using NHibernate.UserTypes;
+
+namespace NHibernate.Test.NHSpecificTest.DataReaderWrapperTest
+{
+ public class TheUserType : IUserType
+ {
+ public SqlType[] SqlTypes
+ {
+ get { return new[] {new SqlType(DbType.String)}; }
+ }
+
+ public System.Type ReturnedType
+ {
+ get { return typeof(string); }
+ }
+
+ public bool Equals(object x, object y)
+ {
+ return x.Equals(y);
+ }
+
+ public int GetHashCode(object x)
+ {
+ return x.GetHashCode();
+ }
+
+ public object NullSafeGet(IDataReader rs, string[] names, object owner)
+ {
+ return rs.GetValue(rs.GetOrdinal(names[0]));
+ }
+
+ public void NullSafeSet(IDbCommand cmd, object value, int index)
+ {
+ NHibernateUtil.String.NullSafeSet(cmd, value, index);
+ }
+
+ public object DeepCopy(object value)
+ {
+ return value;
+ }
+
+ public bool IsMutable
+ {
+ get { return NHibernateUtil.String.IsMutable; }
+ }
+
+ public object Replace(object original, object target, object owner)
+ {
+ return original;
+ }
+
+ public object Assemble(object cached, object owner)
+ {
+ return cached;
+ }
+
+ public object Disassemble(object value)
+ {
+ return value;
+ }
+ }
+}
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-13 17:02:42 UTC (rev 5685)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-13 17:12:52 UTC (rev 5686)
@@ -571,6 +571,9 @@
<Compile Include="NHSpecificTest\AccessAndCorrectPropertyName\Model.cs" />
<Compile Include="NHSpecificTest\BagWithLazyExtraAndFilter\Domain.cs" />
<Compile Include="NHSpecificTest\BagWithLazyExtraAndFilter\Fixture.cs" />
+ <Compile Include="NHSpecificTest\DataReaderWrapperTest\Fixture.cs" />
+ <Compile Include="NHSpecificTest\DataReaderWrapperTest\Model.cs" />
+ <Compile Include="NHSpecificTest\DataReaderWrapperTest\TheUserType.cs" />
<Compile Include="NHSpecificTest\EntityNameAndCompositeId\Fixture.cs" />
<Compile Include="NHSpecificTest\EntityNameAndInheritance\Fixture.cs" />
<Compile Include="NHSpecificTest\EntityNameWithFullName\Fixture.cs" />
@@ -2568,6 +2571,7 @@
<EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" />
</ItemGroup>
<ItemGroup>
+ <EmbeddedResource Include="NHSpecificTest\DataReaderWrapperTest\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\SqlConverterAndMultiQuery\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2489\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2603\Mappings.hbm.xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|