public static void Load(LightDBMapper mapper, bool failException) { try { if (EnableCaching && mapper.SupportsCaching && mapper.LoadCache()) { return; } mapper.Fetch(); if (!EnableCaching || !mapper.SupportsCaching) { return; } log.Info("Saving cache for: " + mapper.Mapping.DataHolderDefinitions .ToString(", ")); mapper.SaveCache(); } catch (Exception ex) { if (failException) { throw new ContentException(ex, "Unable to load entries using \"{0}\"", (object)mapper); } } }
private static bool LoadCache(this LightDBMapper mapper) { var file = GetCacheFilename(mapper); if (mapper.IsCached()) { try { // Utility.Measure("Loading contnt from Cache - " + mapper, 1, () => { if (mapper.LoadCache(file)) { // loaded cache successfully return(true); } log.Warn("Cache signature in file \"{0}\" is out of date.", file); log.Warn("Reloading content from Database..."); //}); //return; } catch (Exception ex) { if (ex is EndOfStreamException) { log.Warn("Cache signature in file \"{0}\" is out of date.", file); } else { LogUtil.ErrorException(ex, "Unable to load cache from \"" + file + "\"."); } log.Warn("Reloading content from Database..."); } } return(false); }
public static void Load(LightDBMapper mapper, bool failException) { try { if (ContentMgr.EnableCaching && mapper.SupportsCaching && mapper.LoadCache()) { return; } mapper.Fetch(); if (!ContentMgr.EnableCaching || !mapper.SupportsCaching) { return; } ContentMgr.log.Info("Saving cache for: " + ((IEnumerable <DataHolderDefinition>)mapper.Mapping.DataHolderDefinitions) .ToString <DataHolderDefinition>(", ")); mapper.SaveCache(); } catch (Exception ex) { if (failException) { throw new ContentException(ex, "Unable to load entries using \"{0}\"", new object[1] { (object)mapper }); } } }
private static bool LoadCache(this LightDBMapper mapper) { string cacheFilename = mapper.GetCacheFilename(); if (mapper.IsCached()) { try { if (mapper.LoadCache(cacheFilename)) { return(true); } ContentMgr.log.Warn("Cache signature in file \"{0}\" is out of date.", cacheFilename); ContentMgr.log.Warn("Reloading content from Database..."); } catch (Exception ex) { if (ex is EndOfStreamException) { ContentMgr.log.Warn("Cache signature in file \"{0}\" is out of date.", cacheFilename); } else { LogUtil.ErrorException(ex, "Unable to load cache from \"" + cacheFilename + "\".", new object[0]); } ContentMgr.log.Warn("Reloading content from Database..."); } } return(false); }
public static void Load(LightDBMapper mapper, bool failException) { try { if (EnableCaching && mapper.SupportsCaching) { if (mapper.LoadCache()) { // loaded cache successfully return; } } //Utility.Measure("Loading content from DB - " + mapper + "", 1, () => { mapper.Fetch(); //}); if (EnableCaching && mapper.SupportsCaching) { log.Info("Saving cache for: " + mapper.Mapping.DataHolderDefinitions.ToString(", ")); mapper.SaveCache(); } } catch (Exception e) { if (failException) { throw new ContentException(e, "Unable to load entries using \"{0}\"", mapper); } // LogUtil.ErrorException(e, "Unable to load entries using \"{0}\"", mapper); } }
public static void FlushCache(this LightDBMapper mapper) { var file = GetCacheFilename(mapper); if (File.Exists(file)) { File.Delete(file); } }
public static void FlushCache(this LightDBMapper mapper) { string cacheFilename = mapper.GetCacheFilename(); if (!File.Exists(cacheFilename)) { return; } File.Delete(cacheFilename); }
public static string GetCacheFilename(this LightDBMapper mapper) { var str = new StringBuilder(mapper.Mapping.DataHolderDefinitions.Length * 12); foreach (var def in mapper.Mapping.DataHolderDefinitions) { str.Append(def.Name); } str.Append(CacheFileSuffix); return(RealmServerConfiguration.Instance.GetCacheFile(str.ToString())); }
public static string GetCacheFilename(this LightDBMapper mapper) { StringBuilder stringBuilder = new StringBuilder(mapper.Mapping.DataHolderDefinitions.Length * 12); foreach (DataHolderDefinition holderDefinition in mapper.Mapping.DataHolderDefinitions) { stringBuilder.Append(holderDefinition.Name); } stringBuilder.Append(".cache"); return(RealmServerConfiguration.Instance.GetCacheFile(stringBuilder.ToString())); }
public void Prepare(LightDBMapper mapper) { TableDefinition[] tableDefinitions = mapper.Mapping.TableDefinitions; m_selectCommands = new IDbCommand[tableDefinitions.Length]; for (int index = 0; index < tableDefinitions.Length; ++index) { TableDefinition tableDefinition = tableDefinitions[index]; IDbCommand command = CreateCommand(SqlUtil.BuildSelect(tableDefinition.AllColumns, tableDefinition.Name)); m_selectCommands[index] = command; } }
public static Dictionary <Type, LightDBMapper> CreateMappersByType() { var map = new Dictionary <Type, LightDBMapper>(); foreach (var mapping in s_definitions.Mappings) { var mapper = new LightDBMapper(mapping, new NHibernateDbWrapper()); foreach (var def in mapping.DataHolderDefinitions) { map.Add(def.Type, mapper); } } return(map); }
public void Prepare(LightDBMapper mapper) { var tables = mapper.Mapping.TableDefinitions; m_selectCommands = new IDbCommand[tables.Length]; for (var i = 0; i < tables.Length; i++) { var table = tables[i]; var cmd = CreateCommand(SqlUtil.BuildSelect(table.AllColumns, table.Name) //+ " ORDER BY " + table.PrimaryColumns[0].Name ); //tables[i].QueryString, emptySqlTypeArr); m_selectCommands[i] = cmd; } }
public void Prepare(LightDBMapper mapper) { var tables = mapper.Mapping.TableDefinitions; m_selectCommands = new IDbCommand[tables.Length]; for (var i = 0; i < tables.Length; i++) { var table = tables[i]; var cmd = CreateCommand(string.Format("select {0} from {1}",string.Join(",",table.AllColumns), table.Name) //TODO: Check this generates the query as intended //+ " ORDER BY " + table.PrimaryColumns[0].Name ); //tables[i].QueryString, emptySqlTypeArr); m_selectCommands[i] = cmd; } }
public static void SaveCache(this LightDBMapper mapper) { string cacheFilename = mapper.GetCacheFilename(); try { mapper.SaveCache(cacheFilename); } catch (Exception ex) { File.Delete(cacheFilename); LogUtil.ErrorException(ex, "Failed to save cache to file: " + cacheFilename, new object[0]); } }
public static void SaveCache(this LightDBMapper mapper) { // save cache after loading var file = GetCacheFilename(mapper); try { mapper.SaveCache(file); } catch (Exception e) { File.Delete(file); LogUtil.ErrorException(e, "Failed to save cache to file: " + file); } }
public static Dictionary <Type, LightDBMapper> CreateMappersByType() { Dictionary <Type, LightDBMapper> dictionary = new Dictionary <Type, LightDBMapper>(); foreach (DataHolderTableMapping mapping in ContentMgr.s_definitions.Mappings) { LightDBMapper lightDbMapper = new LightDBMapper(mapping, (IDbWrapper) new NHibernateDbWrapper()); foreach (DataHolderDefinition holderDefinition in mapping.DataHolderDefinitions) { dictionary.Add(holderDefinition.Type, lightDbMapper); } } return(dictionary); }
/// <summary> /// Ensures that the DataHolder of the given type and those that are connected with it, are loaded. /// /// </summary> /// <param name="force">Whether to re-load if already loaded.</param> public static bool Load <T>(bool force) where T : IDataHolder { ContentMgr.EnsureInitialized(); LightDBMapper mapper = ContentMgr.GetMapper <T>(); if (!force && mapper.Fetched) { return(false); } if (force && mapper.IsCached()) { mapper.FlushCache(); } ContentMgr.Load(mapper); return(true); }
/// <summary> /// Flush all commited changes to the underlying Database. /// FlushCommit() needs to be called to persist the operation. /// Will be executed in the global IO context. /// </summary> public static void FlushCommit(Type t) { LightDBMapper mapper = GetMapper(t); ServerApp <RealmServer> .IOQueue.ExecuteInContext(() => mapper.Flush()); }
public static bool IsCached(this LightDBMapper mapper) { var file = GetCacheFilename(mapper); return(File.Exists(file)); }
public static bool IsCached(this LightDBMapper mapper) { return(File.Exists(mapper.GetCacheFilename())); }
/// <summary> /// Flush all commited changes to the underlying Database. /// FlushCommit() needs to be called to persist the operation. /// Will be executed in the global IO context. /// </summary> public static void FlushCommit(Type t) { LightDBMapper mapper = ContentMgr.GetMapper(t); ServerApp <WCell.RealmServer.RealmServer> .IOQueue.ExecuteInContext((Action)(() => mapper.Flush())); }
/// <summary> /// Flush all commited changes to the underlying Database. /// FlushCommit() needs to be called to persist the operation. /// Will be executed in the global IO context. /// </summary> public static void FlushCommit <T>() where T : IDataHolder { LightDBMapper mapper = ContentMgr.GetMapper(typeof(T)); ServerApp <WCell.RealmServer.RealmServer> .IOQueue.ExecuteInContext((Action)(() => mapper.Flush())); }
public static void Load(LightDBMapper mapper) { Load(mapper, true); }
public static void Load(LightDBMapper mapper) { ContentMgr.Load(mapper, true); }