Skip to content

Commit

Permalink
Support autoindexing for all operations
Browse files Browse the repository at this point in the history
In order to do this we had to move some exceptions out of kernel and
with that we also moved EntityType
  • Loading branch information
pontusmelke committed Dec 4, 2017
1 parent 6166f41 commit 95f746c
Show file tree
Hide file tree
Showing 95 changed files with 575 additions and 297 deletions.
Expand Up @@ -20,8 +20,8 @@
package org.neo4j.cypher.internal.codegen;

import org.neo4j.graphdb.Direction;
import org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException;
import org.neo4j.kernel.api.ReadOperations;
import org.neo4j.kernel.api.exceptions.EntityNotFoundException;
import org.neo4j.kernel.impl.api.RelationshipDataExtractor;
import org.neo4j.kernel.impl.api.RelationshipVisitor;
import org.neo4j.kernel.impl.api.store.RelationshipIterator;
Expand Down
Expand Up @@ -43,14 +43,15 @@ import org.neo4j.graphdb.RelationshipType._
import org.neo4j.graphdb._
import org.neo4j.graphdb.security.URLAccessValidationError
import org.neo4j.graphdb.traversal.{Evaluators, TraversalDescription, Uniqueness}
import org.neo4j.internal.kernel.api
import org.neo4j.internal.kernel.api.IndexQuery
import org.neo4j.kernel.GraphDatabaseQueryService
import org.neo4j.kernel.api._
import org.neo4j.kernel.api.exceptions.schema.{AlreadyConstrainedException, AlreadyIndexedException}
import org.neo4j.kernel.api.index.InternalIndexState
import org.neo4j.kernel.api.schema.SchemaDescriptorFactory
import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptorFactory
import org.neo4j.kernel.api.schema.index.IndexDescriptorFactory
import org.neo4j.kernel.api.schema.SchemaDescriptorFactory
import org.neo4j.kernel.api.{exceptions, _}
import org.neo4j.kernel.impl.core.NodeManager
import org.neo4j.values.storable.Values

Expand Down Expand Up @@ -276,15 +277,15 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper)
try {
tc.statement.dataWriteOperations().nodeDelete(obj.getId)
} catch {
case _: exceptions.EntityNotFoundException => // node has been deleted by another transaction, oh well...
case _: api.exceptions.EntityNotFoundException => // node has been deleted by another transaction, oh well...
}
}

def detachDelete(obj: Node): Int = {
try {
tc.statement.dataWriteOperations().nodeDetachDelete(obj.getId)
} catch {
case _: exceptions.EntityNotFoundException => // the node has been deleted by another transaction, oh well...
case _: api.exceptions.EntityNotFoundException => // the node has been deleted by another transaction, oh well...
0
}
}
Expand All @@ -300,35 +301,35 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper)
override def next(): Int = try {
inner.next()
} catch {
case _: org.neo4j.kernel.api.exceptions.EntityNotFoundException => null.asInstanceOf[Int]
case _: api.exceptions.EntityNotFoundException => null.asInstanceOf[Int]
}
}
} catch {
case _: exceptions.EntityNotFoundException => Iterator.empty
case _: api.exceptions.EntityNotFoundException => Iterator.empty
}

def getProperty(id: Long, propertyKeyId: Int): Any = try {
tc.statement.readOperations().nodeGetProperty(id, propertyKeyId).asObject()
} catch {
case _: org.neo4j.kernel.api.exceptions.EntityNotFoundException => null.asInstanceOf[Int]
case _: api.exceptions.EntityNotFoundException => null.asInstanceOf[Int]
}

def hasProperty(id: Long, propertyKey: Int): Boolean = try {
tc.statement.readOperations().nodeHasProperty(id, propertyKey)
} catch {
case _: org.neo4j.kernel.api.exceptions.EntityNotFoundException => false
case _: api.exceptions.EntityNotFoundException => false
}

def removeProperty(id: Long, propertyKeyId: Int): Unit = try {
tc.statement.dataWriteOperations().nodeRemoveProperty(id, propertyKeyId)
} catch {
case _: org.neo4j.kernel.api.exceptions.EntityNotFoundException => //ignore
case _: api.exceptions.EntityNotFoundException => //ignore
}

