public override bool HasProperty(string key) { if (null == key) { return(false); } KernelTransaction transaction = _spi.kernelTransaction(); int propertyKey = transaction.TokenRead().propertyKey(key); if (propertyKey == [email protected]_Fields.NO_TOKEN) { return(false); } RelationshipScanCursor relationships = transaction.AmbientRelationshipCursor(); PropertyCursor properties = transaction.AmbientPropertyCursor(); SingleRelationship(transaction, relationships); relationships.Properties(properties); while (properties.Next()) { if (propertyKey == properties.PropertyKey()) { return(true); } } return(false); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldAccessRelationshipLabels() public virtual void ShouldAccessRelationshipLabels() { // given IDictionary <int, int> counts = new Dictionary <int, int>(); using (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor()) { // when read.allRelationshipsScan(relationships); while (relationships.Next()) { Counts.compute(relationships.Type(), (k, v) => v == null ? 1 : v + 1); } } // then assertEquals(3, Counts.Count); int[] values = new int[3]; int i = 0; foreach (int value in Counts.Values) { values[i++] = value; } Arrays.sort(values); assertArrayEquals(new int[] { 1, 6, 6 }, values); }
public override object GetProperty(string key, object defaultValue) { if (null == key) { throw new System.ArgumentException("(null) property key is not allowed"); } KernelTransaction transaction = _spi.kernelTransaction(); RelationshipScanCursor relationships = transaction.AmbientRelationshipCursor(); PropertyCursor properties = transaction.AmbientPropertyCursor(); int propertyKey = transaction.TokenRead().propertyKey(key); if (propertyKey == [email protected]_Fields.NO_TOKEN) { return(defaultValue); } SingleRelationship(transaction, relationships); relationships.Properties(properties); while (properties.Next()) { if (propertyKey == properties.PropertyKey()) { Value value = properties.PropertyValue(); return(value == Values.NO_VALUE ? defaultValue : value.AsObjectCopy()); } } return(defaultValue); }
public override RelationshipScanCursor AllocateRelationshipScanCursor() { RelationshipScanCursor n = _cursors.allocateRelationshipScanCursor(); _allCursors.Add(n); return(n); }
private void SingleRelationship(KernelTransaction transaction, RelationshipScanCursor relationships) { transaction.DataRead().singleRelationship(_id, relationships); if (!relationships.Next()) { throw new NotFoundException(new EntityNotFoundException(EntityType.RELATIONSHIP, _id)); } }
internal virtual FulltextIndexTransactionStateVisitor Init(AllStoreHolder read, NodeCursor nodeCursor, RelationshipScanCursor relationshipCursor, PropertyCursor propertyCursor) { this._read = read; this._nodeCursor = nodeCursor; this._relationshipCursor = relationshipCursor; this._propertyCursor = propertyCursor; return(this); }
private void ScanEverythingBelongingToRelationships(RelationshipMappings relMappings) { using (RelationshipScanCursor relationshipScanCursor = _cursors.allocateRelationshipScanCursor(), PropertyCursor propertyCursor = _cursors.allocatePropertyCursor()) { _dataRead.allRelationshipsScan(relationshipScanCursor); while (relationshipScanCursor.Next()) { int typeId = relationshipScanCursor.Type(); relationshipScanCursor.Properties(propertyCursor); MutableIntSet propertyIds = IntSets.mutable.empty(); while (propertyCursor.Next()) { int propertyKey = propertyCursor.PropertyKey(); Value currentValue = propertyCursor.PropertyValue(); Pair <int, int> key = Pair.of(typeId, propertyKey); UpdateValueTypeInMapping(currentValue, key, relMappings.RelationshipTypeIdANDPropertyTypeIdToValueType); propertyIds.add(propertyKey); } propertyCursor.Close(); MutableIntSet oldPropertyKeySet = relMappings.RelationshipTypeIdToPropertyKeys.getOrDefault(typeId, _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 rels with this type, set all of them nullable relMappings.NullableRelationshipTypes.Add(typeId); } 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 rel propertyIds.addAll(oldPropertyKeySet); propertyIds.forEach(id => { Pair <int, int> key = Pair.of(typeId, id); relMappings.RelationshipTypeIdANDPropertyTypeIdToValueType[key].setNullable(); }); propertyIds.addAll(currentPropertyIdsHelperSet); } relMappings.RelationshipTypeIdToPropertyKeys[typeId] = propertyIds; } relationshipScanCursor.Close(); } }
// This is functionality which is only required for the hacky db.schema not to leak real data //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotAccessNegativeReferences() public virtual void ShouldNotAccessNegativeReferences() { // given using (RelationshipScanCursor relationship = cursors.allocateRelationshipScanCursor()) { // when read.singleRelationship(-2L, relationship); // then assertFalse("should not access negative reference relationship", relationship.Next()); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotAccessDeletedRelationship() public virtual void ShouldNotAccessDeletedRelationship() { // given using (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor()) { // when read.singleRelationship(_none, relationships); // then assertFalse("should not access deleted relationship", relationships.Next()); } }
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 = _spi.kernelTransaction(); int itemsToReturn = keys.Length; 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); } IDictionary <string, object> properties = new Dictionary <string, object>(itemsToReturn); RelationshipScanCursor relationships = transaction.AmbientRelationshipCursor(); PropertyCursor propertyCursor = transaction.AmbientPropertyCursor(); SingleRelationship(transaction, relationships); relationships.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); }
internal static int CountRelationships(Transaction transaction) { int result = 0; using (RelationshipScanCursor cursor = transaction.Cursors().allocateRelationshipScanCursor()) { transaction.DataRead().allRelationshipsScan(cursor); while (cursor.Next()) { result++; } } return(result); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldScanRelationships() public virtual void ShouldScanRelationships() { // given IList <long> ids = new List <long>(); using (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor()) { // when read.allRelationshipsScan(relationships); while (relationships.Next()) { ids.Add(relationships.RelationshipReference()); } } assertEquals(_relationshipIds, ids); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldAccessRelationshipByReference() public virtual void ShouldAccessRelationshipByReference() { // given using (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor()) { foreach (long id in _relationshipIds) { // when read.singleRelationship(id, relationships); // then assertTrue("should access defined relationship", relationships.Next()); assertEquals("should access the correct relationship", id, relationships.RelationshipReference()); assertFalse("should only access a single relationship", relationships.Next()); } } }
public virtual bool InitializeData() { // It enough to check only start node, since it's absence will indicate that data was not yet loaded. if (_startNode == AbstractBaseRecord.NO_ID) { KernelTransaction transaction = _spi.kernelTransaction(); using (Statement ignore = transaction.AcquireStatement()) { RelationshipScanCursor relationships = transaction.AmbientRelationshipCursor(); transaction.DataRead().singleRelationship(_id, relationships); // At this point we don't care if it is there or not just load what we got. bool wasPresent = relationships.Next(); this._type = relationships.Type(); this._startNode = relationships.SourceNodeReference(); this._endNode = relationships.TargetNodeReference(); // But others might care, e.g. the Bolt server needs to know for serialisation purposes. return(wasPresent); } } return(true); }
internal virtual Value RelationshipGetProperty(Transaction transaction, long relationship, int property) { using (RelationshipScanCursor cursor = transaction.Cursors().allocateRelationshipScanCursor(), PropertyCursor properties = transaction.Cursors().allocatePropertyCursor()) { transaction.DataRead().singleRelationship(relationship, cursor); if (!cursor.Next()) { return(NO_VALUE); } else { cursor.Properties(properties); while (properties.Next()) { if (properties.PropertyKey() == property) { return(properties.PropertyValue()); } } return(NO_VALUE); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldAccessNodes() public virtual void ShouldAccessNodes() { // given using (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor()) { // when read.singleRelationship(_one, relationships); // then assertTrue(relationships.Next()); assertEquals(_c, relationships.SourceNodeReference()); assertEquals(_d, relationships.TargetNodeReference()); assertFalse(relationships.Next()); // when read.singleRelationship(_loop, relationships); // then assertTrue(relationships.Next()); assertEquals(relationships.SourceNodeReference(), relationships.TargetNodeReference()); assertFalse(relationships.Next()); } }
public override void RelationshipTypeScan(int type, RelationshipScanCursor cursor) { throw new System.NotSupportedException(); }
public override void AllRelationshipsScan(RelationshipScanCursor cursor) { throw new System.NotSupportedException(); }
public override void SingleRelationship(long reference, RelationshipScanCursor cursor) { throw new System.NotSupportedException(); }
public override void RelationshipTypeScan(int type, RelationshipScanCursor cursor) { Ktx.assertOpen(); (( DefaultRelationshipScanCursor )cursor).Scan(type, this); }
public override void AllRelationshipsScan(RelationshipScanCursor cursor) { Ktx.assertOpen(); (( DefaultRelationshipScanCursor )cursor).Scan(-1, this); }
public override void SingleRelationship(long reference, RelationshipScanCursor cursor) { Ktx.assertOpen(); (( DefaultRelationshipScanCursor )cursor).Single(reference, this); }