protected SQLitePublisherBase(SQLiteConfiguration config)
        {
            myConfig = config;

            Enabled = config.Enabled;
            FriendlyId = config.FriendlyId;
        }
Example #2
0
        public void ConnectToDatabase()
        {
            string fileName = Settings.GetById(SettingKeys.DatabasePath)?.Value;

            if (string.IsNullOrWhiteSpace(fileName))
            {
                fileName = Constants.DefaultDatabasePath;
            }

            var dbConfig = new SQLiteConfiguration().UsingFile(fileName)

#if !DEBUG
                           .DoNot
#endif
                           .ShowSql();

            var cfg = Fluently.Configure().Database(dbConfig)
                      .Mappings(map => map.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))
                      .BuildConfiguration();

            new SchemaUpdate(cfg).Execute(false, true);
            var factory = cfg.BuildSessionFactory();

            Session = factory.OpenSession();
        }
        public void Execute(Action<ISession> action)
        {
            var cfg = new SQLiteConfiguration()
                .InMemory()
                .ShowSql()
                .ConfigureProperties(new Configuration());

            // UGLY HACK
            var nhVersion = typeof(Configuration).Assembly.GetName().Version;
            if (!nhVersion.ToString().StartsWith("2.0."))
            {
                cfg.SetProperty("proxyfactory.factory_class",
                                "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");
            }

            PersistenceModel.Configure(cfg);

            var sessionFactory = cfg.BuildSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                using (var tx = session.BeginTransaction())
                {
                    SchemaExport export = new SchemaExport(cfg);
                    export.Execute(true, true, false, false, session.Connection, null);
                    tx.Commit();
                }

                using (var tx = session.BeginTransaction())
                {
                    action(session);
                    tx.Commit();
                }
            }
        }
Example #4
0
    public static void Log(LoggingLevel level, SQLiteConfiguration config, string message)
    {
        if (((int)level) >= (int)config.LoggingLevel)
        {
            switch (level)
            {
            case LoggingLevel.TRACE:
            case LoggingLevel.LOG:
                config.SQLiteLogger.Log(message);
                break;

            case LoggingLevel.WARN:
                config.SQLiteLogger.Warn(message);
                break;

            case LoggingLevel.ERROR:
                config.SQLiteLogger.Error(message);
                break;

            case LoggingLevel.FATAL:
                config.SQLiteLogger.Fatal(message);
                break;

            default:
                break;
            }
        }
    }
        public static ISession OpenTemporarySession()
        {
            lock (factorylock)
            {
                if (_sessionSource == null)
                {
                    var persistenceModel = new PersistenceModel();
                    persistenceModel.AddMappingsFromAssembly(typeof(JiraIssueMap).Assembly);

                    var sqLiteConfiguration = new SQLiteConfiguration()
                                              .InMemory()
                                              .ShowSql();

                    var sessionSource = new SessionSource(sqLiteConfiguration.ToProperties(), persistenceModel);

                    _sessionSource = sessionSource;
                }
            }

            var session = _sessionSource.CreateSession();

            _sessionSource.BuildSchema(session);

            return(session);
        }
Example #6
0
        protected virtual Configuration FluentlyConfigureSqlite(SqliteDatabase database)
        {
            var filePath = database.FilePath;
            SQLiteConfiguration liteConfiguration =
                SQLiteConfiguration.Standard
                .UsingFile(filePath)
                .ProxyFactoryFactory(typeof(ProxyFactoryFactory));

            var fluentConfig =
                Fluently
                .Configure()
                .Database(liteConfiguration)
                .Mappings(m => m.FluentMappings.AddFromAssembly(GetType().Assembly))
                // Install the database if it doesn't exist
                .ExposeConfiguration(config =>
            {
                if (File.Exists(filePath))
                {
                    return;
                }

                SchemaExport export = new SchemaExport(config);
                export.Drop(false, true);
                export.Create(false, true);
            })
                .BuildConfiguration();

            AddProperties(fluentConfig);

            return(fluentConfig);
        }
        public IPersistenceConfigurer GetPersistenceProvider(string sessionAlias)
        {
            SQLiteConfiguration persistenceConfigurer = SQLiteConfiguration
                                                        .Standard
                                                        .UsingFile("Local.db3");

            return(persistenceConfigurer);
        }
