コード例 #1
0
        protected void Application_Start()
        {
            new Configurator().StartServer<Configurator>();

            var cfg = Simply.Do.GetNHibernateConfig();

            var check = new SchemaValidator(cfg);

            try
            {
                check.Validate();
            }
            catch
            {
                var exp = new SchemaExport(Simply.Do.GetNHibernateConfig());
                exp.Drop(true, true);
                exp.Create(true, true);

                using (Simply.Do.EnterContext())
                {
                    UserSample.Init();
                    GroupSample.Init();
                }
            }

            RegisterRoutes(RouteTable.Routes);
        }
コード例 #2
0
 public static void ValidateSchema(string ConnString)
 {
     FNHMVC.Data.Infrastructure.ConnectionHelper.GetConfiguration(ConnString).ExposeConfiguration(cfg =>
     {
         var schemaValidate = new NHibernate.Tool.hbm2ddl.SchemaValidator(cfg);
         schemaValidate.Validate();
     }).BuildConfiguration();
 }
コード例 #3
0
ファイル: SchemaTool.cs プロジェクト: kostyrin/FNHMVC
 public static void ValidateSchema(string ConnString)
 {
     FNHMVC.Data.Infrastructure.ConnectionHelper.GetConfiguration(ConnString).ExposeConfiguration(cfg =>
     {
         var schemaValidate = new NHibernate.Tool.hbm2ddl.SchemaValidator(cfg);
         schemaValidate.Validate();
     }).BuildConfiguration();
 }
コード例 #4
0
ファイル: NHibernateHelper.cs プロジェクト: hansuky/HubCrawl
 private Boolean Validation(Configuration config)
 {
     try
     {
         SchemaValidator schemeValidator = new SchemaValidator(config);
         schemeValidator.Validate();
         return true;
     }
     catch { return false; }
 }
コード例 #5
0
		public void ShouldVerifySameTable()
		{
			string resource1 = "NHibernate.Test.Tools.hbm2ddl.SchemaValidator.1_Version.hbm.xml";
			Configuration v1cfg = TestConfigurationHelper.GetDefaultConfiguration();
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource1))
			new NHibernate.Tool.hbm2ddl.SchemaExport(v1cfg).Execute(true,true,false);

			var v1schemaValidator = new NHibernate.Tool.hbm2ddl.SchemaValidator((v1cfg));
			v1schemaValidator.Validate();

		}
コード例 #6
0
        public void ShouldVerifySameTable()
        {
            string        resource1 = "NHibernate.Test.Tools.hbm2ddl.SchemaValidator.1_Version.hbm.xml";
            Configuration v1cfg     = TestConfigurationHelper.GetDefaultConfiguration();

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource1))
                new NHibernate.Tool.hbm2ddl.SchemaExport(v1cfg).Execute(true, true, false);

            var v1schemaValidator = new NHibernate.Tool.hbm2ddl.SchemaValidator((v1cfg));

            v1schemaValidator.Validate();
        }
コード例 #7
0
 public static void ValidateSchema(NHibernate.Cfg.Configuration config)
 {
     var validator = new SchemaValidator(config);
     try
     {
         validator.Validate();
     }
     catch (HibernateException)
     {
         var update = new SchemaUpdate(config);
         update.Execute(false, true);
     }
 }
コード例 #8
0
		public void SchemaExport_Validate_CausesValidateException()
		{
			Configuration configuration = GetConfiguration();
			SchemaValidator validator = new SchemaValidator(configuration);
			try
			{
				validator.Validate();
			}
			catch (HibernateException he)
			{
				Assert.IsTrue(he.Message.Contains("Home_Validate"));
				return;
			}
			throw new Exception("Should not get to this exception");
		}
コード例 #9
0
        public bool IsSchemaValid(Configuration config)
        {
            if (config == null) throw new ArgumentNullException("config");

            var validator = new SchemaValidator(config);
            try
            {
                validator.Validate();
                return true;
            }
            catch (HibernateException)
            {
                // not valid, needs to updating
                return false;
            }
        }
コード例 #10
0
		public void ShouldNotVerifyModifiedTable()
		{
			string resource1 = "NHibernate.Test.Tools.hbm2ddl.SchemaValidator.1_Version.hbm.xml";
			string resource2 = "NHibernate.Test.Tools.hbm2ddl.SchemaValidator.2_Version.hbm.xml";
			Configuration v1cfg = TestConfigurationHelper.GetDefaultConfiguration();
			Configuration v2cfg = TestConfigurationHelper.GetDefaultConfiguration();
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource1))
				v1cfg.AddInputStream(stream);
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource2))
				v2cfg.AddInputStream(stream);
			new NHibernate.Tool.hbm2ddl.SchemaExport(v1cfg).Execute(true, true, false);
			var v2schemaValidator = new NHibernate.Tool.hbm2ddl.SchemaValidator((v2cfg));
			try
			{
				v2schemaValidator.Validate();				
			}
			catch (HibernateException e)
			{
				Assert.That(e.Message, Text.StartsWith("Missing column: Name"));
			}
		}
