예제 #1
0
파일: Database.cs 프로젝트: yuanfei05/vita
        // 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
        }
예제 #2
0
        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;
        }
예제 #3
0
 public DbModelLoader(DbSettings settings, MemoryLog log)
 {
     Settings = settings;
       Log = log;
       Driver = Settings.ModelConfig.Driver;
       SetupSchemas(Settings.GetSchemas());
 }
예제 #4
0
 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;
 }
예제 #5
0
 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);
 }
예제 #6
0
 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)
 {
 }
예제 #7
0
        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);
            }
        }
예제 #8
0
        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;
        }
예제 #9
0
        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));
        }
예제 #10
0
 public LinqSqlProvider(DbModel dbModel)
 {
     DbModel = dbModel;
     Driver = dbModel.Driver;
 }
예제 #11
0
 public DbTypeRegistry(DbDriver driver)
 {
     Driver = driver;
 }
예제 #12
0
 public DbModelLoader(DbSettings settings, IActivationLog log)
 {
     Settings = settings;
     Log      = log;
     Driver   = Settings.ModelConfig.Driver;
 }
예제 #13
0
        //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");
        }
예제 #14
0
 public DbSqlDialect(DbDriver driver, SqlPrecedenceHandler precedenceHandler = null)
 {
     _driver           = driver;
     PrecedenceHandler = precedenceHandler ?? new SqlPrecedenceHandler();
     InitTemplates();
 }
예제 #15
0
 //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);
       }
 }
예제 #16
0
 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;
       }
 }