//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void addingANodeWithPropertyShouldGetIndexed() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void AddingANodeWithPropertyShouldGetIndexed() { // Given string indexProperty = "indexProperty"; GatheringIndexWriter writer = NewWriter(); createIndex(_db, _myLabel, indexProperty); // When int value1 = 12; string otherProperty = "otherProperty"; int otherValue = 17; Node node = CreateNode(map(indexProperty, value1, otherProperty, otherValue), _myLabel); // Then, for now, this should trigger two NodePropertyUpdates using (Transaction tx = _db.beginTx()) { KernelTransaction ktx = _ctxSupplier.getKernelTransactionBoundToThisThread(true); TokenRead tokenRead = ktx.TokenRead(); int propertyKey1 = tokenRead.PropertyKey(indexProperty); int label = tokenRead.NodeLabel(_myLabel.name()); LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(label, propertyKey1); assertThat(writer.UpdatesCommitted, equalTo(asSet(IndexEntryUpdate.add(node.Id, descriptor, Values.of(value1))))); tx.Success(); } // We get two updates because we both add a label and a property to be indexed // in the same transaction, in the future, we should optimize this down to // one NodePropertyUpdate. }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void batchInserterShouldUseConfiguredIndexProvider() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void BatchInserterShouldUseConfiguredIndexProvider() { Config config = Config.defaults(stringMap(default_schema_provider.name(), _schemaIndex.providerName())); BatchInserter inserter = NewBatchInserter(config); inserter.CreateDeferredSchemaIndex(TestLabels.LABEL_ONE).on("key").create(); inserter.Shutdown(); GraphDatabaseService db = GraphDatabaseService(config); AwaitIndexesOnline(db); try { using (Transaction tx = Db.beginTx()) { DependencyResolver dependencyResolver = (( GraphDatabaseAPI )db).DependencyResolver; ThreadToStatementContextBridge threadToStatementContextBridge = dependencyResolver.ResolveDependency(typeof(ThreadToStatementContextBridge)); KernelTransaction kernelTransaction = threadToStatementContextBridge.GetKernelTransactionBoundToThisThread(true); TokenRead tokenRead = kernelTransaction.TokenRead(); SchemaRead schemaRead = kernelTransaction.SchemaRead(); int labelId = tokenRead.NodeLabel(TestLabels.LABEL_ONE.name()); int propertyId = tokenRead.PropertyKey("key"); IndexReference index = schemaRead.Index(labelId, propertyId); assertTrue(UnexpectedIndexProviderMessage(index), _schemaIndex.providerName().contains(index.ProviderKey())); assertTrue(UnexpectedIndexProviderMessage(index), _schemaIndex.providerName().contains(index.ProviderVersion())); tx.Success(); } } finally { Db.shutdown(); } }
private void AssertCorrectProvider(GraphDatabaseAPI db, Label label, string property) { KernelTransaction kernelTransaction = Db.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(false); TokenRead tokenRead = kernelTransaction.TokenRead(); int labelId = tokenRead.NodeLabel(label.Name()); int propId = tokenRead.PropertyKey(property); SchemaRead schemaRead = kernelTransaction.SchemaRead(); IndexReference index = schemaRead.Index(labelId, propId); assertEquals("correct provider key", "lucene+native", index.ProviderKey()); assertEquals("correct provider version", "1.0", index.ProviderVersion()); }
public override IDictionary <string, object> GetProperties(params string[] keys) { Objects.requireNonNull(keys, "Properties keys should be not null array."); if (keys.Length == 0) { return(Collections.emptyMap()); } KernelTransaction transaction = SafeAcquireTransaction(); int itemsToReturn = keys.Length; IDictionary <string, object> properties = new Dictionary <string, object>(itemsToReturn); TokenRead token = transaction.TokenRead(); //Find ids, note we are betting on that the number of keys //is small enough not to use a set here. int[] propertyIds = new int[itemsToReturn]; for (int i = 0; i < itemsToReturn; i++) { string key = keys[i]; if (string.ReferenceEquals(key, null)) { throw new System.NullReferenceException(string.Format("Key {0:D} was null", i)); } propertyIds[i] = token.PropertyKey(key); } NodeCursor nodes = transaction.AmbientNodeCursor(); PropertyCursor propertyCursor = transaction.AmbientPropertyCursor(); SingleNode(transaction, nodes); nodes.Properties(propertyCursor); int propertiesToFind = itemsToReturn; while (propertiesToFind > 0 && propertyCursor.Next()) { //Do a linear check if this is a property we are interested in. int currentKey = propertyCursor.PropertyKey(); for (int i = 0; i < itemsToReturn; i++) { if (propertyIds[i] == currentKey) { properties[keys[i]] = propertyCursor.PropertyValue().asObjectCopy(); propertiesToFind--; break; } } } return(properties); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void assertIndexProvider(org.neo4j.graphdb.GraphDatabaseService db, String expectedProviderIdentifier) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException private void AssertIndexProvider(GraphDatabaseService db, string expectedProviderIdentifier) { GraphDatabaseAPI graphDatabaseAPI = ( GraphDatabaseAPI )db; using (Transaction tx = graphDatabaseAPI.BeginTx()) { KernelTransaction ktx = graphDatabaseAPI.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true); TokenRead tokenRead = ktx.TokenRead(); int labelId = tokenRead.NodeLabel(LABEL.name()); int propertyId = tokenRead.PropertyKey(KEY); IndexReference index = ktx.SchemaRead().index(labelId, propertyId); assertEquals("expected IndexProvider.Descriptor", expectedProviderIdentifier, (new IndexProviderDescriptor(index.ProviderKey(), index.ProviderVersion())).name()); tx.Success(); } }
public override void DropRelationshipPropertyExistenceConstraint(RelationshipType type, string propertyKey) { KernelTransaction transaction = SafeAcquireTransaction(TransactionSupplier); using (Statement ignore = transaction.AcquireStatement()) { try { TokenRead tokenRead = transaction.TokenRead(); int typeId = tokenRead.RelationshipType(type.Name()); int propertyKeyId = tokenRead.PropertyKey(propertyKey); transaction.SchemaWrite().constraintDrop(ConstraintDescriptorFactory.existsForRelType(typeId, propertyKeyId)); } catch (DropConstraintFailureException e) { throw new ConstraintViolationException(e.GetUserMessage(new SilentTokenNameLookup(transaction.TokenRead())), e); } catch (Exception e) when(e is InvalidTransactionTypeKernelException || e is SchemaKernelException) { throw new ConstraintViolationException(e.Message, e); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void addingALabelToPreExistingNodeShouldGetIndexed() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void AddingALabelToPreExistingNodeShouldGetIndexed() { // GIVEN string indexProperty = "indexProperty"; GatheringIndexWriter writer = NewWriter(); createIndex(_db, _myLabel, indexProperty); // WHEN string otherProperty = "otherProperty"; int value = 12; int otherValue = 17; Node node = CreateNode(map(indexProperty, value, otherProperty, otherValue)); // THEN assertThat(writer.UpdatesCommitted.Count, equalTo(0)); // AND WHEN using (Transaction tx = _db.beginTx()) { node.AddLabel(_myLabel); tx.Success(); } // THEN using (Transaction tx = _db.beginTx()) { KernelTransaction ktx = _ctxSupplier.getKernelTransactionBoundToThisThread(true); TokenRead tokenRead = ktx.TokenRead(); int propertyKey1 = tokenRead.PropertyKey(indexProperty); int label = tokenRead.NodeLabel(_myLabel.name()); LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(label, propertyKey1); assertThat(writer.UpdatesCommitted, equalTo(asSet(IndexEntryUpdate.add(node.Id, descriptor, Values.of(value))))); tx.Success(); } }