Skip to content

Commit

Permalink
Updated Cypher for latest Kernel API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rickardoberg committed Jul 6, 2015
1 parent dd0a2c0 commit 5ea466a
Show file tree
Hide file tree
Showing 30 changed files with 366 additions and 236 deletions.
Expand Up @@ -25,7 +25,8 @@ import java.util.Collections

import org.neo4j.cypher.internal.compiler.v2_3._
import org.neo4j.cypher.internal.compiler.v2_3.commands.values.KeyToken
import org.neo4j.cypher.internal.compiler.v2_3.helpers.{Eagerly, IsCollection}
import org.neo4j.cypher.internal.compiler.v2_3.helpers.JavaConversionSupport.asScala
import org.neo4j.cypher.internal.compiler.v2_3.helpers.{JavaConversionSupport, Eagerly, IsCollection}
import org.neo4j.cypher.internal.compiler.v2_3.notification.InternalNotification
import org.neo4j.cypher.internal.compiler.v2_3.planDescription.InternalPlanDescription
import org.neo4j.cypher.internal.compiler.v2_3.planDescription.InternalPlanDescription.Arguments.{Planner, Runtime}
Expand Down Expand Up @@ -174,12 +175,12 @@ class CompiledExecutionResult(taskCloser: TaskCloser,
private def props(x: PropertyContainer): String = {
val readOperations = statement.readOperations()
val (properties, propFcn, id) = x match {
case n: Node => (readOperations.nodeGetAllProperties(n.getId).asScala.map(_.propertyKeyId()), readOperations.nodeGetProperty _, n.getId )
case r: Relationship => (readOperations.relationshipGetAllProperties(r.getId).asScala.map(_.propertyKeyId()), readOperations.relationshipGetProperty _, r.getId)
case n: Node => (asScala(readOperations.nodeGetPropertyKeys(n.getId)), readOperations.nodeGetProperty _, n.getId )
case r: Relationship => (asScala(readOperations.relationshipGetPropertyKeys(r.getId)), readOperations.relationshipGetProperty _, r.getId)
}

val keyValStrings = properties.
map(pkId => readOperations.propertyKeyGetName(pkId) + ":" + text(propFcn(id, pkId).value(null)))
map(pkId => readOperations.propertyKeyGetName(pkId) + ":" + text(propFcn(id, pkId)))

keyValStrings.mkString("{", ",", "}")
}
Expand Down
Expand Up @@ -111,10 +111,10 @@ final class TransactionBoundQueryContext(graph: GraphDatabaseAPI,
JavaConversionSupport.asScala(statement.readOperations().nodeGetLabels(node))

def getPropertiesForNode(node: Long) =
JavaConversionSupport.mapToScala(statement.readOperations().nodeGetAllPropertiesKeys(node))(_.toLong)
JavaConversionSupport.mapToScala(statement.readOperations().nodeGetPropertyKeys(node))(_.toLong)

def getPropertiesForRelationship(relId: Long) =
JavaConversionSupport.mapToScala(statement.readOperations().relationshipGetAllPropertiesKeys(relId))(_.toLong)
JavaConversionSupport.mapToScala(statement.readOperations().relationshipGetPropertyKeys(relId))(_.toLong)

override def isLabelSetOnNode(label: Int, node: Long) =
statement.readOperations().nodeHasLabel(node, label)
Expand Down Expand Up @@ -159,14 +159,14 @@ final class TransactionBoundQueryContext(graph: GraphDatabaseAPI,
}

def propertyKeyIds(id: Long): Iterator[Int] =
statement.readOperations().nodeGetAllProperties(id).asScala.map(_.propertyKeyId())
asScala(statement.readOperations().nodeGetPropertyKeys(id))

def getProperty(id: Long, propertyKeyId: Int): Any = {
statement.readOperations().nodeGetProperty(id, propertyKeyId).value(null)
statement.readOperations().nodeGetProperty(id, propertyKeyId)
}

def hasProperty(id: Long, propertyKey: Int) =
statement.readOperations().nodeGetProperty(id, propertyKey).isDefined
statement.readOperations().nodeHasProperty(id, propertyKey)

def removeProperty(id: Long, propertyKeyId: Int) {
statement.dataWriteOperations().nodeRemoveProperty(id, propertyKeyId)
Expand Down Expand Up @@ -200,13 +200,13 @@ final class TransactionBoundQueryContext(graph: GraphDatabaseAPI,
}

def propertyKeyIds(id: Long): Iterator[Int] =
statement.readOperations().relationshipGetAllProperties(id).asScala.map(_.propertyKeyId())
asScala(statement.readOperations().relationshipGetPropertyKeys(id))

def getProperty(id: Long, propertyKeyId: Int): Any =
statement.readOperations().relationshipGetProperty(id, propertyKeyId).value(null)
statement.readOperations().relationshipGetProperty(id, propertyKeyId)

def hasProperty(id: Long, propertyKey: Int) =
statement.readOperations().relationshipGetProperty(id, propertyKey).isDefined
statement.readOperations().relationshipHasProperty(id, propertyKey)

def removeProperty(id: Long, propertyKeyId: Int) {
statement.dataWriteOperations().relationshipRemoveProperty(id, propertyKeyId)
Expand Down
Expand Up @@ -678,37 +678,29 @@ private case class Method(fields: Fields, generator: CodeBlock, aux:AuxGenerator
val local = locals(propValueVar)
Templates.handleExceptions(generator, fields.ro) { body =>

body.assign(local, Expression.invoke(
Expression.invoke(readOperations, Methods.nodeGetProperty, body.load(nodeIdVar), body.load(propIdVar)),
Methods.value, Expression.constant(null)))
body.assign(local, Expression.invoke(readOperations, Methods.nodeGetProperty, body.load(nodeIdVar), body.load(propIdVar)))

}
}

override def nodeGetPropertyById(nodeIdVar: String, propId: Int, propValueVar: String) = {
val local = locals(propValueVar)
Templates.handleExceptions(generator, fields.ro) { body =>
body.assign(local, Expression.invoke(
Expression.invoke(readOperations, Methods.nodeGetProperty, body.load(nodeIdVar), Expression.constant(propId)),
Methods.value, Expression.constant(null)))
body.assign(local, Expression.invoke(readOperations, Methods.nodeGetProperty, body.load(nodeIdVar), Expression.constant(propId)))
}
}

override def relationshipGetPropertyForVar(relIdVar: String, propIdVar: String, propValueVar: String) = {
val local = locals(propValueVar)
Templates.handleExceptions(generator, fields.ro) { body =>
body.assign(local, Expression.invoke(
Expression.invoke(readOperations, Methods.relationshipGetProperty, body.load(relIdVar), body.load(propIdVar)),
Methods.value, Expression.constant(null)))
body.assign(local, Expression.invoke(readOperations, Methods.relationshipGetProperty, body.load(relIdVar), body.load(propIdVar)))
}
}

override def relationshipGetPropertyById(relIdVar: String, propId: Int, propValueVar: String) = {
val local = locals(propValueVar)
Templates.handleExceptions(generator, fields.ro) { body =>
body.assign(local, Expression.invoke(
Expression.invoke(readOperations, Methods.relationshipGetProperty, body.load(relIdVar), Expression.constant(propId)),
Methods.value, Expression.constant(null)))
body.assign(local, Expression.invoke(readOperations, Methods.relationshipGetProperty, body.load(relIdVar), Expression.constant(propId)))
}
}

Expand Down Expand Up @@ -803,7 +795,6 @@ private object Methods {
val executeOperator = method[QueryExecutionTracer, QueryExecutionEvent]("executeOperator", typeRef[Id])
val dbHit = method[QueryExecutionEvent, Unit]("dbHit")
val row = method[QueryExecutionEvent, Unit]("row")
val value = method[Property, Object]("value", typeRef[Object])
}

private object Templates {
Expand Down
Expand Up @@ -114,10 +114,10 @@ final class TransactionBoundQueryContext(graph: GraphDatabaseAPI,
JavaConversionSupport.asScala(statement.readOperations().nodeGetLabels(node))

def getPropertiesForNode(node: Long) =
JavaConversionSupport.asScala(statement.readOperations().nodeGetAllPropertiesKeys(node))
JavaConversionSupport.asScala(statement.readOperations().nodeGetPropertyKeys(node))

def getPropertiesForRelationship(relId: Long) =
JavaConversionSupport.asScala(statement.readOperations().relationshipGetAllPropertiesKeys(relId))
JavaConversionSupport.asScala(statement.readOperations().relationshipGetPropertyKeys(relId))

override def isLabelSetOnNode(label: Int, node: Long) =
statement.readOperations().nodeHasLabel(node, label)
Expand Down Expand Up @@ -173,16 +173,16 @@ final class TransactionBoundQueryContext(graph: GraphDatabaseAPI,
}

def propertyKeyIds(id: Long): Iterator[Int] =
JavaConversionSupport.asScala(statement.readOperations().nodeGetAllPropertiesKeys(id))
JavaConversionSupport.asScala(statement.readOperations().nodeGetPropertyKeys(id))

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

def hasProperty(id: Long, propertyKey: Int) =
statement.readOperations().nodeGetProperty(id, propertyKey).isDefined
statement.readOperations().nodeHasProperty(id, propertyKey)

def removeProperty(id: Long, propertyKeyId: Int) {
statement.dataWriteOperations().nodeRemoveProperty(id, propertyKeyId)
Expand Down Expand Up @@ -216,13 +216,13 @@ final class TransactionBoundQueryContext(graph: GraphDatabaseAPI,
}

def propertyKeyIds(id: Long): Iterator[Int] =
statement.readOperations().relationshipGetAllProperties(id).asScala.map(_.propertyKeyId())
asScala(statement.readOperations().relationshipGetPropertyKeys(id))

def getProperty(id: Long, propertyKeyId: Int): Any =
statement.readOperations().relationshipGetProperty(id, propertyKeyId).value(null)
statement.readOperations().relationshipGetProperty(id, propertyKeyId)

def hasProperty(id: Long, propertyKey: Int) =
statement.readOperations().relationshipGetProperty(id, propertyKey).isDefined
statement.readOperations().relationshipHasProperty(id, propertyKey)

def removeProperty(id: Long, propertyKeyId: Int) {
statement.dataWriteOperations().relationshipRemoveProperty(id, propertyKeyId)
Expand Down
23 changes: 10 additions & 13 deletions community/kernel/src/main/java/org/neo4j/kernel/api/DataRead.java
Expand Up @@ -19,17 +19,13 @@
*/
package org.neo4j.kernel.api;

import java.util.Iterator;

import org.neo4j.collection.primitive.PrimitiveIntIterator;
import org.neo4j.collection.primitive.PrimitiveLongIterator;
import org.neo4j.graphdb.Direction;
import org.neo4j.kernel.api.exceptions.EntityNotFoundException;
import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException;
import org.neo4j.kernel.api.exceptions.schema.IndexBrokenKernelException;
import org.neo4j.kernel.api.index.IndexDescriptor;
import org.neo4j.kernel.api.properties.DefinedProperty;
import org.neo4j.kernel.api.properties.Property;
import org.neo4j.kernel.impl.api.RelationshipVisitor;
import org.neo4j.kernel.impl.api.store.RelationshipIterator;

Expand Down Expand Up @@ -116,24 +112,25 @@ long nodeGetFromUniqueIndexSeek( IndexDescriptor index, Object value ) throws In
*/
PrimitiveIntIterator nodeGetLabels( long nodeId ) throws EntityNotFoundException;

PrimitiveIntIterator nodeGetAllPropertiesKeys( long nodeId ) throws EntityNotFoundException;
PrimitiveIntIterator nodeGetPropertyKeys( long nodeId ) throws EntityNotFoundException;

PrimitiveIntIterator relationshipGetPropertyKeys( long relationshipId ) throws EntityNotFoundException;

PrimitiveIntIterator relationshipGetAllPropertiesKeys( long relationshipId ) throws EntityNotFoundException;
PrimitiveIntIterator graphGetPropertyKeys();

PrimitiveIntIterator nodeGetRelationshipTypes( long nodeId ) throws EntityNotFoundException;

Property nodeGetProperty( long nodeId, int propertyKeyId ) throws EntityNotFoundException;
boolean nodeHasProperty( long nodeId, int propertyKeyId ) throws EntityNotFoundException;

Property relationshipGetProperty( long relationshipId, int propertyKeyId ) throws EntityNotFoundException;
Object nodeGetProperty( long nodeId, int propertyKeyId ) throws EntityNotFoundException;

Property graphGetProperty( int propertyKeyId );
boolean relationshipHasProperty( long relationshipId, int propertyKeyId ) throws EntityNotFoundException;

Iterator<DefinedProperty> nodeGetAllProperties( long nodeId ) throws EntityNotFoundException;
Object relationshipGetProperty( long relationshipId, int propertyKeyId ) throws EntityNotFoundException;

Iterator<DefinedProperty> relationshipGetAllProperties( long relationshipId )
throws EntityNotFoundException;
boolean graphHasProperty( int propertyKeyId );

Iterator<DefinedProperty> graphGetAllProperties();
Object graphGetProperty( int propertyKeyId );

<EXCEPTION extends Exception> void relationshipVisit( long relId, RelationshipVisitor<EXCEPTION> visitor )
throws EntityNotFoundException, EXCEPTION;
Expand Down
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2002-2015 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.api.cursor;

import org.neo4j.cursor.Cursor;

/**
* Cursor for iterating over a set of entities (nodes or relationships).
*/
public interface EntityCursor
extends Cursor
{
/**
* @return id of current entity
* @throws IllegalStateException if no current entity is selected
*/
long getId();

/**
* @return cursor for properties of current entity
* @throws IllegalStateException if no current entity is selected
*/
PropertyCursor properties();
}
Expand Up @@ -72,5 +72,8 @@ public void close()
*/
boolean seek( int labelId );

/**
* @return id of current label
*/
int getLabel();
}
Expand Up @@ -19,22 +19,29 @@
*/
package org.neo4j.kernel.api.cursor;

import org.neo4j.cursor.Cursor;
import org.neo4j.graphdb.Direction;

/**
* Cursor for iterating over a set of nodes.
*/
public interface NodeCursor
extends Cursor
extends EntityCursor
{
long getId();

/**
* @return label cursor for current node
* @throws IllegalStateException if no current node is selected
*/
LabelCursor labels();

PropertyCursor properties();

/**
* @return relationship cursor for current node
* @throws IllegalStateException if no current node is selected
*/
RelationshipCursor relationships( Direction direction, int... relTypes );

/**
* @return relationship cursor for current node
* @throws IllegalStateException if no current node is selected
*/
RelationshipCursor relationships( Direction direction );
}
Expand Up @@ -26,6 +26,9 @@

/**
* Cursor for iterating over the properties of a node or relationship.
*
* If the cursor is not in a valid state ({@link #next()} or {@link #seek(int)} returns false,
* then accessor calls will result in IllegalStateException being thrown.
*/
public interface PropertyCursor
extends Cursor
Expand Down Expand Up @@ -102,19 +105,54 @@ public void close()
}
};

/**
* Move the cursor to a particular property.
*
* @param keyId of the property to find
* @return true if found
*/
boolean seek( int keyId );

/**
* @return the key id of the current property.
*/
int propertyKeyId();

/**
* @return the value of the current property.
*/
Object value();

/**
* @return the boolean value of the current property
* @throws IllegalStateException if current property is not a boolean
*/
boolean booleanValue();

/**
* @return the integer value of the current property
* @throws IllegalStateException if current property is not an integer number
*/
long longValue();

/**
* @return the real value of the current property
* @throws IllegalStateException if current property is not a real number
*/
double doubleValue();

/**
* @return the string value of the current property
*/
String stringValue();

/**
* The byte representation of the current value.
*
* NOTE: this is currently less than useful as it will return
* the internal formats for e.g. strings, rather than UTF-8.
*
* @param channel to write the data into
*/
void propertyData( WritableByteChannel channel );
}

0 comments on commit 5ea466a

Please sign in to comment.