コード例 #11
0
ファイル: EntityTest.cs プロジェクト: JZO001/Forge
        public static void MyClassInitialize(TestContext testContext)
        {
            // define mapping schema
            HbmSerializer.Default.HbmAssembly = typeof(Product).Assembly.GetName().FullName;
            //HbmSerializer.Default.HbmNamespace = typeof( Product ).Namespace;
            HbmSerializer.Default.HbmAutoImport = true;
            HbmSerializer.Default.Validate = true;
            HbmSerializer.Default.WriteDateComment = false;
            HbmSerializer.Default.HbmDefaultAccess = "field";
            //HbmSerializer.Default.Serialize(typeof(Product).Assembly, "output.hbm.xml"); // serialize mapping xml into file to spectate it

            // create configuration and load assembly
            NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
            //cfg.Properties[NHibernate.Cfg.Environment.CollectionTypeFactoryClass] = typeof(Net4CollectionTypeFactory).AssemblyQualifiedName;
            cfg.Configure();
            //cfg.AddAssembly( typeof( Product ).Assembly ); // use this only, if hbm.xml exists in the assembly
            cfg.AddInputStream(HbmSerializer.Default.Serialize(typeof(Product).Assembly)); // ez bármikor müxik, de lassabb

            try
            {
                SchemaValidator schemaValidator = new SchemaValidator(cfg);
                schemaValidator.Validate(); // validate the database schema
            }
            catch (Exception)
            {
                SchemaUpdate schemaUpdater = new SchemaUpdate(cfg); // try to update schema
                schemaUpdater.Execute(false, true);
                if (schemaUpdater.Exceptions.Count > 0)
                {
                    throw new Exception("FAILED TO UPDATE SCHEMA");
                }
            }

            //SchemaExport export = new SchemaExport(cfg);
            //export.Execute( false, true, false );
            //new SchemaExport( cfg ).Execute( false, true, false );
            mSessionFactory = cfg.BuildSessionFactory();
        }
コード例 #12
0
        public void ShouldNotVerifyModifiedTable()
        {
            string        resource1 = "NHibernate.Test.Tools.hbm2ddl.SchemaValidator.1_Version.hbm.xml";
            string        resource2 = "NHibernate.Test.Tools.hbm2ddl.SchemaValidator.2_Version.hbm.xml";
            Configuration v1cfg     = TestConfigurationHelper.GetDefaultConfiguration();
            Configuration v2cfg     = TestConfigurationHelper.GetDefaultConfiguration();

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource1))
                v1cfg.AddInputStream(stream);
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource2))
                v2cfg.AddInputStream(stream);
            new NHibernate.Tool.hbm2ddl.SchemaExport(v1cfg).Execute(true, true, false);
            var v2schemaValidator = new NHibernate.Tool.hbm2ddl.SchemaValidator((v2cfg));

            try
            {
                v2schemaValidator.Validate();
            }
            catch (HibernateException e)
            {
                Assert.That(e.Message, Is.StringStarting("Missing column: Name"));
            }
        }
コード例 #13
0
        public bool ValidateSchema(global::NHibernate.Cfg.Configuration configuration)
        {
            using (new WriteLockDisposable(SchemaValidationLocker))
            {
                var myvalidator = new SchemaValidator(configuration);
                try
                {
                    myvalidator.Validate();
                    return true;
                }
                catch (HibernateException ex)
                {
                    /* SchemaValidator.Validate() returns void - FFS */
                    LogHelper.Error<ProviderBootstrapper>("While running SchemaValidator: " + ex.Message, ex);

                    // New in 5.2 (limited support for schema upgrades - pending full migration support)
                    // Use our own validator to actually get back metadata about the missing tables rather than
                    // just an exception of the first failure
                    // Then if it's something we're OK to try to handle, try to handle it...
                    if (_localConfig.AutoUpdateDbSchema)
                    {
                        var customValidator = new SchemaChangeValidator(configuration);
                        var result = customValidator.Validate();
                        if (!result.IsValid)
                        {
                            // 5.2: Just check for whether AggregateNodeStatus is the only missing one
                            if (result.MissingTables.Any())
                            {
                                var missingTables = string.Join(", ", result.MissingTables.Select(x => x.Name));
                                LogHelper.Warn<ProviderBootstrapper>("The following tables are missing from the database: {0}", missingTables);

                                var agg = result.MissingTables.FirstOrDefault(x => x.Name == typeof(AggregateNodeStatus).Name);
                                if (agg != null && result.MissingTables.Count == 1)
                                {
                                    // It's the only missing table, so we've already done one install
                                    LogHelper.Warn<ProviderBootstrapper>("Automatically attempting to update the database schema to add the following missing tables: {0}. You can prevent this behaviour by setting '{1}' to false in the configuration for this provider", missingTables, ProviderConfigurationSection.XAutoUpdateSchema);
                                    try
                                    {
                                        UpdateSchema(configuration);
                                        // Everything went OK, so can return true since we're now "valid"
                                        return true;
                                    }
                                    catch (Exception updateEx)
                                    {
                                        LogHelper.Error<ProviderBootstrapper>("Auto-update of db schema failed. Does the db user have the correct permissions? If you need to manually run the update script, the script should be in the logfile preceding this entry", updateEx);
                                    }
                                }
                            }
                        }
                    }
                    return false;
                }
            }
        }
