/// <summary>
        /// Builds the configuration properties.
        /// </summary>
        /// <param name="config"></param>
        /// <param name="node"> </param>
        /// <returns></returns>
        protected void BuildProperties(SessionFactoryConfig config, XmlNode node)
        {
            foreach (XmlNode addNode in node.SelectNodes("add"))
            {
                var keyAtt   = addNode.Attributes["key"];
                var valueAtt = addNode.Attributes["value"];

                if (keyAtt == null || valueAtt == null)
                {
                    var message = String.Format("For each 'add' element you must specify 'key' and 'value' attributes");

                    throw new ConfigurationErrorsException(message);
                }
                var name  = keyAtt.Value;
                var value = valueAtt.Value;

                if (name.Equals("assembly"))
                {
                    config.Assemblies.Add(Assembly.Load(value));
                }
                else
                {
                    config.Properties[name] = value;
                }
            }
        }
 public static SessionFactoryConfig AddAssemblies(this SessionFactoryConfig config, IEnumerable <Assembly> assemblies)
 {
     foreach (var asm in assemblies)
     {
         config.Assemblies.Add(asm);
     }
     return(config);
 }
 public static SessionFactoryConfig Set(this SessionFactoryConfig config, IDictionary <string, string> properties)
 {
     foreach (var property in properties)
     {
         config.Set(property.Key, property.Value);
     }
     return(config);
 }
        /// <summary>
        /// Sets the default configuration for database specifiend by <paramref name="name"/>.
        /// </summary>
        /// <param name="config"></param>
        /// <param name="name">Name of the database type.</param>
        /// <param name="connectionStringName">name of the connection string specified in connectionStrings configuration section</param>
        /// <returns></returns>
        protected void SetDefaults(SessionFactoryConfig config, string name, string connectionStringName)
        {
            var names = Enum.GetNames(typeof(DatabaseType));

            if (!Array.Exists(names, n => n.Equals(name, StringComparison.OrdinalIgnoreCase)))
            {
                var builder = new StringBuilder();
                builder.AppendFormat("Specified value ({0}) is not valid for 'database' attribute. Valid values are:", name);
                foreach (var value in Enum.GetValues(typeof(DatabaseType)))
                {
                    builder.AppendFormat(" '{0}'", value.ToString());
                }

                builder.Append(".");
                throw new ConfigurationErrorsException(builder.ToString());
            }

            var type = (DatabaseType)Enum.Parse(typeof(DatabaseType), name, true);

            config.Set(NHibernate.Cfg.Environment.ConnectionStringName, connectionStringName)
            .SetDatabaseType(type);
        }
예제 #5
0
파일: AR.cs 프로젝트: shosca/ActiveRecord
 internal static void RaiseOnHbmMappingCreated(HbmMapping mapping, SessionFactoryConfig sessionFactoryConfig)
 {
     if (OnHbmMappingCreated != null)
         OnHbmMappingCreated(mapping, sessionFactoryConfig);
 }
        /// <summary>
        /// Sets the default configuration for database specifiend by <paramref name="name"/>.
        /// </summary>
        /// <param name="config"></param>
        /// <param name="name">Name of the database type.</param>
        /// <param name="connectionStringName">name of the connection string specified in connectionStrings configuration section</param>
        /// <returns></returns>
        protected void SetDefaults(SessionFactoryConfig config, string name, string connectionStringName)
        {
            var names = Enum.GetNames(typeof(DatabaseType));
            if (!Array.Exists(names, n => n.Equals(name, StringComparison.OrdinalIgnoreCase)))
            {
                var builder = new StringBuilder();
                builder.AppendFormat("Specified value ({0}) is not valid for 'database' attribute. Valid values are:", name);
                foreach (var value in Enum.GetValues(typeof(DatabaseType)))
                {
                    builder.AppendFormat(" '{0}'", value.ToString());
                }

                builder.Append(".");
                throw new ConfigurationErrorsException(builder.ToString());
            }

            var type = (DatabaseType)Enum.Parse(typeof(DatabaseType), name, true);
            config.Set(NHibernate.Cfg.Environment.ConnectionStringName, connectionStringName)
                .SetDatabaseType(type);
        }
