Exemple #1
0
        private object LookupName(ConsolidationType lookupType, string publicIdColumn, long lookupResId)
        {
            object rv = DBNull.Value;

            var rn = _caches.NameCache.Get(ConsolidationTypeUtils.ToEntity(lookupType), lookupResId, _configuration);

            if (publicIdColumn.Contains("unique"))
            {
                if (!string.IsNullOrEmpty(rn.UniqueName))
                {
                    rv = rn.UniqueName;
                }
            }
            else if (!string.IsNullOrEmpty(rn.Name))
            {
                rv = rn.Name;
            }

            return(rv);
        }
Exemple #2
0
        public ResourceName Get(ConsolidationType cType, long id, DataStoreConfiguration c)
        {
            var et = ConsolidationTypeUtils.ToEntity(cType);

            return(Get(et, id, c));
        }
Exemple #3
0
        public void AddColumnMappingLookup(string publicIdColumn, string publicNameColumn, ConsolidationType cType, DataStoreConfiguration c)
        {
            var entityType = ConsolidationTypeUtils.ToEntity(cType);

            AddColumnMappingLookup(publicIdColumn, publicNameColumn, entityType, c);
        }
Exemple #4
0
 public void AddExplicitColumnMappingLookup(string stagingIdColumn, string publicIdColumn, string publicNameColumn, ConsolidationType cType)
 {
     AddExplicitColumnMappingLookup(stagingIdColumn, publicIdColumn, publicNameColumn, ConsolidationTypeUtils.ToEntity(cType));
 }
Exemple #5
0
        private int AddConsolidatedIdValues(TransactionContext tc, V7StagingTable table)
        {
            _log.DebugFormat("Adding consolidated Id values to history table: {0}", table.Name);

            var numChanges = 0;

            foreach (var c in table.ConsolidatedIdCols)
            {
                var ctype = c.ConsolidationType;
                var consolidatedColumnName = c.ConsolidationIdColName;
                var federatedColumnName    = FindFederatedColumnName(c, table);

                if (ctype == ConsolidationType.None)
                {
                    // this is a generic column such as "resource_id" where we don't know
                    // the entity type without reference to the value stored in its corresponding
                    // 'type' column (e.g. "resource_type")...
                    var entityDefCol    = c.EntityDefinitionColName;
                    var entityTypesUsed = GetEntityTypedUsed(tc, table.Name, entityDefCol);

                    foreach (var ct7EType in entityTypesUsed)
                    {
                        // e.g.
                        // update h
                        // set h.consolidated_resource_id = cd.consolidation_id
                        // from HISTORY.CT_AT_AUX_MARK h
                        // inner join
                        // FEDERATION.CONSOLIDATION_DETAIL_ROOM cd
                        // on h.federated_resource_id = cd.ctds_id
                        // and h.history_federated = 0
                        // and h.resource_type = 604
                        // and h.history_status in ('I', 'U')
                        var sb = new SqlBuilder();
                        sb.Append("update h");
                        sb.AppendFormat("set h.{0} = cd.{1}", consolidatedColumnName, FederationSchema.ConsolidationIdColName);
                        sb.AppendFormat(
                            "from {0} h", DatabaseUtils.GetQualifiedTableName(HistorySchema.HistorySchemaName, table.Name));
                        sb.Append("inner join");

                        string qualifiedConsolidationDetailTable =
                            DatabaseUtils.GetQualifiedTableName(
                                FederationSchema.FederationSchemaName, EntityUtils.ToConsolidationDetailTableName(EntityUtils.FromCt7Entity(ct7EType)));

                        sb.AppendFormat("{0} cd", qualifiedConsolidationDetailTable);
                        sb.AppendFormat("on h.{0} = cd.{1}", federatedColumnName, FederationSchema.MasterIdColName);
                        sb.AppendFormat("and h.{0} = 0", HistorySchema.HistoryFederatedColumnName);
                        sb.AppendFormat("and h.{0} = {1}", entityDefCol, (int)ct7EType);
                        sb.AppendFormat("and h.{0} in ({1})", HistorySchema.HistoryStatusColumnName, RestrictedStatusValuesAsCsv());

                        numChanges += DatabaseUtils.ExecuteSql(tc, sb.ToString(), _timeoutSecs);
                    }
                }
                else
                {
                    // e.g.
                    // update h
                    // set h.consolidated_dept_id = cd.consolidation_id
                    // from HISTORY.CT_ROOM h
                    // inner join
                    // FEDERATION.CONSOLIDATION_DETAIL_DEPT cd
                    // on h.federated_dept_id = cd.ctds_id
                    // and h.history_federated = 0
                    // and h.history_status in ('I', 'U')
                    var sb = new SqlBuilder();
                    sb.Append("update h");
                    sb.AppendFormat("set h.{0} = cd.{1}", consolidatedColumnName, FederationSchema.ConsolidationIdColName);
                    sb.AppendFormat(
                        "from {0} h", DatabaseUtils.GetQualifiedTableName(HistorySchema.HistorySchemaName, table.Name));
                    sb.Append("inner join");

                    var qualifiedConsolidationDetailTable =
                        DatabaseUtils.GetQualifiedTableName(
                            FederationSchema.FederationSchemaName,
                            EntityUtils.ToConsolidationDetailTableName(ConsolidationTypeUtils.ToEntity(ctype)));

                    sb.AppendFormat("{0} cd", qualifiedConsolidationDetailTable);
                    sb.AppendFormat("on h.{0} = cd.{1}", federatedColumnName, FederationSchema.MasterIdColName);
                    sb.AppendFormat("and h.{0} = 0", HistorySchema.HistoryFederatedColumnName);
                    sb.AppendFormat("and h.{0} in ({1})", HistorySchema.HistoryStatusColumnName, RestrictedStatusValuesAsCsv());

                    numChanges += DatabaseUtils.ExecuteSql(tc, sb.ToString(), _timeoutSecs);
                }
            }

            return(numChanges);
        }