private KernelTransaction safeAcquireTransaction() { org.neo4j.kernel.api.KernelTransaction transaction = actions.kernelTransaction(); if ( transaction.isTerminated() ) { Status terminationReason = transaction.getReasonIfTerminated().orElse( Status.Transaction.Terminated ); throw new TransactionTerminatedException( terminationReason ); } return transaction; } }
private KernelTransaction safeAcquireTransaction() { KernelTransaction transaction = spi.kernelTransaction(); if ( transaction.isTerminated() ) { Status terminationReason = transaction.getReasonIfTerminated().orElse( Status.Transaction.Terminated ); throw new TransactionTerminatedException( terminationReason ); } return transaction; }
@Override public Iterable<String> getPropertyKeys() { KernelTransaction transaction = spi.kernelTransaction(); List<String> keys = new ArrayList<>(); try { RelationshipScanCursor relationships = transaction.ambientRelationshipCursor(); PropertyCursor properties = transaction.ambientPropertyCursor(); singleRelationship( transaction, relationships ); TokenRead token = transaction.tokenRead(); relationships.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 = spi.kernelTransaction();
@Override public Map<String, Object> getAllProperties() { KernelTransaction transaction = spi.kernelTransaction(); Map<String,Object> properties = new HashMap<>(); try { RelationshipScanCursor relationships = transaction.ambientRelationshipCursor(); PropertyCursor propertyCursor = transaction.ambientPropertyCursor(); TokenRead token = transaction.tokenRead(); singleRelationship( transaction, relationships ); relationships.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 Object removeProperty( String key ) throws NotFoundException { KernelTransaction transaction = spi.kernelTransaction(); try ( Statement ignore = transaction.acquireStatement() ) { int propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName( key ); return transaction.dataWrite().nodeRemoveProperty( nodeId, propertyKeyId ).asObjectCopy(); } catch ( EntityNotFoundException e ) { throw new NotFoundException( e ); } catch ( IllegalTokenNameException e ) { throw new IllegalArgumentException( format( "Invalid property key '%s'.", key ), e ); } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } catch ( AutoIndexingKernelException e ) { throw new IllegalStateException( "Auto indexing encountered a failure while removing property: " + e.getMessage(), e ); } }
@Override public Object removeProperty( String key ) { KernelTransaction transaction = spi.kernelTransaction(); try ( Statement ignore = transaction.acquireStatement() ) { int propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName( key ); return transaction.dataWrite().relationshipRemoveProperty( id, propertyKeyId ).asObjectCopy(); } catch ( EntityNotFoundException e ) { throw new NotFoundException( e ); } catch ( IllegalTokenNameException e ) { throw new IllegalArgumentException( format( "Invalid property key '%s'.", key ), e ); } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } catch ( AutoIndexingKernelException e ) { throw new IllegalStateException( "Auto indexing encountered a failure while removing property: " + e.getMessage(), e ); } }
@Override public void delete() { KernelTransaction transaction = spi.kernelTransaction(); try { boolean deleted = transaction.dataWrite().relationshipDelete( id ); if ( !deleted ) { throw new NotFoundException( "Unable to delete relationship[" + getId() + "] since it is already deleted." ); } } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } catch ( AutoIndexingKernelException e ) { throw new IllegalStateException( "Auto indexing encountered a failure while deleting the relationship: " + e.getMessage(), e ); } }
KernelTransaction transaction = spi.kernelTransaction(); int propertyKey = transaction.tokenRead().propertyKey( key ); if ( propertyKey == TokenRead.NO_TOKEN )
@Override public void setProperty( String key, Object value ) KernelTransaction transaction = spi.kernelTransaction(); int propertyKeyId; try
private void 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(); try ( 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 relationships.next(); this.type = relationships.type(); this.startNode = relationships.sourceNodeReference(); this.endNode = relationships.targetNodeReference(); } } }
@Override public Object getProperty( String key, Object defaultValue ) { if ( null == key ) { throw new IllegalArgumentException( "(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 == TokenRead.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; }
@Override public boolean hasProperty( String key ) { if ( null == key ) { return false; } KernelTransaction transaction = spi.kernelTransaction(); int propertyKey = transaction.tokenRead().propertyKey( key ); if ( propertyKey == TokenRead.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; }
@Override public void setProperty( String key, Object value ) KernelTransaction transaction = spi.kernelTransaction(); int propertyKeyId; try
@Override public void removeLabel( Label label ) { KernelTransaction transaction = spi.kernelTransaction(); try ( Statement ignore = transaction.acquireStatement() ) { int labelId = transaction.tokenRead().nodeLabel( label.name() ); if ( labelId != TokenRead.NO_TOKEN ) { transaction.dataWrite().nodeRemoveLabel( getId(), labelId ); } } catch ( EntityNotFoundException e ) { throw new NotFoundException( "No node with id " + getId() + " found.", e ); } catch ( KernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } }
@Override public void addLabel( Label label ) KernelTransaction transaction = spi.kernelTransaction(); try ( Statement ignore = transaction.acquireStatement() )
private KernelTransaction safeAcquireTransaction() { KernelTransaction transaction = spi.kernelTransaction(); if ( transaction.isTerminated() ) { Status terminationReason = transaction.getReasonIfTerminated().orElse( Status.Transaction.Terminated ); throw new TransactionTerminatedException( terminationReason ); } return transaction; }
private KernelTransaction safeAcquireTransaction() { org.neo4j.kernel.api.KernelTransaction transaction = actions.kernelTransaction(); if ( transaction.isTerminated() ) { Status terminationReason = transaction.getReasonIfTerminated().orElse( Status.Transaction.Terminated ); throw new TransactionTerminatedException( terminationReason ); } return transaction; } }
private void 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(); try ( 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 relationships.next(); this.type = relationships.type(); this.startNode = relationships.sourceNodeReference(); this.endNode = relationships.targetNodeReference(); } } }
@Override public void removeLabel( Label label ) { KernelTransaction transaction = spi.kernelTransaction(); try ( Statement ignore = transaction.acquireStatement() ) { int labelId = transaction.tokenRead().nodeLabel( label.name() ); if ( labelId != TokenRead.NO_TOKEN ) { transaction.dataWrite().nodeRemoveLabel( getId(), labelId ); } } catch ( EntityNotFoundException e ) { throw new NotFoundException( "No node with id " + getId() + " found.", e ); } catch ( KernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } }