Exemplo n.º 1
0
        public void TestDistictColumn()
        {
            var distictColumn = ScanSpec.DistictColumn(new[] { "a", "b:1", "b:2", "c:X", "c", "a:1" });

            Assert.AreEqual(4, distictColumn.Count);
            Assert.IsTrue(distictColumn.Contains("a"));
            Assert.IsFalse(distictColumn.Contains("a:1"));
            Assert.IsFalse(distictColumn.Contains("b"));
            Assert.IsTrue(distictColumn.Contains("b:1"));
            Assert.IsTrue(distictColumn.Contains("b:2"));
            Assert.IsTrue(distictColumn.Contains("c"));
            Assert.IsFalse(distictColumn.Contains("c:X"));

            ISet <string> columnFamilies;

            distictColumn = ScanSpec.DistictColumn(new[] { "a", "b:1", "b:2", "c:X", "c", "a:1" }, out columnFamilies);
            Assert.AreEqual(4, distictColumn.Count);
            Assert.IsTrue(distictColumn.Contains("a"));
            Assert.IsFalse(distictColumn.Contains("a:1"));
            Assert.IsFalse(distictColumn.Contains("b"));
            Assert.IsTrue(distictColumn.Contains("b:1"));
            Assert.IsTrue(distictColumn.Contains("b:2"));
            Assert.IsTrue(distictColumn.Contains("c"));
            Assert.IsFalse(distictColumn.Contains("c:X"));

            Assert.AreEqual(3, columnFamilies.Count);
            Assert.IsTrue(columnFamilies.Contains("a"));
            Assert.IsFalse(columnFamilies.Contains("a:1"));
            Assert.IsTrue(columnFamilies.Contains("b"));
            Assert.IsFalse(columnFamilies.Contains("b:1"));
            Assert.IsFalse(columnFamilies.Contains("b:2"));
            Assert.IsTrue(columnFamilies.Contains("c"));
            Assert.IsFalse(columnFamilies.Contains("c:X"));
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Gets the merged scan spec for the types specified.
        /// </summary>
        /// <param name="entityTypes">
        ///     The query types.
        /// </param>
        /// <returns>
        ///     The merged scan spec.
        /// </returns>
        public ScanSpec ScanSpecForType(IEnumerable <Type> entityTypes)
        {
            if (entityTypes == null)
            {
                throw new ArgumentNullException(nameof(entityTypes));
            }

            var columnNames = new List <string>();

            foreach (var queryType in entityTypes)
            {
                var entityReference = this.EntityReferenceForType(queryType);
                if (entityReference == null)
                {
                    throw new PersistenceException(string.Format(CultureInfo.InvariantCulture,
                                                                 @"{0} is not a valid query type", queryType));
                }

                entityReference.EstablishColumnSets(() => this.ColumnNames(entityReference));
                columnNames.AddRange(entityReference.ColumnSet);
            }

            if (columnNames.Count > 5)
            {
                var registeredColumnNames = this.RegisteredColumnNames();

                foreach (var columnName in columnNames.ToList())
                {
                    var split = columnName.Split(':');
                    if (split.Length > 1)
                    {
                        ISet <string> columnQualifiers;
                        if (registeredColumnNames.TryGetValue(split[0], out columnQualifiers))
                        {
                            if (columnQualifiers.Remove(split[1]) && columnQualifiers.Count == 0)
                            {
                                columnNames.Add(split[0]);
                            }
                        }
                    }
                }
            }

            var scanSpec = new ScanSpec {
                MaxVersions = 1
            };

            scanSpec.AddColumn(ScanSpec.DistictColumn(columnNames));
            if (scanSpec.ColumnCount == 0)
            {
                throw new PersistenceException("Missing or invalid entity types");
            }

            return(scanSpec);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Establish the column set for this entity reference.
        /// </summary>
        /// <param name="establishColumns">
        ///     The establish columns function.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     If the <paramref name="establishColumns" /> is null.
        /// </exception>
        internal void EstablishColumnSets(Func <IEnumerable <string> > establishColumns)
        {
            if (establishColumns == null)
            {
                throw new ArgumentNullException(nameof(establishColumns));
            }

            if (this.columnSet == null)
            {
                this.columnSet = ScanSpec.DistictColumn(establishColumns(), out this.columnFamilySet);
            }
        }