Example #8
0
        public SQLiteExecutor(string connectionString, SQLiteConfiguration configuration)
            : base(configuration)
        {
            Configuration = configuration;

            Connection = new SQLiteConnection(connectionString);
            SyncRoot   = new object();
        }
    public SQLiteDbContext(string databaseName = "MyDatabase.db", SQLiteConfiguration config = null)
    {
        _config = config ?? new DefaultSQLiteConfiguration();

        _database.DBLocation = _config.DatabaseLocation;
        _database.DBName     = databaseName.EndsWith(".db") ? databaseName : String.Concat(databaseName, ".db");

        InitializeDatabase();
    }
Example #10
0
        private static IPersistenceConfigurer SqlLiteMemoryConfigureDatabase(NHConfigurationSection nhConfiguration)
        {
            SQLiteConfiguration cfg = SQLiteConfiguration.Standard
                                      .InMemory()
                                      .UseOuterJoin()
                                      .DefaultSchema(nhConfiguration.DatabaseSchema);

            return(cfg);
        }
Example #11
0
        public void SetUp()
        {
            var properties = new SQLiteConfiguration()
                             .UseOuterJoin()
                             .InMemory()
                             .ToProperties();

            source = new SingleConnectionSessionSourceForSQLiteInMemoryTesting(properties, new TestPersistenceModel());
            source.BuildSchema();
        }
        protected void ShowSchema()
        {
            var cfg = new SQLiteConfiguration()
                      .InMemory()
                      .ShowSql();
            var configuration = new Configuration().AddProperties(cfg.ToProperties());
            var model         = new TModel();

            model.Configure(configuration);
            new SchemaExport(configuration).Create(true, false);
        }
Example #13
0
        public void CanInitializeWithPersistenceConfigurerAndNoConfigFile()
        {
            SQLiteConfiguration persistenceConfigurer =
                SQLiteConfiguration.Standard.ConnectionString(c => c.Is("Data Source=:memory:;Version=3;New=True;"));

            Configuration configuration = new NHibernateSessionFactoryBuilder()
                                          .UsePersistenceConfigurer(persistenceConfigurer)
                                          .BuildConfiguration();

            Assert.That(configuration, Is.Not.Null);
            configuration.BuildSessionFactory();
        }
        public void NHibernateCanLoadOneToManyTargetMapping()
        {
            var cfg = new SQLiteConfiguration()
                      .InMemory()
                      .ConfigureProperties(new Configuration());

            var model = new OneToManyPersistenceModel();

            model.Configure(cfg);

            cfg.BuildSessionFactory();
        }
Example #15
0
        public void CanInitializeWithPersistenceConfigurerAndNoConfigFile()
        {
            SQLiteConfiguration persistenceConfigurer =
                SQLiteConfiguration.Standard.ConnectionString(c => c.Is("Data Source=:memory:;Version=3;New=True;"));

            Configuration configuration = new NHibernateSessionFactoryBuilder()
                                          .WithFileDependency("SharpArch.NHibernate")
                                          .UsePersistenceConfigurer(persistenceConfigurer)
                                          .BuildConfiguration();

            configuration.BuildSessionFactory();
        }
        public void SetUp()
        {
            var properties = new SQLiteConfiguration()
                             .UseOuterJoin()
                             //.ShowSql()
                             .InMemory()
                             .ToProperties();

            var autoPersistenceModel = new NHibernatePersistenceModel().GetPersistenceModel();

            _source = new SingleConnectionSessionSourceForSQLiteInMemoryTesting(properties, autoPersistenceModel);
            _source.BuildSchema();
        }
        private SQLiteConfiguration GetSqlLiteConfiguration(NhibernateSettings nhibernateSettings)
        {
            SQLiteConfiguration config =
                SQLiteConfiguration.Standard
                .ConnectionString(nhibernateSettings.ConnectionString)
                .DefaultSchema(nhibernateSettings.DBSchema);

            if (nhibernateSettings.ShowSQL)
            {
                config.ShowSql();
            }
            return(config);
        }
        private SQLiteConfiguration GetSqlLiteConfiguration()
        {
            SQLiteConfiguration config =
                SQLiteConfiguration.Standard
                .ConnectionString(_connectionString)
                .DefaultSchema(_nhibernateSchema);

            if (_showSql)
            {
                config.ShowSql();
            }
            return(config);
        }
Example #19
0
        public void CanGenerateSchema()
        {
            // Arrange
            var dbConfig = new SQLiteConfiguration().InMemory().ShowSql();

            var cfg = Fluently.Configure().Database( dbConfig )
                .Mappings( map => map.FluentMappings.AddFromAssembly( typeof( Todo ).Assembly ) )
                .BuildConfiguration();

            // Act
            new SchemaExport( cfg ).Execute( false, true, false );

            // Assert
        }
