|
From: <fab...@us...> - 2009-07-02 04:24:54
|
Revision: 4560
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4560&view=rev
Author: fabiomaulo
Date: 2009-07-02 04:24:50 +0000 (Thu, 02 Jul 2009)
Log Message:
-----------
Configuration through lambdas
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ConfigurationExtensions.cs
trunk/nhibernate/src/NHibernate/Cfg/Loquacious/FluentSessionFactoryConfiguration.cs
trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ICacheConfiguration.cs
trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ICommandsConfiguration.cs
trunk/nhibernate/src/NHibernate/Cfg/Loquacious/IDbIntegrationConfiguration.cs
trunk/nhibernate/src/NHibernate/Cfg/Loquacious/IMappingsConfiguration.cs
trunk/nhibernate/src/NHibernate/Cfg/Loquacious/IProxyConfiguration.cs
trunk/nhibernate/src/NHibernate/Cfg/SettingsFactory.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Cfg/Hbm2ddlKeyWords.cs
trunk/nhibernate/src/NHibernate/Cfg/Loquacious/CacheConfiguration.cs
trunk/nhibernate/src/NHibernate/Cfg/Loquacious/DbIntegrationConfiguration.cs
trunk/nhibernate/src/NHibernate/Cfg/Loquacious/MappingsConfiguration.cs
trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ProxyConfiguration.cs
trunk/nhibernate/src/NHibernate/Cfg/SchemaAutoAction.cs
trunk/nhibernate/src/NHibernate.Test/CfgTest/Loquacious/LambdaConfigurationFixture.cs
trunk/nhibernate/src/NHibernate.Test/CfgTest/SchemaAutoActionFixture.cs
Added: trunk/nhibernate/src/NHibernate/Cfg/Hbm2ddlKeyWords.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Hbm2ddlKeyWords.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Cfg/Hbm2ddlKeyWords.cs 2009-07-02 04:24:50 UTC (rev 4560)
@@ -0,0 +1,85 @@
+namespace NHibernate.Cfg
+{
+ public class Hbm2DDLKeyWords
+ {
+ private readonly string value;
+
+ private Hbm2DDLKeyWords(string value)
+ {
+ this.value = value;
+ }
+
+ public override string ToString()
+ {
+ return value;
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj))
+ {
+ return false;
+ }
+ if (ReferenceEquals(this, obj))
+ {
+ return true;
+ }
+ if (obj.GetType() != typeof(Hbm2DDLKeyWords))
+ {
+ return false;
+ }
+ return Equals((Hbm2DDLKeyWords)obj);
+ }
+
+ public bool Equals(string other)
+ {
+ return value.Equals(other);
+ }
+
+ public bool Equals(Hbm2DDLKeyWords other)
+ {
+ if (ReferenceEquals(null, other))
+ {
+ return false;
+ }
+ if (ReferenceEquals(this, other))
+ {
+ return true;
+ }
+ return Equals(other.value, value);
+ }
+
+ public override int GetHashCode()
+ {
+ return (value != null ? value.GetHashCode() : 0);
+ }
+
+ public static bool operator ==(string a, Hbm2DDLKeyWords b)
+ {
+ if (ReferenceEquals(null, b))
+ {
+ return false;
+ }
+ return b.Equals(a);
+ }
+
+ public static bool operator ==(Hbm2DDLKeyWords a, string b)
+ {
+ return b == a;
+ }
+
+ public static bool operator !=(Hbm2DDLKeyWords a, string b)
+ {
+ return !(a == b);
+ }
+
+ public static bool operator !=(string a, Hbm2DDLKeyWords b)
+ {
+ return !(a == b);
+ }
+
+ public static Hbm2DDLKeyWords None = new Hbm2DDLKeyWords("none");
+ public static Hbm2DDLKeyWords Keywords = new Hbm2DDLKeyWords("keywords");
+ public static Hbm2DDLKeyWords AutoQuote = new Hbm2DDLKeyWords("auto-quote");
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate/Cfg/Loquacious/CacheConfiguration.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Loquacious/CacheConfiguration.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Cfg/Loquacious/CacheConfiguration.cs 2009-07-02 04:24:50 UTC (rev 4560)
@@ -0,0 +1,109 @@
+using NHibernate.Cache;
+
+namespace NHibernate.Cfg.Loquacious
+{
+ internal class CacheConfigurationProperties : ICacheConfigurationProperties
+ {
+ private readonly Configuration cfg;
+
+ public CacheConfigurationProperties(Configuration cfg)
+ {
+ this.cfg = cfg;
+ }
+
+ #region Implementation of ICacheConfigurationProperties
+
+ public bool UseMinimalPuts
+ {
+ set { cfg.SetProperty(Environment.UseMinimalPuts, value.ToString().ToLowerInvariant()); }
+ }
+
+ public string RegionsPrefix
+ {
+ set { cfg.SetProperty(Environment.CacheRegionPrefix, value); }
+ }
+
+ public byte DefaultExpiration
+ {
+ set { cfg.SetProperty(Environment.CacheDefaultExpiration, value.ToString()); }
+ }
+
+ public void Provider<TProvider>() where TProvider : ICacheProvider
+ {
+ cfg.SetProperty(Environment.CacheProvider, typeof (TProvider).AssemblyQualifiedName);
+ }
+
+ public void QueryCache<TFactory>() where TFactory : IQueryCache
+ {
+ cfg.SetProperty(Environment.QueryCacheFactory, typeof (TFactory).AssemblyQualifiedName);
+ }
+
+ #endregion
+ }
+
+ internal class CacheConfiguration : ICacheConfiguration
+ {
+ private readonly FluentSessionFactoryConfiguration fc;
+
+ public CacheConfiguration(FluentSessionFactoryConfiguration parent)
+ {
+ fc = parent;
+ Queries = new QueryCacheConfiguration(this);
+ }
+
+ internal Configuration Configuration
+ {
+ get { return fc.Configuration; }
+ }
+
+ #region Implementation of ICacheConfiguration
+
+ public ICacheConfiguration Through<TProvider>() where TProvider : ICacheProvider
+ {
+ fc.Configuration.SetProperty(Environment.CacheProvider, typeof(TProvider).AssemblyQualifiedName);
+ return this;
+ }
+
+ public ICacheConfiguration PrefixingRegionsWith(string regionPrefix)
+ {
+ fc.Configuration.SetProperty(Environment.CacheRegionPrefix, regionPrefix);
+ return this;
+ }
+
+ public ICacheConfiguration UsingMinimalPuts()
+ {
+ fc.Configuration.SetProperty(Environment.UseMinimalPuts, true.ToString().ToLowerInvariant());
+ return this;
+ }
+
+ public IFluentSessionFactoryConfiguration WithDefaultExpiration(byte seconds)
+ {
+ fc.Configuration.SetProperty(Environment.CacheDefaultExpiration, seconds.ToString());
+ return fc;
+ }
+
+ public IQueryCacheConfiguration Queries { get; private set; }
+
+ #endregion
+ }
+
+ internal class QueryCacheConfiguration : IQueryCacheConfiguration
+ {
+ private readonly CacheConfiguration cc;
+
+ public QueryCacheConfiguration(CacheConfiguration cc)
+ {
+ this.cc = cc;
+ }
+
+ #region Implementation of IQueryCacheConfiguration
+
+ public ICacheConfiguration Through<TFactory>() where TFactory : IQueryCache
+ {
+ cc.Configuration.SetProperty(Environment.QueryCacheFactory, typeof(TFactory).AssemblyQualifiedName);
+ return cc;
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ConfigurationExtensions.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ConfigurationExtensions.cs 2009-07-01 20:36:07 UTC (rev 4559)
+++ trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ConfigurationExtensions.cs 2009-07-02 04:24:50 UTC (rev 4560)
@@ -1,3 +1,5 @@
+using System;
+using NHibernate.Hql;
namespace NHibernate.Cfg.Loquacious
{
public static class ConfigurationExtensions
@@ -6,5 +8,48 @@
{
return new FluentSessionFactoryConfiguration(configuration);
}
+
+ public static Configuration SessionFactoryName(this Configuration configuration, string sessionFactoryName)
+ {
+ configuration.SetProperty(Environment.SessionFactoryName, sessionFactoryName);
+ return configuration;
+ }
+
+ public static Configuration Cache(this Configuration configuration, Action<ICacheConfigurationProperties> cacheProperties)
+ {
+ cacheProperties(new CacheConfigurationProperties(configuration));
+ return configuration;
+ }
+
+ public static Configuration CollectionTypeFactory<TCollecionsFactory>(this Configuration configuration)
+ {
+ configuration.SetProperty(Environment.CollectionTypeFactoryClass,
+ typeof(TCollecionsFactory).AssemblyQualifiedName);
+ return configuration;
+ }
+
+ public static Configuration Proxy(this Configuration configuration, Action<IProxyConfigurationProperties> proxyProperties)
+ {
+ proxyProperties(new ProxyConfigurationProperties(configuration));
+ return configuration;
+ }
+
+ public static Configuration HqlQueryTranslator<TQueryTranslator>(this Configuration configuration) where TQueryTranslator : IQueryTranslatorFactory
+ {
+ configuration.SetProperty(Environment.QueryTranslator, typeof(TQueryTranslator).AssemblyQualifiedName);
+ return configuration;
+ }
+
+ public static Configuration Mappings(this Configuration configuration, Action<IMappingsConfigurationProperties> mappingsProperties)
+ {
+ mappingsProperties(new MappingsConfigurationProperties(configuration));
+ return configuration;
+ }
+
+ public static Configuration DataBaseIntegration(this Configuration configuration, Action<IDbIntegrationConfigurationProperties> dataBaseIntegration)
+ {
+ dataBaseIntegration(new DbIntegrationConfigurationProperties(configuration));
+ return configuration;
+ }
}
}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate/Cfg/Loquacious/DbIntegrationConfiguration.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Loquacious/DbIntegrationConfiguration.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Cfg/Loquacious/DbIntegrationConfiguration.cs 2009-07-02 04:24:50 UTC (rev 4560)
@@ -0,0 +1,382 @@
+using System.Data;
+using System.Data.Common;
+using NHibernate.Connection;
+using NHibernate.Driver;
+using NHibernate.AdoNet;
+using NHibernate.Exceptions;
+using NHibernate.Transaction;
+
+namespace NHibernate.Cfg.Loquacious
+{
+ internal class DbIntegrationConfiguration : IDbIntegrationConfiguration
+ {
+ private readonly Configuration configuration;
+
+ public DbIntegrationConfiguration(Configuration configuration)
+ {
+ this.configuration = configuration;
+ Connected = new ConnectionConfiguration(this);
+ BatchingQueries = new BatcherConfiguration(this);
+ Transactions = new TransactionConfiguration(this);
+ CreateCommands = new CommandsConfiguration(this);
+ Schema = new DbSchemaIntegrationConfiguration(this);
+ }
+
+ public Configuration Configuration
+ {
+ get { return configuration; }
+ }
+
+ #region Implementation of IDbIntegrationConfiguration
+
+ public IDbIntegrationConfiguration Using<TDialect>() where TDialect : Dialect.Dialect
+ {
+ configuration.SetProperty(Environment.Dialect, typeof(TDialect).AssemblyQualifiedName);
+ return this;
+ }
+
+ public IDbIntegrationConfiguration DisableKeywordsAutoImport()
+ {
+ configuration.SetProperty(Environment.Hbm2ddlKeyWords, "none");
+ return this;
+ }
+
+ public IDbIntegrationConfiguration AutoQuoteKeywords()
+ {
+ configuration.SetProperty(Environment.Hbm2ddlKeyWords, "auto-quote");
+ return this;
+ }
+
+ public IDbIntegrationConfiguration LogSqlInConsole()
+ {
+ configuration.SetProperty(Environment.ShowSql, "true");
+ return this;
+ }
+
+ public IDbIntegrationConfiguration DisableLogFormatedSql()
+ {
+ configuration.SetProperty(Environment.FormatSql, "false");
+ return this;
+ }
+
+ public IConnectionConfiguration Connected { get; private set; }
+ public IBatcherConfiguration BatchingQueries { get; private set; }
+ public ITransactionConfiguration Transactions { get; private set; }
+
+ public ICommandsConfiguration CreateCommands { get; private set; }
+
+ public IDbSchemaIntegrationConfiguration Schema { get; private set; }
+
+ #endregion
+ }
+
+ internal class DbSchemaIntegrationConfiguration : IDbSchemaIntegrationConfiguration
+ {
+ private readonly DbIntegrationConfiguration dbc;
+
+ public DbSchemaIntegrationConfiguration(DbIntegrationConfiguration dbc)
+ {
+ this.dbc = dbc;
+ }
+
+ #region Implementation of IDbSchemaIntegrationConfiguration
+
+ public IDbIntegrationConfiguration Recreating()
+ {
+ dbc.Configuration.SetProperty(Environment.Hbm2ddlAuto, SchemaAutoAction.Recreate.ToString());
+ return dbc;
+ }
+
+ public IDbIntegrationConfiguration Creating()
+ {
+ dbc.Configuration.SetProperty(Environment.Hbm2ddlAuto, SchemaAutoAction.Create.ToString());
+ return dbc;
+ }
+
+ public IDbIntegrationConfiguration Updating()
+ {
+ dbc.Configuration.SetProperty(Environment.Hbm2ddlAuto, SchemaAutoAction.Update.ToString());
+ return dbc;
+ }
+
+ public IDbIntegrationConfiguration Validating()
+ {
+ dbc.Configuration.SetProperty(Environment.Hbm2ddlAuto, SchemaAutoAction.Validate.ToString());
+ return dbc;
+ }
+
+ #endregion
+ }
+
+ internal class CommandsConfiguration : ICommandsConfiguration
+ {
+ private readonly DbIntegrationConfiguration dbc;
+
+ public CommandsConfiguration(DbIntegrationConfiguration dbc)
+ {
+ this.dbc = dbc;
+ }
+
+ #region Implementation of ICommandsConfiguration
+
+ public ICommandsConfiguration Preparing()
+ {
+ dbc.Configuration.SetProperty(Environment.PrepareSql, "true");
+ return this;
+ }
+
+ public ICommandsConfiguration WithTimeout(byte seconds)
+ {
+ dbc.Configuration.SetProperty(Environment.CommandTimeout, seconds.ToString());
+ return this;
+ }
+
+ public ICommandsConfiguration ConvertingExceptionsThrough<TExceptionConverter>()
+ where TExceptionConverter : ISQLExceptionConverter
+ {
+ dbc.Configuration.SetProperty(Environment.SqlExceptionConverter, typeof(TExceptionConverter).AssemblyQualifiedName);
+ return this;
+ }
+
+ public ICommandsConfiguration AutoCommentingSql()
+ {
+ dbc.Configuration.SetProperty(Environment.UseSqlComments, "true");
+ return this;
+ }
+
+ public IDbIntegrationConfiguration WithHqlToSqlSubstitutions(string csvQuerySubstitutions)
+ {
+ dbc.Configuration.SetProperty(Environment.QuerySubstitutions, csvQuerySubstitutions);
+ return dbc;
+ }
+
+ public IDbIntegrationConfiguration WithDefaultHqlToSqlSubstitutions()
+ {
+ return dbc;
+ }
+
+ public ICommandsConfiguration WithMaximumDepthOfOuterJoinFetching(byte maxFetchDepth)
+ {
+ dbc.Configuration.SetProperty(Environment.MaxFetchDepth, maxFetchDepth.ToString());
+ return this;
+ }
+
+ #endregion
+ }
+
+ internal class TransactionConfiguration : ITransactionConfiguration
+ {
+ private readonly DbIntegrationConfiguration dbc;
+
+ public TransactionConfiguration(DbIntegrationConfiguration dbc)
+ {
+ this.dbc = dbc;
+ }
+
+ #region Implementation of ITransactionConfiguration
+
+ public IDbIntegrationConfiguration Through<TFactory>() where TFactory : ITransactionFactory
+ {
+ dbc.Configuration.SetProperty(Environment.TransactionStrategy, typeof(TFactory).AssemblyQualifiedName);
+ return dbc;
+ }
+
+ #endregion
+ }
+
+ internal class BatcherConfiguration : IBatcherConfiguration
+ {
+ private readonly DbIntegrationConfiguration dbc;
+
+ public BatcherConfiguration(DbIntegrationConfiguration dbc)
+ {
+ this.dbc = dbc;
+ }
+
+ #region Implementation of IBatcherConfiguration
+
+ public IBatcherConfiguration Through<TBatcher>() where TBatcher : IBatcherFactory
+ {
+ dbc.Configuration.SetProperty(Environment.BatchStrategy, typeof(TBatcher).AssemblyQualifiedName);
+ return this;
+ }
+
+ public IDbIntegrationConfiguration Each(short batchSize)
+ {
+ dbc.Configuration.SetProperty(Environment.BatchSize, batchSize.ToString());
+ return dbc;
+ }
+
+ #endregion
+ }
+
+ internal class ConnectionConfiguration : IConnectionConfiguration
+ {
+ private readonly DbIntegrationConfiguration dbc;
+
+ public ConnectionConfiguration(DbIntegrationConfiguration dbc)
+ {
+ this.dbc = dbc;
+ }
+
+ #region Implementation of IConnectionConfiguration
+
+ public IConnectionConfiguration Through<TProvider>() where TProvider : IConnectionProvider
+ {
+ dbc.Configuration.SetProperty(Environment.ConnectionProvider, typeof(TProvider).AssemblyQualifiedName);
+ return this;
+ }
+
+ public IConnectionConfiguration By<TDriver>() where TDriver : IDriver
+ {
+ dbc.Configuration.SetProperty(Environment.ConnectionDriver, typeof(TDriver).AssemblyQualifiedName);
+ return this;
+ }
+
+ public IConnectionConfiguration With(IsolationLevel level)
+ {
+ dbc.Configuration.SetProperty(Environment.Isolation, level.ToString());
+ return this;
+ }
+
+ public IConnectionConfiguration Releasing(ConnectionReleaseMode releaseMode)
+ {
+ dbc.Configuration.SetProperty(Environment.ReleaseConnections, ConnectionReleaseModeParser.ToString(releaseMode));
+ return this;
+ }
+
+ public IDbIntegrationConfiguration Using(string connectionString)
+ {
+ dbc.Configuration.SetProperty(Environment.ConnectionString, connectionString);
+ return dbc;
+ }
+
+ public IDbIntegrationConfiguration Using(DbConnectionStringBuilder connectionStringBuilder)
+ {
+ dbc.Configuration.SetProperty(Environment.ConnectionString, connectionStringBuilder.ConnectionString);
+ return dbc;
+ }
+
+ public IDbIntegrationConfiguration ByAppConfing(string connectionStringName)
+ {
+ dbc.Configuration.SetProperty(Environment.ConnectionStringName, connectionStringName);
+ return dbc;
+ }
+
+ #endregion
+ }
+
+ internal class DbIntegrationConfigurationProperties: IDbIntegrationConfigurationProperties
+ {
+ private readonly Configuration configuration;
+
+ public DbIntegrationConfigurationProperties(Configuration configuration)
+ {
+ this.configuration = configuration;
+ }
+
+ #region Implementation of IDbIntegrationConfigurationProperties
+
+ public void Dialect<TDialect>() where TDialect : Dialect.Dialect
+ {
+ configuration.SetProperty(Environment.Dialect, typeof(TDialect).AssemblyQualifiedName);
+ }
+
+ public Hbm2DDLKeyWords KeywordsAutoImport
+ {
+ set { configuration.SetProperty(Environment.Hbm2ddlKeyWords, value.ToString()); }
+ }
+
+ public bool LogSqlInConsole
+ {
+ set { configuration.SetProperty(Environment.ShowSql, value.ToString().ToLowerInvariant()); }
+ }
+
+ public bool LogFormatedSql
+ {
+ set { configuration.SetProperty(Environment.FormatSql, value.ToString().ToLowerInvariant()); }
+ }
+
+ public void ConnectionProvider<TProvider>() where TProvider : IConnectionProvider
+ {
+ configuration.SetProperty(Environment.ConnectionProvider, typeof(TProvider).AssemblyQualifiedName);
+ }
+
+ public void Driver<TDriver>() where TDriver : IDriver
+ {
+ configuration.SetProperty(Environment.ConnectionDriver, typeof(TDriver).AssemblyQualifiedName);
+ }
+
+ public IsolationLevel IsolationLevel
+ {
+ set { configuration.SetProperty(Environment.Isolation, value.ToString()); }
+ }
+
+ public ConnectionReleaseMode ConnectionReleaseMode
+ {
+ set { configuration.SetProperty(Environment.ReleaseConnections, ConnectionReleaseModeParser.ToString(value)); }
+ }
+
+ public string ConnectionString
+ {
+ set { configuration.SetProperty(Environment.ConnectionString, value); }
+ }
+
+ public string ConnectionStringName
+ {
+ set { configuration.SetProperty(Environment.ConnectionStringName, value); }
+ }
+
+ public void Batcher<TBatcher>() where TBatcher : IBatcherFactory
+ {
+ configuration.SetProperty(Environment.BatchStrategy, typeof(TBatcher).AssemblyQualifiedName);
+ }
+
+ public short BatchSize
+ {
+ set { configuration.SetProperty(Environment.BatchSize, value.ToString()); }
+ }
+
+ public void TransactionFactory<TFactory>() where TFactory : ITransactionFactory
+ {
+ configuration.SetProperty(Environment.TransactionStrategy, typeof(TFactory).AssemblyQualifiedName);
+ }
+
+ public bool PrepareCommands
+ {
+ set { configuration.SetProperty(Environment.PrepareSql, value.ToString().ToLowerInvariant()); }
+ }
+
+ public byte Timeout
+ {
+ set { configuration.SetProperty(Environment.CommandTimeout, value.ToString()); }
+ }
+
+ public void ExceptionConverter<TExceptionConverter>() where TExceptionConverter : ISQLExceptionConverter
+ {
+ configuration.SetProperty(Environment.SqlExceptionConverter, typeof(TExceptionConverter).AssemblyQualifiedName);
+ }
+
+ public bool AutoCommentSql
+ {
+ set { configuration.SetProperty(Environment.UseSqlComments, value.ToString().ToLowerInvariant()); }
+ }
+
+ public string HqlToSqlSubstitutions
+ {
+ set { configuration.SetProperty(Environment.QuerySubstitutions, value); }
+ }
+
+ public byte MaximumDepthOfOuterJoinFetching
+ {
+ set { configuration.SetProperty(Environment.MaxFetchDepth, value.ToString()); }
+ }
+
+ public SchemaAutoAction SchemaAction
+ {
+ set { configuration.SetProperty(Environment.Hbm2ddlAuto, value.ToString()); }
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Cfg/Loquacious/FluentSessionFactoryConfiguration.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Loquacious/FluentSessionFactoryConfiguration.cs 2009-07-01 20:36:07 UTC (rev 4559)
+++ trunk/nhibernate/src/NHibernate/Cfg/Loquacious/FluentSessionFactoryConfiguration.cs 2009-07-02 04:24:50 UTC (rev 4560)
@@ -1,13 +1,5 @@
-using System.Data;
-using System.Data.Common;
-using NHibernate.AdoNet;
using NHibernate.Bytecode;
-using NHibernate.Cache;
-using NHibernate.Connection;
-using NHibernate.Driver;
-using NHibernate.Exceptions;
using NHibernate.Hql;
-using NHibernate.Transaction;
namespace NHibernate.Cfg.Loquacious
{
@@ -68,358 +60,6 @@
#endregion
}
- internal class DbIntegrationConfiguration : IDbIntegrationConfiguration
- {
- private readonly Configuration configuration;
-
- public DbIntegrationConfiguration(Configuration configuration)
- {
- this.configuration = configuration;
- Connected = new ConnectionConfiguration(this);
- BatchingQueries = new BatcherConfiguration(this);
- Transactions = new TransactionConfiguration(this);
- CreateCommands = new CommandsConfiguration(this);
- Schema = new DbSchemaIntegrationConfiguration(this);
- }
-
- public Configuration Configuration
- {
- get { return configuration; }
- }
-
- #region Implementation of IDbIntegrationConfiguration
-
- public IDbIntegrationConfiguration Using<TDialect>() where TDialect : Dialect.Dialect
- {
- configuration.SetProperty(Environment.Dialect, typeof (TDialect).AssemblyQualifiedName);
- return this;
- }
-
- public IDbIntegrationConfiguration DisableKeywordsAutoImport()
- {
- configuration.SetProperty(Environment.Hbm2ddlKeyWords, "none");
- return this;
- }
-
- public IDbIntegrationConfiguration AutoQuoteKeywords()
- {
- configuration.SetProperty(Environment.Hbm2ddlKeyWords, "auto-quote");
- return this;
- }
-
- public IDbIntegrationConfiguration LogSqlInConsole()
- {
- configuration.SetProperty(Environment.ShowSql, "true");
- return this;
- }
-
- public IDbIntegrationConfiguration DisableLogFormatedSql()
- {
- configuration.SetProperty(Environment.FormatSql, "false");
- return this;
- }
-
- public IConnectionConfiguration Connected { get; private set; }
- public IBatcherConfiguration BatchingQueries { get; private set; }
- public ITransactionConfiguration Transactions { get; private set; }
-
- public ICommandsConfiguration CreateCommands { get; private set; }
-
- public IDbSchemaIntegrationConfiguration Schema { get; private set; }
-
- #endregion
- }
-
- internal class DbSchemaIntegrationConfiguration : IDbSchemaIntegrationConfiguration
- {
- private readonly DbIntegrationConfiguration dbc;
-
- public DbSchemaIntegrationConfiguration(DbIntegrationConfiguration dbc)
- {
- this.dbc = dbc;
- }
-
- #region Implementation of IDbSchemaIntegrationConfiguration
-
- public IDbIntegrationConfiguration Recreating()
- {
- dbc.Configuration.SetProperty(Environment.Hbm2ddlAuto, "create-drop");
- return dbc;
- }
-
- public IDbIntegrationConfiguration Creating()
- {
- dbc.Configuration.SetProperty(Environment.Hbm2ddlAuto, "create");
- return dbc;
- }
-
- public IDbIntegrationConfiguration Updating()
- {
- dbc.Configuration.SetProperty(Environment.Hbm2ddlAuto, "update");
- return dbc;
- }
-
- public IDbIntegrationConfiguration Validating()
- {
- dbc.Configuration.SetProperty(Environment.Hbm2ddlAuto, "validate");
- return dbc;
- }
-
- #endregion
- }
-
- internal class CommandsConfiguration : ICommandsConfiguration
- {
- private readonly DbIntegrationConfiguration dbc;
-
- public CommandsConfiguration(DbIntegrationConfiguration dbc)
- {
- this.dbc = dbc;
- }
-
- #region Implementation of ICommandsConfiguration
-
- public ICommandsConfiguration Preparing()
- {
- dbc.Configuration.SetProperty(Environment.PrepareSql, "true");
- return this;
- }
-
- public ICommandsConfiguration WithTimeout(int seconds)
- {
- dbc.Configuration.SetProperty(Environment.CommandTimeout, seconds.ToString());
- return this;
- }
-
- public ICommandsConfiguration ConvertingExceptionsThrough<TExceptionConverter>()
- where TExceptionConverter : ISQLExceptionConverter
- {
- dbc.Configuration.SetProperty(Environment.SqlExceptionConverter, typeof (TExceptionConverter).AssemblyQualifiedName);
- return this;
- }
-
- public ICommandsConfiguration AutoCommentingSql()
- {
- dbc.Configuration.SetProperty(Environment.UseSqlComments, "true");
- return this;
- }
-
- public IDbIntegrationConfiguration WithHqlToSqlSubstitutions(string csvQuerySubstitutions)
- {
- dbc.Configuration.SetProperty(Environment.QuerySubstitutions, csvQuerySubstitutions);
- return dbc;
- }
-
- public IDbIntegrationConfiguration WithDefaultHqlToSqlSubstitutions()
- {
- return dbc;
- }
-
- public ICommandsConfiguration WithMaximumDepthOfOuterJoinFetching(byte maxFetchDepth)
- {
- dbc.Configuration.SetProperty(Environment.MaxFetchDepth, maxFetchDepth.ToString());
- return this;
- }
-
- #endregion
- }
-
- internal class TransactionConfiguration : ITransactionConfiguration
- {
- private readonly DbIntegrationConfiguration dbc;
-
- public TransactionConfiguration(DbIntegrationConfiguration dbc)
- {
- this.dbc = dbc;
- }
-
- #region Implementation of ITransactionConfiguration
-
- public IDbIntegrationConfiguration Through<TFactory>() where TFactory : ITransactionFactory
- {
- dbc.Configuration.SetProperty(Environment.TransactionStrategy, typeof (TFactory).AssemblyQualifiedName);
- return dbc;
- }
-
- #endregion
- }
-
- internal class BatcherConfiguration : IBatcherConfiguration
- {
- private readonly DbIntegrationConfiguration dbc;
-
- public BatcherConfiguration(DbIntegrationConfiguration dbc)
- {
- this.dbc = dbc;
- }
-
- #region Implementation of IBatcherConfiguration
-
- public IBatcherConfiguration Through<TBatcher>() where TBatcher : IBatcherFactory
- {
- dbc.Configuration.SetProperty(Environment.BatchStrategy, typeof (TBatcher).AssemblyQualifiedName);
- return this;
- }
-
- public IDbIntegrationConfiguration Each(short batchSize)
- {
- dbc.Configuration.SetProperty(Environment.BatchSize, batchSize.ToString());
- return dbc;
- }
-
- #endregion
- }
-
- internal class ConnectionConfiguration : IConnectionConfiguration
- {
- private readonly DbIntegrationConfiguration dbc;
-
- public ConnectionConfiguration(DbIntegrationConfiguration dbc)
- {
- this.dbc = dbc;
- }
-
- #region Implementation of IConnectionConfiguration
-
- public IConnectionConfiguration Through<TProvider>() where TProvider : IConnectionProvider
- {
- dbc.Configuration.SetProperty(Environment.ConnectionProvider, typeof (TProvider).AssemblyQualifiedName);
- return this;
- }
-
- public IConnectionConfiguration By<TDriver>() where TDriver : IDriver
- {
- dbc.Configuration.SetProperty(Environment.ConnectionDriver, typeof (TDriver).AssemblyQualifiedName);
- return this;
- }
-
- public IConnectionConfiguration With(IsolationLevel level)
- {
- dbc.Configuration.SetProperty(Environment.Isolation, level.ToString());
- return this;
- }
-
- public IConnectionConfiguration Releasing(ConnectionReleaseMode releaseMode)
- {
- dbc.Configuration.SetProperty(Environment.ReleaseConnections, ConnectionReleaseModeParser.ToString(releaseMode));
- return this;
- }
-
- public IDbIntegrationConfiguration Using(string connectionString)
- {
- dbc.Configuration.SetProperty(Environment.ConnectionString, connectionString);
- return dbc;
- }
-
- public IDbIntegrationConfiguration Using(DbConnectionStringBuilder connectionStringBuilder)
- {
- dbc.Configuration.SetProperty(Environment.ConnectionString, connectionStringBuilder.ConnectionString);
- return dbc;
- }
-
- public IDbIntegrationConfiguration ByAppConfing(string connectionStringName)
- {
- dbc.Configuration.SetProperty(Environment.ConnectionStringName, connectionStringName);
- return dbc;
- }
-
- #endregion
- }
-
- internal class CacheConfiguration : ICacheConfiguration
- {
- private readonly FluentSessionFactoryConfiguration fc;
-
- public CacheConfiguration(FluentSessionFactoryConfiguration parent)
- {
- fc = parent;
- Queries = new QueryCacheConfiguration(this);
- }
-
- internal Configuration Configuration
- {
- get { return fc.Configuration; }
- }
-
- #region Implementation of ICacheConfiguration
-
- public ICacheConfiguration Through<TProvider>() where TProvider : ICacheProvider
- {
- fc.Configuration.SetProperty(Environment.CacheProvider, typeof (TProvider).AssemblyQualifiedName);
- return this;
- }
-
- public ICacheConfiguration PrefixingRegionsWith(string regionPrefix)
- {
- fc.Configuration.SetProperty(Environment.CacheRegionPrefix, regionPrefix);
- return this;
- }
-
- public ICacheConfiguration UsingMinimalPuts()
- {
- fc.Configuration.SetProperty(Environment.UseMinimalPuts, "true");
- return this;
- }
-
- public IFluentSessionFactoryConfiguration WithDefaultExpiration(byte seconds)
- {
- fc.Configuration.SetProperty(Environment.CacheDefaultExpiration, seconds.ToString());
- return fc;
- }
-
- public IQueryCacheConfiguration Queries { get; private set; }
-
- #endregion
- }
-
- internal class QueryCacheConfiguration : IQueryCacheConfiguration
- {
- private readonly CacheConfiguration cc;
-
- public QueryCacheConfiguration(CacheConfiguration cc)
- {
- this.cc = cc;
- }
-
- #region Implementation of IQueryCacheConfiguration
-
- public ICacheConfiguration Through<TFactory>() where TFactory : IQueryCache
- {
- cc.Configuration.SetProperty(Environment.QueryCacheFactory, typeof (TFactory).AssemblyQualifiedName);
- return cc;
- }
-
- #endregion
- }
-
- internal class ProxyConfiguration : IProxyConfiguration
- {
- private readonly FluentSessionFactoryConfiguration fc;
-
- public ProxyConfiguration(FluentSessionFactoryConfiguration parent)
- {
- fc = parent;
- }
-
- #region Implementation of IProxyConfiguration
-
- public IProxyConfiguration DisableValidation()
- {
- fc.Configuration.SetProperty(Environment.UseProxyValidator, "false");
- return this;
- }
-
- public IFluentSessionFactoryConfiguration Through<TProxyFactoryFactory>()
- where TProxyFactoryFactory : IProxyFactoryFactory
- {
- fc.Configuration.SetProperty(Environment.ProxyFactoryFactoryClass,
- typeof (TProxyFactoryFactory).AssemblyQualifiedName);
- return fc;
- }
-
- #endregion
- }
-
internal class CollectionFactoryConfiguration : ICollectionFactoryConfiguration
{
private readonly FluentSessionFactoryConfiguration fc;
@@ -441,30 +81,4 @@
#endregion
}
-
- internal class MappingsConfiguration : IMappingsConfiguration
- {
- private readonly FluentSessionFactoryConfiguration fc;
-
- public MappingsConfiguration(FluentSessionFactoryConfiguration parent)
- {
- fc = parent;
- }
-
- #region Implementation of IMappingsConfiguration
-
- public IMappingsConfiguration UsingDefaultCatalog(string defaultCatalogName)
- {
- fc.Configuration.SetProperty(Environment.DefaultCatalog, defaultCatalogName);
- return this;
- }
-
- public IFluentSessionFactoryConfiguration UsingDefaultSchema(string defaultSchemaName)
- {
- fc.Configuration.SetProperty(Environment.DefaultSchema, defaultSchemaName);
- return fc;
- }
-
- #endregion
- }
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ICacheConfiguration.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ICacheConfiguration.cs 2009-07-01 20:36:07 UTC (rev 4559)
+++ trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ICacheConfiguration.cs 2009-07-02 04:24:50 UTC (rev 4560)
@@ -9,4 +9,13 @@
IFluentSessionFactoryConfiguration WithDefaultExpiration(byte seconds);
IQueryCacheConfiguration Queries { get; }
}
+
+ public interface ICacheConfigurationProperties
+ {
+ bool UseMinimalPuts { set; }
+ string RegionsPrefix { set; }
+ byte DefaultExpiration { set; }
+ void Provider<TProvider>() where TProvider : ICacheProvider;
+ void QueryCache<TFactory>() where TFactory : IQueryCache;
+ }
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ICommandsConfiguration.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ICommandsConfiguration.cs 2009-07-01 20:36:07 UTC (rev 4559)
+++ trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ICommandsConfiguration.cs 2009-07-02 04:24:50 UTC (rev 4560)
@@ -4,7 +4,7 @@
public interface ICommandsConfiguration
{
ICommandsConfiguration Preparing();
- ICommandsConfiguration WithTimeout(int seconds);
+ ICommandsConfiguration WithTimeout(byte seconds);
ICommandsConfiguration ConvertingExceptionsThrough<TExceptionConverter>() where TExceptionConverter : ISQLExceptionConverter;
ICommandsConfiguration AutoCommentingSql();
IDbIntegrationConfiguration WithHqlToSqlSubstitutions(string csvQuerySubstitutions);
Modified: trunk/nhibernate/src/NHibernate/Cfg/Loquacious/IDbIntegrationConfiguration.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Loquacious/IDbIntegrationConfiguration.cs 2009-07-01 20:36:07 UTC (rev 4559)
+++ trunk/nhibernate/src/NHibernate/Cfg/Loquacious/IDbIntegrationConfiguration.cs 2009-07-02 04:24:50 UTC (rev 4560)
@@ -1,3 +1,10 @@
+using System.Data;
+using NHibernate.AdoNet;
+using NHibernate.Driver;
+using NHibernate.Connection;
+using NHibernate.Transaction;
+using NHibernate.Exceptions;
+
namespace NHibernate.Cfg.Loquacious
{
public interface IDbIntegrationConfiguration
@@ -22,6 +29,34 @@
ICommandsConfiguration CreateCommands { get; }
IDbSchemaIntegrationConfiguration Schema { get; }
+ }
+ public interface IDbIntegrationConfigurationProperties
+ {
+ void Dialect<TDialect>() where TDialect : Dialect.Dialect;
+ Hbm2DDLKeyWords KeywordsAutoImport { set; }
+ bool LogSqlInConsole { set; }
+ bool LogFormatedSql { set; }
+
+ void ConnectionProvider<TProvider>() where TProvider : IConnectionProvider;
+ void Driver<TDriver>() where TDriver : IDriver;
+ IsolationLevel IsolationLevel { set; }
+ ConnectionReleaseMode ConnectionReleaseMode { set; }
+ string ConnectionString { set; }
+ string ConnectionStringName { set; }
+
+ void Batcher<TBatcher>() where TBatcher : IBatcherFactory;
+ short BatchSize { set; }
+
+ void TransactionFactory<TFactory>() where TFactory : ITransactionFactory;
+
+ bool PrepareCommands { set; }
+ byte Timeout { set; }
+ void ExceptionConverter<TExceptionConverter>() where TExceptionConverter : ISQLExceptionConverter;
+ bool AutoCommentSql { set; }
+ string HqlToSqlSubstitutions { set; }
+ byte MaximumDepthOfOuterJoinFetching { set; }
+
+ SchemaAutoAction SchemaAction { set; }
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Cfg/Loquacious/IMappingsConfiguration.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Loquacious/IMappingsConfiguration.cs 2009-07-01 20:36:07 UTC (rev 4559)
+++ trunk/nhibernate/src/NHibernate/Cfg/Loquacious/IMappingsConfiguration.cs 2009-07-02 04:24:50 UTC (rev 4560)
@@ -5,4 +5,10 @@
IMappingsConfiguration UsingDefaultCatalog(string defaultCatalogName);
IFluentSessionFactoryConfiguration UsingDefaultSchema(string defaultSchemaName);
}
+
+ public interface IMappingsConfigurationProperties
+ {
+ string DefaultCatalog { set; }
+ string DefaultSchema { set; }
+ }
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Cfg/Loquacious/IProxyConfiguration.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Loquacious/IProxyConfiguration.cs 2009-07-01 20:36:07 UTC (rev 4559)
+++ trunk/nhibernate/src/NHibernate/Cfg/Loquacious/IProxyConfiguration.cs 2009-07-02 04:24:50 UTC (rev 4560)
@@ -6,4 +6,10 @@
IProxyConfiguration DisableValidation();
IFluentSessionFactoryConfiguration Through<TProxyFactoryFactory>() where TProxyFactoryFactory : IProxyFactoryFactory;
}
+
+ public interface IProxyConfigurationProperties
+ {
+ bool Validation { set; }
+ void ProxyFactoryFactory<TProxyFactoryFactory>() where TProxyFactoryFactory : IProxyFactoryFactory;
+ }
}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate/Cfg/Loquacious/MappingsConfiguration.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Loquacious/MappingsConfiguration.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Cfg/Loquacious/MappingsConfiguration.cs 2009-07-02 04:24:50 UTC (rev 4560)
@@ -0,0 +1,54 @@
+using System;
+
+namespace NHibernate.Cfg.Loquacious
+{
+ internal class MappingsConfiguration : IMappingsConfiguration
+ {
+ private readonly FluentSessionFactoryConfiguration fc;
+
+ public MappingsConfiguration(FluentSessionFactoryConfiguration parent)
+ {
+ fc = parent;
+ }
+
+ #region Implementation of IMappingsConfiguration
+
+ public IMappingsConfiguration UsingDefaultCatalog(string defaultCatalogName)
+ {
+ fc.Configuration.SetProperty(Environment.DefaultCatalog, defaultCatalogName);
+ return this;
+ }
+
+ public IFluentSessionFactoryConfiguration UsingDefaultSchema(string defaultSchemaName)
+ {
+ fc.Configuration.SetProperty(Environment.DefaultSchema, defaultSchemaName);
+ return fc;
+ }
+
+ #endregion
+ }
+
+ internal class MappingsConfigurationProperties:IMappingsConfigurationProperties
+ {
+ private readonly Configuration configuration;
+
+ public MappingsConfigurationProperties(Configuration configuration)
+ {
+ this.configuration = configuration;
+ }
+
+ #region Implementation of IMappingsConfigurationProperties
+
+ public string DefaultCatalog
+ {
+ set { configuration.SetProperty(Environment.DefaultCatalog, value); }
+ }
+
+ public string DefaultSchema
+ {
+ set { configuration.SetProperty(Environment.DefaultSchema, value); }
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ProxyConfiguration.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ProxyConfiguration.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ProxyConfiguration.cs 2009-07-02 04:24:50 UTC (rev 4560)
@@ -0,0 +1,57 @@
+using NHibernate.Bytecode;
+
+namespace NHibernate.Cfg.Loquacious
+{
+ internal class ProxyConfiguration : IProxyConfiguration
+ {
+ private readonly FluentSessionFactoryConfiguration fc;
+
+ public ProxyConfiguration(FluentSessionFactoryConfiguration parent)
+ {
+ fc = parent;
+ }
+
+ #region Implementation of IProxyConfiguration
+
+ public IProxyConfiguration DisableValidation()
+ {
+ fc.Configuration.SetProperty(Environment.UseProxyValidator, "false");
+ return this;
+ }
+
+ public IFluentSessionFactoryConfiguration Through<TProxyFactoryFactory>()
+ where TProxyFactoryFactory : IProxyFactoryFactory
+ {
+ fc.Configuration.SetProperty(Environment.ProxyFactoryFactoryClass,
+ typeof(TProxyFactoryFactory).AssemblyQualifiedName);
+ return fc;
+ }
+
+ #endregion
+ }
+
+ internal class ProxyConfigurationProperties: IProxyConfigurationProperties
+ {
+ private readonly Configuration configuration;
+
+ public ProxyConfigurationProperties(Configuration configuration)
+ {
+ this.configuration = configuration;
+ }
+
+ #region Implementation of IProxyConfigurationProperties
+
+ public bool Validation
+ {
+ set { configuration.SetProperty(Environment.UseProxyValidator, value.ToString().ToLowerInvariant()); }
+ }
+
+ public void ProxyFactoryFactory<TProxyFactoryFactory>() where TProxyFactoryFactory : IProxyFactoryFactory
+ {
+ configuration.SetProperty(Environment.ProxyFactoryFactoryClass,
+ typeof(TProxyFactoryFactory).AssemblyQualifiedName);
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate/Cfg/SchemaAutoAction.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/SchemaAutoAction.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Cfg/SchemaAutoAction.cs 2009-07-02 04:24:50 UTC (rev 4560)
@@ -0,0 +1,86 @@
+namespace NHibernate.Cfg
+{
+ public class SchemaAutoAction
+ {
+ private readonly string value;
+
+ private SchemaAutoAction(string value)
+ {
+ this.value = value;
+ }
+
+ public override string ToString()
+ {
+ return value;
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj))
+ {
+ return false;
+ }
+ if (ReferenceEquals(this, obj))
+ {
+ return true;
+ }
+ if (obj.GetType() != typeof(SchemaAutoAction))
+ {
+ return false;
+ }
+ return Equals((SchemaAutoAction)obj);
+ }
+
+ public bool Equals(string other)
+ {
+ return value.Equals(other);
+ }
+
+ public bool Equals(SchemaAutoAction other)
+ {
+ if (ReferenceEquals(null, other))
+ {
+ return false;
+ }
+ if (ReferenceEquals(this, other))
+ {
+ return true;
+ }
+ return Equals(other.value, value);
+ }
+
+ public override int GetHashCode()
+ {
+ return (value != null ? value.GetHashCode() : 0);
+ }
+
+ public static bool operator ==(string a, SchemaAutoAction b)
+ {
+ if (ReferenceEquals(null, b))
+ {
+ return false;
+ }
+ return b.Equals(a);
+ }
+
+ public static bool operator ==(SchemaAutoAction a, string b)
+ {
+ return b == a;
+ }
+
+ public static bool operator !=(SchemaAutoAction a, string b)
+ {
+ return !(a == b);
+ }
+
+ public static bool operator !=(string a, SchemaAutoAction b)
+ {
+ return !(a == b);
+ }
+
+ public static SchemaAutoAction Recreate = new SchemaAutoAction("create-drop");
+ public static SchemaAutoAction Create = new SchemaAutoAction("create");
+ public static SchemaAutoAction Update = new SchemaAutoAction("update");
+ public static SchemaAutoAction Validate = new SchemaAutoAction("validate");
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Cfg/SettingsFactory.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/SettingsFactory.cs 2009-07-01 20:36:07 UTC (rev 4559)
+++ trunk/nhibernate/src/NHibernate/Cfg/SettingsFactory.cs 2009-07-02 04:24:50 UTC (rev 4560)
@@ -142,43 +142,45 @@
#region Hbm2DDL
string autoSchemaExport = PropertiesHelper.GetString(Environment.Hbm2ddlAuto, properties, null);
- if ("update" == autoSchemaExport)
+ if (SchemaAutoAction.Update == autoSchemaExport)
{
settings.IsAutoUpdateSchema = true;
}
- if ("create" == autoSchemaExport)
+ else if (SchemaAutoAction.Create == autoSchemaExport)
{
settings.IsAutoCreateSchema = true;
}
- if ("create-drop" == autoSchemaExport)
+ else if (SchemaAutoAction.Recreate == autoSchemaExport)
{
settings.IsAutoCreateSchema = true;
settings.IsAutoDropSchema = true;
}
- if ("validate" == autoSchemaExport)
+ else if (SchemaAutoAction.Validate == autoSchemaExport)
{
settings.IsAutoValidateSchema = true;
}
string autoKeyWordsImport = PropertiesHelper.GetString(Environment.Hbm2ddlKeyWords, properties, "not-defined");
- switch (autoKeyWordsImport.ToLowerInvariant())
+ autoKeyWordsImport = autoKeyWordsImport.ToLowerInvariant();
+ if (autoKeyWordsImport == Hbm2DDLKeyWords.None)
{
- case "none":
- settings.IsKeywordsImportEnabled = false;
- settings.IsAutoQuoteEnabled = false;
- break;
- case "keywords":
- settings.IsKeywordsImportEnabled = true;
- break;
- case "auto-quote":
- settings.IsKeywordsImportEnabled = true;
- settings.IsAutoQuoteEnabled = true;
- break;
- case "not-defined":
- settings.IsKeywordsImportEnabled = true;
- settings.IsAutoQuoteEnabled = false;
- break;
+ settings.IsKeywordsImportEnabled = false;
+ settings.IsAutoQuoteEnabled = false;
}
+ else if (autoKeyWordsImport == Hbm2DDLKeyWords.Keywords)
+ {
+ settings.IsKeywordsImportEnabled = true;
+ }
+ else if (autoKeyWordsImport == Hbm2DDLKeyWords.AutoQuote)
+ {
+ settings.IsKeywordsImportEnabled = true;
+ settings.IsAutoQuoteEnabled = true;
+ }
+ else if (autoKeyWordsImport == "not-defined")
+ {
+ settings.IsKeywordsImportEnabled = true;
+ settings.IsAutoQuoteEnabled = false;
+ }
#endregion
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-07-01 20:36:07 UTC (rev 4559)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-07-02 04:24:50 UTC (rev 4560)
@@ -459,7 +459,10 @@
<Compile Include="Bytecode\ProxyFactoryFactoryNotConfiguredException.cs" />
<Compile Include="Bytecode\UnableToLoadProxyFactoryFactoryException.cs" />
<Compile Include="Cache\FakeCache.cs" />
+ <Compile Include="Cfg\Hbm2ddlKeyWords.cs" />
+ <Compile Include="Cfg\Loquacious\CacheConfiguration.cs" />
<Compile Include="Cfg\Loquacious\ConfigurationExtensions.cs" />
+ <Compile Include="Cfg\Loquacious\DbIntegrationConfiguration.cs" />
<Compile Include="Cfg\Loquacious\FluentSessionFactoryConfiguration.cs" />
<Compile Include="Cfg\Loquacious\IBatcherConfiguration.cs" />
<Compile Include="Cfg\Loquacious\ICacheConfiguration.cs" />
@@ -473,6 +476,9 @@
<Compile Include="Cfg\Loquacious\IProxyConfiguration.cs" />
<Compile Include="Cfg\Loquacious\IQueryCacheConfiguration.cs" />
<Compile Include="Cfg\Loquacious\ITransactionConfiguration.cs" />
+ <Compile Include="Cfg\Loquacious\MappingsConfiguration.cs" />
+ <Compile Include="Cfg\Loquacious\ProxyConfiguration.cs" />
+ <Compile Include="Cfg\SchemaAutoAction.cs" />
<Compile Include="Cfg\SessionFactoryConfigurationBase.cs" />
<Compile Include="Cfg\ISessionFactoryConfiguration.cs" />
<Compile Include="Cfg\MappingSchema\AbstractDecoratable.cs" />
Added: trunk/nhibernate/src/NHibernate.Test/CfgTest/Loquacious/LambdaConfigurationFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CfgTest/Loquacious/LambdaConfigurationFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/CfgTest/Loquacious/LambdaConfigurationFixture.cs 2009-07-02 04:24:50 UTC (rev 4560)
@@ -0,0 +1,104 @@
+using NHibernate.AdoNet;
+using NHibernate.Cache;
+using NHibernate.Cfg;
+using NHibernate.Dialect;
+using NHibernate.Driver;
+using NHibernate.Hql.Classic;
+using NHibernate.Type;
+using NUnit.Framework;
+using NHibernate.Cfg.Loquacious;
+using System.Data;
+using NHibernate.Exceptions;
+
+namespace NHibernate.Test.CfgTest.Loquacious
+{
+ [TestFixture]
+ public class LambdaConfigurationFixture
+ {
+ [Test]
+ public void FullConfiguration()
+ {
+ var configure = new Configuration();
+ configure.SessionFactoryName("SomeName");
+ configure.Cache(c =>
+ {
+ c.UseMinimalPuts = true;
+ c.DefaultExpiration = 15;
+ c.RegionsPrefix = "xyz";
+ c.Provider<HashtableCacheProvider>();
+ c.QueryCache<StandardQueryCache>();
+ });
+ configure.CollectionTypeFactory<DefaultCollectionTypeFactory>();
+ configure.HqlQueryTranslator<ClassicQueryTranslatorFactory>();
+ configure.Proxy(p =>
+ {
+ p.Validation = false;
+ p.ProxyFactoryFactory<ByteCode.LinFu.ProxyFactoryFactory>();
+ });
+ configure.Mappings(m=>
+ {
+ m.DefaultCatalog = "MyCatalog";
+ m.DefaultSchema = "MySche";
+ });
+ configure.DataBaseIntegration(db =>
+ {
+ db.Dialect<MsSql2000Dialect>();
+ db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
+ db.Batcher<SqlClientBatchingBatcherFactory>();
+ db.BatchSize = 15;
+ db.ConnectionProvider<DebugConnectionProvider>();
+ db.Driver<SqlClientDriver>();
+ db.ConnectionReleaseMode = ConnectionReleaseMode.AfterTransaction;
+ db.IsolationLevel = IsolationLevel.ReadCommitted;
+ db.ConnectionString = "The connection string";
+ db.AutoCommentSql = true;
+ db.ExceptionConverter<SQLStateConverter>();
+ db.PrepareCommands = true;
+ db.Timeout = 10;
+ db.MaximumDepthOfOuterJoinFetching = 11;
+ db.HqlToSqlSubstitutions = "true 1, false 0, yes 'Y', no 'N'";
+ db.SchemaAction = SchemaAutoAction.Validate;
+ });
+
+ Assert.That(configure.Properties[Environment.SessionFactoryName], Is.EqualTo("SomeName"));
+ Assert.That(configure.Properties[Environment.CacheProvider],
+ Is.EqualTo(typeof(HashtableCacheProvider).AssemblyQualifiedName));
+ Assert.That(configure.Properties[Environment.CacheRegionPrefix], Is.EqualTo("xyz"));
+ Assert.That(configure.Properties[Environment.QueryCacheFactory],
+ Is.EqualTo(typeof(StandardQueryCache).AssemblyQualifiedName));
+ Assert.That(configure.Properties[Environment.UseMinimalPuts], Is.EqualTo("true"));
+ Assert.That(configure.Properties[Environment.CacheDefaultExpiration], Is.EqualTo("15"));
+ Assert.That(configure.Properties[Environment.CollectionTypeFactoryClass],
+ Is.EqualTo(typeof(DefaultCollectionTypeFactory).AssemblyQualifiedName));
+ Assert.That(configure.Properties[Environment.UseProxyValidator], Is.EqualTo("false"));
+ Assert.That(configure.Properties[Environment.ProxyFactoryFactoryClass],
+ Is.EqualTo(typeof(ByteCode.LinFu.ProxyFactoryFactory).AssemblyQualifiedName));
+ Assert.That(configure.Properties[Environment.QueryTranslator],
+ Is.EqualTo(typeof(ClassicQueryTranslatorFactory).AssemblyQualifiedName));
+ Assert.That(configure.Properties[Environment.DefaultCatalog], Is.EqualTo("MyCatalog"));
+ Assert.That(configure.Properties[Environment.DefaultSchema], Is.EqualTo("MySche"));
+ Assert.That(configure.Properties[Environment.Dialect],
+ Is.EqualTo(typeof(MsSql2000Dialect).AssemblyQualifiedName));
+ Assert.That(configure.Properties[Environment.Hbm2ddlKeyWords], Is.EqualTo("auto-quote"));
+ Assert.That(configure.Properties[Environment.BatchStrategy],
+ Is.EqualTo(typeof(SqlClientBatchingBatcherFactory).AssemblyQualifiedName));
+ Assert.That(configure.Properties[Environment.BatchSize], Is.EqualTo("15"));
+ Assert.That(configure.Properties[Environment.ConnectionProvider],
+ Is.EqualTo(typeof(DebugConnectionProvider).AssemblyQualifiedName));
+ Assert.That(configure.Properties[Environment.ConnectionDriver],
+ Is.EqualTo(typeof(SqlClientDriver).AssemblyQualifiedName));
+ Assert.That(configure.Properties[Environment.ReleaseConnections],
+ Is.EqualTo(ConnectionReleaseModeParser.ToString(ConnectionReleaseMode.AfterTransaction)));
+ Assert.That(configure.Properties[Environment.Isolation], Is.EqualTo("ReadCommitted"));
+ Assert.That(configure.Properties[Environment.ConnectionString], Is.EqualTo("The connection string"));
+ Assert.That(configure.Properties[Environment.UseSqlComments], Is.EqualTo("true"));
+ Assert.That(configure.Properties[Environment.SqlExceptionConverter],
+ Is.EqualTo(typeof(SQLStateConverter).AssemblyQualifiedName));
+ Assert.That(configure.Properties[Environment.PrepareSql], Is.EqualTo("true"));
+ Assert.That(configure.Properties[Environment.CommandTimeout], Is.EqualTo("10"));
+ Assert.That(configure.Properties[Environment.MaxFetchDepth], Is.EqualTo("11"));
+ Assert.That(configure.Properties[Environment.QuerySubstitutions], Is.EqualTo("true 1, false 0, yes 'Y', no 'N'"));
+ Assert.That(configure.Properties[Environment.Hbm2ddlAuto], Is.EqualTo("validate"));
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/CfgTest/SchemaAutoActionFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CfgTest/SchemaAutoActionFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/CfgTest/SchemaAutoActionFixture.cs 2009-07-02 04:24:50 UTC (rev 4560)
@@ -0,0 +1,22 @@
+using NHibernate.Cfg;
+using NUnit.Framework;
+
+namespace NHibernate.Test.CfgTest
+{
+ [TestFixture]
+ public class SchemaAutoActionFixture
+ {
+ [Test]
+ public void Equality()
+ {
+ Assert.That(SchemaAutoAction.Recreate.Equals("create-drop"));
+ Assert.That(SchemaAutoAction.Recreate == "create-drop");
+ Assert.That(SchemaAutoAction.Create.Equals("create"));
+ Assert.That(SchemaAutoAction.Create == "create");
+ Assert.That(SchemaAutoAction.Update.Equals("update"));
+ Assert.That(SchemaAutoAction.Update == "update");
+ Assert.That(SchemaAutoAction.Validate.Equals("validate"));
+ Assert.That(SchemaAutoAction.Validate == "validate");
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-07-01 20:36:07 UTC (rev 4559)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-07-02 04:24:50 UTC (rev 4560)
@@ -108,8 +108,10 @@
<Compile Include="CfgTest\HbmOrderingFixture.cs" />
<Compile Include="CfgTest\LocatedInTestAssembly.cs" />
<Compile Include="CfgTest\Loquacious\ConfigurationFixture.cs" />
+ <Compile Include="CfgTest\Loquacious\LambdaConfigurationFixture.cs" />
<Compile Include="CfgTest\MappingDocumentAggregatorTests.cs" />
<Compile Include="CfgTest\MappingDocumentParserTests.cs" />
+ <Compile Include="CfgTest\SchemaAutoActionFixture.cs" />
<Compile Include="CfgTest\SettingsFactoryFixture.cs" />
<Compile Include="Classic\EntityWithLifecycle.cs" />
<Compile Include="Classic\LifecycleFixture.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|