예제 #7
0
 protected void RegisterConfiguration(SessionFactoryConfig config)
 {
     var cfg = config.BuildConfiguration();
     RegisterConfiguration(cfg, config.Name);
 }
        public static SessionFactoryConfig SetDatabaseType(this SessionFactoryConfig config, DatabaseType type)
        {
            switch (type)
            {
            case DatabaseType.MsSqlServer2000:
                config
                .ConnectionDriver <SqlClientDriver>()
                .Dialect <MsSql2000Dialect>();
                break;

            case DatabaseType.MsSqlServer2005:
                config
                .ConnectionDriver <SqlClientDriver>()
                .Dialect <MsSql2005Dialect>();
                break;

            case DatabaseType.MsSqlServer2008:
                config
                .ConnectionDriver <SqlClientDriver>()
                .Dialect <MsSql2008Dialect>();
                break;

            case DatabaseType.MsSqlServer2012:
                config
                .ConnectionDriver <SqlClientDriver>()
                .Dialect <MsSql2012Dialect>();
                break;

            case DatabaseType.SQLite:
                config
                .ConnectionDriver <SQLite20Driver>()
                .Dialect <SQLiteDialect>()
                .QuerySubstitutions("true=1;false=0");                                 // based on https://www.hibernate.org/361.html#A9
                break;

            case DatabaseType.MySql:
                config
                .ConnectionDriver <MySqlDataDriver>()
                .Dialect <MySQLDialect>();
                break;

            case DatabaseType.MySql5:
                config
                .ConnectionDriver <MySqlDataDriver>()
                .Dialect <MySQL5Dialect>();
                break;

            case DatabaseType.Firebird:
                config
                .ConnectionDriver <FirebirdDriver>()
                .Dialect <FirebirdDialect>()
                // based on https://www.hibernate.org/361.html#A5
                .QuerySubstitutions("true 1, false 0, yes 1, no 0")
                .Isolation(IsolationLevel.ReadCommitted)
                .CommandTimeout(444)
                .Set("use_outer_join", true.ToString(CultureInfo.InvariantCulture));
                break;

            case DatabaseType.PostgreSQL:
                config
                .ConnectionDriver <NpgsqlDriver>()
                .Dialect <PostgreSQLDialect>();
                break;

            case DatabaseType.PostgreSQL81:
                config
                .ConnectionDriver <NpgsqlDriver>()
                .Dialect <PostgreSQL81Dialect>();
                break;

            case DatabaseType.PostgreSQL82:
                config
                .ConnectionDriver <NpgsqlDriver>()
                .Dialect <PostgreSQL82Dialect>();
                break;

            case DatabaseType.MsSqlCe:
                config
                .ConnectionDriver <SqlServerCeDriver>()
                .Dialect <MsSqlCeDialect>()
                // to workaround exception being thrown with default setting
                // when an implicit transaction is used with identity id
                // see: AR-ISSUE-273 for details
                .Set(Environment.ReleaseConnections, "on_close");
                break;

            // using oracle's own data driver since Microsoft
            // discontinued theirs, and that's what everyone
            // seems to be using anyway.
            case DatabaseType.Oracle8i:
                config
                .ConnectionDriver <OracleDataClientDriver>()
                .Dialect <Oracle8iDialect>();
                break;

            case DatabaseType.Oracle9i:
                config
                .ConnectionDriver <OracleDataClientDriver>()
                .Dialect <Oracle9iDialect>();
                break;

            case DatabaseType.Oracle10g:
                config
                .ConnectionDriver <OracleDataClientDriver>()
                .Dialect <Oracle10gDialect>();
                break;
            }
            return(config);
        }
 public static SessionFactoryConfig Dialect <T>(this SessionFactoryConfig config) where T : Dialect
 {
     return(config.Set(Environment.Dialect, LongName <T>()));
 }
예제 #10
0
 public static SessionFactoryConfig ConnectionString(this SessionFactoryConfig config, string connectionstring)
 {
     return(config.Set(Environment.ConnectionString, connectionstring));
 }
예제 #11
0
 public static SessionFactoryConfig MaxFetchDepth(this SessionFactoryConfig config, int depth)
 {
     return(config.Set(Environment.MaxFetchDepth, Math.Min(3, depth).ToString(CultureInfo.InvariantCulture)));
 }
예제 #12
0
 public static SessionFactoryConfig QuerySubstitutions(this SessionFactoryConfig config, string substitutions)
 {
     return(config.Set(Environment.QuerySubstitutions, substitutions));
 }
예제 #13
0
 public static SessionFactoryConfig AddAssembly(this SessionFactoryConfig config, Assembly assembly)
 {
     config.Assemblies.Add(assembly);
     return(config);
 }
예제 #14
0
 public static SessionFactoryConfig Set(this SessionFactoryConfig config, string key, string value)
 {
     config.Properties[key] = value;
     return(config);
 }