Example #20
0
        private static IPersistenceConfigurer SqlLiteConfigureDatabase(NHConfigurationSection nhConfiguration)
        {
            SQLiteConfiguration cfg = SQLiteConfiguration.Standard
                                      //.UsingFile(filePath)
                                      .ConnectionString(c => c.FromConnectionStringWithKey(nhConfiguration.ConnectionStringName))
                                      .UseOuterJoin()
                                      .DefaultSchema(nhConfiguration.DatabaseSchema);

#if DEBUG
            cfg.ShowSql();
#endif

            return(cfg);
        }
Example #21
0
        public void CanGenerateSchema()
        {
            // Arrange
            var dbConfig = new SQLiteConfiguration().InMemory().ShowSql();

            var cfg = Fluently.Configure().Database(dbConfig)
                      .Mappings(map => map.FluentMappings.AddFromAssembly(typeof(Todo).Assembly))
                      .BuildConfiguration();

            // Act
            new SchemaExport(cfg).Execute(false, true, false);

            // Assert
        }
Example #22
0
        public void SetUp()
        {
            var properties = new SQLiteConfiguration()
                             .UseOuterJoin()
                             //.ShowSql()
                             .InMemory()
                             .ToProperties();

            _persistenceModel = new TestPersistenceModel <MAPTYPE, ENTITY>();

            ReferencesAdditionalMaps(_persistenceModel);

            _source = new SingleConnectionSessionSourceForSQLiteInMemoryTesting(properties, _persistenceModel);
            _source.BuildSchema();
        }
        public Configuration GetConfiguration()
        {
            SQLiteConfiguration persistenceConfigurer = SQLiteConfiguration.Standard
                                                        .Dialect <MySQLiteDialect>()
                                                        .InMemory()
                                                        .ShowSql();

            FluentConfiguration cfg = Fluently.Configure()
                                      .Database(persistenceConfigurer)
                                      .ExposeConfiguration(ExtendConfiguration)
                                      .ProxyFactoryFactory <DefaultProxyFactoryFactory>()
                                      .Mappings(mappings);

            return(cfg.BuildConfiguration());
        }
Example #24
0
    /// <summary>
    /// 创建一个空白的数据库文件并连接
    /// </summary>
    /// <param name="filepath">文件路径</param>
    /// <param name="overwrite">若文件已经存在是否覆盖(默认为false)</param>
    /// <param name="configuration">SQLite 数据库配置</param>
    /// <returns>SQLite 数据库访问器</returns>
    public static SQLiteExecutor ConnectNewFile( string filepath, bool overwrite = false, SQLiteConfiguration configuration = null )
    {

      if ( File.Exists( filepath ) )
      {
        if ( overwrite )
          File.Delete( filepath );

        else
          throw new InvalidOperationException( "文件已存在" );
      }

      SQLiteConnection.CreateFile( filepath );

      return ConnectFile( filepath, false, configuration );
    }
        public void SetupContext()
        {
            var cfg = new SQLiteConfiguration()
                      .InMemory()
                      .ShowSql();

            SessionSource = new SessionSource(cfg.ToProperties(), new TModel());
            Session       = SessionSource.CreateSession();
            SessionSource.BuildSchema(Session);

            Context();
            Session.Flush();
            Session.Clear();

            Because();
        }
        /// <summary>
        /// Use the NHibernate backed saga persister implementation on top of SQLite.
        /// SagaData classes are automatically mapped using Fluent NHibernate conventions
        /// and there persistence schema is also automatically generated.
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public static Configure NHibernateSagaPersisterWithSQLiteAndAutomaticSchemaGeneration(this Configure config)
        {
            var nhibernateProperties = SQLiteConfiguration.UsingFile(".\\NServiceBus.Sagas.sqlite");

            AppDomain.CurrentDomain.UnhandledException += (o, e) =>
            {
                if (e.ExceptionObject.GetType() ==
                    typeof(AccessViolationException))
                {
                    LogManager.GetLogger("System.Data.SQLite").Fatal(
                        "NServiceBus has detected an error in the operation of SQLite. SQLite is the database used to store sagas from NServiceBus when running under the 'Integration' profile. This error usually occurs only under load. If you wish to use sagas under load, it is recommended to run NServiceBus under the 'Production' profile. This can be done by passing the value 'NServiceBus.Production' on the command line to the NServiceBus.Host.exe process. For more information see http://www.NServiceBus.com/Profiles.aspx .");
                }
            };

            return(NHibernateSagaPersister(config, nhibernateProperties, true));
        }
    public SQLiteTable(SQLiteDB db, string tableIdentifier, SQLiteConfiguration config)
    {
        _db = db;
        _tableIdentifier = tableIdentifier;
        _config          = config;

        _itemProperties = typeof(T).GetProperties();

        foreach (var property in _itemProperties)
        {
            if (property.GetCustomAttributes(typeof(PrimaryKeyAttribute), false).Length != 0)
            {
                _primaryKeyProperty = property;
                break;
            }
        }
    }
