Inheritance: IDatabaseObject
Esempio n. 1
0
        public ICollection<IDatabaseObject> ReadDatabaseObjects()
        {
            var databaseObject = new DatabaseObject {Type = _cfg.GetMandatoryConfigValue("RootObject") };
            LoadObject(databaseObject);

            return new List<IDatabaseObject> { databaseObject };
        }
Esempio n. 2
0
        private void LoadChildObjects(IDatabaseObject dbObject)
        {
            if (null == dbObject)
            {
                return;
            }

            var objectType = dbObject.Type;
            var childObjectsString = _cfg.GetConfigValue($"{objectType}.ChildObjectTypes");
            if (string.IsNullOrEmpty(childObjectsString))
            {
                return;
            }

            var childObjectTypes = childObjectsString.Split(",;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            foreach (var childObjectType in childObjectTypes)
            {
                var dataDictionaryTablesString = _cfg.GetMandatoryConfigValue($"{childObjectType}.DataDictionaryTables");
                var dataDictionaryTables = dataDictionaryTablesString.Split(",;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                var primaryDataDictionaryTable = dataDictionaryTables.First();

                var sqlCmd = _cfg.GetConfigValue($"{childObjectType}.{primaryDataDictionaryTable}.SQL");
                sqlCmd = ApplyContentToCriteria(dbObject, sqlCmd);

                using (var cmd = new OracleCommand())
                {
                    cmd.Connection = GetDbConnection();
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = sqlCmd;

                    var reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        var childObject = new DatabaseObject { Type = childObjectType, ParentObject = dbObject };
                        var propertiesDictionary = new Dictionary<string, object>();

                        for (var fieldIndex = 0; fieldIndex < reader.FieldCount; fieldIndex++)
                        {
                            propertiesDictionary.Add(reader.GetName(fieldIndex).ToLowerInvariant(), reader.GetValue(fieldIndex));
                        }
                        childObject.Properties.Add(primaryDataDictionaryTable.ToLowerInvariant(),propertiesDictionary);
                        LoadObject(childObject);
                        dbObject.ChildObjects.Add(childObject);
                    }
                }
            }
        }