Exemple #1
1
		public static void main(String[] args)
		{
			try
			{
				Configuration cfg = new Configuration();

				bool script = true;
				// If true then execute db updates, otherwise just generate and display updates
				bool doUpdate = true;
				//String propFile = null;

				for (int i = 0; i < args.Length; i++)
				{
					if (args[i].StartsWith("--"))
					{
						if (args[i].Equals("--quiet"))
						{
							script = false;
						}
						else if (args[i].StartsWith("--properties="))
						{
							throw new NotSupportedException("No properties file for .NET, use app.config instead");
							//propFile = args[i].Substring( 13 );
						}
						else if (args[i].StartsWith("--config="))
						{
							cfg.Configure(args[i].Substring(9));
						}
						else if (args[i].StartsWith("--text"))
						{
							doUpdate = false;
						}
						else if (args[i].StartsWith("--naming="))
						{
							cfg.SetNamingStrategy(
								(INamingStrategy) Activator.CreateInstance(ReflectHelper.ClassForName(args[i].Substring(9)))
								);
						}
					}
					else
					{
						cfg.AddFile(args[i]);
					}
				}

				/* NH: No props file for .NET
				 * if ( propFile != null ) {
					Hashtable props = new Hashtable();
					props.putAll( cfg.Properties );
					props.load( new FileInputStream( propFile ) );
					cfg.SetProperties( props );
				}*/

				new SchemaUpdate(cfg).Execute(script, doUpdate);
			}
			catch (Exception e)
			{
				log.Error("Error running schema update", e);
				Console.WriteLine(e);
			}
		}
 public static ISession OpenSession()
 {
     var configuration = new Configuration();
     var configurationPath = HttpContext.Current.Server.MapPath(@"~\Models\hibernate.cfg.xml");
     configuration.Configure(configurationPath);
     configuration.AddFile(HttpContext.Current.Server.MapPath(@"~\Models\Comment.hbm.xml"));
     configuration.AddFile(HttpContext.Current.Server.MapPath(@"~\Models\UserProfile.hbm.xml"));
     ISessionFactory sessionFactory = configuration.BuildSessionFactory();
     return sessionFactory.OpenSession();
 }
Exemple #3
0
        public static ISession MakeSession()
        {
            var configuration = new Configuration();

            configuration.Configure(@"C:\GitRepository\PersonCRUD\PersonCRUD.Domain\Nhibernate\Configuration\hibernate.cfg.xml");
            configuration.AddFile(@"C:\GitRepository\PersonCRUD\PersonCRUD.Domain\Nhibernate\Mapping\Person.hbm.xml");
            configuration.AddFile(@"C:\GitRepository\PersonCRUD\PersonCRUD.Domain\Nhibernate\Mapping\Phone.hbm.xml");

            ISessionFactory sessionFactory = configuration.BuildSessionFactory();
            return sessionFactory.OpenSession();
        }
        public static void InitalizeSessionFactory(params FileInfo[] hbmFiles)
        {
            if (SessionFactory != null)
                return;

            var properties = new Dictionary<string, string>
                                 {
                                     {"connection.driver_class", "NHibernate.Driver.SQLite20Driver"},
                                     {"dialect", "NHibernate.Dialect.SQLiteDialect"},
                                     {"connection.provider", "NHibernate.Connection.DriverConnectionProvider"},
                                     {"connection.connection_string", "Data Source=askme.db;Version=3;New=True;"},
                                     {"connection.release_mode", "on_close"},
                                     {"show_sql", "true"},
                                     {"proxyfactory.factory_class", "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle"}
                                 };

            Config = new Configuration {Properties = properties};

            foreach (FileInfo mappingFile in hbmFiles)
            {
                Config = Config.AddFile(mappingFile);
            }
            Config.BuildMapping();
            SessionFactory = Config.BuildSessionFactory();
        }
 public static ISession OpenSession()
 {
     var configuration = new Configuration();
     var configurationPath = HttpContext.Current.Server.MapPath(@"~\Models\Nhibernate\hibernate.cfg.xml");
     configuration.Configure(configurationPath);
     var employeeConfigurationFile = HttpContext.Current.Server.MapPath(@"~\Models\Nhibernate\Employee.hbm.xml");
     configuration.AddFile(employeeConfigurationFile);
     ISessionFactory sessionFactory = configuration.BuildSessionFactory();
     return sessionFactory.OpenSession();
 }
    static void AddMappingsFromFilesystem(Configuration nhConfiguration)
    {
        var folder = Directory.GetCurrentDirectory();
        var hmbFiles = Directory.GetFiles(folder, "*.hbm.xml", SearchOption.TopDirectoryOnly);

        foreach (var file in hmbFiles)
        {
            nhConfiguration.AddFile(file);
        }
    }
        public static ISession OpenSession()
        {
            var nHConfig = new Configuration();
            var configurationPath= HttpContext.Current.Server.MapPath(@"~\Models\NHibernate\hibernate.cfg.xml");
            nHConfig.Configure(configurationPath);

            var employeeConfig = HttpContext.Current.Server.MapPath(@"~\Models\NHibernate\EmployeeBranch.hbm.xml");
            nHConfig.AddFile(employeeConfig);
            ISessionFactory sessionFactory = nHConfig.BuildSessionFactory();

            return sessionFactory.OpenSession();
        }
 public void Process(string name, Configuration nhConfig)
 {
     foreach (var file in GetMappingFiles())
     {
         nhConfig.AddFile(file);
         // HBM.XML file must be named to match entity-name.
         var entityName = file.Name.Replace(".hbm.xml", string.Empty);
         var nhMappingInfo = nhConfig.GetClassMapping(entityName);
         var entityDefinition = definitionCreator.CreateFrom(nhMappingInfo);
         definitionProvider.Add(entityDefinition);
     }
 }
        public static ISession OpenSession()
        {
            Configuration configuration1    = new NHibernate.Cfg.Configuration();
            string        configurationPath = HttpContext.Current.Server.MapPath(@"~\Models\hibernate.cfg.xml");

            configuration1.Configure(configurationPath);
            string bookConfigurationFile = HttpContext.Current.Server.MapPath(@"~\Mappings\Book.hbm.xml");

            configuration1.AddFile(bookConfigurationFile);
            ISessionFactory sessionFactory = configuration1.BuildSessionFactory();

            return(sessionFactory.OpenSession());
        }
