protected override void Configure(Cfg.Configuration configuration) { if (Dialect is MsSql2000Dialect) { configuration.SetProperty( Cfg.Environment.SqlExceptionConverter, typeof(MSSQLExceptionConverterExample).AssemblyQualifiedName); } if (Dialect is Oracle8iDialect) { configuration.SetProperty( Cfg.Environment.SqlExceptionConverter, typeof(OracleClientExceptionConverterExample).AssemblyQualifiedName); } if (Dialect is PostgreSQLDialect) { configuration.SetProperty( Cfg.Environment.SqlExceptionConverter, typeof(PostgresExceptionConverterExample).AssemblyQualifiedName); } if (Dialect is FirebirdDialect) { configuration.SetProperty( Cfg.Environment.SqlExceptionConverter, typeof(FbExceptionConverterExample).AssemblyQualifiedName); } }
private static void setupSqlServer(Cfg.Configuration cfg) { var connStr = cfg.Properties[Cfg.Environment.ConnectionString].ReplaceCaseInsensitive("initial catalog=envers", "initial catalog=master"); using (var conn = new SqlConnection(connStr)) { conn.Open(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = "drop database envers"; try { cmd.ExecuteNonQuery(); } catch (Exception e) { Console.WriteLine(e); } cmd.CommandText = "create database envers"; cmd.ExecuteNonQuery(); } } }
protected override void AddMappings(Cfg.Configuration configuration) { var mapper = new ModelMapper(); mapper.Class <Employee>(mc => { mc.Id(x => x.Id, m => { m.Generator(Generators.Increment); m.Column("Id"); }); mc.OneToOne <EmployeeInfo>(x => x.Info, map => { map.Cascade(Mapping.ByCode.Cascade.All | Mapping.ByCode.Cascade.DeleteOrphans); map.Constrained(false); }); mc.Property(x => x.Name); }); mapper.Class <EmployeeInfo>(mc => { mc.Id(x => x.Id, map => { map.Generator(Generators.Assigned); map.Column("Id"); }); }); configuration.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities()); }
protected override void AddToConfiguration(Cfg.Configuration configuration) { if (ForceModifiedFlags) { configuration.SetEnversProperty(ConfigurationKey.GlobalWithModifiedFlag, true); } }
private static void SetupSqlAnywhere(Cfg.Configuration cfg) { var connStr = cfg.Properties[Cfg.Environment.ConnectionString]; var factory = DbProviderFactories.GetFactory("Sap.Data.SQLAnywhere"); var connBuilder = factory.CreateConnectionStringBuilder(); connBuilder.ConnectionString = connStr; var filename = (string)connBuilder["DBF"]; RunProcess("dbstop", $"-c \"UID=nhibernate;PWD=nhibernate;DBN=nhibernate\" -d", false); RunProcess("dberase", $"-y {filename}", false); // -dba: login,pwd RunProcess("dbinit", $"-dba nhibernate,nhibernate {filename}", true); using (var conn = factory.CreateConnection()) { conn.ConnectionString = connStr; conn.Open(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = "set option ansi_update_constraints = 'Off'"; cmd.ExecuteNonQuery(); } } }
public void SetupDatabase() { var cfg = new Cfg.Configuration(); var connStr = cfg.Properties["connection.connection_string"]; connStr = @"Server=.\SQLExpress;initial catalog=nhibernate;Integrated Security=SSPI"; using (var conn = new SqlConnection(connStr)) { conn.Open(); using (var cmd = new System.Data.SqlClient.SqlCommand("use master", conn)) { cmd.ExecuteNonQuery(); cmd.CommandText = "drop database nhibernate"; try { cmd.ExecuteNonQuery(); } catch (Exception) { } cmd.CommandText = "create database nhibernate"; cmd.ExecuteNonQuery(); } } }
public MetaDataStore(Cfg.Configuration nhConfiguration, IMetaDataProvider metaDataProvider, IEnumerable <IMetaDataAdder> metaDataAdders) { _nhConfiguration = nhConfiguration; EntityMetas = initializeMetas(metaDataProvider, metaDataAdders); }
public void WhenGetAuditConfMultipleTimesThenDoesNotThrowsForDupicatedMappings() { var cfg = new Cfg.Configuration(); cfg.Configure().OverrideSettingsFromEnvironmentVariables(); cfg.AddXml(SimpleMapping); AuditConfiguration.GetFor(cfg); //<< external call AuditConfiguration.SetConfigMetas(cfg, new AttributeConfiguration()); var listeners = new[] { new AuditEventListener() }; cfg.AppendListeners(ListenerType.PostInsert, listeners); cfg.AppendListeners(ListenerType.PostUpdate, listeners); cfg.AppendListeners(ListenerType.PostDelete, listeners); cfg.AppendListeners(ListenerType.PostCollectionRecreate, listeners); cfg.AppendListeners(ListenerType.PreCollectionRemove, listeners); cfg.AppendListeners(ListenerType.PreCollectionUpdate, listeners); Executing.This(() => { using (cfg.BuildSessionFactory()) { // build the session factory to run initialization of listeners and be completelly sure // there isn't problems } }).Should().NotThrow(); }
private static void SetupSqlServerOdbc(Cfg.Configuration cfg) { var connStr = cfg.Properties[Cfg.Environment.ConnectionString]; using (var conn = new OdbcConnection(connStr.Replace("Database=nhibernateOdbc", "Database=master"))) { conn.Open(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = "drop database nhibernateOdbc"; try { cmd.ExecuteNonQuery(); } catch (Exception e) { Console.WriteLine(e); } cmd.CommandText = "create database nhibernateOdbc"; cmd.ExecuteNonQuery(); } } }
protected override void AddToConfiguration(Cfg.Configuration configuration) { configuration.SetEnversProperty(ConfigurationKey.AuditTablePrefix, "VP_"); configuration.SetEnversProperty(ConfigurationKey.AuditTableSuffix, "_VS"); configuration.SetEnversProperty(ConfigurationKey.RevisionFieldName, "ver_rev"); configuration.SetEnversProperty(ConfigurationKey.RevisionTypeFieldName, "ver_rev_type"); }
public IDictionary <System.Type, IEntityMeta> CreateMetaData(Cfg.Configuration nhConfiguration) { var ret = new Dictionary <System.Type, IEntityMeta>(); var auditedTypes = new HashSet <System.Type>(); foreach (var attributeFactory in attributeFactories) { foreach (var memberInfoAndAttribute in attributeFactory.Attributes(nhConfiguration)) { var type = memberInfoAndAttribute.Type; var entMeta = createOrGetEntityMeta(ret, type); if (memberInfoAndAttribute.MemberInfo.MemberType == MemberTypes.TypeInfo) { addClassMetaAndLog(type, memberInfoAndAttribute.Attribute, entMeta); } else { addMemberMetaAndLog(type, memberInfoAndAttribute, entMeta); } if (memberInfoAndAttribute.Attribute.GetType() == typeof(AuditedAttribute)) { auditedTypes.Add(type); } } } addBaseTypesForAuditAttribute(ret, auditedTypes); throwIfUsingNonMappedRevisionEntity(nhConfiguration); return(ret); }
private static void SetupOracle(Cfg.Configuration cfg) { // disabled until system password is set on TeamCity //var connStr = // cfg.Properties[Cfg.Environment.ConnectionString] // .Replace("User ID=nhibernate", "User ID=SYSTEM") // .Replace("Password=nhibernate", "Password=password"); //cfg.DataBaseIntegration(db => // { // db.ConnectionString = connStr; // db.Dialect<NHibernate.Dialect.Oracle10gDialect>(); // db.KeywordsAutoImport = Hbm2DDLKeyWords.None; // }); //using (var sf = cfg.BuildSessionFactory()) //{ // try // { // using(var s = sf.OpenSession()) // s.CreateSQLQuery("drop user nhibernate cascade").ExecuteUpdate(); // } // catch {} // using (var s = sf.OpenSession()) // { // s.CreateSQLQuery("create user nhibernate identified by nhibernate").ExecuteUpdate(); // s.CreateSQLQuery("grant dba to nhibernate with admin option").ExecuteUpdate(); // } //} }
public void SetupDatabase() { var cfg = new Cfg.Configuration(); var connStr = cfg.Properties["connection.connection_string"]; using (var conn = new SqlConnection(connStr)) { conn.Open(); using (var cmd = new System.Data.SqlClient.SqlCommand("use master", conn)) { cmd.ExecuteNonQuery(); cmd.CommandText = "drop database nhibernate"; try { cmd.ExecuteNonQuery(); } catch(Exception) { } cmd.CommandText = "create database nhibernate"; cmd.ExecuteNonQuery(); } } }
protected override void AddMappings(Cfg.Configuration configuration) { var mapper = new ModelMapper(); mapper.Class <Employee>(mc => { mc.Id(x => x.Id, map => { map.Generator(Generators.Increment); map.Column("Id"); }); mc.ManyToOne <EmployeeInfo>(x => x.Info, map => { // Columns have to be declared first otherwise other properties are reset. map.Columns(x => { x.Name("COMP_ID"); }, x => { x.Name("PERS_ID"); }); map.Unique(true); map.Cascade(Mapping.ByCode.Cascade.All | Mapping.ByCode.Cascade.DeleteOrphans); map.NotFound(NotFoundMode.Exception); }); mc.Property(x => x.Name); }); mapper.Class <EmployeeInfo>(mc => { mc.ComponentAsId <EmployeeInfo.Identifier>(x => x.Id, map => { map.Property(x => x.CompanyId, m => m.Column("COMPS_ID")); map.Property(x => x.PersonId, m => m.Column("PERS_ID")); }); }); configuration.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities()); }
private static void SetupSQLite(Cfg.Configuration cfg) { if (File.Exists("NHibernate.db")) { File.Delete("NHibernate.db"); } }
private readonly Cfg.Configuration _configuration; //for serialization private AuditConfiguration(Cfg.Configuration cfg, IMetaDataProvider metaDataProvider) { //this might be over kill - move back into MetaDataStore later if not needed for other stuff... var metaDataAdders = new List <IMetaDataAdder> { new AuditMappedByMetaDataAdder(cfg) }; var mds = new MetaDataStore(cfg, metaDataProvider, metaDataAdders); var properties = cfg.Properties; GlobalCfg = new GlobalConfiguration(this, properties); var revInfoCfg = new RevisionInfoConfiguration(GlobalCfg, mds); var revInfoCfgResult = revInfoCfg.Configure(cfg); AuditEntCfg = new AuditEntitiesConfiguration(properties, revInfoCfgResult.RevisionInfoEntityName); AuditProcessManager = new AuditProcessManager(revInfoCfgResult.RevisionInfoGenerator); RevisionTimestampGetter = ReflectionTools.GetGetter(revInfoCfgResult.RevisionInfoClass, revInfoCfgResult.RevisionInfoTimestampData); RevisionInfoQueryCreator = revInfoCfgResult.RevisionInfoQueryCreator; RevisionInfoNumberReader = revInfoCfgResult.RevisionInfoNumberReader; ModifiedEntityNamesReader = revInfoCfgResult.ModifiedEntityNamesReader; EntCfg = new EntitiesConfigurator() .Configure(cfg, mds, GlobalCfg, AuditEntCfg, revInfoCfgResult.RevisionInfoXmlMapping, revInfoCfgResult.RevisionInfoRelationMapping); _configuration = cfg; }
protected override void Configure(Cfg.Configuration configuration) { configuration.SetProperty(Cfg.Environment.BatchSize, "10"); configuration.SetProperty(Cfg.Environment.SqlExceptionConverter, typeof(MSSQLExceptionConverterExample).AssemblyQualifiedName); }
protected override void AddMappings(Cfg.Configuration configuration) { // Set some properties that must be set before the mappings are added. // (The overridable Configure(cfg) is called AFTER AddMappings(cfg).) configuration.SetProperty(Cfg.Environment.PreferPooledValuesLo, _preferLo.ToString().ToLower()); base.AddMappings(configuration); }
private void throwIfUsingNonMappedRevisionEntity(Cfg.Configuration nhConfiguration) { foreach (var revAttr in attributeFactories.OfType <FluentRevision>() .Where(revAttr => nhConfiguration.GetClassMapping(revAttr.RevisionEntityType) == null)) { throw new MappingException("Custom revision entity " + revAttr.RevisionEntityType + " must be mapped!"); } }
protected override void Configure(Cfg.Configuration configuration) { configuration.DataBaseIntegration(x => { x.BatchSize = 0; x.Batcher <NonBatchingBatcherFactory>(); }); }
protected override void Configure(Cfg.Configuration configuration) { configuration.Cache(x => { x.Provider <HashtableCacheProvider>(); x.UseQueryCache = true; }); }
private Cfg.Configuration CreateConfig() { var cfg = new Cfg.Configuration(); cfg.Configure(); addMappings(cfg); return(cfg); }
private void Cleanup() { sessions.Close(); sessions = null; connectionProvider = null; lastOpenedSession = null; cfg = null; }
public void ShouldUseDefaultValue() { var nhConfiguration = new Cfg.Configuration(); nhConfiguration.IntegrateWithEnvers(); AuditConfiguration.GetFor(nhConfiguration).GlobalCfg.StoreDataAtDelete .Should().Be.False(); }
///<summary> /// Create a NHibernate Configuration ///</summary> ///<returns></returns> private Cfg.Configuration CreateNHConfiguration() { Cfg.Configuration retVal = new Cfg.Configuration(); if(!string.IsNullOrEmpty(configuration.NHConfigFile)) { string configFile = configuration.NHConfigFile.Replace("~", AppDomain.CurrentDomain.BaseDirectory); retVal.Configure(configFile); } return retVal; }
private void addMappings(Cfg.Configuration cfg) { var ass = Assembly.Load(TestAssembly); foreach (var mapping in Mappings) { cfg.AddResource(TestAssembly + "." + mapping, ass); } }
public void ShouldThrowCorrectException() { var cfg = new Cfg.Configuration(); cfg.Configure(); cfg.AddResource("NHibernate.Envers.Tests.NetSpecific.UnitTests.Ids.Mapping.hbm.xml", GetType().Assembly); Assert.Throws <AuditException>(() => cfg.IntegrateWithEnvers()); }
public void ShouldThrow() { var cfg = new Cfg.Configuration(); var fluent = new FluentConfiguration(); fluent.SetRevisionEntity <RevisionEntity>(rev => rev.Number, rev => rev.Timestamp); cfg.Executing(x => x.IntegrateWithEnvers(new AuditEventListener(), fluent)) .Throws <FluentException>(); }
public void CanBeSetByConfigurationKeyMethod() { var nhConfiguration = new Cfg.Configuration(); ConfigurationKey.StoreDataAtDelete.SetUserValue(nhConfiguration, true); nhConfiguration.IntegrateWithEnvers(); AuditConfiguration.GetFor(nhConfiguration).GlobalCfg.StoreDataAtDelete .Should().Be.True(); }
public void CanBeSetByConfigurationKey() { var nhConfiguration = new Cfg.Configuration(); nhConfiguration.SetEnversProperty(ConfigurationKey.StoreDataAtDelete, true); nhConfiguration.IntegrateWithEnvers(); AuditConfiguration.GetFor(nhConfiguration).GlobalCfg.StoreDataAtDelete .Should().Be.True(); }
public void CanBeSetNhCoreWay() { var nhConfiguration = new Cfg.Configuration(); nhConfiguration.SetProperty("nhibernate.envers.store_data_at_delete", "true"); nhConfiguration.IntegrateWithEnvers(); AuditConfiguration.GetFor(nhConfiguration).GlobalCfg.StoreDataAtDelete .Should().Be.True(); }
public void SetupDatabase() { var cfg = new Cfg.Configuration(); var driver = cfg.Properties[Cfg.Environment.ConnectionDriver]; Assert.That(SetupMethods.ContainsKey(driver), "No setup method found for " + driver); var setupMethod = SetupMethods[driver]; setupMethod(cfg); }
public void WhenCallIntegrationThenMappingsShouldBeAvailableImmediately() { var cfg = new Cfg.Configuration(); cfg.Configure(); cfg.AddXml(SimpleMapping); cfg.IntegrateWithEnvers(); cfg.ClassMappings.Where(cm => cm.EntityName.Contains("SimpleAuiditableForConfEntity")).Should().Have.Count.EqualTo(2); }
internal PersistenceUnit(IPersistenceUnitCfg cfg, IConfigurator configurator) { configuration = cfg; nHConfiguration = CreateNHConfiguration(); if(configurator != null) configurator.Config(cfg, nHConfiguration); if (cfg.AutoUpdateSchema) new SchemaUtil().UpdateSchema(false, true, nHConfiguration); ReBuildSessionfactory(); //Temporarily removed auditLog before we decided whether it should stay in Burrow //if (Configuration.EnableAuditLog) // interceptorFactory = AuditLogInterceptorFactory.Instance; }
private void Configure() { cfg = new Cfg.Configuration(); Assembly assembly = Assembly.Load(MappingsAssembly); Configure(cfg); foreach (string file in Mappings) { cfg.AddResource(MappingsAssembly + "." + file, assembly); } }