コード例 #1
0
        protected internal override bool InitializeRangeForQuery(KEY treeKeyFrom, KEY treeKeyTo, IndexQuery[] predicates)
        {
            IndexQuery predicate = predicates[0];

            switch (predicate.Type())
            {
            case exists:
                treeKeyFrom.initValueAsLowest(ValueGroup.UNKNOWN);
                treeKeyTo.initValueAsHighest(ValueGroup.UNKNOWN);
                break;

            case exact:
                IndexQuery.ExactPredicate exactPredicate = (IndexQuery.ExactPredicate)predicate;
                treeKeyFrom.from(exactPredicate.Value());
                treeKeyTo.from(exactPredicate.Value());
                break;

            case range:
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.internal.kernel.api.IndexQuery.RangePredicate<?> rangePredicate = (org.neo4j.internal.kernel.api.IndexQuery.RangePredicate<?>) predicate;
                IndexQuery.RangePredicate <object> rangePredicate = (IndexQuery.RangePredicate <object>)predicate;
                InitFromForRange(rangePredicate, treeKeyFrom);
                InitToForRange(rangePredicate, treeKeyTo);
                break;

            default:
                throw new System.ArgumentException("IndexQuery of type " + predicate.Type() + " is not supported.");
            }
            return(false);              // no filtering
        }
コード例 #2
0
 private static bool IsNumericOrGeometricPredicate(IndexQuery predicate)
 {
     if (predicate.Type() == IndexQuery.IndexQueryType.exact)
     {
         IndexQuery.ExactPredicate exactPredicate = (IndexQuery.ExactPredicate)predicate;
         return(IsNumberGeometryOrArray(exactPredicate.Value()));
     }
     else
     {
         return(predicate.Type() == IndexQuery.IndexQueryType.range && (predicate.ValueGroup() == ValueGroup.NUMBER || predicate.ValueGroup() == ValueGroup.GEOMETRY));
     }
 }
コード例 #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldProvidePopulatorThatAcceptsDuplicateEntries() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
            public virtual void ShouldProvidePopulatorThatAcceptsDuplicateEntries()
            {
                // when
                IndexSamplingConfig indexSamplingConfig = new IndexSamplingConfig(Config.defaults());

                WithPopulator(IndexProvider.getPopulator(Descriptor, indexSamplingConfig, heapBufferFactory(1024)), p => p.add(Arrays.asList(add(1, Descriptor.schema(), "v1", "v2"), add(2, Descriptor.schema(), "v1", "v2"))));

                // then
                using (IndexAccessor accessor = IndexProvider.getOnlineAccessor(Descriptor, indexSamplingConfig))
                {
                    using (IndexReader reader = new QueryResultComparingIndexReader(accessor.NewReader()))
                    {
                        LongIterator nodes = reader.Query(IndexQuery.exact(1, "v1"), IndexQuery.exact(1, "v2"));
                        assertEquals(asSet(1L, 2L), PrimitiveLongCollections.toSet(nodes));
                    }
                }
            }
コード例 #4
0
        internal override bool InitializeRangeForQuery(StringIndexKey treeKeyFrom, StringIndexKey treeKeyTo, IndexQuery[] predicates)
        {
            IndexQuery predicate = predicates[0];

            switch (predicate.Type())
            {
            case exists:
                treeKeyFrom.InitValueAsLowest(ValueGroup.TEXT);
                treeKeyTo.InitValueAsHighest(ValueGroup.TEXT);
                return(false);

            case exact:
                IndexQuery.ExactPredicate exactPredicate = (IndexQuery.ExactPredicate)predicate;
                treeKeyFrom.From(exactPredicate.Value());
                treeKeyTo.From(exactPredicate.Value());
                return(false);

            case range:
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.internal.kernel.api.IndexQuery.RangePredicate<?> rangePredicate = (org.neo4j.internal.kernel.api.IndexQuery.RangePredicate<?>)predicate;
                IndexQuery.RangePredicate <object> rangePredicate = (IndexQuery.RangePredicate <object>)predicate;
                InitFromForRange(rangePredicate, treeKeyFrom);
                InitToForRange(rangePredicate, treeKeyTo);
                return(false);

            case stringPrefix:
                StringPrefixPredicate prefixPredicate = ( StringPrefixPredicate )predicate;
                treeKeyFrom.InitAsPrefixLow(prefixPredicate.prefix());
                treeKeyTo.InitAsPrefixHigh(prefixPredicate.prefix());
                return(false);

            case stringSuffix:
            case stringContains:
                treeKeyFrom.InitValueAsLowest(ValueGroup.TEXT);
                treeKeyTo.InitValueAsHighest(ValueGroup.TEXT);
                return(true);

            default:
                throw new System.ArgumentException("IndexQuery of type " + predicate.Type() + " is not supported.");
            }
        }