Exemple #10
0
        public static ISession OpenSession()
        {
            var configuration     = new NHibernate.Cfg.Configuration();
            var configurationPath = HttpContext.Current.Server.MapPath(@"~\Models\Nhibernate\nhibernate.cfg.xml");

            configuration.Configure(configurationPath);
            var candidateConfigurationFile = HttpContext.Current.Server.MapPath(@"~\Models\Nhibernate\nhibernate.hbm.xml");

            configuration.AddFile(candidateConfigurationFile);
            ISessionFactory sessionFactory = configuration.BuildSessionFactory();

            return(sessionFactory.OpenSession());
        }
Exemple #11
0
		public static void Main(string[] args)
		{
			try
			{
				var cfg = new Configuration();

				//string propFile = null;

				for (int i = 0; i < args.Length; i++)
				{
					if (args[i].StartsWith("--"))
					{
						//if (args[i].StartsWith("--properties="))
						//{
						//  propFile = args[i].Substring(13);
						//}
						//else 
						if (args[i].StartsWith("--config="))
						{
							cfg.Configure(args[i].Substring(9));
						}
						else if (args[i].StartsWith("--naming="))
						{
							cfg.SetNamingStrategy(
								(INamingStrategy)
								Cfg.Environment.BytecodeProvider.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(args[i].Substring(9))));
						}
					}
					else
					{
						cfg.AddFile(args[i]);
					}
				}
				/* NH: No props file for .NET
				if ( propFile != null ) {
					Properties props = new Properties();
					props.putAll( cfg.getProperties() );
					props.load( new FileInputStream( propFile ) );
					cfg.setProperties( props );
				}
				*/
				new SchemaValidator(cfg).Validate();
			}
			catch (Exception e)
			{
				log.Error("Error running schema update", e);
				Console.WriteLine(e);
			}
		}
        public static ISession OpenSession()
        {
            var configuration = new Configuration();

            var configurationPath =
                HttpContext.Current.Server.MapPath(@"~\Models\NHibernate\Configuration\hibernate.cfg.xml");

            configuration.Configure(configurationPath);

            var usersConfigurationFile =
                HttpContext.Current.Server.MapPath(@"~\Models\Nhibernate\Mappings\Users.hbm.xml");

            configuration.AddFile(usersConfigurationFile);

            ISessionFactory sessionFactory = configuration.BuildSessionFactory();

            return sessionFactory.OpenSession();
        }
        public static void InitalizeSessionFactory(params FileInfo[] hbmFiles)
        {
            if (sessionFactory != null)
                return;

            var properties = new Dictionary<string, string>();
            properties.Add("connection.driver_class", "NHibernate.Driver.SQLite20Driver");
            properties.Add("dialect", "NHibernate.Dialect.SQLiteDialect");
            properties.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
            properties.Add("connection.connection_string", "Data Source=../../../database/getin.db;Version=3");
            properties.Add("connection.release_mode", "on_close");
            properties.Add("show_sql", "true");

            configuration = new Configuration();
            configuration.Properties = properties;

            foreach (FileInfo mappingFile in hbmFiles)
            {
                configuration = configuration.AddFile(mappingFile);
            }
            configuration.BuildMapping();
            sessionFactory = configuration.BuildSessionFactory();
        }