// constructors public Database(EntityApp app, DbSettings settings) { _app = app; Settings = settings; _driver = Settings.ModelConfig.Driver; _entityModel = app.Model; _timeService = _app.TimeService; //Set list of all schemas var allSchemas = app.Areas.Select(a => settings.ModelConfig.GetSchema(a)); settings.SetSchemas(allSchemas); //Check if model is shared bool modelIsShared = Settings.ModelConfig.Options.IsSet(DbOptions.ShareDbModel); lock (_lock) { //we need lock to prevent collision on shared model if (modelIsShared) DbModel = Settings.ModelConfig.SharedDbModel; if (DbModel == null) { var dbmBuilder = new DbModelBuilder(app.Model, settings.ModelConfig, app.ActivationLog); DbModel = dbmBuilder.Build(); if (modelIsShared) Settings.ModelConfig.SharedDbModel = DbModel; } }//lock //Save }
int _tableKeyIndex; //is used to generate unique index names #endregion Fields #region Constructors public DbModelBuilder(EntityModel entityModel, DbModelConfig config, MemoryLog log) { _entityModel = entityModel; _config = config; _log = log; _driver = _config.Driver; }
public DbModelLoader(DbSettings settings, MemoryLog log) { Settings = settings; Log = log; Driver = Settings.ModelConfig.Driver; SetupSchemas(Settings.GetSchemas()); }
public DbBatchCommandSetBuilder(Database db, UpdateSet updateSet) { _db = db; _driver = _db.DbModel.Driver; _updateSet = updateSet; // Clear identity holders in record.CustomTag if (_updateSet.UsesOutParams) foreach (var rec in updateSet.AllRecords) rec.CustomTag = null; }
public DbUpdateConfig(XmlDocument xmlConfig) { ProviderType = xmlConfig.GetValue(ToolConfigNames.Provider); ConnectionString = xmlConfig.GetValue(ToolConfigNames.ConnectionString); Driver = ToolHelper.CreateDriver(ProviderType, ConnectionString); ModelUpdateOptions = ReflectionHelper.ParseEnum<DbUpgradeOptions>(xmlConfig.GetValue(ToolConfigNames.ModelUpdateOptions)); DbOptions = ReflectionHelper.ParseEnum<DbOptions>(xmlConfig.GetValue(ToolConfigNames.DbOptions)); AssemblyPath = xmlConfig.GetValue(ToolConfigNames.AssemblyPath); AppClassName = xmlConfig.GetValue(ToolConfigNames.AppClassName); OutputPath = xmlConfig.GetValue(ToolConfigNames.OutputPath); }
public DbSettings(DbDriver driver, DbOptions options, string connectionString, string schemaManagementConnectionString = null, DbUpgradeMode upgradeMode = DbUpgradeMode.NonProductionOnly, DbUpgradeOptions upgradeOptions = DbUpgradeOptions.Default, IDbInfoService dbInfoProvider = null, string dataSourceName = null, DbNamingPolicy namingPolicy = null) : this(new DbModelConfig(driver, options, namingPolicy), connectionString, schemaManagementConnectionString, upgradeMode, upgradeOptions, dbInfoProvider, dataSourceName) { }
public DbModelLoader(DbSettings settings, SystemLog log) { Settings = settings; Log = log; Driver = Settings.ModelConfig.Driver; // if Settings.Schemas set is not empty, set these as restriction/filter var schemas = Settings.GetSchemas().ToList(); if (schemas.Count > 0) { SetSchemasSubSet(schemas); } }
public DbModelConfig(DbDriver driver, DbOptions options = DbOptions.Default, DbNamingPolicy namingPolicy = null, IDictionary<string, string> schemaMappings = null) { Driver = driver; Options = options; NamingPolicy = namingPolicy ?? new DbNamingPolicy(); //import schema mappings if (schemaMappings != null) foreach (var de in schemaMappings) SchemaMappings[de.Key] = de.Value; //Verify options if (!Driver.Supports(DbFeatures.StoredProcedures)) Options &= ~DbOptions.UseStoredProcs; //Batch mode is not available without stored procedures if (!Options.IsSet(DbOptions.UseStoredProcs)) Options &= ~DbOptions.UseBatchMode; }
public DbFirstConfig(XmlDocument xmlConfig) { ProviderType = xmlConfig.GetValue(ToolConfigNames.Provider); ConnectionString = xmlConfig.GetValue(ToolConfigNames.ConnectionString); Driver = ToolHelper.CreateDriver(ProviderType, ConnectionString); Options = ReflectionHelper.ParseEnum<DbFirstOptions>(xmlConfig.GetValue(ToolConfigNames.Options)); Schemas = xmlConfig.GetValueList(ToolConfigNames.Schemas); OutputPath = xmlConfig.GetValue(ToolConfigNames.OutputPath); Namespace = xmlConfig.GetValue(ToolConfigNames.Namespace); AppClassName = xmlConfig.GetValue(ToolConfigNames.AppClassName); var autoValueSpec = xmlConfig.GetValue(ToolConfigNames.AutoValues); AutoValues = ParseAutoValuesSpec(autoValueSpec); var dataTypesSpec = xmlConfig.GetValue(ToolConfigNames.ForceDataTypes); ForceDataTypes = ParseDataTypesSpec(dataTypesSpec); IgnoreTables = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase); var ignoreList = xmlConfig.GetValue(ToolConfigNames.IgnoreTables); if(!string.IsNullOrWhiteSpace(ignoreList)) IgnoreTables.UnionWith(ignoreList.Split(new [] {',', ';'}, StringSplitOptions.RemoveEmptyEntries)); }
public LinqSqlProvider(DbModel dbModel) { DbModel = dbModel; Driver = dbModel.Driver; }
public DbTypeRegistry(DbDriver driver) { Driver = driver; }
public DbModelLoader(DbSettings settings, IActivationLog log) { Settings = settings; Log = log; Driver = Settings.ModelConfig.Driver; }
//Prepares for full run with a specified server internal static void Reset(TestConfig config) { if(BooksApp != null) BooksApp.Flush(); Thread.Sleep(100); //to allow log dump of buffered messages DeleteLogFiles(); //it will happen only once WriteLog("\r\n------------------------ " + config.ToString() + "---------------------------------------------\r\n\r\n"); ServerType = config.ServerType; CacheEnabled = config.EnableCache; UseBatchMode = config.UseBatchMode; BooksApp = null; _initFailed = false; var protectedSection = (NameValueCollection)ConfigurationManager.GetSection("protected"); //Load connection string ConnectionString = ReplaceBinFolderToken(protectedSection[ServerType + "ConnectionString"]); Util.Check(!string.IsNullOrEmpty(ConnectionString), "Connection string not found for server: {0}.", ServerType); LogConnectionString = ReplaceBinFolderToken(protectedSection[ServerType + "LogConnectionString"]); LogConnectionString = LogConnectionString ?? ConnectionString; LoginCryptoKey = protectedSection["LoginInfoCryptoKey"]; Driver = ToolHelper.CreateDriver(ServerType, ConnectionString); var dbOptions = ToolHelper.GetDefaultOptions(ServerType); if (config.UseStoredProcs) dbOptions |= DbOptions.UseStoredProcs; else dbOptions &= ~DbOptions.UseStoredProcs; if (config.UseBatchMode) dbOptions |= DbOptions.UseBatchMode; else dbOptions &= ~DbOptions.UseBatchMode; // dbOptions |= DbOptions.ForceArraysAsLiterals; -- just to test this flag DbSettings = new DbSettings(Driver, dbOptions, ConnectionString, upgradeMode: DbUpgradeMode.Always); //Test: remap login schema into login2 DbSettings.ModelConfig.MapSchema("login", "login2"); }
public DbSqlDialect(DbDriver driver, SqlPrecedenceHandler precedenceHandler = null) { _driver = driver; PrecedenceHandler = precedenceHandler ?? new SqlPrecedenceHandler(); InitTemplates(); }
//Prepares for full run with a specified server public static void Reset(DbServerType serverType) { ServerType = serverType; //Load connection string var connStringName = ServerType.ToString() + "ConnectionString"; var connString = ConfigurationManager.AppSettings[connStringName]; Util.Check(!string.IsNullOrEmpty(connString), "Connection string not found for key: {0}.", connStringName); if(connString.Contains("{bin}")) { var asmPath = Assembly.GetExecutingAssembly().Location; var binFolder = Path.GetDirectoryName(asmPath); connString = connString.Replace("{bin}", binFolder); } ConnectionString = connString; Driver = ToolHelper.CreateDriver(ServerType); //, ConnectionString); DbOptions = ToolHelper.GetDefaultOptions(ServerType); //enable stored procs DbOptions &= ~DbOptions.UseStoredProcs; //it is on by default var useSp = ConfigurationManager.AppSettings["useStoredProcs"] == "true"; if (useSp && Driver.Supports(DbFeatures.StoredProcedures)) DbOptions |= Data.DbOptions.UseStoredProcs; //enable batch var useBatch = ConfigurationManager.AppSettings["useBatchMode"] == "true"; if(useBatch && Driver.Supports(DbFeatures.BatchedUpdates)) DbOptions |= DbOptions.UseBatchMode; //check connection string error; if(!ToolHelper.TestConnection(Driver, ConnectionString, out error)) { Util.Throw("Failed to connection to the database: {0} \r\n Connection string: {1}", error, ConnectionString); } }
public static bool TestConnection(DbDriver driver, string connString, out string message) { message = null; var conn = driver.CreateConnection(connString); try { conn.Open(); conn.Close(); return true; } catch(Exception ex) { message = " Connection test failed: " + ex.Message; return false; } }