mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 20:13:21 +08:00
Add interface for database context factory
This commit is contained in:
parent
64cda9fd0f
commit
a738664167
@ -63,7 +63,7 @@ namespace osu.Game.Tests.Visual
|
||||
var storage = new TestStorage(@"TestCasePlaySongSelect");
|
||||
|
||||
// this is by no means clean. should be replacing inside of OsuGameBase somehow.
|
||||
DatabaseContextFactory factory = new SingletonContextFactory(new OsuDbContext());
|
||||
IDatabaseContextFactory factory = new SingletonContextFactory(new OsuDbContext());
|
||||
|
||||
dependencies.Cache(rulesets = new RulesetStore(factory));
|
||||
dependencies.Cache(manager = new BeatmapManager(storage, factory, rulesets, null)
|
||||
|
@ -60,7 +60,7 @@ namespace osu.Game.Beatmaps
|
||||
/// </summary>
|
||||
public WorkingBeatmap DefaultBeatmap { private get; set; }
|
||||
|
||||
private readonly DatabaseContextFactory contextFactory;
|
||||
private readonly IDatabaseContextFactory contextFactory;
|
||||
|
||||
private readonly FileStore files;
|
||||
|
||||
@ -85,7 +85,7 @@ namespace osu.Game.Beatmaps
|
||||
/// </summary>
|
||||
public Func<Storage> GetStableStorage { private get; set; }
|
||||
|
||||
public BeatmapManager(Storage storage, DatabaseContextFactory contextFactory, RulesetStore rulesets, APIAccess api, IIpcHost importHost = null)
|
||||
public BeatmapManager(Storage storage, IDatabaseContextFactory contextFactory, RulesetStore rulesets, APIAccess api, IIpcHost importHost = null)
|
||||
{
|
||||
this.contextFactory = contextFactory;
|
||||
|
||||
|
@ -20,7 +20,7 @@ namespace osu.Game.Beatmaps
|
||||
public event Action<BeatmapInfo> BeatmapHidden;
|
||||
public event Action<BeatmapInfo> BeatmapRestored;
|
||||
|
||||
public BeatmapStore(DatabaseContextFactory factory)
|
||||
public BeatmapStore(IDatabaseContextFactory factory)
|
||||
: base(factory)
|
||||
{
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ namespace osu.Game.Database
|
||||
/// <summary>
|
||||
/// Create a new <see cref="OsuDbContext"/> instance (separate from the shared context via <see cref="GetContext"/> for performing isolated operations.
|
||||
/// </summary>
|
||||
protected readonly DatabaseContextFactory ContextFactory;
|
||||
protected readonly IDatabaseContextFactory ContextFactory;
|
||||
|
||||
/// <summary>
|
||||
/// Refresh an instance potentially from a different thread with a local context-tracked instance.
|
||||
@ -40,7 +40,7 @@ namespace osu.Game.Database
|
||||
}
|
||||
}
|
||||
|
||||
protected DatabaseBackedStore(DatabaseContextFactory contextFactory, Storage storage = null)
|
||||
protected DatabaseBackedStore(IDatabaseContextFactory contextFactory, Storage storage = null)
|
||||
{
|
||||
ContextFactory = contextFactory;
|
||||
Storage = storage;
|
||||
|
@ -6,7 +6,7 @@ using osu.Framework.Platform;
|
||||
|
||||
namespace osu.Game.Database
|
||||
{
|
||||
public class DatabaseContextFactory
|
||||
public class DatabaseContextFactory : IDatabaseContextFactory
|
||||
{
|
||||
private readonly GameHost host;
|
||||
|
||||
|
20
osu.Game/Database/IDatabaseContextFactory.cs
Normal file
20
osu.Game/Database/IDatabaseContextFactory.cs
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
namespace osu.Game.Database
|
||||
{
|
||||
public interface IDatabaseContextFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Get a context for read-only usage.
|
||||
/// </summary>
|
||||
OsuDbContext Get();
|
||||
|
||||
/// <summary>
|
||||
/// Request a context for write usage. Can be consumed in a nested fashion (and will return the same underlying context).
|
||||
/// This method may block if a write is already active on a different thread.
|
||||
/// </summary>
|
||||
/// <returns>A usage containing a usable context.</returns>
|
||||
DatabaseWriteUsage GetForWrite();
|
||||
}
|
||||
}
|
@ -3,19 +3,17 @@
|
||||
|
||||
namespace osu.Game.Database
|
||||
{
|
||||
public class SingletonContextFactory : DatabaseContextFactory
|
||||
public class SingletonContextFactory : IDatabaseContextFactory
|
||||
{
|
||||
private readonly OsuDbContext context;
|
||||
|
||||
public SingletonContextFactory(OsuDbContext context)
|
||||
: base(null)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
protected override OsuDbContext CreateContext()
|
||||
{
|
||||
return context;
|
||||
}
|
||||
public OsuDbContext Get() => context;
|
||||
|
||||
public DatabaseWriteUsage GetForWrite() => new DatabaseWriteUsage(context, null);
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ namespace osu.Game.IO
|
||||
|
||||
public new Storage Storage => base.Storage;
|
||||
|
||||
public FileStore(DatabaseContextFactory contextFactory, Storage storage) : base(contextFactory, storage.GetStorageForDirectory(@"files"))
|
||||
public FileStore(IDatabaseContextFactory contextFactory, Storage storage) : base(contextFactory, storage.GetStorageForDirectory(@"files"))
|
||||
{
|
||||
Store = new StorageBackedResourceStore(Storage);
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ namespace osu.Game.Rulesets
|
||||
loadRulesetFromFile(file);
|
||||
}
|
||||
|
||||
public RulesetStore(DatabaseContextFactory factory)
|
||||
public RulesetStore(IDatabaseContextFactory factory)
|
||||
: base(factory)
|
||||
{
|
||||
AddMissingRulesets();
|
||||
|
@ -276,6 +276,7 @@
|
||||
<Compile Include="Configuration\SpeedChangeVisualisationMethod.cs" />
|
||||
<Compile Include="Database\DatabaseContextFactory.cs" />
|
||||
<Compile Include="Database\DatabaseWriteUsage.cs" />
|
||||
<Compile Include="Database\IDatabaseContextFactory.cs" />
|
||||
<Compile Include="Database\IHasPrimaryKey.cs" />
|
||||
<Compile Include="Database\SingletonContextFactory.cs" />
|
||||
<Compile Include="Graphics\Containers\LinkFlowContainer.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user