Example #28
0
        /// <summary>
        /// Returns the FluentNHibernate Sqlite configuration data
        /// </summary>
        /// <param name="assembly">The assembly containing the mappings</param>
        /// <returns>SQLite configuration</returns>
        IPersistenceConfigurer IDatabaseConfiguration.Create(Assembly assembly)
        {
            SQLiteConfiguration config = new SQLiteConfiguration()
                                            .UsingFile(m_strDbPath)
                                            .ProxyFactoryFactory("NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu")
                                            .ShowSql();

            if (!File.Exists(m_strDbPath))
            {
                PersistenceModel pm = new PersistenceModel();
                pm.AddMappingsFromAssembly(assembly);

                SessionSource ss = new SessionSource(config.ToProperties(), pm);
                ss.BuildSchema();
                ss = null;
            }

            return config;
        }
        public NHibernateConfig()
        {
            var config = new SQLiteConfiguration()
                         .InMemory()
                         .ShowSql()
                         .Raw("hibernate.generate_statistics", "true");

            var nhConfig = Fluently.Configure()
                           .Database(config)
                           .Mappings(mappings =>
                                     mappings.FluentMappings.AddFromAssemblyOf <CustomerMap>()
                                     .Conventions.AddFromAssemblyOf <IdGenerationConvention>())
                           .ExposeConfiguration(x => new SchemaExport(x).Execute(true, true, false));

            var SessionSource = new SessionSource(nhConfig);

            Session = SessionSource.CreateSession();
            SessionSource.BuildSchema(Session);
        }
        /// <summary>
        /// Create the <see cref="Configuration"/> to use for the database.
        /// </summary>
        /// <returns></returns>
        private Configuration GetConfiguration()
        {
            lock (_lock) {
                if (configuration == null)
                {
                    lock (_lock) {
                        var filePath = CurrentDatabaseResolver.FilePath;
                        SQLiteConfiguration liteConfiguration =
                            SQLiteConfiguration.Standard
                            .UsingFile(filePath)
                            .ProxyFactoryFactory(typeof(ProxyFactoryFactory));

                        configuration =
                            Fluently
                            .Configure()
                            .Database(liteConfiguration)
                            .Mappings(m => m.FluentMappings.AddFromAssemblyOf <OkonauPersistence>())
                            // Install the database if it doesn't exist
                            .ExposeConfiguration(config =>
                        {
                            if (File.Exists(filePath))
                            {
                                return;
                            }

                            SchemaExport export = new SchemaExport(config);
                            export.Drop(false, true);
                            export.Create(false, true);
                        })
                            .BuildConfiguration();


                        if (!configuration.Properties.ContainsKey("current_session_context_class"))
                        {
                            configuration.Properties.Add("current_session_context_class", "managed_web");
                        }
                    }
                }

                return(configuration);
            }
        }
Example #31
0
    /// <summary>
    /// 连接到指定的数据库文件
    /// </summary>
    /// <param name="filepath">数据库文件路径</param>
    /// <param name="create">如果数据库文件不存在,是否自动创建(默认为true)</param>
    /// <param name="configuration">SQLite 数据库配置</param>
    /// <returns>SQLite 数据库访问器</returns>
    public static SQLiteExecutor ConnectFile( string filepath, bool create = true, SQLiteConfiguration configuration = null )
    {

      if ( !File.Exists( filepath ) )
      {
        if ( create )
        {
          Directory.CreateDirectory( Path.GetDirectoryName( filepath ) );
          SQLiteConnection.CreateFile( filepath );
        }

        else
          throw new FileNotFoundException( "要连接的数据库文件不存在" );
      }

      var builder = new SQLiteConnectionStringBuilder();
      builder.DataSource = filepath;

      return Connect( builder.ConnectionString, configuration ?? DefaultConfiguration );
    }
        public void SetUp()
        {
            var properties = new SQLiteConfiguration()
                             .UseOuterJoin()
                             //.ShowSql()
                             .InMemory()
                             .ToProperties();

            //var properties = MsSqlConfiguration
            //    .MsSql2005
            //    .ConnectionString
            //    .Server(".")
            //    .Database("FluentNHibernate")
            //    .TrustedConnection
            //    .CreateProperties
            //    .ToProperties();

            _source = new SingleConnectionSessionSourceForSQLiteInMemoryTesting(properties, new TestPersistenceModel());
            _source.BuildSchema();
        }