예제 #15
0
파일: AR.cs 프로젝트: shosca/ActiveRecord
 internal static void RaiseOnMapperCreated(ConventionModelMapper mapper, SessionFactoryConfig sessionFactoryConfig)
 {
     if (OnMapperCreated != null)
         OnMapperCreated(mapper, sessionFactoryConfig);
 }
예제 #16
0
 public static SessionFactoryConfig UseSecondLevelCache(this SessionFactoryConfig config, bool cache)
 {
     return(config.Set(Environment.UseSecondLevelCache, cache.ToString(CultureInfo.InvariantCulture)));
 }
예제 #17
0
 public static SessionFactoryConfig UseQueryCache(this SessionFactoryConfig config, bool usequerycache)
 {
     return(config.Set(Environment.UseQueryCache, usequerycache.ToString(CultureInfo.InvariantCulture)));
 }
예제 #18
0
 public static SessionFactoryConfig ProxyFactoryFactoryClass <T>(this SessionFactoryConfig config) where T : IProxyFactoryFactory
 {
     return(config.Set(Environment.ProxyFactoryFactoryClass, LongName <T>()));
 }
예제 #19
0
 public static SessionFactoryConfig CommandTimeout(this SessionFactoryConfig config, int timeout)
 {
     return(config.Set(Environment.CommandTimeout, timeout.ToString(CultureInfo.InvariantCulture)));
 }
예제 #20
0
 public static SessionFactoryConfig BatchSize(this SessionFactoryConfig config, int batchsize)
 {
     return(config.Set(Environment.BatchSize, batchsize.ToString(CultureInfo.InvariantCulture)));
 }
예제 #21
0
 public static SessionFactoryConfig ConnectionDriver <T>(this SessionFactoryConfig config) where T : IDriver
 {
     return(config.Set(Environment.ConnectionDriver, LongName <T>()));
 }
예제 #22
0
 public static SessionFactoryConfig Isolation(this SessionFactoryConfig config, IsolationLevel isolation)
 {
     return(config.Set(Environment.Isolation, isolation.ToString()));
 }
예제 #23
0
 public static SessionFactoryConfig AddContributor(this SessionFactoryConfig config, INHContributor contributor)
 {
     config.Contributors.Add(contributor);
     return(config);
 }
예제 #24
0
 public static SessionFactoryConfig ShowSql(this SessionFactoryConfig config, bool showsql)
 {
     return(config.Set(Environment.ShowSql, showsql.ToString(CultureInfo.InvariantCulture)));
 }
예제 #25
0
 public static SessionFactoryConfig CacheDefaultExpiration(this SessionFactoryConfig config, int expiration)
 {
     return(config.Set(Environment.CacheDefaultExpiration, expiration.ToString(CultureInfo.InvariantCulture)));
 }
예제 #26
0
 public static SessionFactoryConfig CacheProvider <T>(this SessionFactoryConfig config) where T : ICacheProvider
 {
     return(config.Set(Environment.CacheProvider, LongName <T>()));
 }
        /// <summary>
        /// Adds the specified type with configuration
        /// </summary>
        /// <param name="config">The config.</param>
        public void Add(SessionFactoryConfig config)
        {
            var key = string.IsNullOrEmpty(config.Name) ? string.Empty : config.Name;

            _configs.Add(key, config);
        }
예제 #28
0
 public static SessionFactoryConfig CacheRegion(this SessionFactoryConfig config, string region)
 {
     return(config.Set(Environment.CacheRegionPrefix, region));
 }
        /// <summary>
        /// Builds the configuration properties.
        /// </summary>
        /// <param name="config"></param>
        /// <param name="node"> </param>
        /// <returns></returns>
        protected void BuildProperties(SessionFactoryConfig config, XmlNode node)
        {
            foreach(XmlNode addNode in node.SelectNodes("add"))
            {
                var keyAtt = addNode.Attributes["key"];
                var valueAtt = addNode.Attributes["value"];

                if (keyAtt == null || valueAtt == null)
                {
                    var message = String.Format("For each 'add' element you must specify 'key' and 'value' attributes");

                    throw new ConfigurationErrorsException(message);
                }
                var name = keyAtt.Value;
                var value = valueAtt.Value;

                if (name.Equals("assembly")) {
                    config.Assemblies.Add(Assembly.Load(value));
                } else {
                    config.Properties[name] = value;
                }
            }
        }
예제 #30
0
파일: AR.cs 프로젝트: shosca/ActiveRecord
 internal static void RaiseOnConfigurationCreated(Configuration cfg, SessionFactoryConfig sessionFactoryConfig)
 {
     if (OnConfigurationCreated != null)
         OnConfigurationCreated(cfg, sessionFactoryConfig);
 }