Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Data;
using System.Data.SQLite;
using Microsoft.Data.Sqlite;

namespace OSPSuite.Infrastructure.Serialization.Journal
{
Expand All @@ -12,8 +12,12 @@ public class ConnectionProvider : IConnectionProvider
{
public IDbConnection CreateConnection(string databasePath)
{
var connectionString = $"Data Source={databasePath};Version=3;New=True;Compress=True;foreign keys=True";
var cn = new SQLiteConnection(connectionString);
// Note: The original System.Data.SQLite connection string included "Compress=True",
// but Microsoft.Data.Sqlite does not support the Compress parameter.
// SQLite works fine without compression, and compression adds CPU overhead.
// See COMPRESS_INVESTIGATION.md for details.
var connectionString = $"Data Source={databasePath};Foreign Keys=True";
var cn = new SqliteConnection(connectionString);
cn.Open();
return cn;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Newtonsoft.Json.Schema" Version="4.0.1" />
<PackageReference Include="NHibernate" Version="5.5.2" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.119" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Data.Common;
using System.Data.SQLite;
using Microsoft.Data.Sqlite;
using OSPSuite.Core.Extensions;

namespace OSPSuite.Infrastructure.Serialization.Services
Expand All @@ -10,7 +10,7 @@ public class SQLiteProjectCommandExecuter
public virtual void ExecuteCommand(string projectFile, Action<DbConnection> command )
{
string file = projectFile.ToUNCPath();
using (var sqlLite = new SQLiteConnection($"Data Source={file}"))
using (var sqlLite = new SqliteConnection($"Data Source={file};Foreign Keys=True"))
{
sqlLite.Open();
command(sqlLite);
Expand All @@ -20,7 +20,7 @@ public virtual void ExecuteCommand(string projectFile, Action<DbConnection> comm
public virtual TResult ExecuteCommand<TResult>(string projectFile, Func<DbConnection, TResult> command)
{
string file = projectFile.ToUNCPath();
using (var sqlLite = new SQLiteConnection($"Data Source={file}"))
using (var sqlLite = new SqliteConnection($"Data Source={file};Foreign Keys=True"))
{
sqlLite.Open();
return command(sqlLite);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Dialect;
using NHibernate.Driver;
using NHibernate.Tool.hbm2ddl;

namespace OSPSuite.Infrastructure.Serialization.Services
{
public class SessionFactoryProvider : ISessionFactoryProvider
{
public ISessionFactory InitalizeSessionFactoryFor(string dataSource)
{
var configuration = CreateConfiguration(dataSource);
var sessionFactory = configuration.BuildSessionFactory();
return sessionFactory;
}

public ISessionFactory OpenSessionFactoryFor(string dataSource)
{
var configuration = CreateConfiguration(dataSource);
var sessionFactory = configuration.BuildSessionFactory();
return sessionFactory;
}

public SchemaExport GetSchemaExport(string dataSource)
{
var configuration = CreateConfiguration(dataSource);
return new SchemaExport(configuration);
}

private Configuration CreateConfiguration(string dataSource)
{
var configuration = new Configuration();

// Configure database integration with Microsoft.Data.Sqlite
configuration.DataBaseIntegration(db =>
{
// Use the SQLite driver that works with Microsoft.Data.Sqlite
db.Driver<NHibernate.Driver.SQLite20Driver>();
db.Dialect<SQLiteDialect>();
db.ConnectionString = $"Data Source={dataSource};Foreign Keys=True";
db.Timeout = 20;
});

// Add mapping assemblies (you may need to adjust these based on your actual mapping assemblies)
configuration.AddAssembly(typeof(SessionFactoryProvider).Assembly);

return configuration;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="OSPSuite.BDDHelper" Version="4.0.1.1" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.0" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.8" GeneratePathProperty="true" />
<PackageReference Include="System.Drawing.Common" Version="9.0.2" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.119" />
</ItemGroup>
<ItemGroup>
Expand All @@ -31,6 +34,7 @@
<Folder Include="Data\PKAnalysesFiles\" />
<Folder Include="Data\SensitivityAnalysisResultsFiles\" />
</ItemGroup>

<PropertyGroup>
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
<CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
Expand Down
3 changes: 3 additions & 0 deletions tests/OSPSuite.R.Performance/OSPSuite.R.Performance.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@
<PackageReference Include="OSPSuite.FuncParser" Version="4.0.0.75" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.SimModel" Version="4.0.0.77" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.SimModelSolver_CVODES" Version="4.1.0.19" GeneratePathProperty="true" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.0" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.8" GeneratePathProperty="true" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.119" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\OSPSuite.Core\OSPSuite.Core.csproj" />
<ProjectReference Include="..\..\src\OSPSuite.R\OSPSuite.R.csproj" />
</ItemGroup>

<PropertyGroup>
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
<CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
Expand Down
7 changes: 6 additions & 1 deletion tests/OSPSuite.Starter/OSPSuite.Starter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
<PackageReference Include="OSPSuite.FuncParser" Version="4.0.0.75" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.SimModel" Version="4.0.0.77" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.SimModelSolver_CVODES" Version="4.1.0.19" GeneratePathProperty="true" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.119" GeneratePathProperty="true" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.0" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.8" GeneratePathProperty="true" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\OSPSuite.Assets.Images\OSPSuite.Assets.Images.csproj" />
Expand All @@ -66,6 +67,10 @@
<ProjectReference Include="..\OSPSuite.HelpersForTests\OSPSuite.HelpersForTests.csproj" />
</ItemGroup>

<ItemGroup>
<Reference Include="System.Windows.Forms" />
</ItemGroup>

<PropertyGroup>
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
<CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
Expand Down