|
|
|
@ -250,49 +250,48 @@ public final function LocalDatabaseInstance LoadLocal(BaseText databaseName)
|
|
|
|
|
local DBRecord rootRecord; |
|
|
|
|
local Text rootRecordName; |
|
|
|
|
local LocalDatabase newConfig; |
|
|
|
|
local LocalDatabaseInstance newLocalDBInstance, result; |
|
|
|
|
local LocalDatabaseInstance newLocalDBInstance; |
|
|
|
|
local Text dbKey; |
|
|
|
|
|
|
|
|
|
if (databaseName == none) { |
|
|
|
|
return none; |
|
|
|
|
} |
|
|
|
|
CreateLocalDBMapIfMissing(); |
|
|
|
|
dbKey = databaseName.Copy(); |
|
|
|
|
if (loadedLocalDatabases.HasKey(dbKey)) |
|
|
|
|
if (loadedLocalDatabases.HasKey(databaseName)) |
|
|
|
|
{ |
|
|
|
|
result = LocalDatabaseInstance(loadedLocalDatabases.GetItem(dbKey)); |
|
|
|
|
_.memory.Free(dbKey); |
|
|
|
|
return result; |
|
|
|
|
return LocalDatabaseInstance(loadedLocalDatabases |
|
|
|
|
.GetItem(databaseName)); |
|
|
|
|
} |
|
|
|
|
// No need to check `dbKey` for being valid, |
|
|
|
|
// No need to check `databaseName` for being valid, |
|
|
|
|
// since `Load()` will just return `none` if it is not. |
|
|
|
|
newConfig = class'LocalDatabase'.static.Load(dbKey); |
|
|
|
|
newConfig = class'LocalDatabase'.static.Load(databaseName); |
|
|
|
|
if (newConfig == none) { |
|
|
|
|
_.memory.Free(dbKey); |
|
|
|
|
return none; |
|
|
|
|
} |
|
|
|
|
if (!newConfig.HasDefinedRoot() && !newConfig.ShouldCreateIfMissing()) { |
|
|
|
|
_.memory.Free(dbKey); |
|
|
|
|
return none; |
|
|
|
|
} |
|
|
|
|
newLocalDBInstance = LocalDatabaseInstance(_.memory.Allocate(localDBClass)); |
|
|
|
|
dbKey = databaseName.Copy(); |
|
|
|
|
loadedLocalDatabases.SetItem(dbKey, newLocalDBInstance); |
|
|
|
|
dbKey.FreeSelf(); |
|
|
|
|
if (newConfig.HasDefinedRoot()) |
|
|
|
|
{ |
|
|
|
|
rootRecordName = newConfig.GetRootName(); |
|
|
|
|
rootRecord = class'DBRecord'.static.LoadRecord(rootRecordName, dbKey); |
|
|
|
|
rootRecord = class'DBRecord'.static |
|
|
|
|
.LoadRecord(rootRecordName, databaseName); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
rootRecord = class'DBRecord'.static.NewRecord(dbKey); |
|
|
|
|
rootRecord = class'DBRecord'.static.NewRecord(databaseName); |
|
|
|
|
rootRecordName = _.text.FromString(string(rootRecord.name)); |
|
|
|
|
newConfig.SetRootName(rootRecordName); |
|
|
|
|
newConfig.Save(); |
|
|
|
|
} |
|
|
|
|
newLocalDBInstance.Initialize(newConfig, rootRecord); |
|
|
|
|
_.logger.Auto(infoLocalDatabaseLoaded).Arg(dbKey); |
|
|
|
|
_.logger.Auto(infoLocalDatabaseLoaded).Arg(databaseName.Copy()); |
|
|
|
|
_.memory.Free(rootRecordName); |
|
|
|
|
_.memory.Free(newLocalDBInstance); |
|
|
|
|
return newLocalDBInstance; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|