-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
188 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
manual/cypher/cypher-docs/src/docs/dev/ql/call/index.asciidoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[[query-call]] | ||
= Call | ||
|
||
[abstract] | ||
The `CALL` clause is used to call a procedure deployed in the database. | ||
|
||
The examples showing how to use arguments when invoking procedures all use the following procedure: | ||
|
||
[snippet,java] | ||
---- | ||
component=neo4j-cypher-docs | ||
source=org/neo4j/procedure/example/IndexingProcedure.java | ||
classifier=sources | ||
tag=indexingProcedure | ||
---- | ||
|
||
[NOTE] | ||
This clause cannot be combined with other clauses. | ||
|
||
:leveloffset: 2 | ||
|
||
include::call-a-procedure.asciidoc[] | ||
|
||
:leveloffset: 2 | ||
|
||
include::call-a-procedure-with-literal-arguments.asciidoc[] | ||
|
||
:leveloffset: 2 | ||
|
||
include::call-a-procedure-with-parameter-arguments.asciidoc[] | ||
|
||
:leveloffset: 2 | ||
|
||
include::call-a-procedure-with-mixed-literal-and-parameter-arguments.asciidoc[] |
54 changes: 54 additions & 0 deletions
54
manual/cypher/cypher-docs/src/main/java/org/neo4j/procedure/example/IndexingProcedure.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "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.procedure.example; | ||
|
||
import org.neo4j.graphdb.GraphDatabaseService; | ||
import org.neo4j.graphdb.Node; | ||
import org.neo4j.procedure.Name; | ||
import org.neo4j.procedure.PerformsWrites; | ||
import org.neo4j.procedure.Procedure; | ||
import org.neo4j.procedure.Context; | ||
|
||
// START SNIPPET: indexingProcedure | ||
public class IndexingProcedure | ||
{ | ||
@Context | ||
public GraphDatabaseService db; | ||
|
||
/** | ||
* Adds a node to a named legacy index. Useful to, for instance, update | ||
* a full-text index through cypher. | ||
* @param indexName the name of the index in question | ||
* @param nodeId id of the node to add to the index | ||
* @param propKey property to index (value is read from the node) | ||
*/ | ||
@Procedure | ||
@PerformsWrites | ||
public void addNodeToIndex( @Name("indexName") String indexName, | ||
@Name("node") long nodeId, | ||
@Name("propKey" ) String propKey ) | ||
{ | ||
Node node = db.getNodeById( nodeId ); | ||
db.index() | ||
.forNodes( indexName ) | ||
.add( node, propKey, node.getProperty( propKey ) ); | ||
} | ||
} | ||
// END SNIPPET: indexingProcedure |
82 changes: 82 additions & 0 deletions
82
manual/cypher/cypher-docs/src/test/scala/org/neo4j/cypher/docgen/CallTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "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.cypher.docgen | ||
|
||
import org.junit.Test | ||
import org.neo4j.cypher.QueryStatisticsTestSupport | ||
import org.neo4j.graphdb.{Label, Node} | ||
import org.neo4j.kernel.GraphDatabaseAPI | ||
import org.neo4j.kernel.impl.proc.Procedures | ||
import org.neo4j.procedure.example.IndexingProcedure | ||
|
||
class CallTest extends DocumentingTestBase with QueryStatisticsTestSupport with HardReset { | ||
|
||
var nodeId:Long = -1 | ||
|
||
override def section = "Call" | ||
|
||
override def hardReset() = { | ||
super.hardReset() | ||
db.getDependencyResolver.resolveDependency(classOf[Procedures]).register( classOf[IndexingProcedure] ) | ||
db.inTx { | ||
val node = db.createNode(Label.label("User"), Label.label("Administrator")) | ||
node.setProperty("name", "Adrian") | ||
nodeId = node.getId | ||
} | ||
} | ||
|
||
@Test def call_a_procedure() { | ||
testQuery( | ||
title = "Call a procedure", | ||
text = "This invokes the built-in procedure 'sys.db.labels', which lists all in-use labels in the database.", | ||
queryText = "CALL sys.db.labels", | ||
optionalResultExplanation = "", | ||
assertions = (p) => assert(p.hasNext) ) | ||
} | ||
|
||
@Test def call_a_procedure_with_literal_arguments() { | ||
testQuery( | ||
title = "Call a procedure with literal arguments", | ||
text = "This invokes the example procedure `org.neo4j.procedure.example.addNodeToIndex` using arguments that are written out directly in the statement text. This is called literal arguments.", | ||
queryText = "CALL org.neo4j.procedure.example.addNodeToIndex('users', "+nodeId+", 'name')", | ||
optionalResultExplanation = "Since our example procedure does not return any result, the result is empty.", | ||
assertions = (p) => assert(!p.hasNext) ) | ||
} | ||
|
||
@Test def call_a_procedure_with_parameter_arguments() { | ||
testQuery( | ||
title = "Call a procedure with parameter arguments", | ||
text = "This invokes the example procedure `org.neo4j.procedure.example.addNodeToIndex` using parameters. The procedure arguments are satisfied by matching the parameter keys to the named procedure arguments.", | ||
queryText = "CALL org.neo4j.procedure.example.addNodeToIndex", | ||
parameters = Map("indexName"->"users", "node"->nodeId, "propKey"-> "name"), | ||
optionalResultExplanation = "Since our example procedure does not return any result, the result is empty.", | ||
assertions = (p) => assert(!p.hasNext) ) | ||
} | ||
|
||
@Test def call_a_procedure_with_mixed_arguments() { | ||
testQuery( | ||
title = "Call a procedure with mixed literal and parameter arguments", | ||
text = "This invokes the example procedure `org.neo4j.procedure.example.addNodeToIndex` using both literal and parameterized arguments.", | ||
queryText = "CALL org.neo4j.procedure.example.addNodeToIndex('users', {node}, 'name')", | ||
parameters = Map("node"->nodeId), | ||
optionalResultExplanation = "Since our example procedure does not return any result, the result is empty.", | ||
assertions = (p) => assert(!p.hasNext) ) | ||
} | ||
} |