def setProperty(id: Long, propertyKeyId: Int, value: Any): Unit = try {
tc.statement.dataWriteOperations().nodeSetProperty(id, propertyKeyId, Values.of(value))
} catch {
case _: org.neo4j.kernel.api.exceptions.EntityNotFoundException => //ignore
case _: api.exceptions.EntityNotFoundException => //ignore
}

override def getById(id: Long) = try {
Expand All @@ -355,7 +356,7 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper)
try {
tc.statement.dataWriteOperations().relationshipDelete(obj.getId)
} catch {
case _: exceptions.EntityNotFoundException => // node has been deleted by another transaction, oh well...
case _: api.exceptions.EntityNotFoundException => // node has been deleted by another transaction, oh well...
}
}

Expand All @@ -370,35 +371,35 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper)
override def next(): Int = try {
inner.next()
} catch {
case _: org.neo4j.kernel.api.exceptions.EntityNotFoundException => null.asInstanceOf[Int]
case _: api.exceptions.EntityNotFoundException => null.asInstanceOf[Int]
}
}
} catch {
case _: exceptions.EntityNotFoundException => Iterator.empty
case _: api.exceptions.EntityNotFoundException => Iterator.empty
}

override def getProperty(id: Long, propertyKeyId: Int): Any = try {
tc.statement.readOperations().relationshipGetProperty(id, propertyKeyId).asObject()
} catch {
case _: exceptions.EntityNotFoundException => null
case _: api.exceptions.EntityNotFoundException => null
}

override def hasProperty(id: Long, propertyKey: Int): Boolean = try {
tc.statement.readOperations().relationshipHasProperty(id, propertyKey)
} catch {
case _: exceptions.EntityNotFoundException => false
case _: api.exceptions.EntityNotFoundException => false
}

override def removeProperty(id: Long, propertyKeyId: Int): Unit = try {
tc.statement.dataWriteOperations().relationshipRemoveProperty(id, propertyKeyId)
} catch {
case _: exceptions.EntityNotFoundException => //ignore
case _: api.exceptions.EntityNotFoundException => //ignore
}

override def setProperty(id: Long, propertyKeyId: Int, value: Any): Unit = try {
tc.statement.dataWriteOperations().relationshipSetProperty(id, propertyKeyId, Values.of(value))
} catch {
case _: exceptions.EntityNotFoundException => //ignore
case _: api.exceptions.EntityNotFoundException => //ignore
}

