private void CopyMembers(GraywulfDataset old)
        {
            this.context = old.context;

            this.databaseDefinition = new EntityProperty <DatabaseDefinition>(old.databaseDefinition);
            this.databaseVersion    = new EntityProperty <DatabaseVersion>(old.databaseVersion);
            this.databaseInstance   = new EntityProperty <DatabaseInstance>(old.databaseInstance);
        }
Exemple #2
0
        public static GraywulfDataset CreateDataset(DatabaseDefinition dd)
        {
            if (dd.RunningState != RunningState.Running)
            {
                throw new SchemaException(String.Format(ExceptionMessages.AccessDeniedToDataset, dd.Name));
            }

            GraywulfDataset ds = new GraywulfDataset();
            ds.Name = dd.Name;
            ds.DatabaseDefinition.Value = dd;
            ds.IsCacheable = true;

            ds.CacheSchemaConnectionString();

            return ds;
        }
Exemple #3
0
        public static GraywulfDataset CreateDataset(DatabaseDefinition dd)
        {
            if (dd.RunningState != RunningState.Running)
            {
                throw new SchemaException(String.Format(ExceptionMessages.AccessDeniedToDataset, dd.Name));
            }

            GraywulfDataset ds = new GraywulfDataset();

            ds.Name = dd.Name;
            ds.DatabaseDefinition.Value = dd;
            ds.IsCacheable = true;

            ds.CacheSchemaConnectionString();

            return(ds);
        }
        protected override void GetInitializedQuery_Graywulf(QueryBase query, string queryString, string outputTable)
        {
            var federationname = Federation.AppSettings.FederationName;

            var ef = new EntityFactory(Context);

            var federation = ef.LoadEntity<Federation>(federationname);

            var jd = ef.LoadEntity<JobDefinition>(federationname, typeof(SqlQueryJob).Name);

            var user = new User(Context);
            user.Guid = Context.UserGuid;
            user.Load();

            // Load settings
            // **** TODO: this always takes settings from SqlQueryJob!!
            var settings = Jhu.Graywulf.Registry.Util.LoadSettings<Settings>(jd.Settings);

            query.ExecutionMode = ExecutionMode.Graywulf;
            query.FederationReference.Name = federationname;
            query.QueryString = queryString;

            query.SourceDatabaseVersionName = settings[Settings.HotDatabaseVersionName];
            query.StatDatabaseVersionName = settings[Settings.StatDatabaseVersionName];

            query.QueryTimeout = int.Parse(settings[Settings.LongQueryTimeout]);

            // Add MyDB as custom source
            var mydbds = new GraywulfDataset();
            mydbds.Name = settings[Settings.DefaultDatasetName];
            mydbds.DefaultSchemaName = settings[Settings.DefaultSchemaName];
            mydbds.DatabaseInstance.Value = user.GetUserDatabaseInstance(federation.MyDBDatabaseVersion);
            mydbds.CacheSchemaConnectionString();
            query.CustomDatasets.Add(mydbds);

            query.DefaultDataset = mydbds;

            // Set up MYDB for destination
            // ****** TODO add output table name to settings */
            query.Destination.Table = new Table()
            {
                Dataset = mydbds,
                SchemaName = settings[Settings.DefaultSchemaName],
                TableName = String.IsNullOrWhiteSpace(outputTable) ? "outputtable" : outputTable
            };
            query.Destination.Operation = DestinationTableOperation.Drop | DestinationTableOperation.Create;

            // Set up temporary database
            var tempds = new GraywulfDataset();
            tempds.IsOnLinkedServer = false;
            tempds.DatabaseVersion.Value = federation.TempDatabaseVersion;
            query.TemporaryDataset = tempds;
            query.TemporaryDataset.DefaultSchemaName = settings[Settings.TemporarySchemaName];

            // Set up code database
            var codeds = new GraywulfDataset();
            codeds.Name = "Code";   //  *** TODO
            codeds.IsOnLinkedServer = false;
            codeds.DatabaseVersion.Value = federation.CodeDatabaseVersion;
            query.CodeDataset = codeds;
            query.CodeDataset.DefaultSchemaName = "dbo";    // *** TODO
        }
        protected void LoadSystemDatabaseInstance(EntityProperty<DatabaseInstance> databaseInstance, GraywulfDataset dataset, bool forceReinitialize)
        {
            if (!AssignedServerInstanceReference.IsEmpty && (databaseInstance.IsEmpty || forceReinitialize))
            {
                dataset.Context = Context;
                var dd = dataset.DatabaseVersion.Value.DatabaseDefinition;

                dd.LoadDatabaseInstances(false);
                foreach (var di in dd.DatabaseInstances.Values)
                {
                    di.Context = Context;
                }

                // Find database instance that is on the same machine
                try
                {
                    // TODO: only server instance and database definition is checked here, maybe database version would be better
                    databaseInstance.Value = dd.DatabaseInstances.Values.FirstOrDefault(ddi => ddi.ServerInstanceReference.Guid == AssignedServerInstance.Guid);
                    databaseInstance.Value.GetConnectionString();
                }
                catch (Exception ex)
                {
                    throw new Exception("Cannot determine system database", ex); // TODO ***
                }
            }
            else if (AssignedServerInstanceReference.IsEmpty)
            {
                databaseInstance.Value = null;
            }
        }
 public GraywulfDataset(GraywulfDataset old)
     : base(old)
 {
     CopyMembers(old);
 }