コード例 #14
0
ファイル: Global.asax.cs プロジェクト: 1andy/plcdev
        private static void SetupDatabase(Configuration configuration)
        {
            try
            {
                var validator = new SchemaValidator(configuration);
                validator.Validate();
            }
            catch (HibernateException)
            {
                var update = new SchemaUpdate(configuration);
                update.Execute(true, true);

                if (update.Exceptions.Count != 0)
                {
                    throw new HibernateException("The following errors occurred when trying to setup database:\n"
                        + string.Join(Environment.NewLine, update.Exceptions.Select(e => e.Message)));
                }
            }
        }
コード例 #15
0
        private static bool ValidateSchema()
        {
            NHibernate.Tool.hbm2ddl.SchemaValidator myvalidator = new NHibernate.Tool.hbm2ddl.SchemaValidator(_nhConfig);

            try
            {
                myvalidator.Validate();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                myvalidator = null;
            }
        }
コード例 #16
0
ファイル: DatabaseFixture.cs プロジェクト: juanplopes/simple
 public void SchemaIsCorrectlyMapped()
 {
     var validator = new SchemaValidator(Simply.Do.GetNHibernateConfig());
     validator.Validate();
 }
コード例 #17
0
        private static void CreateOrUpdateSchema(Configuration config)
        {
            string value = string.Empty;
            using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["__NAME__Data"].ConnectionString))
            {
                con.Open();
                var cmd = con.CreateCommand();

             cmd.CommandType = CommandType.Text;
              cmd.CommandText = @"IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE') " +
                                 "select 'True'; " +
                                 "ELSE " +
                                  "select 'False' ";

                var reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    value = reader.GetString(0);
                }
            }

            // replace this with your test for existence of schema
            // (i.e., with SQLite, you can just test for the DB file)
            if (value.IsEmpty() || value == "False")
            {
                try
                {
                    var export = new SchemaExport(config);
                    export.Execute(true, true, false);
                }
                catch (HibernateException e)
                {
                    // create was not successful
                    // you problably want to break out your application here
                    Console.WriteLine(
                        String.Format("Problem while creating database: {0}", e),
                        "Problem");
                }
            }
            else
            {

                // already something: validate
                SchemaValidator validator = new SchemaValidator(config);
                try
                {
                    validator.Validate();
                }
                catch (HibernateException)
                {
                    // not valid, try to update
                    try
                    {
                        SchemaUpdate update = new SchemaUpdate(config);
                        update.Execute(true, true);

                        //var export = new SchemaExport(config);
                        //export.SetOutputFile("d:\\code\\coachesaid3\\schemaauto.txt");
                        //export.Execute(true, true, false);
                    }
                    catch (HibernateException e)
                    {
                        // update was not successful
                        // you problably want to break out your application here
                        Console.WriteLine(
                            String.Format("Problem while updating database: {0}", e),
                            "Problem");
                    }
                }
            }
        }
コード例 #18
0
 public void ValidateSchema()
 {
     var validator = new SchemaValidator(currentConfiguration);
     validator.Validate();
 }
コード例 #19
0
 public static bool ValidateSchema(global::NHibernate.Cfg.Configuration configuration)
 {
     using (new WriteLockDisposable(SchemaValidationLocker))
     {
         var myvalidator = new SchemaValidator(configuration);
         try
         {
             myvalidator.Validate();
             return true;
         }
         catch (HibernateException ex)
         {
             /* SchemaValidator.Validate() returns void - FFS */
             return false;
         }
     }
 }
コード例 #20
0
 /// <summary>
 /// validates that the DB schema and the schema in code are the same
 /// </summary>
 private void ValidateSchema()
 {
     var schemaValidator = new SchemaValidator(this.DBConfiguration);
     schemaValidator.Validate();
 }