mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 15:16:38 +09:00
Rename RealmContextFactory
to RealmAccess
This commit is contained in:
@ -35,7 +35,7 @@ namespace osu.Game.Database
|
||||
private DatabaseContextFactory efContextFactory { get; set; } = null!;
|
||||
|
||||
[Resolved]
|
||||
private RealmContextFactory realmContextFactory { get; set; } = null!;
|
||||
private RealmAccess realm { get; set; } = null!;
|
||||
|
||||
[Resolved]
|
||||
private OsuConfigManager config { get; set; } = null!;
|
||||
@ -101,7 +101,7 @@ namespace osu.Game.Database
|
||||
{
|
||||
using (var ef = efContextFactory.Get())
|
||||
{
|
||||
realmContextFactory.Write(realm =>
|
||||
realm.Write(realm =>
|
||||
{
|
||||
// Before beginning, ensure realm is in an empty state.
|
||||
// Migrations which are half-completed could lead to issues if the user tries a second time.
|
||||
@ -158,7 +158,7 @@ namespace osu.Game.Database
|
||||
|
||||
int count = existingBeatmapSets.Count();
|
||||
|
||||
realmContextFactory.Run(realm =>
|
||||
realm.Run(realm =>
|
||||
{
|
||||
log($"Found {count} beatmaps in EF");
|
||||
|
||||
@ -280,7 +280,7 @@ namespace osu.Game.Database
|
||||
|
||||
int count = existingScores.Count();
|
||||
|
||||
realmContextFactory.Run(realm =>
|
||||
realm.Run(realm =>
|
||||
{
|
||||
log($"Found {count} scores in EF");
|
||||
|
||||
@ -369,7 +369,7 @@ namespace osu.Game.Database
|
||||
break;
|
||||
}
|
||||
|
||||
realmContextFactory.Run(realm =>
|
||||
realm.Run(realm =>
|
||||
{
|
||||
using (var transaction = realm.BeginWrite())
|
||||
{
|
||||
@ -428,7 +428,7 @@ namespace osu.Game.Database
|
||||
|
||||
log("Beginning settings migration to realm");
|
||||
|
||||
realmContextFactory.Run(realm =>
|
||||
realm.Run(realm =>
|
||||
{
|
||||
using (var transaction = realm.BeginWrite())
|
||||
{
|
||||
|
@ -32,7 +32,7 @@ namespace osu.Game.Database
|
||||
/// <summary>
|
||||
/// A factory which provides both the main (update thread bound) realm context and creates contexts for async usage.
|
||||
/// </summary>
|
||||
public class RealmContextFactory : IDisposable
|
||||
public class RealmAccess : IDisposable
|
||||
{
|
||||
private readonly Storage storage;
|
||||
|
||||
@ -123,7 +123,7 @@ namespace osu.Game.Database
|
||||
/// <param name="storage">The game storage which will be used to create the realm backing file.</param>
|
||||
/// <param name="filename">The filename to use for the realm backing file. A ".realm" extension will be added automatically if not specified.</param>
|
||||
/// <param name="efContextFactory">An EF factory used only for migration purposes.</param>
|
||||
public RealmContextFactory(Storage storage, string filename, IDatabaseContextFactory? efContextFactory = null)
|
||||
public RealmAccess(Storage storage, string filename, IDatabaseContextFactory? efContextFactory = null)
|
||||
{
|
||||
this.storage = storage;
|
||||
this.efContextFactory = efContextFactory;
|
||||
@ -365,7 +365,7 @@ namespace osu.Game.Database
|
||||
private Realm createContext()
|
||||
{
|
||||
if (isDisposed)
|
||||
throw new ObjectDisposedException(nameof(RealmContextFactory));
|
||||
throw new ObjectDisposedException(nameof(RealmAccess));
|
||||
|
||||
bool tookSemaphoreLock = false;
|
||||
|
||||
@ -592,7 +592,7 @@ namespace osu.Game.Database
|
||||
public IDisposable BlockAllOperations()
|
||||
{
|
||||
if (isDisposed)
|
||||
throw new ObjectDisposedException(nameof(RealmContextFactory));
|
||||
throw new ObjectDisposedException(nameof(RealmAccess));
|
||||
|
||||
SynchronizationContext? syncContext = null;
|
||||
|
||||
@ -652,7 +652,7 @@ namespace osu.Game.Database
|
||||
throw;
|
||||
}
|
||||
|
||||
return new InvokeOnDisposal<RealmContextFactory>(this, factory =>
|
||||
return new InvokeOnDisposal<RealmAccess>(this, factory =>
|
||||
{
|
||||
factory.contextCreationLock.Release();
|
||||
Logger.Log(@"Restoring realm operations.", LoggingTarget.Database);
|
@ -24,17 +24,17 @@ namespace osu.Game.Database
|
||||
/// </summary>
|
||||
private readonly T data;
|
||||
|
||||
private readonly RealmContextFactory realmFactory;
|
||||
private readonly RealmAccess realm;
|
||||
|
||||
/// <summary>
|
||||
/// Construct a new instance of live realm data.
|
||||
/// </summary>
|
||||
/// <param name="data">The realm data.</param>
|
||||
/// <param name="realmFactory">The realm factory the data was sourced from. May be null for an unmanaged object.</param>
|
||||
public RealmLive(T data, RealmContextFactory realmFactory)
|
||||
/// <param name="realm">The realm factory the data was sourced from. May be null for an unmanaged object.</param>
|
||||
public RealmLive(T data, RealmAccess realm)
|
||||
{
|
||||
this.data = data;
|
||||
this.realmFactory = realmFactory;
|
||||
this.realm = realm;
|
||||
|
||||
ID = data.ID;
|
||||
}
|
||||
@ -51,7 +51,7 @@ namespace osu.Game.Database
|
||||
return;
|
||||
}
|
||||
|
||||
realmFactory.Run(realm =>
|
||||
realm.Run(realm =>
|
||||
{
|
||||
perform(retrieveFromID(realm, ID));
|
||||
});
|
||||
@ -66,7 +66,7 @@ namespace osu.Game.Database
|
||||
if (!IsManaged)
|
||||
return perform(data);
|
||||
|
||||
return realmFactory.Run(realm =>
|
||||
return realm.Run(realm =>
|
||||
{
|
||||
var returnData = perform(retrieveFromID(realm, ID));
|
||||
|
||||
@ -104,7 +104,7 @@ namespace osu.Game.Database
|
||||
if (!ThreadSafety.IsUpdateThread)
|
||||
throw new InvalidOperationException($"Can't use {nameof(Value)} on managed objects from non-update threads");
|
||||
|
||||
return realmFactory.Context.Find<T>(ID);
|
||||
return realm.Realm.Find<T>(ID);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,16 +216,16 @@ namespace osu.Game.Database
|
||||
return new RealmLiveUnmanaged<T>(realmObject);
|
||||
}
|
||||
|
||||
public static List<ILive<T>> ToLive<T>(this IEnumerable<T> realmList, RealmContextFactory realmContextFactory)
|
||||
public static List<ILive<T>> ToLive<T>(this IEnumerable<T> realmList, RealmAccess realm)
|
||||
where T : RealmObject, IHasGuidPrimaryKey
|
||||
{
|
||||
return realmList.Select(l => new RealmLive<T>(l, realmContextFactory)).Cast<ILive<T>>().ToList();
|
||||
return realmList.Select(l => new RealmLive<T>(l, realm)).Cast<ILive<T>>().ToList();
|
||||
}
|
||||
|
||||
public static ILive<T> ToLive<T>(this T realmObject, RealmContextFactory realmContextFactory)
|
||||
public static ILive<T> ToLive<T>(this T realmObject, RealmAccess realm)
|
||||
where T : RealmObject, IHasGuidPrimaryKey
|
||||
{
|
||||
return new RealmLive<T>(realmObject, realmContextFactory);
|
||||
return new RealmLive<T>(realmObject, realm);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -271,8 +271,8 @@ namespace osu.Game.Database
|
||||
public static IDisposable? QueryAsyncWithNotifications<T>(this IRealmCollection<T> collection, NotificationCallbackDelegate<T> callback)
|
||||
where T : RealmObjectBase
|
||||
{
|
||||
if (!RealmContextFactory.CurrentThreadSubscriptionsAllowed)
|
||||
throw new InvalidOperationException($"Make sure to call {nameof(RealmContextFactory)}.{nameof(RealmContextFactory.RegisterForNotifications)}");
|
||||
if (!RealmAccess.CurrentThreadSubscriptionsAllowed)
|
||||
throw new InvalidOperationException($"Make sure to call {nameof(RealmAccess)}.{nameof(RealmAccess.RegisterForNotifications)}");
|
||||
|
||||
return collection.SubscribeForNotifications(callback);
|
||||
}
|
||||
|
Reference in New Issue
Block a user