@Override public ResourceIterable<Relationship> getRelationships( final Direction direction ) { KernelTransaction transaction = safeAcquireTransaction(); return innerGetRelationships( transaction, direction, null ); }
@Override public boolean hasRelationship( Direction direction ) { KernelTransaction transaction = safeAcquireTransaction(); return innerHasRelationships( transaction, direction, null ); }
@Override public ResourceIterable<Relationship> getRelationships( final Direction direction, RelationshipType... types ) { KernelTransaction transaction = safeAcquireTransaction(); int[] typeIds = relTypeIds( types, transaction.tokenRead() ); return innerGetRelationships( transaction, direction, typeIds ); }
@Override public boolean hasRelationship( Direction direction, RelationshipType... types ) { KernelTransaction transaction = safeAcquireTransaction(); int[] typeIds = relTypeIds( types, transaction.tokenRead() ); return innerHasRelationships( transaction, direction, typeIds ); }
@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; }
KernelTransaction transaction = safeAcquireTransaction();
@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; }
@Override public void delete() { KernelTransaction transaction = safeAcquireTransaction(); try { boolean deleted = transaction.dataWrite().nodeDelete( getId() ); if ( !deleted ) { throw new NotFoundException( "Unable to delete Node[" + nodeId + "] since it has already been deleted." ); } } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } catch ( AutoIndexingKernelException e ) { throw new IllegalStateException( "Auto indexing encountered a failure while deleting the node: " + e.getMessage(), e ); } }
KernelTransaction transaction = safeAcquireTransaction(); int propertyKey = transaction.tokenRead().propertyKey( key ); if ( propertyKey == TokenRead.NO_TOKEN )
@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 hasLabel( Label label ) { KernelTransaction transaction = safeAcquireTransaction(); NodeCursor nodes = transaction.ambientNodeCursor(); try ( Statement ignore = transaction.acquireStatement() ) { int labelId = transaction.tokenRead().nodeLabel( label.name() ); if ( labelId == NO_SUCH_LABEL ) { return false; } transaction.dataRead().singleNode( nodeId, nodes ); return nodes.next() && nodes.hasLabel( labelId ); } }
@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; }
KernelTransaction transaction = safeAcquireTransaction(); try ( Statement ignore = transaction.acquireStatement() )
@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 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( 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 ResourceIterable<Relationship> getRelationships( final Direction direction ) { KernelTransaction transaction = safeAcquireTransaction(); return innerGetRelationships( transaction, direction, null ); }