override def getById(id: Long) = try {
Expand Down Expand Up @@ -617,7 +618,7 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper)
try {
tc.statement.dataWriteOperations().nodeDetachDelete(node.getId)
} catch {
case _: exceptions.EntityNotFoundException => // the node has been deleted by another transaction, oh well...
case _: api.exceptions.EntityNotFoundException => // the node has been deleted by another transaction, oh well...
0
}
}
Expand Down
Expand Up @@ -25,6 +25,7 @@ import java.util.function.Predicate
import org.neo4j.collection.RawIterator
import org.neo4j.collection.primitive.PrimitiveLongIterator
import org.neo4j.collection.primitive.base.Empty.EMPTY_PRIMITIVE_LONG_COLLECTION
import org.neo4j.cypher.InternalException
import org.neo4j.cypher.internal.compiler.v3_1.MinMaxOrdering.{BY_NUMBER, BY_STRING, BY_VALUE}
import org.neo4j.cypher.internal.compiler.v3_1._
import org.neo4j.cypher.internal.compiler.v3_1.ast.convert.commands.DirectionConverter.toGraphDb
Expand All @@ -39,13 +40,13 @@ import org.neo4j.cypher.internal.frontend.v3_1.{Bound, EntityNotFoundException,
import org.neo4j.cypher.internal.javacompat.GraphDatabaseCypherService
import org.neo4j.cypher.internal.runtime.interpreted.BeansAPIRelationshipIterator
import org.neo4j.cypher.internal.spi.v3_1.TransactionBoundQueryContext.IndexSearchMonitor
import org.neo4j.cypher.{InternalException, internal}
import org.neo4j.graphalgo.impl.path.ShortestPath
import org.neo4j.graphalgo.impl.path.ShortestPath.ShortestPathPredicate
import org.neo4j.graphdb.RelationshipType._
import org.neo4j.graphdb._
import org.neo4j.graphdb.security.URLAccessValidationError
import org.neo4j.graphdb.traversal.{Evaluators, TraversalDescription, Uniqueness}
import org.neo4j.internal.kernel.api
import org.neo4j.internal.kernel.api.IndexQuery
import org.neo4j.kernel.GraphDatabaseQueryService
import org.neo4j.kernel.api._
Expand All @@ -54,9 +55,9 @@ import org.neo4j.kernel.api.exceptions.ProcedureException
import org.neo4j.kernel.api.exceptions.schema.{AlreadyConstrainedException, AlreadyIndexedException}
import org.neo4j.kernel.api.index.InternalIndexState
import org.neo4j.kernel.api.proc.{QualifiedName => KernelQualifiedName}
import org.neo4j.kernel.api.schema.SchemaDescriptorFactory
import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptorFactory
import org.neo4j.kernel.api.schema.index.IndexDescriptorFactory
import org.neo4j.kernel.api.schema.SchemaDescriptorFactory
import org.neo4j.kernel.impl.core.NodeManager
import org.neo4j.kernel.impl.locking.ResourceTypes
import org.neo4j.values.storable.Values
Expand Down Expand Up @@ -111,7 +112,7 @@ final class TransactionBoundQueryContext(txContext: TransactionalContextWrapper)
override def getLabelsForNode(node: Long) = try {
JavaConversionSupport.asScala(txContext.statement.readOperations().nodeGetLabels(node))
} catch {
case e: org.neo4j.kernel.api.exceptions.EntityNotFoundException =>
case e: api.exceptions.EntityNotFoundException =>
if (nodeOps.isDeletedInThisTx(node))
throw new EntityNotFoundException(s"Node with id $node has been deleted in this transaction", e)
else
Expand Down Expand Up @@ -294,20 +295,20 @@ final class TransactionBoundQueryContext(txContext: TransactionalContextWrapper)
try {
txContext.statement.dataWriteOperations().nodeDelete(obj.getId)
} catch {
case _: exceptions.EntityNotFoundException => // node has been deleted by another transaction, oh well...
case _: api.exceptions.EntityNotFoundException => // node has been deleted by another transaction, oh well...
}
}

override def propertyKeyIds(id: Long): Iterator[Int] = try {
JavaConversionSupport.asScalaENFXSafe(txContext.statement.readOperations().nodeGetPropertyKeys(id))
} catch {
case _: exceptions.EntityNotFoundException => Iterator.empty
case _: api.exceptions.EntityNotFoundException => Iterator.empty
}

override def getProperty(id: Long, propertyKeyId: Int): Any = try {
txContext.statement.readOperations().nodeGetProperty(id, propertyKeyId).asObject()
} catch {
case e: org.neo4j.kernel.api.exceptions.EntityNotFoundException =>
case e: api.exceptions.EntityNotFoundException =>
if (isDeletedInThisTx(id))
throw new EntityNotFoundException(s"Node with id $id has been deleted in this transaction", e)
else
Expand All @@ -317,22 +318,22 @@ final class TransactionBoundQueryContext(txContext: TransactionalContextWrapper)
override def hasProperty(id: Long, propertyKey: Int): Boolean = try {
txContext.statement.readOperations().nodeHasProperty(id, propertyKey)
} catch {
case _: exceptions.EntityNotFoundException => false
case _: api.exceptions.EntityNotFoundException => false
}

override def removeProperty(id: Long, propertyKeyId: Int): Unit = {
try {
txContext.statement.dataWriteOperations().nodeRemoveProperty(id, propertyKeyId)
} catch {
case _: exceptions.EntityNotFoundException => //ignore
case _: api.exceptions.EntityNotFoundException => //ignore
}
}

override def setProperty(id: Long, propertyKeyId: Int, value: Any): Unit = {
try {
txContext.statement.dataWriteOperations().nodeSetProperty(id, propertyKeyId, Values.of(value) )
} catch {
case _: exceptions.EntityNotFoundException => //ignore
case _: api.exceptions.EntityNotFoundException => //ignore
}
}

Expand Down Expand Up @@ -369,20 +370,20 @@ final class TransactionBoundQueryContext(txContext: TransactionalContextWrapper)
try {
txContext.statement.dataWriteOperations().relationshipDelete(obj.getId)
} catch {
case _: exceptions.EntityNotFoundException => // node has been deleted by another transaction, oh well...
case _: api.exceptions.EntityNotFoundException => // node has been deleted by another transaction, oh well...
}
}

override def propertyKeyIds(id: Long): Iterator[Int] = try {
asScalaENFXSafe(txContext.statement.readOperations().relationshipGetPropertyKeys(id))
} catch {
case _: exceptions.EntityNotFoundException => Iterator.empty
case _: api.exceptions.EntityNotFoundException => Iterator.empty
}

override def getProperty(id: Long, propertyKeyId: Int): Any = try {
txContext.statement.readOperations().relationshipGetProperty(id, propertyKeyId).asObject()
} catch {
case e: org.neo4j.kernel.api.exceptions.EntityNotFoundException =>
case e: api.exceptions.EntityNotFoundException =>
if (isDeletedInThisTx(id))
throw new EntityNotFoundException(s"Relationship with id $id has been deleted in this transaction", e)
else
Expand All @@ -392,22 +393,22 @@ final class TransactionBoundQueryContext(txContext: TransactionalContextWrapper)
override def hasProperty(id: Long, propertyKey: Int): Boolean = try {
txContext.statement.readOperations().relationshipHasProperty(id, propertyKey)
} catch {
case _: exceptions.EntityNotFoundException => false
case _: api.exceptions.EntityNotFoundException => false
}

override def removeProperty(id: Long, propertyKeyId: Int): Unit = {
try {
txContext.statement.dataWriteOperations().relationshipRemoveProperty(id, propertyKeyId)
} catch {
case _: exceptions.EntityNotFoundException => //ignore
case _: api.exceptions.EntityNotFoundException => //ignore
}
}

override def setProperty(id: Long, propertyKeyId: Int, value: Any): Unit = {
try {
txContext.statement.dataWriteOperations().relationshipSetProperty(id, propertyKeyId, Values.of(value) )
} catch {
case _: exceptions.EntityNotFoundException => //ignore
case _: api.exceptions.EntityNotFoundException => //ignore
}
}

Expand Down Expand Up @@ -697,7 +698,7 @@ final class TransactionBoundQueryContext(txContext: TransactionalContextWrapper)
try {
txContext.statement.dataWriteOperations().nodeDetachDelete(node.getId)
} catch {
case _: exceptions.EntityNotFoundException => 0 // node has been deleted by another transaction, oh well...
case _: api.exceptions.EntityNotFoundException => 0 // node has been deleted by another transaction, oh well...
}
}

Expand Down
Expand Up @@ -22,8 +22,8 @@
import org.junit.Test;

import org.neo4j.graphdb.Direction;
import org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException;
import org.neo4j.kernel.api.ReadOperations;
import org.neo4j.kernel.api.exceptions.EntityNotFoundException;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
Expand Down
Expand Up @@ -21,6 +21,7 @@ package org.neo4j.cypher.internal.runtime.interpreted

import org.neo4j.collection.primitive.{PrimitiveIntIterator, PrimitiveLongIterator}
import org.neo4j.cypher.internal.util.v3_4.EntityNotFoundException
import org.neo4j.internal.kernel.api.exceptions

object JavaConversionSupport {

Expand All @@ -44,7 +45,7 @@ object JavaConversionSupport {
try {
_next = Some(f(more()))
} catch {
case _: org.neo4j.kernel.api.exceptions.EntityNotFoundException => // IGNORE
case _: exceptions.EntityNotFoundException => // IGNORE
case _: EntityNotFoundException => // IGNORE
}
}
Expand Down

0 comments on commit 95f746c

Please sign in to comment.