//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void propertyTypeShouldBeTxStateAware() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void PropertyTypeShouldBeTxStateAware() { // Given long node; using (Transaction tx = beginTransaction()) { node = tx.DataWrite().nodeCreate(); tx.Success(); } // Then using (Transaction tx = beginTransaction()) { using (NodeCursor nodes = tx.Cursors().allocateNodeCursor(), PropertyCursor properties = tx.Cursors().allocatePropertyCursor()) { tx.DataRead().singleNode(node, nodes); assertTrue(nodes.Next()); assertFalse(HasProperties(nodes, properties)); int prop = tx.TokenWrite().propertyKeyGetOrCreateForName("prop"); tx.DataWrite().nodeSetProperty(node, prop, stringValue("foo")); nodes.Properties(properties); assertTrue(properties.Next()); assertThat(properties.PropertyType(), equalTo(ValueGroup.TEXT)); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldSeeNewNodePropertyInTransaction() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldSeeNewNodePropertyInTransaction() { long nodeId; string propKey1 = "prop1"; string propKey2 = "prop2"; using (Transaction tx = beginTransaction()) { nodeId = tx.DataWrite().nodeCreate(); int prop1 = tx.Token().propertyKeyGetOrCreateForName(propKey1); int prop2 = tx.Token().propertyKeyGetOrCreateForName(propKey2); assertEquals(tx.DataWrite().nodeSetProperty(nodeId, prop1, stringValue("hello")), NO_VALUE); assertEquals(tx.DataWrite().nodeSetProperty(nodeId, prop2, stringValue("world")), NO_VALUE); using (NodeCursor node = tx.Cursors().allocateNodeCursor(), PropertyCursor property = tx.Cursors().allocatePropertyCursor()) { tx.DataRead().singleNode(nodeId, node); assertTrue("should access node", node.Next()); node.Properties(property); assertTrue(property.Next()); //First property assertEquals(prop1, property.PropertyKey()); assertEquals(property.PropertyValue(), stringValue("hello")); //second property assertTrue(property.Next()); assertEquals(prop2, property.PropertyKey()); assertEquals(property.PropertyValue(), stringValue("world")); assertFalse("should only find two properties", property.Next()); assertFalse("should only find one node", node.Next()); } tx.Success(); } }
public override bool HasProperty(string key) { if (null == key) { return(false); } KernelTransaction transaction = SafeAcquireTransaction(); int propertyKey = transaction.TokenRead().propertyKey(key); if (propertyKey == [email protected]_Fields.NO_TOKEN) { return(false); } NodeCursor nodes = transaction.AmbientNodeCursor(); PropertyCursor properties = transaction.AmbientPropertyCursor(); SingleNode(transaction, nodes); nodes.Properties(properties); while (properties.Next()) { if (propertyKey == properties.PropertyKey()) { return(true); } } return(false); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public Object getProperty(String key) throws org.neo4j.graphdb.NotFoundException public override object GetProperty(string key) { if (null == key) { throw new System.ArgumentException("(null) property key is not allowed"); } KernelTransaction transaction = SafeAcquireTransaction(); int propertyKey = transaction.TokenRead().propertyKey(key); if (propertyKey == [email protected]_Fields.NO_TOKEN) { throw new NotFoundException(format("No such property, '%s'.", key)); } NodeCursor nodes = transaction.AmbientNodeCursor(); PropertyCursor properties = transaction.AmbientPropertyCursor(); SingleNode(transaction, nodes); nodes.Properties(properties); while (properties.Next()) { if (propertyKey == properties.PropertyKey()) { Value value = properties.PropertyValue(); if (value == Values.NO_VALUE) { throw new NotFoundException(format("No such property, '%s'.", key)); } return(value.AsObjectCopy()); } } throw new NotFoundException(format("No such property, '%s'.", key)); }
private void ScanEverythingBelongingToNodes(NodeMappings nodeMappings) { using (NodeCursor nodeCursor = _cursors.allocateNodeCursor(), PropertyCursor propertyCursor = _cursors.allocatePropertyCursor()) { _dataRead.allNodesScan(nodeCursor); while (nodeCursor.Next()) { // each node SortedLabels labels = SortedLabels.From(nodeCursor.Labels()); nodeCursor.Properties(propertyCursor); MutableIntSet propertyIds = IntSets.mutable.empty(); while (propertyCursor.Next()) { Value currentValue = propertyCursor.PropertyValue(); int propertyKeyId = propertyCursor.PropertyKey(); Pair <SortedLabels, int> key = Pair.of(labels, propertyKeyId); UpdateValueTypeInMapping(currentValue, key, nodeMappings.LabelSetANDNodePropertyKeyIdToValueType); propertyIds.add(propertyKeyId); } propertyCursor.Close(); MutableIntSet oldPropertyKeySet = nodeMappings.LabelSetToPropertyKeys.getOrDefault(labels, _emptyPropertyIdSet); // find out which old properties we did not visited and mark them as nullable if (oldPropertyKeySet == _emptyPropertyIdSet) { if (propertyIds.size() == 0) { // Even if we find property key on other nodes with those labels, set all of them nullable nodeMappings.NullableLabelSets.Add(labels); } propertyIds.addAll(oldPropertyKeySet); } else { MutableIntSet currentPropertyIdsHelperSet = new IntHashSet(propertyIds.size()); currentPropertyIdsHelperSet.addAll(propertyIds); propertyIds.removeAll(oldPropertyKeySet); // only the brand new ones in propIds now oldPropertyKeySet.removeAll(currentPropertyIdsHelperSet); // only the old ones that are not on the new node propertyIds.addAll(oldPropertyKeySet); propertyIds.forEach(id => { Pair <SortedLabels, int> key = Pair.of(labels, id); nodeMappings.LabelSetANDNodePropertyKeyIdToValueType[key].setNullable(); }); propertyIds.addAll(currentPropertyIdsHelperSet); } nodeMappings.LabelSetToPropertyKeys[labels] = propertyIds; } nodeCursor.Close(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldAllowManyLabelsAndPropertyCursor() public virtual void ShouldAllowManyLabelsAndPropertyCursor() { int propertyCount = 10; int labelCount = 15; GraphDatabaseAPI db = DbRule.GraphDatabaseAPI; Node node; using (Transaction tx = Db.beginTx()) { node = Db.createNode(); for (int i = 0; i < propertyCount; i++) { node.SetProperty("foo" + i, "bar"); } for (int i = 0; i < labelCount; i++) { node.AddLabel(label("label" + i)); } tx.Success(); } ISet <int> seenProperties = new HashSet <int>(); ISet <int> seenLabels = new HashSet <int>(); using (Transaction tx = Db.beginTx()) { DependencyResolver resolver = Db.DependencyResolver; ThreadToStatementContextBridge bridge = resolver.ResolveDependency(typeof(ThreadToStatementContextBridge)); KernelTransaction ktx = bridge.GetKernelTransactionBoundToThisThread(true); using (NodeCursor nodes = ktx.Cursors().allocateNodeCursor(), PropertyCursor propertyCursor = ktx.Cursors().allocatePropertyCursor()) { ktx.DataRead().singleNode(node.Id, nodes); while (nodes.Next()) { nodes.Properties(propertyCursor); while (propertyCursor.Next()) { seenProperties.Add(propertyCursor.PropertyKey()); } LabelSet labels = nodes.Labels(); for (int i = 0; i < labels.NumberOfLabels(); i++) { seenLabels.Add(labels.Label(i)); } } } tx.Success(); } assertEquals(propertyCount, seenProperties.Count); assertEquals(labelCount, seenLabels.Count); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldSeeAddedPropertyFromExistingNodeWithPropertiesInTransaction() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldSeeAddedPropertyFromExistingNodeWithPropertiesInTransaction() { // Given long nodeId; string propKey1 = "prop1"; string propKey2 = "prop2"; int propToken1; int propToken2; using (Transaction tx = beginTransaction()) { nodeId = tx.DataWrite().nodeCreate(); propToken1 = tx.Token().propertyKeyGetOrCreateForName(propKey1); assertEquals(tx.DataWrite().nodeSetProperty(nodeId, propToken1, stringValue("hello")), NO_VALUE); tx.Success(); } // When/Then using (Transaction tx = beginTransaction()) { propToken2 = tx.Token().propertyKeyGetOrCreateForName(propKey2); assertEquals(tx.DataWrite().nodeSetProperty(nodeId, propToken2, stringValue("world")), NO_VALUE); using (NodeCursor node = tx.Cursors().allocateNodeCursor(), PropertyCursor property = tx.Cursors().allocatePropertyCursor()) { tx.DataRead().singleNode(nodeId, node); assertTrue("should access node", node.Next()); node.Properties(property); //property 2, start with tx state assertTrue(property.Next()); assertEquals(propToken2, property.PropertyKey()); assertEquals(property.PropertyValue(), stringValue("world")); //property 1, from disk assertTrue(property.Next()); assertEquals(propToken1, property.PropertyKey()); assertEquals(property.PropertyValue(), stringValue("hello")); assertFalse("should only find two properties", property.Next()); assertFalse("should only find one node", node.Next()); } tx.Success(); } using (Org.Neo4j.Graphdb.Transaction ignored = graphDb.beginTx()) { assertThat(graphDb.getNodeById(nodeId).getProperty(propKey1), equalTo("hello")); assertThat(graphDb.getNodeById(nodeId).getProperty(propKey2), equalTo("world")); } }
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 TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotAccessNonExistentProperties() public virtual void ShouldNotAccessNonExistentProperties() { // given using (NodeCursor node = cursors.allocateNodeCursor(), PropertyCursor props = cursors.allocatePropertyCursor()) { // when read.singleNode(_bare, node); assertTrue("node by reference", node.Next()); assertFalse("no properties", HasProperties(node, props)); node.Properties(props); assertFalse("no properties by direct method", props.Next()); read.nodeProperties(node.NodeReference(), node.PropertiesReference(), props); assertFalse("no properties via property ref", props.Next()); assertFalse("only one node", node.Next()); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldSeeRemovedThenAddedPropertyInTransaction() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldSeeRemovedThenAddedPropertyInTransaction() { // Given long nodeId; string propKey = "prop1"; int propToken; using (Transaction tx = beginTransaction()) { nodeId = tx.DataWrite().nodeCreate(); propToken = tx.Token().propertyKeyGetOrCreateForName(propKey); assertEquals(tx.DataWrite().nodeSetProperty(nodeId, propToken, stringValue("hello")), NO_VALUE); tx.Success(); } // When/Then using (Transaction tx = beginTransaction()) { assertEquals(tx.DataWrite().nodeRemoveProperty(nodeId, propToken), stringValue("hello")); assertEquals(tx.DataWrite().nodeSetProperty(nodeId, propToken, stringValue("world")), NO_VALUE); using (NodeCursor node = tx.Cursors().allocateNodeCursor(), PropertyCursor property = tx.Cursors().allocatePropertyCursor()) { tx.DataRead().singleNode(nodeId, node); assertTrue("should access node", node.Next()); node.Properties(property); assertTrue(property.Next()); assertEquals(propToken, property.PropertyKey()); assertEquals(property.PropertyValue(), stringValue("world")); assertFalse("should not find any properties", property.Next()); assertFalse("should only find one node", node.Next()); } tx.Success(); } using (Org.Neo4j.Graphdb.Transaction ignored = graphDb.beginTx()) { assertThat(graphDb.getNodeById(nodeId).getProperty(propKey), equalTo("world")); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldAccessAllNodeProperties() public virtual void ShouldAccessAllNodeProperties() { // given using (NodeCursor node = cursors.allocateNodeCursor(), PropertyCursor props = cursors.allocatePropertyCursor()) { // when read.singleNode(_allProps, node); assertTrue("node by reference", node.Next()); assertTrue("has properties", HasProperties(node, props)); node.Properties(props); ISet <object> values = new HashSet <object>(); while (props.Next()) { values.Add(props.PropertyValue().asObject()); } assertTrue("byteProp", values.Contains(( sbyte )13)); assertTrue("shortProp", values.Contains(( short )13)); assertTrue("intProp", values.Contains(13)); assertTrue("inlineLongProp", values.Contains(13L)); assertTrue("longProp", values.Contains(long.MaxValue)); assertTrue("floatProp", values.Contains(13.0f)); assertTrue("doubleProp", values.Contains(13.0)); assertTrue("trueProp", values.Contains(true)); assertTrue("falseProp", values.Contains(false)); assertTrue("charProp", values.Contains('x')); assertTrue("emptyStringProp", values.Contains("")); assertTrue("shortStringProp", values.Contains("hello")); assertTrue("utf8Prop", values.Contains(_chinese)); if (SupportsBigProperties()) { assertTrue("longStringProp", values.Contains(LONG_STRING)); assertThat("smallArray", values, hasItem(IntArray(1, 2, 3, 4))); assertThat("bigArray", values, hasItem(arrayContaining(LONG_STRING))); } assertTrue("pointProp", values.Contains(_pointValue)); int expected = SupportsBigProperties() ? 18 : 15; assertEquals("number of values", expected, values.Count); } }
private Value[] GetValueTuple(NodeCursor node, PropertyCursor propertyCursor, int changedPropertyKeyId, Value changedValue, int[] indexPropertyIds, MutableIntObjectMap <Value> materializedValues) { Value[] values = new Value[indexPropertyIds.Length]; int missing = 0; // First get whatever values we already have on the stack, like the value change that provoked this update in the first place // and already loaded values that we can get from the map of materialized values. for (int k = 0; k < indexPropertyIds.Length; k++) { values[k] = indexPropertyIds[k] == changedPropertyKeyId ? changedValue : materializedValues.get(indexPropertyIds[k]); if (values[k] == null) { missing++; } } // If we couldn't get all values that we wanted we need to load from the node. While we're loading values // we'll place those values in the map so that other index updates from this change can just used them. if (missing > 0) { node.Properties(propertyCursor); while (missing > 0 && propertyCursor.Next()) { int k = ArrayUtils.IndexOf(indexPropertyIds, propertyCursor.PropertyKey()); if (k >= 0 && values[k] == null) { int propertyKeyId = indexPropertyIds[k]; bool thisIsTheChangedProperty = propertyKeyId == changedPropertyKeyId; values[k] = thisIsTheChangedProperty ? changedValue : propertyCursor.PropertyValue(); if (!thisIsTheChangedProperty) { materializedValues.put(propertyKeyId, values[k]); } missing--; } } } return(values); }
private void AssertAccessSingleProperty(long nodeId, object expectedValue, ValueGroup expectedValueType) { // given using (NodeCursor node = cursors.allocateNodeCursor(), PropertyCursor props = cursors.allocatePropertyCursor()) { // when read.singleNode(nodeId, node); assertTrue("node by reference", node.Next()); assertTrue("has properties", HasProperties(node, props)); node.Properties(props); assertTrue("has properties by direct method", props.Next()); assertEquals("correct value", expectedValue, props.PropertyValue()); assertEquals("correct value type ", expectedValueType, props.PropertyType()); assertFalse("single property", props.Next()); read.nodeProperties(node.NodeReference(), node.PropertiesReference(), props); assertTrue("has properties via property ref", props.Next()); assertEquals("correct value", expectedValue, props.PropertyValue()); assertFalse("single property", props.Next()); } }
private bool HasProperties(NodeCursor cursor, PropertyCursor props) { cursor.Properties(props); return(props.Next()); }
private bool HasProperties(NodeCursor node, PropertyCursor props) { node.Properties(props); return(props.Next()); }