コード例 #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ParameterizedTest @ValueSource(ints = {7, 11, 14, 20, 35, 58}) void partitionedIndexPopulation(int affectedNodes) throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void PartitionedIndexPopulation(int affectedNodes)
        {
            File rootFolder = new File(_testDir.directory("partitionIndex" + affectedNodes), "uniqueIndex" + affectedNodes);

            using (SchemaIndex uniqueIndex = LuceneSchemaIndexBuilder.create(_descriptor, Config.defaults()).withFileSystem(_fileSystem).withIndexRootFolder(rootFolder).build())
            {
                uniqueIndex.open();

                // index is empty and not yet exist
                assertEquals(0, uniqueIndex.allDocumentsReader().maxCount());
                assertFalse(uniqueIndex.exists());

                using (LuceneIndexAccessor indexAccessor = new LuceneIndexAccessor(uniqueIndex, _descriptor))
                {
                    GenerateUpdates(indexAccessor, affectedNodes);
                    indexAccessor.Force(Org.Neo4j.Io.pagecache.IOLimiter_Fields.Unlimited);

                    // now index is online and should contain updates data
                    assertTrue(uniqueIndex.Online);

                    using (IndexReader indexReader = indexAccessor.NewReader(), IndexSampler indexSampler = indexReader.CreateSampler())
                    {
                        long[] nodes = PrimitiveLongCollections.asArray(indexReader.Query(IndexQuery.exists(1)));
                        assertEquals(affectedNodes, nodes.Length);

                        IndexSample sample = indexSampler.SampleIndex();
                        assertEquals(affectedNodes, sample.IndexSize());
                        assertEquals(affectedNodes, sample.UniqueValues());
                        assertEquals(affectedNodes, sample.SampleSize());
                    }
                }
            }
        }
コード例 #6
0
ファイル: IndexQueryHelper.cs プロジェクト: Neo4Net/Neo4Net
 public static IndexQuery Exact(int propertyKeyId, Value value)
 {
     return(IndexQuery.exact(propertyKeyId, value));
 }
コード例 #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void defaultQueryImplementationMustThrowForUnsupportedIndexOrder()
        internal virtual void DefaultQueryImplementationMustThrowForUnsupportedIndexOrder()
        {
            // Given
            IndexReader indexReader = StubIndexReader();

            // Then
            string expectedMessage = string.Format("This reader only have support for index order {0}. Provided index order was {1}.", IndexOrder.NONE, IndexOrder.ASCENDING);

            System.NotSupportedException operationException = assertThrows(typeof(System.NotSupportedException), () => indexReader.Query(new SimpleNodeValueClient(), IndexOrder.ASCENDING, false, IndexQuery.exists(1)));
            assertEquals(expectedMessage, operationException.Message);
        }
コード例 #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAllowConcurrentViolationOfConstraint() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotAllowConcurrentViolationOfConstraint()
        {
            // Given
            GraphDatabaseAPI graphDb = Db.GraphDatabaseAPI;

            System.Func <KernelTransaction> ktxSupplier = () => graphDb.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true);

            Label  label            = label("Foo");
            string propertyKey      = "bar";
            string conflictingValue = "baz";

            // a constraint
            using (Transaction tx = graphDb.BeginTx())
            {
                graphDb.Schema().constraintFor(label).assertPropertyIsUnique(propertyKey).create();
                tx.Success();
            }

            // When
            using (Transaction tx = graphDb.BeginTx())
            {
                KernelTransaction ktx         = ktxSupplier();
                int             labelId       = ktx.TokenRead().nodeLabel(label.Name());
                int             propertyKeyId = ktx.TokenRead().propertyKey(propertyKey);
                IndexDescriptor index         = TestIndexDescriptorFactory.uniqueForLabel(labelId, propertyKeyId);
                Read            read          = ktx.DataRead();
                using (NodeValueIndexCursor cursor = ktx.Cursors().allocateNodeValueIndexCursor())
                {
                    read.NodeIndexSeek(ktx.SchemaRead().index(labelId, propertyKeyId), cursor, IndexOrder.NONE, false, IndexQuery.exact(index.Schema().PropertyId, "The value is irrelevant, we just want to perform some sort of lookup against this " + "index"));
                }
                // then let another thread come in and create a node
                Threads.execute(Db =>
                {
                    using (Transaction transaction = Db.beginTx())
                    {
                        Db.createNode(label).setProperty(propertyKey, conflictingValue);
                        transaction.success();
                    }
                    return(null);
                }, graphDb).get();

                // before we create a node with the same property ourselves - using the same statement that we have
                // already used for lookup against that very same index
                long node = ktx.DataWrite().nodeCreate();
                ktx.DataWrite().nodeAddLabel(node, labelId);
                try
                {
                    ktx.DataWrite().nodeSetProperty(node, propertyKeyId, Values.of(conflictingValue));

                    fail("exception expected");
                }
                // Then
                catch (UniquePropertyValueValidationException e)
                {
                    assertEquals(ConstraintDescriptorFactory.uniqueForLabel(labelId, propertyKeyId), e.Constraint());
                    IndexEntryConflictException conflict = Iterators.single(e.Conflicts().GetEnumerator());
                    assertEquals(Values.stringValue(conflictingValue), conflict.SinglePropertyValue);
                }

                tx.Success();
            }
        }