@Override public int getDegree() { KernelTransaction transaction = safeAcquireTransaction(); try ( Statement ignore = transaction.acquireStatement() ) { NodeCursor nodes = transaction.ambientNodeCursor(); singleNode( transaction, nodes ); return Nodes.countAll( nodes, transaction.cursors() ); } }
@Override public Iterable<String> getPropertyKeys() { KernelTransaction transaction = safeAcquireTransaction(); List<String> keys = new ArrayList<>(); try { NodeCursor nodes = transaction.ambientNodeCursor(); PropertyCursor properties = transaction.ambientPropertyCursor(); singleNode( transaction, nodes ); TokenRead token = transaction.tokenRead(); nodes.properties( properties ); while ( properties.next() ) { keys.add( token.propertyKeyName( properties.propertyKey() ) ); } } catch ( PropertyKeyIdNotFoundKernelException e ) { throw new IllegalStateException( "Property key retrieved through kernel API should exist.", e ); } return keys; }
singleNode( transaction, nodes ); nodes.properties( propertyCursor ); int propertiesToFind = itemsToReturn;
@Override public Iterable<Label> getLabels() { KernelTransaction transaction = safeAcquireTransaction(); NodeCursor nodes = transaction.ambientNodeCursor(); try ( Statement ignore = spi.statement() ) { singleNode( transaction, nodes ); LabelSet labelSet = nodes.labels(); TokenRead tokenRead = transaction.tokenRead(); ArrayList<Label> list = new ArrayList<>( labelSet.numberOfLabels() ); for ( int i = 0; i < labelSet.numberOfLabels(); i++ ) { list.add( label( tokenRead.nodeLabelName( labelSet.label( i ) ) ) ); } return list; } catch ( LabelNotFoundKernelException e ) { throw new IllegalStateException( "Label retrieved through kernel API should exist.", e ); } }
@Override public Map<String,Object> getAllProperties() { KernelTransaction transaction = safeAcquireTransaction(); Map<String,Object> properties = new HashMap<>(); try { NodeCursor nodes = transaction.ambientNodeCursor(); PropertyCursor propertyCursor = transaction.ambientPropertyCursor(); TokenRead token = transaction.tokenRead(); singleNode( transaction, nodes ); nodes.properties( propertyCursor ); while ( propertyCursor.next() ) { properties.put( token.propertyKeyName( propertyCursor.propertyKey() ), propertyCursor.propertyValue().asObjectCopy() ); } } catch ( PropertyKeyIdNotFoundKernelException e ) { throw new IllegalStateException( "Property key retrieved through kernel API should exist.", e ); } return properties; }
singleNode( transaction, nodes ); nodes.properties( properties ); while ( properties.next() )
@Override public int getDegree( Direction direction ) { KernelTransaction transaction = safeAcquireTransaction(); try ( Statement ignore = transaction.acquireStatement() ) { NodeCursor nodes = transaction.ambientNodeCursor(); singleNode( transaction, nodes ); switch ( direction ) { case OUTGOING: return Nodes.countOutgoing( nodes, transaction.cursors() ); case INCOMING: return Nodes.countIncoming( nodes, transaction.cursors() ); case BOTH: return Nodes.countAll( nodes, transaction.cursors() ); default: throw new IllegalStateException( "Unknown direction " + direction ); } } }
@Override public int getDegree( RelationshipType type ) { KernelTransaction transaction = safeAcquireTransaction(); int typeId = transaction.tokenRead().relationshipType( type.name() ); if ( typeId == NO_TOKEN ) { // This type doesn't even exist. Return 0 return 0; } try ( Statement ignore = transaction.acquireStatement() ) { NodeCursor nodes = transaction.ambientNodeCursor(); singleNode( transaction, nodes ); return Nodes.countAll( nodes, transaction.cursors(), typeId ); } }
@Override public Object getProperty( String key, Object defaultValue ) { if ( null == key ) { throw new IllegalArgumentException( "(null) property key is not allowed" ); } KernelTransaction transaction = safeAcquireTransaction(); NodeCursor nodes = transaction.ambientNodeCursor(); PropertyCursor properties = transaction.ambientPropertyCursor(); int propertyKey = transaction.tokenRead().propertyKey( key ); if ( propertyKey == TokenRead.NO_TOKEN ) { return defaultValue; } singleNode( transaction, nodes ); nodes.properties( properties ); while ( properties.next() ) { if ( propertyKey == properties.propertyKey() ) { Value value = properties.propertyValue(); return value == Values.NO_VALUE ? defaultValue : value.asObjectCopy(); } } return defaultValue; }
@Override public boolean hasProperty( String key ) { if ( null == key ) { return false; } KernelTransaction transaction = safeAcquireTransaction(); int propertyKey = transaction.tokenRead().propertyKey( key ); if ( propertyKey == TokenRead.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; }
@Override public int getDegree( RelationshipType type, Direction direction ) { KernelTransaction transaction = safeAcquireTransaction(); int typeId = transaction.tokenRead().relationshipType( type.name() ); if ( typeId == NO_TOKEN ) { // This type doesn't even exist. Return 0 return 0; } try ( Statement ignore = transaction.acquireStatement() ) { NodeCursor nodes = transaction.ambientNodeCursor(); singleNode( transaction, nodes ); switch ( direction ) { case OUTGOING: return Nodes.countOutgoing( nodes, transaction.cursors(), typeId ); case INCOMING: return Nodes.countIncoming( nodes, transaction.cursors(), typeId ); case BOTH: return Nodes.countAll( nodes, transaction.cursors(), typeId ); default: throw new IllegalStateException( "Unknown direction " + direction ); } } }
@Override public Iterable<RelationshipType> getRelationshipTypes() { KernelTransaction transaction = safeAcquireTransaction(); try ( RelationshipGroupCursor relationships = transaction.cursors().allocateRelationshipGroupCursor(); Statement ignore = transaction.acquireStatement() ) { NodeCursor nodes = transaction.ambientNodeCursor(); TokenRead tokenRead = transaction.tokenRead(); singleNode( transaction, nodes ); nodes.relationships( relationships ); List<RelationshipType> types = new ArrayList<>(); while ( relationships.next() ) { // only include this type if there are any relationships with this type int type = relationships.type(); if ( relationships.totalCount() > 0 ) { types.add( RelationshipType.withName( tokenRead.relationshipTypeName( relationships.type() ) ) ); } } return types; } catch ( KernelException e ) { throw new NotFoundException( "Relationship name not found.", e ); } }
@Override public int getDegree() { KernelTransaction transaction = safeAcquireTransaction(); try ( Statement ignore = transaction.acquireStatement() ) { NodeCursor nodes = transaction.ambientNodeCursor(); singleNode( transaction, nodes ); return Nodes.countAll( nodes, transaction.cursors() ); } }
@Override public Iterable<String> getPropertyKeys() { KernelTransaction transaction = safeAcquireTransaction(); List<String> keys = new ArrayList<>(); try { NodeCursor nodes = transaction.ambientNodeCursor(); PropertyCursor properties = transaction.ambientPropertyCursor(); singleNode( transaction, nodes ); TokenRead token = transaction.tokenRead(); nodes.properties( properties ); while ( properties.next() ) { keys.add( token.propertyKeyName( properties.propertyKey() ) ); } } catch ( PropertyKeyIdNotFoundKernelException e ) { throw new IllegalStateException( "Property key retrieved through kernel API should exist.", e ); } return keys; }
@Override public Map<String,Object> getAllProperties() { KernelTransaction transaction = safeAcquireTransaction(); Map<String,Object> properties = new HashMap<>(); try { NodeCursor nodes = transaction.ambientNodeCursor(); PropertyCursor propertyCursor = transaction.ambientPropertyCursor(); TokenRead token = transaction.tokenRead(); singleNode( transaction, nodes ); nodes.properties( propertyCursor ); while ( propertyCursor.next() ) { properties.put( token.propertyKeyName( propertyCursor.propertyKey() ), propertyCursor.propertyValue().asObjectCopy() ); } } catch ( PropertyKeyIdNotFoundKernelException e ) { throw new IllegalStateException( "Property key retrieved through kernel API should exist.", e ); } return properties; }
@Override public Iterable<Label> getLabels() { KernelTransaction transaction = safeAcquireTransaction(); NodeCursor nodes = transaction.ambientNodeCursor(); try ( Statement ignore = spi.statement() ) { singleNode( transaction, nodes ); LabelSet labelSet = nodes.labels(); TokenRead tokenRead = transaction.tokenRead(); ArrayList<Label> list = new ArrayList<>( labelSet.numberOfLabels() ); for ( int i = 0; i < labelSet.numberOfLabels(); i++ ) { list.add( label( tokenRead.nodeLabelName( labelSet.label( i ) ) ) ); } return list; } catch ( LabelNotFoundKernelException e ) { throw new IllegalStateException( "Label retrieved through kernel API should exist.", e ); } }
@Override public int getDegree( Direction direction ) { KernelTransaction transaction = safeAcquireTransaction(); try ( Statement ignore = transaction.acquireStatement() ) { NodeCursor nodes = transaction.ambientNodeCursor(); singleNode( transaction, nodes ); switch ( direction ) { case OUTGOING: return Nodes.countOutgoing( nodes, transaction.cursors() ); case INCOMING: return Nodes.countIncoming( nodes, transaction.cursors() ); case BOTH: return Nodes.countAll( nodes, transaction.cursors() ); default: throw new IllegalStateException( "Unknown direction " + direction ); } } }
@Override public int getDegree( RelationshipType type ) { KernelTransaction transaction = safeAcquireTransaction(); int typeId = transaction.tokenRead().relationshipType( type.name() ); if ( typeId == NO_TOKEN ) { // This type doesn't even exist. Return 0 return 0; } try ( Statement ignore = transaction.acquireStatement() ) { NodeCursor nodes = transaction.ambientNodeCursor(); singleNode( transaction, nodes ); return Nodes.countAll( nodes, transaction.cursors(), typeId ); } }
@Override public boolean hasProperty( String key ) { if ( null == key ) { return false; } KernelTransaction transaction = safeAcquireTransaction(); int propertyKey = transaction.tokenRead().propertyKey( key ); if ( propertyKey == TokenRead.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; }
@Override public int getDegree( RelationshipType type, Direction direction ) { KernelTransaction transaction = safeAcquireTransaction(); int typeId = transaction.tokenRead().relationshipType( type.name() ); if ( typeId == NO_TOKEN ) { // This type doesn't even exist. Return 0 return 0; } try ( Statement ignore = transaction.acquireStatement() ) { NodeCursor nodes = transaction.ambientNodeCursor(); singleNode( transaction, nodes ); switch ( direction ) { case OUTGOING: return Nodes.countOutgoing( nodes, transaction.cursors(), typeId ); case INCOMING: return Nodes.countIncoming( nodes, transaction.cursors(), typeId ); case BOTH: return Nodes.countAll( nodes, transaction.cursors(), typeId ); default: throw new IllegalStateException( "Unknown direction " + direction ); } } }