예제 #1
0
        private static IEnumerable <IRow> GetReferencingRows(
            [NotNull] ReferencedTableInfo referencedTableInfo,
            [NotNull] ReferencingTableInfo referencingTableInfo)
        {
            const bool recycle     = true;
            const int  maxKeyCount = 20;

            if (referencedTableInfo.KeySet.Count <= maxKeyCount)
            {
                return(GdbQueryUtils.GetRowsInList(
                           referencingTableInfo.Table,
                           referencingTableInfo.ForeignKeyFieldName,
                           referencedTableInfo.KeySet, recycle,
                           referencingTableInfo.Filter));
            }

            var queryFilter =
                new QueryFilterClass
            {
                WhereClause = string.Format("{0} IS NOT NULL",
                                            referencingTableInfo.ForeignKeyFieldName)
            };

            return(GdbQueryUtils.GetRows(referencingTableInfo.Table, queryFilter,
                                         recycle));
        }
        private IList <IRow> GetRowsByRelatedGeometry(
            [NotNull] ITable table,
            [NotNull] IObjectDataset objectDataset,
            [NotNull] ITest testWithTable,
            [NotNull] IEnumerable <IList <IRelationshipClass> > relClassChains)
        {
            Assert.ArgumentNotNull(table, nameof(table));
            Assert.ArgumentNotNull(objectDataset, nameof(objectDataset));
            Assert.ArgumentNotNull(testWithTable, nameof(testWithTable));

            HashSet <int> oids = ReferenceGeometryUtils.GetOidsByRelatedGeometry(
                table, relClassChains, Assert.NotNull(_testPerimeter), testWithTable);

            // Add oids of selected rows
            if (ObjectSelection != null)
            {
                oids.UnionWith(ObjectSelection.GetSelectedOIDs(objectDataset));
            }

            if (oids.Count == 0)
            {
                return(new List <IRow>());
            }

            return(new List <IRow>(GdbQueryUtils.GetRowsInList(
                                       table, table.OIDFieldName, oids,
                                       recycle: false)));
        }
예제 #3
0
        public void CanGetRowsInLongList()
        {
            IFeatureWorkspace ws = OpenTestWorkspace();
            IFeatureClass     fc = ws.OpenFeatureClass("TOPGIS_TLM.TLM_STRASSE");

            // fill list
            const int max = 2000;
            Dictionary <int, IRow> dic = GetFirstNRows((ITable)fc, max);

            var selList = new List <int>(max);

            foreach (IRow row in GdbQueryUtils.GetRowsInList((ITable)fc, fc.OIDFieldName,
                                                             dic.Keys, false, null))
            {
                selList.Add(row.OID);
                IRow origRow = dic[row.OID];
                Assert.AreEqual(origRow.OID, row.OID, "");
                //dic[row.OID] = null; REMARK: this changes list dic.Keys and leads to an error in foreach
            }

            Assert.AreEqual(dic.Count, selList.Count, "List counts differ");

            var oidList = new List <int>(dic.Keys);

            oidList.Sort();
            selList.Sort();
            for (var i = 0; i < oidList.Count; i++)
            {
                Assert.AreEqual(oidList[i], selList[i], "{0}th element differs", i);
            }
        }
예제 #4
0
        private static IEnumerable <IRow> TryGetRows(
            [NotNull] ITable table,
            [NotNull] ICollection <int> objectIDs)
        {
            if (objectIDs.Count == 0)
            {
                return(null);
            }

            const bool recycle = false;

            try
            {
                return(GdbQueryUtils.GetRowsByObjectIds(table, objectIDs, recycle));
            }
            catch (Exception e)
            {
                _msg.WarnFormat(
                    "Error getting involved rows for table {0}: {1} (see log for details)",
                    DatasetUtils.GetName(table),
                    e.Message);
                using (_msg.IncrementIndentation())
                {
                    _msg.DebugFormat("Object IDs of involved rows: {0}",
                                     StringUtils.Concatenate(objectIDs, ","));
                    LogTableDebugInfo(table);
                }

                _msg.WarnFormat("Trying again using alternative query method");

                // try again using different fetch method (where clause)
                try
                {
                    return(GdbQueryUtils.GetRowsInList(table, table.OIDFieldName,
                                                       objectIDs, recycle));
                }
                catch (Exception e2)
                {
                    _msg.WarnFormat("Error getting involved rows for table {0}: {1}",
                                    DatasetUtils.GetName(table),
                                    e2.Message);
                    using (_msg.IncrementIndentation())
                    {
                        _msg.WarnFormat("Object IDs of involved rows: {0}",
                                        StringUtils.Concatenate(objectIDs, ","));
                    }

                    return(null);
                }
            }
        }