Exemple #7
0
 public GraywulfDataset(GraywulfDataset old)
     : base(old)
 {
     CopyMembers(old);
 }
Exemple #8
0
        private void CopyMembers(GraywulfDataset old)
        {
            this.context = old.context;

            this.databaseDefinition = new EntityProperty<DatabaseDefinition>(old.databaseDefinition);
            this.databaseVersion = new EntityProperty<DatabaseVersion>(old.databaseVersion);
            this.databaseInstance = new EntityProperty<DatabaseInstance>(old.databaseInstance);
        }
Exemple #9
0
        protected override void GetInitializedQuery_Graywulf(QueryBase query, string queryString, string outputTable)
        {
            var ef = new EntityFactory(Context);

            var federation = ef.LoadEntity<Federation>(Registry.AppSettings.FederationName);
            var jd = ef.LoadEntity<JobDefinition>(Registry.AppSettings.FederationName, typeof(SqlQueryJob).Name);

            var settings = new SqlQueryJobSettings(jd.Settings);

            var user = new User(Context);
            user.Guid = Context.UserGuid;
            user.Load();

            query.ExecutionMode = ExecutionMode.Graywulf;
            query.FederationReference.Name = Registry.AppSettings.FederationName;
            query.QueryString = queryString;

            query.SourceDatabaseVersionName = settings.HotDatabaseVersionName;
            query.StatDatabaseVersionName = settings.StatDatabaseVersionName;

            query.QueryTimeout = settings.QueryTimeout;

            // Add MyDB as custom source
            var mydbds = new GraywulfDataset();
            mydbds.Name = settings.DefaultDatasetName;
            mydbds.DefaultSchemaName = settings.DefaultSchemaName;
            mydbds.DatabaseInstance.Value = federation.MyDBDatabaseVersion.GetUserDatabaseInstance(user);
            mydbds.CacheSchemaConnectionString();
            mydbds.IsMutable = true;
            query.CustomDatasets.Add(mydbds);

            query.DefaultDataset = mydbds;

            // Set up MYDB for destination
            // ****** TODO add output table name to settings */
            query.Destination = new DestinationTable(
                mydbds,
                mydbds.DatabaseName,
                settings.DefaultSchemaName,
                String.IsNullOrWhiteSpace(outputTable) ? "outputtable" : outputTable,
                TableInitializationOptions.Drop | TableInitializationOptions.Create);

            // Set up temporary database
            var tempds = new GraywulfDataset();
            tempds.Name = Registry.Constants.TempDbName;
            tempds.IsOnLinkedServer = false;
            tempds.DatabaseVersion.Value = federation.TempDatabaseVersion;
            query.TemporaryDataset = tempds;

            // Set up code database
            var codeds = new GraywulfDataset();
            codeds.Name = Registry.Constants.CodeDbName;
            codeds.IsOnLinkedServer = false;
            codeds.DatabaseVersion.Value = federation.CodeDatabaseVersion;
            query.CodeDataset = codeds;
        }