Skip to content

Commit

Permalink
Code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed Feb 23, 2018
1 parent 99f7041 commit 1c14911
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 37 deletions.
Expand Up @@ -706,11 +706,15 @@ sealed class TransactionBoundQueryContext(val transactionalContext: Transactiona
case e: NotFoundException => throw new EntityNotFoundException(s"Relationship with id $id", e)
}

override def getByIdIfExists(id: Long): Option[RelationshipValue] =
if (reads().relationshipExists(id))
Some(fromRelationshipProxy(entityAccessor.newRelationshipProxy(id)))
override def getByIdIfExists(id: Long): Option[RelationshipValue] = {
val cursor = relationshipScanCursor
reads().singleRelationship(id, cursor)
if (cursor.next())
Some(fromRelationshipProxy(entityAccessor.newRelationshipProxy(id, cursor.sourceNodeReference(), cursor.label(),
cursor.targetNodeReference()))
else
None
}

override def all: Iterator[RelationshipValue] = {
val relCursor = allocateAndTraceRelationshipScanCursor()
Expand Down
Expand Up @@ -41,7 +41,7 @@ public interface Write
* @param node the internal id of the node to delete
* @return returns true if it deleted a node or false if no node was found for this id
*/
boolean nodeDelete( long node ) throws AutoIndexingKernelException, EntityNotFoundException;
boolean nodeDelete( long node ) throws AutoIndexingKernelException;

/**
* Create a relationship between two nodes.
Expand All @@ -56,8 +56,7 @@ public interface Write
* Delete a relationship
* @param relationship the internal id of the relationship to delete
*/
boolean relationshipDelete( long relationship ) throws AutoIndexingKernelException, EntityNotFoundException;

boolean relationshipDelete( long relationship ) throws AutoIndexingKernelException;
/**
* Add a label to a node
* @param node the internal node id
Expand Down
Expand Up @@ -263,7 +263,6 @@ public void shouldCreateExplicitIndexTwice() throws Exception
}
}

//TODO unignore when we support relationship creation.
@Test
public void shouldAddRelationshipToExplicitIndex() throws Exception
{
Expand Down
Expand Up @@ -119,11 +119,6 @@ public void delete()
throw new IllegalStateException( "Auto indexing encountered a failure while deleting the node: "
+ e.getMessage(), e );
}
catch ( EntityNotFoundException e )
{
throw new NotFoundException( "Unable to delete node[" +
getId() + "] since it is already deleted." );
}
}

@Override
Expand Down Expand Up @@ -311,10 +306,6 @@ public Object removeProperty( String key ) throws NotFoundException
throw new IllegalStateException( "Auto indexing encountered a failure while removing property: "
+ e.getMessage(), e );
}
catch ( KernelException e )
{
throw new ConstraintViolationException( e.getMessage(), e );
}
}

@Override
Expand Down
Expand Up @@ -40,7 +40,6 @@
import org.neo4j.internal.kernel.api.TokenRead;
import org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException;
import org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException;
import org.neo4j.internal.kernel.api.exceptions.KernelException;
import org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException;
import org.neo4j.internal.kernel.api.exceptions.explicitindex.AutoIndexingKernelException;
import org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException;
Expand Down Expand Up @@ -140,17 +139,14 @@ public void delete()
boolean deleted = transaction.dataWrite().relationshipDelete( id );
if ( !deleted )
{
alreadyDeleted();
throw new NotFoundException( "Unable to delete relationship[" +
getId() + "] since it is already deleted." );
}
}
catch ( InvalidTransactionTypeKernelException e )
{
throw new ConstraintViolationException( e.getMessage(), e );
}
catch ( EntityNotFoundException e )
{
alreadyDeleted();
}
catch ( AutoIndexingKernelException e )
{
throw new IllegalStateException( "Auto indexing encountered a failure while deleting the relationship: "
Expand Down Expand Up @@ -452,10 +448,7 @@ public void setProperty( String key, Object value )
throw new IllegalStateException( "Auto indexing encountered a failure while setting property: "
+ e.getMessage(), e );
}
catch ( KernelException e )
{
throw new ConstraintViolationException( e.getMessage(), e );
}

}

@Override
Expand Down Expand Up @@ -484,10 +477,6 @@ public Object removeProperty( String key )
throw new IllegalStateException( "Auto indexing encountered a failure while removing property: "
+ e.getMessage(), e );
}
catch ( KernelException e )
{
throw new ConstraintViolationException( e.getMessage(), e );
}
}

@Override
Expand Down Expand Up @@ -559,9 +548,4 @@ private void assertInUnterminatedTransaction()
actions.assertInUnterminatedTransaction();
}

private void alreadyDeleted()
{
throw new NotFoundException( "Unable to delete relationship[" +
getId() + "] since it is already deleted." );
}
}
Expand Up @@ -172,7 +172,7 @@ public long relationshipCreate( long sourceNode, int relationshipType, long targ
}

@Override
public boolean relationshipDelete( long relationship ) throws AutoIndexingKernelException, EntityNotFoundException
public boolean relationshipDelete( long relationship ) throws AutoIndexingKernelException
{
ktx.assertOpen();

Expand All @@ -182,7 +182,10 @@ public boolean relationshipDelete( long relationship ) throws AutoIndexingKernel
{
lockRelationshipNodes( relationshipCursor.sourceNodeReference(), relationshipCursor.targetNodeReference() );
acquireExclusiveRelationshipLock( relationship );
assertRelationshipExists( relationship );
if ( !allStoreHolder.relationshipExists( relationship ) )
{
return false;
}

ktx.assertOpen();

Expand Down

0 comments on commit 1c14911

Please sign in to comment.