Skip to content

Commit

Permalink
Add CALL to cypher documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jakewins committed Feb 1, 2016
1 parent 036f14e commit 1d4ff83
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 45 deletions.
9 changes: 8 additions & 1 deletion manual/contents/pom.xml
Expand Up @@ -139,6 +139,13 @@
<classifier>docs</classifier>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.neo4j.doc</groupId>
<artifactId>neo4j-cypher-docs</artifactId>
<version>${neo4j.version}</version>
<classifier>sources</classifier>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.neo4j.doc</groupId>
<artifactId>neo4j-cypher-docs</artifactId>
Expand Down Expand Up @@ -374,7 +381,7 @@
<excludes>META-INF,META-INF/**</excludes>
<type>jar</type>
<outputDirectory>${docs.sourcecode}</outputDirectory>
<includeArtifactIds>neo4j-examples,neo4j-server-examples</includeArtifactIds>
<includeArtifactIds>neo4j-examples,neo4j-server-examples,neo4j-cypher-docs</includeArtifactIds>
</configuration>
</execution>
</executions>
Expand Down
37 changes: 1 addition & 36 deletions manual/cypher/cypher-docs/LICENSES.txt
Expand Up @@ -4,11 +4,8 @@ libraries. For an overview of the licenses see the NOTICE.txt file.
------------------------------------------------------------------------------
Apache Software License, Version 2.0
Apache Commons Lang
ConcurrentLinkedHashMap
Lucene Core
opencsv
parboiled-core
parboiled-scala
Lucene Memory
------------------------------------------------------------------------------

Apache License
Expand Down Expand Up @@ -256,36 +253,4 @@ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.


------------------------------------------------------------------------------
BSD License
ASM Core
Scala Compiler
------------------------------------------------------------------------------

Copyright (c) <year>, <copyright holder>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the <organization> nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.



9 changes: 1 addition & 8 deletions manual/cypher/cypher-docs/NOTICE.txt
Expand Up @@ -27,16 +27,9 @@ Third-party licenses

Apache Software License, Version 2.0
Apache Commons Lang
ConcurrentLinkedHashMap
Lucene Core
opencsv
parboiled-core
parboiled-scala
Lucene Memory

BSD - Scala License
Scala Library

BSD License
ASM Core
Scala Compiler

4 changes: 4 additions & 0 deletions manual/cypher/cypher-docs/pom.xml
Expand Up @@ -78,6 +78,10 @@

<!-- neo4j -->

<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-kernel</artifactId>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-kernel</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions manual/cypher/cypher-docs/src/docs/dev/general.asciidoc
Expand Up @@ -29,4 +29,8 @@ include::ql/unwind/index.asciidoc[]

include::ql/union/index.asciidoc[]

:leveloffset: 2

include::ql/call/index.asciidoc[]

:leveloffset: 0
34 changes: 34 additions & 0 deletions manual/cypher/cypher-docs/src/docs/dev/ql/call/index.asciidoc
@@ -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[]
@@ -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
@@ -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) )
}
}

0 comments on commit 1d4ff83

Please sign in to comment.