Example #33
0
        public void ConnectToDatabase()
        {
            string fileName = Settings.GetById( SettingKeys.DatabasePath )?.Value;
            if( string.IsNullOrWhiteSpace( fileName ) )
            {
                fileName = Constants.DefaultDatabasePath;
            }

            var dbConfig = new SQLiteConfiguration().UsingFile( fileName )

            #if !DEBUG
                .DoNot
            #endif
                .ShowSql();

            var cfg = Fluently.Configure().Database( dbConfig )
                .Mappings( map => map.FluentMappings.AddFromAssembly( Assembly.GetExecutingAssembly() ) )
                .BuildConfiguration();

            new SchemaUpdate( cfg ).Execute( false, true );
            var factory = cfg.BuildSessionFactory();

            Session = factory.OpenSession();
        }
Example #34
0
 static SQLite()
 {
   DefaultConfiguration = new SQLiteConfiguration();
 }
Example #35
0
 /// <summary>
 /// 根据连接字符串连接到指定的 SQLite 服务器
 /// </summary>
 /// <param name="connectionString">连接字符串</param>
 /// <param name="configuration">SQLite 数据库配置</param>
 /// <returns>SQLite 数据库访问器</returns>
 public static SQLiteExecutor Connect(string connectionString, SQLiteConfiguration configuration = null)
 {
     return(new SQLiteExecutor(connectionString, configuration));
 }
Example #36
0
        /// <summary>
        /// 连接到指定的数据库文件
        /// </summary>
        /// <param name="filepath">数据库文件路径</param>
        /// <param name="create">如果数据库文件不存在,是否自动创建(默认为true)</param>
        /// <param name="configuration">SQLite 数据库配置</param>
        /// <returns>SQLite 数据库访问器</returns>
        public static SQLiteExecutor ConnectFile(string filepath, bool create = true, SQLiteConfiguration configuration = null)
        {
            if (!File.Exists(filepath))
            {
                if (create)
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(filepath));
                    SQLiteConnection.CreateFile(filepath);
                }

                else
                {
                    throw new FileNotFoundException("要连接的数据库文件不存在");
                }
            }

            var builder = new SQLiteConnectionStringBuilder();

            builder.DataSource = filepath;

            return(Connect(builder.ConnectionString, configuration ?? DefaultConfiguration));
        }
Example #37
0
        /// <summary>
        /// 创建一个空白的数据库文件并连接
        /// </summary>
        /// <param name="filepath">文件路径</param>
        /// <param name="overwrite">若文件已经存在是否覆盖(默认为false)</param>
        /// <param name="configuration">SQLite 数据库配置</param>
        /// <returns>SQLite 数据库访问器</returns>
        public static SQLiteExecutor ConnectNewFile(string filepath, bool overwrite = false, SQLiteConfiguration configuration = null)
        {
            if (File.Exists(filepath))
            {
                if (overwrite)
                {
                    File.Delete(filepath);
                }

                else
                {
                    throw new InvalidOperationException("文件已存在");
                }
            }

            SQLiteConnection.CreateFile(filepath);

            return(ConnectFile(filepath, false, configuration));
        }
Example #38
0
 static SQLite()
 {
     DefaultConfiguration = new SQLiteConfiguration();
 }
Example #39
0
 /// <summary>
 /// 根据连接字符串连接到指定的 SQLite 服务器
 /// </summary>
 /// <param name="connectionString">连接字符串</param>
 /// <param name="configuration">SQLite 数据库配置</param>
 /// <returns>SQLite 数据库访问器</returns>
 public static SQLiteExecutor Connect( string connectionString, SQLiteConfiguration configuration = null )
 {
   return new SQLiteExecutor( connectionString, configuration );
 }
Example #40
0
 public SQLitePublisher(SQLiteConfiguration config)
     : base(config)
 {
 }