public UpdateSqlBuilder(IDbConfig dbConfig) { DbConfig = dbConfig; DbType = dbConfig?.DbType ?? SupportedDatabaseTypes.Postgres; UpdateFieldSelector = new UpdateFieldSelector <TClass>(DbConfig); }
public ConsumerRocksDbProvider(string basePath, IDbConfig dbConfig, ILogManager logManager) { ConsumerDepositApprovalsDb = new ConsumerDepositApprovalsRocksDb(basePath, dbConfig, logManager); ConsumerReceiptsDb = new ConsumerReceiptsRocksDb(basePath, dbConfig, logManager); ConsumerSessionsDb = new ConsumerSessionsRocksDb(basePath, dbConfig, logManager); DepositsDb = new DepositsRocksDb(basePath, dbConfig, logManager); }
private void UpdateDbConfig(uint cpuCount, ISyncConfig syncConfig, IDbConfig dbConfig, IInitConfig initConfig) { if (initConfig.DiagnosticMode == DiagnosticMode.MemDb) { DbMemory = _remainingMemory; return; } DbMemory = _remainingMemory; long remaining = DbMemory; DbNeeds dbNeeds = GetHeaderNeeds(cpuCount, syncConfig); DbGets dbGets = GiveItWhatYouCan(dbNeeds, DbMemory, remaining); remaining -= dbGets.CacheMem + dbGets.Buffers * dbGets.SingleBufferMem; dbConfig.HeadersDbWriteBufferNumber = dbGets.Buffers; dbConfig.HeadersDbWriteBufferSize = (ulong)dbGets.SingleBufferMem; dbConfig.HeadersDbBlockCacheSize = (ulong)dbGets.CacheMem; dbNeeds = GetBlocksNeeds(cpuCount, syncConfig); dbGets = GiveItWhatYouCan(dbNeeds, DbMemory, remaining); remaining -= dbGets.CacheMem + dbGets.Buffers * dbGets.SingleBufferMem; dbConfig.BlocksDbWriteBufferNumber = dbGets.Buffers; dbConfig.BlocksDbWriteBufferSize = (ulong)dbGets.SingleBufferMem; dbConfig.BlocksDbBlockCacheSize = (ulong)dbGets.CacheMem; dbNeeds = GetBlockInfosNeeds(cpuCount, syncConfig); dbGets = GiveItWhatYouCan(dbNeeds, DbMemory, remaining); remaining -= dbGets.CacheMem + dbGets.Buffers * dbGets.SingleBufferMem; dbConfig.BlockInfosDbWriteBufferNumber = dbGets.Buffers; dbConfig.BlockInfosDbWriteBufferSize = (ulong)dbGets.SingleBufferMem; dbConfig.BlockInfosDbBlockCacheSize = (ulong)dbGets.CacheMem; dbNeeds = GetReceiptsNeeds(cpuCount, syncConfig); dbGets = GiveItWhatYouCan(dbNeeds, DbMemory, remaining); remaining -= dbGets.CacheMem + dbGets.Buffers * dbGets.SingleBufferMem; dbConfig.ReceiptsDbWriteBufferNumber = dbGets.Buffers; dbConfig.ReceiptsDbWriteBufferSize = (ulong)dbGets.SingleBufferMem; dbConfig.ReceiptsDbBlockCacheSize = (ulong)dbGets.CacheMem; dbNeeds = GetCodeNeeds(cpuCount, syncConfig); dbGets = GiveItWhatYouCan(dbNeeds, DbMemory, remaining); remaining -= dbGets.CacheMem + dbGets.Buffers * dbGets.SingleBufferMem; dbConfig.CodeDbWriteBufferNumber = dbGets.Buffers; dbConfig.CodeDbWriteBufferSize = (ulong)dbGets.SingleBufferMem; dbConfig.CodeDbBlockCacheSize = (ulong)dbGets.CacheMem; dbNeeds = GetPendingTxNeeds(cpuCount, syncConfig); dbGets = GiveItWhatYouCan(dbNeeds, DbMemory, remaining); remaining -= dbGets.CacheMem + dbGets.Buffers * dbGets.SingleBufferMem; dbConfig.PendingTxsDbWriteBufferNumber = dbGets.Buffers; dbConfig.PendingTxsDbWriteBufferSize = (ulong)dbGets.SingleBufferMem; dbConfig.PendingTxsDbBlockCacheSize = (ulong)dbGets.CacheMem; dbNeeds = GetStateNeeds(cpuCount, syncConfig); dbGets = GiveItWhatYouCan(dbNeeds, DbMemory, remaining); remaining -= dbGets.CacheMem + dbGets.Buffers * dbGets.SingleBufferMem; dbConfig.WriteBufferNumber = dbGets.Buffers; dbConfig.WriteBufferSize = (ulong)dbGets.SingleBufferMem; dbConfig.BlockCacheSize = (ulong)dbGets.CacheMem; }
private void InitDbApi(IInitConfig initConfig, IDbConfig dbConfig, bool storeReceipts) { switch (initConfig.DiagnosticMode) { case DiagnosticMode.RpcDb: _api.DbProvider = new DbProvider(DbModeHint.Persisted); var rocksDbFactory = new RocksDbFactory(dbConfig, _api.LogManager, Path.Combine(initConfig.BaseDbPath, "debug")); var rpcDbFactory = new RpcDbFactory(new MemDbFactory(), rocksDbFactory, _api.EthereumJsonSerializer, new BasicJsonRpcClient(new Uri(initConfig.RpcDbUrl), _api.EthereumJsonSerializer, _api.LogManager), _api.LogManager); _api.RocksDbFactory = rpcDbFactory; _api.MemDbFactory = rpcDbFactory; break; case DiagnosticMode.ReadOnlyDb: var rocksDbProvider = new DbProvider(DbModeHint.Persisted); _api.DbProvider = new ReadOnlyDbProvider(rocksDbProvider, storeReceipts); // ToDo storeReceipts as createInMemoryWriteStore - bug? _api.DisposeStack.Push(rocksDbProvider); _api.RocksDbFactory = new RocksDbFactory(dbConfig, _api.LogManager, Path.Combine(initConfig.BaseDbPath, "debug")); _api.MemDbFactory = new MemDbFactory(); break; case DiagnosticMode.MemDb: _api.DbProvider = new DbProvider(DbModeHint.Mem); _api.RocksDbFactory = new RocksDbFactory(dbConfig, _api.LogManager, Path.Combine(initConfig.BaseDbPath, "debug")); _api.MemDbFactory = new MemDbFactory(); break; default: _api.DbProvider = new DbProvider(DbModeHint.Persisted); _api.RocksDbFactory = new RocksDbFactory(dbConfig, _api.LogManager, initConfig.BaseDbPath); _api.MemDbFactory = new MemDbFactory(); break; } }
public MongoCollectionBase(IDbConfig dbConfig, string collectionName) { var client = new MongoClient(dbConfig.ConnectionString); var db = client.GetDatabase(DATABASE_NAME); collection = db.GetCollection <T>(collectionName); }
/// <inheritdoc/> public IDatabaseInterface Boot(IDbConfig config) { if (booted) { throw new DataException("Database was booted more than once."); } // Local connections are formatted as; // 'Local/[type]/[connect_id]' string hostString = String.Format("{0}/Boot/", KnownConnectionProtocols.Local); // Start the DbSystem and bind it to a IDatabaseInterface. if (controller.IsInitialized(databaseName)) { dbsys = controller.ConnectToDatabase(config, databaseName); } else { dbsys = controller.StartDatabase(config, databaseName); } IDatabaseInterface dbInterface = new LocalDatabaseInterface(this, hostString); booted = true; ++openConnections; return(dbInterface); }
protected ColumnsDb(string basePath, string dbPath, IDbConfig dbConfig, ILogManager logManager, params T[] keys) : base(basePath, dbPath, dbConfig, logManager, GetColumnFamilies(keys)) { foreach (var key in keys) { _columnDbs[key] = new ColumnDb(Db, this, key.ToString()); } }
private async Task <RocksDbProvider> GetRocksDbProvider(IDbConfig dbConfig, string basePath, bool useReceiptsDb) { RocksDbProvider debugRecorder = new RocksDbProvider(_context.LogManager); await debugRecorder.Init(basePath, dbConfig, useReceiptsDb); return(debugRecorder); }
public DbOnTheRocks(string basePath, string dbPath, IDbConfig dbConfig, ILogManager logManager = null) // TODO: check column families { string fullPath = dbPath.GetApplicationResourcePath(basePath); _logger = logManager?.GetClassLogger() ?? NullLogger.Instance; if (!Directory.Exists(fullPath)) { Directory.CreateDirectory(fullPath); } if (_logger.IsInfo) { _logger.Info($"Using database directory {fullPath}"); } try { DbOptions options = BuildOptions(dbConfig); _db = DbsByPath.GetOrAdd(fullPath, path => RocksDb.Open(options, path)); } catch (DllNotFoundException e) when(e.Message.Contains("libdl")) { throw new ApplicationException($"Unable to load 'libdl' necessary to init the RocksDB database. Please run{Environment.NewLine}" + "sudo apt update && sudo apt install libsnappy-dev libc6-dev libc6"); } }
public PersonRepository( ILogger <PersonRepository> logger, IDbConfig dbConfig) { Logger = logger; DbConfig = dbConfig; }
public async Task Init(string basePath, IDbConfig dbConfig, bool useReceiptsDb) { HashSet <Task> allInitializers = new HashSet <Task>(); allInitializers.Add(Task.Run(() => BlocksDb = new BlocksRocksDb(basePath, dbConfig, _logManager))); allInitializers.Add(Task.Run(() => HeadersDb = new HeadersRocksDb(basePath, dbConfig, _logManager))); allInitializers.Add(Task.Run(() => BlockInfosDb = new BlockInfosRocksDb(basePath, dbConfig, _logManager))); allInitializers.Add(Task.Run(() => StateDb = new StateDb(new StateRocksDb(basePath, dbConfig, _logManager)))); allInitializers.Add(Task.Run(() => CodeDb = new StateDb(new CodeRocksDb(basePath, dbConfig, _logManager)))); allInitializers.Add(Task.Run(() => PendingTxsDb = new PendingTxsRocksDb(basePath, dbConfig, _logManager))); allInitializers.Add(Task.Run(() => BloomDb = new BloomRocksDb(basePath, dbConfig, _logManager))); allInitializers.Add(Task.Run(() => ChtDb = new CanonicalHashRocksDb(basePath, dbConfig, _logManager))); allInitializers.Add(Task.Run(() => ConfigsDb = _addNdmDbs ? new ConfigsRocksDb(basePath, dbConfig, _logManager) : (IDb) new MemDb())); allInitializers.Add(Task.Run(() => EthRequestsDb = _addNdmDbs ? new EthRequestsRocksDb(basePath, dbConfig, _logManager) : (IDb) new MemDb())); allInitializers.Add(Task.Run(() => { if (useReceiptsDb) { ReceiptsDb = new ReceiptsRocksDb(basePath, dbConfig, _logManager); } else { ReceiptsDb = new ReadOnlyColumnsDb <ReceiptsColumns>(new MemColumnsDb <ReceiptsColumns>(), false); } })); await Task.WhenAll(allInitializers); }
/// <summary> /// Get granting users from configuration /// </summary> /// <param name="dbConfig"></param> /// <returns></returns> public static IEnumerable <string> GetUserGrantsFromConfig(this IDbConfig dbConfig) { var userGrants = dbConfig.GetAllDatabaseConfigValues() .Where(x => x.Key.ContainsIgnoreCase("grants:users") && x.Value.IsNotEmpty()) .Select(x => x.Value) .ToList(); if (userGrants.Any() == false && UserGrantsFromConfigKey.IsNotEmpty()) { var outboxSchema = dbConfig.GetAllDatabaseConfigValues().FirstOrDefault(x => x.Key.EqualsIgnoreCase($"database:{UserGrantsFromConfigKey}Schema") && x.Value.IsNotEmpty()).Value; var schema = dbConfig.GetAllDatabaseConfigValues().FirstOrDefault(x => x.Key.EqualsIgnoreCase("database:schema") && x.Value.IsNotEmpty()).Value; if (string.Equals(outboxSchema, schema, StringComparison.OrdinalIgnoreCase)) { userGrants = dbConfig.GetAllDatabaseConfigValues() .Where(x => x.Key.ContainsIgnoreCase($"grants:{UserGrantsFromConfigKey}Users") && x.Value.IsNotEmpty()) .Select(x => x.Value) .ToList(); } } var defaultAppUser = dbConfig.GetAllDatabaseConfigValues().GetValue("defaultApp:user"); if (defaultAppUser.IsNotEmpty()) { userGrants.Add(defaultAppUser); } var result = userGrants.Distinct().SelectMany(userGrant => userGrant.Split(',')).ToArray(); return(result.Select(x => x.Trim()).Distinct()); }
protected override DbOptions BuildOptions(IDbConfig dbConfig) { DbOptions options = base.BuildOptions(dbConfig); options.SetCreateMissingColumnFamilies(); return(options); }
public async Task Execute(CancellationToken _) { ILogger logger = _api.LogManager.GetClassLogger(); /* sync */ IDbConfig dbConfig = _api.Config <IDbConfig>(); ISyncConfig syncConfig = _api.Config <ISyncConfig>(); IInitConfig initConfig = _api.Config <IInitConfig>(); IPruningConfig pruningConfig = _api.Config <IPruningConfig>(); foreach (PropertyInfo propertyInfo in typeof(IDbConfig).GetProperties()) { if (logger.IsDebug) { logger.Debug($"DB {propertyInfo.Name}: {propertyInfo.GetValue(dbConfig)}"); } } try { bool useReceiptsDb = initConfig.StoreReceipts || syncConfig.DownloadReceiptsInFastSync; InitDbApi(initConfig, dbConfig, initConfig.StoreReceipts || syncConfig.DownloadReceiptsInFastSync); StandardDbInitializer dbInitializer = new(_api.DbProvider, _api.RocksDbFactory, _api.MemDbFactory, _api.FileSystem, pruningConfig.Mode.IsFull()); await dbInitializer.InitStandardDbsAsync(useReceiptsDb); } catch (TypeInitializationException e) { if (logger.IsError) { logger.Error("RocksDb was not found, please make sure it is installed on your machine. \n On macOs : 'brew install rocksdb'", e); } } }
public RocksDbProvider(string dbBasePath, ILogManager logManager, IDbConfig dbConfig) { _logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager)); _stateDb = new SnapshotableDb(new DbOnTheRocks(Path.Combine(dbBasePath, DbOnTheRocks.StateDbPath), dbConfig)); _codeDb = new SnapshotableDb(new DbOnTheRocks(Path.Combine(dbBasePath, DbOnTheRocks.CodeDbPath), dbConfig)); }
public async Task Execute() { ILogger logger = _context.LogManager.GetClassLogger(); /* sync */ IDbConfig dbConfig = _context.Config <IDbConfig>(); ISyncConfig syncConfig = _context.Config <ISyncConfig>(); IInitConfig initConfig = _context.Config <IInitConfig>(); foreach (PropertyInfo propertyInfo in typeof(IDbConfig).GetProperties()) { if (logger.IsDebug) { logger.Debug($"DB {propertyInfo.Name}: {propertyInfo.GetValue(dbConfig)}"); } } _context.DbProvider = await GetDbProvider(initConfig, dbConfig, initConfig.StoreReceipts || syncConfig.DownloadReceiptsInFastSync); if (syncConfig.BeamSync) { BeamSyncDbProvider beamSyncProvider = new BeamSyncDbProvider(_context.DbProvider, "processor DB", _context.LogManager); _context.DbProvider = beamSyncProvider; _context.NodeDataConsumer = beamSyncProvider.NodeDataConsumer; } }
public ExtendedOracleMigrationGenerator( OracleQuoterBase quoter, IDbConfig dbConfig) { Quoter = quoter; DbConfig = dbConfig; }
public CommanderService(IDbConfig settings) { var client = new MongoClient(settings.ConnectionString); var database = client.GetDatabase(settings.DbName); _CommandCollection = database.GetCollection <Command>(settings.Command); }
public static string GetAdminConnectionString(this IDbConfig dbConfig) { var dbType = dbConfig.DbType; AssertDbConnectionImplemented(dbType); return(DbConnectionProviders[dbType].GetAdminConnectionString(dbConfig)); }
/// <inheritdoc/> public IDatabaseInterface Create(string username, string password, IDbConfig config) { if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password)) { throw new DataException("Username and Password must both be set."); } if (booted) { throw new DataException("Database is already created."); } // Local connections are formatted as; // 'Local/[type]/[connect_id]' string hostString = String.Format("{0}/Create/", KnownConnectionProtocols.Local); // Create the DbSystem and bind it to a IDatabaseInterface. dbsys = controller.CreateDatabase(config, databaseName, username, password); IDatabaseInterface dbInterface = new LocalDatabaseInterface(this, hostString); booted = true; ++openConnections; return(dbInterface); }
public RocksDbProvider(string basePath, IDbConfig dbConfig, ILogManager logManager) { BlocksDb = new DbOnTheRocks( Path.Combine(basePath, DbOnTheRocks.BlocksDbPath), dbConfig, logManager); BlockInfosDb = new DbOnTheRocks( Path.Combine(basePath, DbOnTheRocks.BlockInfosDbPath), dbConfig, logManager); ReceiptsDb = new DbOnTheRocks( Path.Combine(basePath, DbOnTheRocks.ReceiptsDbPath), dbConfig, logManager); StateDb = new StateDb( new DbOnTheRocks(Path.Combine(basePath, DbOnTheRocks.StateDbPath), dbConfig, logManager)); CodeDb = new StateDb( new DbOnTheRocks(Path.Combine(basePath, DbOnTheRocks.CodeDbPath), dbConfig, logManager)); PendingTxsDb = new DbOnTheRocks( Path.Combine(basePath, DbOnTheRocks.PendingTxsDbPath), dbConfig, logManager); TraceDb = new DbOnTheRocks( Path.Combine(basePath, DbOnTheRocks.TraceDbPath), dbConfig, logManager); }
public ExtendedPostgresGenerator( PostgresQuoter quoter, IDbConfig dbConfig) { Quoter = quoter; DbConfig = dbConfig; }
public async Task Execute(CancellationToken _) { ILogger logger = _context.LogManager.GetClassLogger(); /* sync */ IDbConfig dbConfig = _context.Config <IDbConfig>(); ISyncConfig syncConfig = _context.Config <ISyncConfig>(); IInitConfig initConfig = _context.Config <IInitConfig>(); foreach (PropertyInfo propertyInfo in typeof(IDbConfig).GetProperties()) { if (logger.IsDebug) { logger.Debug($"DB {propertyInfo.Name}: {propertyInfo.GetValue(dbConfig)}"); } } _context.DbProvider = await GetDbProvider(initConfig, dbConfig, initConfig.StoreReceipts || syncConfig.DownloadReceiptsInFastSync); if (syncConfig.BeamSync) { _context.SyncModeSelector = new PendingSyncModeSelector(); BeamSyncDbProvider beamSyncProvider = new BeamSyncDbProvider(_context.SyncModeSelector, _context.DbProvider, _context.Config <ISyncConfig>(), _context.LogManager); _context.DbProvider = beamSyncProvider; } }
public RocksDbProvider(string basePath, IDbConfig dbConfig, ILogManager logManager, bool useTraceDb, bool useReceiptsDb) { BlocksDb = new BlocksRocksDb(basePath, dbConfig, logManager); HeadersDb = new HeadersRocksDb(basePath, dbConfig, logManager); BlockInfosDb = new BlockInfosRocksDb(basePath, dbConfig, logManager); StateDb = new StateDb(new StateRocksDb(basePath, dbConfig, logManager)); CodeDb = new StateDb(new CodeRocksDb(basePath, dbConfig, logManager)); PendingTxsDb = new PendingTxsRocksDb(basePath, dbConfig, logManager); ConfigsDb = new ConfigsRocksDb(basePath, dbConfig, logManager); EthRequestsDb = new EthRequestsRocksDb(basePath, dbConfig, logManager); if (useReceiptsDb) { ReceiptsDb = new ReceiptsRocksDb(basePath, dbConfig, logManager); } else { ReceiptsDb = new ReadOnlyDb(new MemDb(), false); } if (useTraceDb) { TraceDb = new TraceRocksDb(basePath, dbConfig, logManager); } else { TraceDb = new ReadOnlyDb(new MemDb(), false); } }
public async Task Init(string basePath, IDbConfig dbConfig, bool useReceiptsDb) { _dbConfig = dbConfig; _basePath = basePath; HashSet <Task> allInitializers = new HashSet <Task>(); allInitializers.Add(Task.Run(() => BlocksDb = new BlocksRocksDb(basePath, dbConfig, _logManager))); allInitializers.Add(Task.Run(() => HeadersDb = new HeadersRocksDb(basePath, dbConfig, _logManager))); allInitializers.Add(Task.Run(() => BlockInfosDb = new BlockInfosRocksDb(basePath, dbConfig, _logManager))); allInitializers.Add(Task.Run(() => StateDb = new StateDb(new StateRocksDb(basePath, dbConfig, _logManager)))); allInitializers.Add(Task.Run(() => CodeDb = new StateDb(new CodeRocksDb(basePath, dbConfig, _logManager)))); allInitializers.Add(Task.Run(() => PendingTxsDb = new PendingTxsRocksDb(basePath, dbConfig, _logManager))); allInitializers.Add(Task.Run(() => BloomDb = new BloomRocksDb(basePath, dbConfig, _logManager))); allInitializers.Add(Task.Run(() => { if (useReceiptsDb) { ReceiptsDb = new ReceiptsRocksDb(basePath, dbConfig, _logManager); } else { ReceiptsDb = new ReadOnlyDb(new MemDb(), false); } })); await Task.WhenAll(allInitializers); }
/// <summary> /// Return a new instance if IDbConnection created from dbConfig settings /// </summary> /// <param name="dbConfig"></param> /// <param name="withAdminPrivileges">If true, a IDbConnection with AdminConnectionString is created</param> /// <returns></returns> public static IDbConnection CreateDbConnection(this IDbConfig dbConfig, bool withAdminPrivileges = false) { var dbType = dbConfig.DbType; AssertDbConnectionImplemented(dbType); AssertDbProviderFactoryImplemented(dbType); return(dbConfig.GetDbProviderFactory(withAdminPrivileges).CreateConnection()); }
public string GetAdminConnectionString(IDbConfig dbConfig) => string.Format(dbConfig.ConnectionStringTemplate ?? DefaultConnectionStringTemplate, dbConfig.AdminUser.ToUpper(), dbConfig.AdminPassword, dbConfig.Hostname, dbConfig.Port, dbConfig.DatabaseConnectionName.ToLower(), dbConfig.Pooling);
public SimpleRocksDb( string basePath, RocksDbSettings rocksDbSettings, IDbConfig dbConfig, ILogManager logManager = null) : base(basePath, rocksDbSettings, dbConfig, logManager) { }
protected static void InitCache(IDbConfig dbConfig) { if (Interlocked.CompareExchange(ref _cacheInitialized, 1, 0) == 0) { _cache = RocksDbSharp.Native.Instance.rocksdb_cache_create_lru(new UIntPtr(dbConfig.BlockCacheSize)); Interlocked.Add(ref _maxRocksSize, (long)dbConfig.BlockCacheSize); } }
public DbMetricsUpdater(string dbName, DbOptions dbOptions, RocksDb db, IDbConfig dbConfig, ILogger logger) { _dbName = dbName; _dbOptions = dbOptions; _db = db; _dbConfig = dbConfig; _logger = logger; }
public static void SetTo(IDbConfig config) { //config.SetKey(DatabaseName); config.SetKey(IgnoreIdentifiersCase); config.SetKey(MaxWorkerThreads); config.SetKey(ReadOnly); config.SetKey(DefaultSchema); config.SetKey(AutoCommit); }
/// <summary> /// Constructs the <see cref="DbConfig"/> from the given parent. /// </summary> /// <param name="parent">The parent <see cref="DbConfig"/> object that /// will provide fallback configurations</param> /// <param name="source"></param> public DbConfig(IDbConfig parent, IConfigSource source) : this(false) { Parent = parent; Source = source; if (source != null) this.Load(source); }
public SystemContext(IDbConfig configuration) { if (configuration == null) throw new ArgumentNullException("configuration"); Configuration = configuration; EventRegistry = new SystemEventRegistry(this); Init(); }
public override void Configure(IDbConfig config) { base.Configure(config); // Find a prime hash size depending on the size of the cache. int hashSize = ClosestPrime(MaxCacheSize / 55); nodeHash = new ListNode[hashSize]; listStart = null; listEnd = null; }
internal DbSystem(DbController controller, string name, IDbConfig config, IDatabase database) { this.name = name; this.controller = controller; this.config = config; this.Database = database; internalCounter = 0; // Register the shut down delegate, database.Context.OnShutdown += new EventHandler(Shutdown); // Enable commands to the database system... database.Context.IsExecutingCommands = true; }
public DbContext(string cnsconfig, bool transaction, IsolationLevel il) { _cfg = GetConfiguration(cnsconfig); _cn = _cfg.GetConnection(); _cmd = _cn.CreateCommand(); _da = _cfg.GetDataAdapter(_cmd); if (transaction) { _trans = _cn.BeginTransaction(il); _cmd.Transaction = _trans; } else { _trans = null; } }
public DatabaseContext(ISystemContext systemContext, IDbConfig configuration) { if (systemContext == null) throw new ArgumentNullException("systemContext"); if (configuration == null) throw new ArgumentNullException("configuration"); SystemContext = systemContext; SystemContext.ServiceProvider.AttachContext(this); Configuration = configuration; Locker = new Locker(this); Sessions = new ActiveSessionList(this); Init(); }
public IServerConnector Boot(IDbConfig config) { if (IsBooted) throw new DatabaseException("Database was booted more than once."); // Start the DbSystem and bind it to a IDatabaseInterface. if (System.Controller.IsInitialized(databaseName)) dbsys = System.Controller.ConnectToDatabase(config, databaseName); else dbsys = System.Controller.StartDatabase(config, databaseName); var connector = new LocalEmbeddedServerConnector(this); IsBooted = true; ++openConnections; return connector; }
/// <summary> /// This object can not be constructed publicaly. /// </summary> private DbController(IDbConfig configContext) { this.configContext = configContext; databases = new Hashtable(); SetupLog(configContext); }
public UserRepository(IDbConfig config) { _config = config; }
// ---------- Static methods ---------- /// <summary> /// Creates a Database object for the given DbConfig configuration. /// </summary> /// <param name="config"></param> /// <param name="name"></param> /// <returns></returns> private static IDatabase CreateDatabase(IDbConfig config, string name) { var context = new DatabaseContext(); // Initialize the DatabaseSystem first, // ------------------------------------ // This will throw an Error exception if the database system has already // been initialized. context.Init(config); // Start the database class // ------------------------ var database = new Database(context, name); // Start up message database.Context.Logger.Trace(typeof(DbController), "Starting Database Server"); return database; }
public DbConfig(IDbConfig parent) : this(parent, null) { }
// ---------- Private methods ---------- /// <summary> /// Disposes of all the resources associated with this system. /// </summary> /// <remarks> /// It may only be called from the shutdown delegate registered /// in the constructor. /// </remarks> private void InternalDispose() { if (connections != null && connections.Count > 0) { ArrayList list = new ArrayList(connections.Keys); for (int i = list.Count - 1; i >= 0; i--) { int id = (int) list[i]; IDbConnection connection = connections[id] as IDbConnection; try { if (connection != null) connection.Dispose(); } catch(Exception) { // we ignore this ... } } } connections = null; controller = null; config = null; }
private bool ChangeDatabaseInterface(IDbConfig config, string databaseName) { if (!controller.DatabaseExists(config, databaseName)) return false; DatabaseInterface dbi; if (!dbInterfaces.TryGetValue(databaseName, out dbi)) { dbi = new DatabaseInterface(controller, databaseName, hostString); dbInterfaces[databaseName] = dbi; } Database = controller.GetDatabase(databaseName); dbInterface = dbi; return true; }
public TrackRepository(IDbConfig config) { _config = config; }
/// <inheritdoc/> public IDatabaseInterface Create(string username, string password, IDbConfig config) { if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password)) throw new DataException("Username and Password must both be set."); if (booted) throw new DataException("Database is already created."); // Local connections are formatted as; // 'Local/[type]/[connect_id]' string hostString = String.Format("{0}/Create/", KnownConnectionProtocols.Local); // Create the DbSystem and bind it to a IDatabaseInterface. dbsys = controller.CreateDatabase(config, databaseName, username, password); IDatabaseInterface dbInterface = new LocalDatabaseInterface(this, hostString); booted = true; ++openConnections; return dbInterface; }
/// <inheritdoc/> public IDatabaseInterface Boot(IDbConfig config) { if (booted) throw new DataException("Database was booted more than once."); // Local connections are formatted as; // 'Local/[type]/[connect_id]' string hostString = String.Format("{0}/Boot/", KnownConnectionProtocols.Local); // Start the DbSystem and bind it to a IDatabaseInterface. if (controller.IsInitialized(databaseName)) dbsys = controller.ConnectToDatabase(config, databaseName); else dbsys = controller.StartDatabase(config, databaseName); IDatabaseInterface dbInterface = new LocalDatabaseInterface(this, hostString); booted = true; ++openConnections; return dbInterface; }
public QueryReader(IDbConfig config) : base(config.ConnectionString) { }
private static IDbConfig GetConfig(IDbConfig parentConfig, string path, string configFile) { if (configFile == null) configFile = DefaultConfigFileName; configFile = Path.Combine(path, configFile); bool fileExists = File.Exists(configFile); if (!fileExists) { // if we didn't find the file where it was supposed to be, try to // look for a .conf file into the directory... string[] files = Directory.GetFiles(path, "*.conf"); // if, and only if, we have exactly one .conf file set it as our // config file, otherwise we quit... configFile = files.Length == 1 ? Path.GetFileName(files[0]) : configFile; fileExists = files.Length == 1; } if (!fileExists) return parentConfig; // if the config file exists, we load the settings from there... //TODO: support more formats var config = new DbConfig(parentConfig); config.Load(configFile); return config; }
public DataManagerFactory(IDbConfig Config) { config = Config; }
private void SetupLog(IDbConfig config) { //TODO: Logger = new EmptyLogger(); }
public IServerConnector Create(IDbConfig config, string userName, string password) { if (String.IsNullOrEmpty(userName)) throw new ArgumentNullException("userName"); if (String.IsNullOrEmpty(password)) throw new ArgumentNullException("password"); if (IsBooted) throw new DatabaseException("The database was already booted."); // Create the DbSystem and bind it to a IDatabaseInterface. dbsys = System.Controller.CreateDatabase(config, databaseName, userName, password); var connector = new LocalEmbeddedServerConnector(this); IsBooted = true; ++openConnections; return connector; }
public void Init(IDbConfig config) { }
public bool CheckExists(IDbConfig config) { if (IsBooted) return true; return System.Controller.DatabaseExists(config, databaseName); }
/// <summary> /// Gets the type of storage for the system defined in the /// configuration given. /// </summary> /// <param name="config">The <see cref="DbConfig">database /// configuration object</see> that defines the storage system /// for which to retrieve its kind of storage.</param> /// <returns> /// Returns a <see cref="StorageType"/> defined by the storage /// system configured. /// </returns> /// <seealso cref="GetStorageType(string)"/> private static StorageType GetStorageType(IDbConfig config) { // if we don't have any configuration given let's assume it's in-memory if (config == null) return StorageType.Memory; string typeName = config.StorageSystem(); if (typeName == null) throw new InvalidOperationException("A storage system must be specified."); return GetStorageType(typeName); }
public IServerConnector Connect(IDbConfig config) { if (!IsBooted) throw new DatabaseException("The database is not started."); var connector = new LocalEmbeddedServerConnector(this); ++openConnections; return connector; }
/// <inheritdoc/> public bool CheckExists(IDbConfig config) { if (booted) throw new DataException("The database is already booted."); return controller.DatabaseExists(config, databaseName); }
public CommandHandler(IDbConfig config, IBus bus) : base(bus, config.ConnectionString) { }
public SegmentRepository(IDbConfig config) { _config = config; }
/// <summary> /// Starts up the database identified with the given name. /// </summary> /// <param name="config">The configurations used to start the database.</param> /// <param name="name">The name of the database to start.</param> /// <returns> /// Returns a <see cref="DbSystem"/> instance used to access the database created. /// </returns> /// <exception cref="ArgumentNullException"> /// If the <paramref name="name"/> of the database is <b>null</b>. /// </exception> /// <exception cref="ArgumentException"> /// If a database with the given <paramref name="name"/> already exists. /// </exception> /// <exception cref="InvalidOperationException"> /// If an error occurred while initializing the database. /// </exception> public DbSystem StartDatabase(IDbConfig config, string name) { if (!DatabaseExists(config, name)) throw new ArgumentException("Database '" + name + "' not existing.", "name"); if (config == null) config = DbConfig.Default; config.Parent = Config; IDatabase database = GetDatabase(name); if (database.IsInitialized) throw new ArgumentException("The database is already initialized."); // First initialise the database try { database.Init(); } catch (DatabaseException e) { database.Context.Logger.Error(this, "Database init failed"); database.Context.Logger.Error(this, e); throw new InvalidOperationException(e.Message); } // Return the DbSystem object for the newly created database. return new DbSystem(this, name, config, database); }