예제 #5
0
            private IEnumerable <KeyValuePair <int, object> > LookupKeys(
                [NotNull] IEnumerable <int> oids)
            {
                string oidFieldName = _table.OIDFieldName;

                var queryFilter = new QueryFilterClass();

                GdbQueryUtils.SetSubFields(queryFilter, oidFieldName, KeyFieldName);

                const bool recycle = true;

                foreach (IRow row in GdbQueryUtils.GetRowsInList(
                             _table, oidFieldName, oids, recycle, queryFilter))
                {
                    yield return(new KeyValuePair <int, object>(row.OID, row.Value[_keyFieldIndex]));
                }
            }
예제 #6
0
        private int VerifyRowsExist(
            [NotNull] ReferencedTableInfo referencedTableInfo,
            [NotNull] IEnumerable <ReferencingTableInfo> referencingTableInfos)
        {
            int errorCount = RemoveExist(referencedTableInfo, referencingTableInfos);

            if (referencedTableInfo.KeySet.Count == 0)
            {
                return(errorCount);
            }

            const bool recycle = true;

            foreach (IRow row in GdbQueryUtils.GetRowsInList(referencedTableInfo.Table,
                                                             referencedTableInfo
                                                             .KeyFieldName,
                                                             referencedTableInfo.KeySet,
                                                             recycle,
                                                             _referencedTableFilter))
            {
                if (CancelTestingRow(row, recycleUnique: Guid.NewGuid()))
                {
                    continue;
                }

                object key = row.Value[referencedTableInfo.KeyFieldIndex];

                string description =
                    string.Format(
                        "Value [{0}] is not referenced by any table",
                        key);

                string fieldName;
                TestUtils.GetFieldDisplayName(row, referencedTableInfo.KeyFieldIndex,
                                              out fieldName);

                errorCount += ReportError(description, TestUtils.GetShapeCopy(row),
                                          Codes[Code.ValueNotReferenced], fieldName,
                                          row);
            }

            referencedTableInfo.KeySet.Clear();

            return(errorCount);
        }
예제 #7
0
        private static ICollection <int> GetExistingInvolvedObjectIds(
            [NotNull] IObjectDataset involvedObjectDataset,
            [NotNull] IDatasetContext datasetContext,
            [NotNull] IDictionary <int, List <AllowedError> > allowedErrorsByInvolvedObjectID,
            bool invalidateIfAnyInvolvedObjectChanged)
        {
            var result = new SimpleSet <int>(allowedErrorsByInvolvedObjectID.Count);

            IQueryFilter queryFilter;
            int          dateOfChangeFieldIndex;
            ITable       involvedTable = GetInvolvedTableAndQueryFilter(
                involvedObjectDataset, datasetContext,
                invalidateIfAnyInvolvedObjectChanged,
                out queryFilter, out dateOfChangeFieldIndex);

            const bool recycle = true;

            foreach (IRow involvedRow in GdbQueryUtils.GetRowsInList(
                         involvedTable,
                         involvedTable.OIDFieldName,
                         allowedErrorsByInvolvedObjectID.Keys,
                         recycle, queryFilter))
            {
                // these are all involved rows in all the allowed errors.
                int oid = involvedRow.OID;

                result.TryAdd(oid);

                if (dateOfChangeFieldIndex >= 0)
                {
                    InvalidateIfAnyInvolvedObjectChanged(allowedErrorsByInvolvedObjectID[oid],
                                                         involvedRow,
                                                         dateOfChangeFieldIndex);
                }
            }

            return(result);
        }