Skip to content

Commit e75bd94

Browse files
committed
mostly cypher syntax fixes for deprecated experessions in 5.0
1 parent ff78c91 commit e75bd94

20 files changed

+94
-98
lines changed

pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>org.neo4j</groupId>
77
<artifactId>neosemantics</artifactId>
8-
<version>4.4.0.2</version>
8+
<version>5.1.0.0</version>
99
<packaging>jar</packaging>
1010
<name>neosemantics (n10s)</name>
1111
<description>n10s is a plugin that enables the use of RDF in Neo4j</description>
@@ -34,8 +34,8 @@
3434
</developers>
3535

3636
<properties>
37-
<neo4j.version>4.4.11</neo4j.version>
38-
<sesame.version>3.7.7</sesame.version>
37+
<neo4j.version>5.1.0</neo4j.version>
38+
<sesame.version>4.2.0</sesame.version>
3939
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4040
</properties>
4141

src/main/java/n10s/Util.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private static String buildCypher(String uri, String graphUri, Map<String, Objec
126126
cypher.append("AND n.graphUri = $graphUri ");
127127
params.put("graphUri", graphUri);
128128
} else {
129-
cypher.append("AND NOT EXISTS(n.graphUri) ");
129+
cypher.append("AND n.graphUri is null ");
130130
}
131131
cypher.append("RETURN n");
132132
return cypher.toString();

src/main/java/n10s/endpoint/RDFEndpoint.java

-11
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.neo4j.graphdb.GraphDatabaseService;
3838
import org.neo4j.graphdb.NotFoundException;
3939
import org.neo4j.graphdb.Transaction;
40-
import org.neo4j.logging.Log;
4140

4241
/**
4342
* Created by jbarrasa on 08/09/2016.
@@ -70,10 +69,6 @@ public class RDFEndpoint {
7069
RDFFormat.TURTLE, RDFFormat.NTRIPLES, RDFFormat.TRIG, RDFFormat.NQUADS, RDFFormat.TURTLESTAR,
7170
RDFFormat.TRIGSTAR};
7271

73-
@Context
74-
public Log log;
75-
76-
7772
@GET
7873
@Path("/ping")
7974
public Response ping() throws IOException {
@@ -321,27 +316,21 @@ private void handleSerialisationError(OutputStream outputStream, Exception e,
321316
private RDFFormat getFormat(String mimetype, String formatParam) {
322317
// format request param overrides the one defined in the accept header param
323318
if (formatParam != null) {
324-
log.debug("serialization from param in request: " + formatParam);
325319
for (RDFFormat parser : availableParsers) {
326320
if (parser.getName().contains(formatParam)) {
327-
log.debug("parser to be used: " + parser.getDefaultMIMEType());
328321
return parser;
329322
}
330323
}
331324
} else {
332325
if (mimetype != null) {
333-
log.debug("serialization from media type in request: " + mimetype);
334326
for (RDFFormat parser : availableParsers) {
335327
if (parser.getMIMETypes().contains(mimetype)) {
336-
log.debug("parser to be used: " + parser.getDefaultMIMEType());
337328
return parser;
338329
}
339330
}
340331
}
341332
}
342333

343-
log.debug("Unrecognized or undefined serialization. Defaulting to Turtle serialization");
344-
345334
return RDFFormat.TURTLE;
346335

347336
}

src/main/java/n10s/mapping/MappingUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public Stream<MappingDesc> add(@Name("elementUri") String rdfVocElement,
6565
+ "DETACH DELETE oldmd";
6666

6767
String cleanOrphansIfAny = "MATCH (oldns:`_MapNs`)\n"
68-
+ " WHERE size((oldns)<-[:_IN]-())=0\n"
68+
+ " WHERE not (oldns)<-[:_IN]-() \n"
6969
+ " DELETE oldns";
7070

7171
String createNewMapping = "MERGE (newmns:`_MapNs` { _ns: $namespace, _prefix: $prefix }) \n"

src/main/java/n10s/quadrdf/RDFQuadToLPGStatementProcessor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ String buildCypher(String uri, String graphUri, Map<String, Object> params) {
106106
cypher.append("AND n.graphUri = $graphUri ");
107107
params.put("graphUri", graphUri);
108108
} else {
109-
cypher.append("AND NOT EXISTS(n.graphUri) ");
109+
cypher.append("AND n.graphUri is null ");
110110
}
111111
cypher.append("RETURN n");
112112
return cypher.toString();

src/main/java/n10s/rdf/export/LPGRDFToRDFProcesssor.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,19 @@ public Stream<Statement> streamNodeByUri(String uri, String graphId, boolean exc
161161
params.put("uri", uri);
162162
if (graphId == null || graphId.equals("")) {
163163
queryWithContext = "MATCH (x:Resource {uri:$uri}) " +
164-
"WHERE NOT EXISTS(x.graphUri)\n" +
164+
"WHERE x.graphUri is null \n" +
165165
"OPTIONAL MATCH (x)-[r]-(val:Resource) " +
166-
"WHERE exists(val.uri)\n" +
167-
"AND NOT EXISTS(val.graphUri)\n" +
166+
"WHERE val.uri is not null \n" +
167+
"AND val.graphUri is null \n" +
168168
"RETURN x, r, val.uri AS value";
169169

170170
queryNoContext = "MATCH (x:Resource {uri:$uri}) " +
171-
"WHERE NOT EXISTS(x.graphUri)\n" +
171+
"WHERE x.graphUri is null \n" +
172172
"RETURN x, null AS r, null AS value";
173173
} else {
174174
queryWithContext = "MATCH (x:Resource {uri:$uri, graphUri:$graphUri}) " +
175175
"OPTIONAL MATCH (x)-[r]-(val:Resource {graphUri:$graphUri}) " +
176-
"WHERE exists(val.uri)\n" +
176+
"WHERE val.uri is not null \n" +
177177
"RETURN x, r, val.uri AS value";
178178

179179
queryNoContext = "MATCH (x:Resource {uri:$uri, graphUri:$graphUri}) " +
@@ -441,7 +441,7 @@ public Stream<Statement> streamTriplesFromTriplePattern(TriplePattern tp)
441441
result = tx.execute("MATCH (r:Resource) WHERE size(labels(r))>1 RETURN r");
442442
} else {
443443
result = tx.execute(String
444-
.format("MATCH (r:Resource) WHERE exists(r.`%s`) RETURN r\n"
444+
.format("MATCH (r:Resource) WHERE r.`%s` is not null RETURN r\n"
445445
+ "UNION \n"
446446
+ "MATCH (:Resource)-[r:`%s`]->() RETURN r",
447447
predicate, predicate));

src/main/java/n10s/rdf/export/LPGToRDFProcesssor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ public Stream<Statement> streamTriplesFromTriplePattern(TriplePattern tp)
400400
//CHECK IF predicate is <NONE>, in which case there's no point in running the query
401401
if (!predicate.equals(NOT_MATCHING_NS)) {
402402
result = tx.execute(String
403-
.format("MATCH (s) WHERE exists(s.`%s`) RETURN s, s.`%s` as o\n"
403+
.format("MATCH (s) WHERE s.`%s` is not null RETURN s, s.`%s` as o\n"
404404
+ "UNION \n"
405405
+ "MATCH (s)-[:`%s`]->(o) RETURN s, o",
406406
predicate, predicate, predicate));

src/main/java/n10s/result/VirtualNode.java

+16-14
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@
1111
import java.util.concurrent.atomic.AtomicLong;
1212
import java.util.stream.Collectors;
1313
import n10s.Util;
14-
import org.neo4j.graphdb.Direction;
15-
import org.neo4j.graphdb.Label;
16-
import org.neo4j.graphdb.Node;
17-
import org.neo4j.graphdb.Relationship;
18-
import org.neo4j.graphdb.RelationshipType;
14+
import org.neo4j.graphdb.*;
1915
import org.neo4j.internal.helpers.collection.FilteringIterable;
2016
import org.neo4j.internal.helpers.collection.Iterables;
2117

@@ -61,6 +57,12 @@ public long getId() {
6157
return id;
6258
}
6359

60+
@Override
61+
public String getElementId()
62+
{
63+
return String.valueOf( id );
64+
}
65+
6466
@Override
6567
public void delete() {
6668
for (Relationship rel : rels) {
@@ -69,8 +71,8 @@ public void delete() {
6971
}
7072

7173
@Override
72-
public Iterable<Relationship> getRelationships() {
73-
return rels;
74+
public ResourceIterable<Relationship> getRelationships() {
75+
return Iterables.asResourceIterable(rels);
7476
}
7577

7678
@Override
@@ -79,8 +81,8 @@ public boolean hasRelationship() {
7981
}
8082

8183
@Override
82-
public Iterable<Relationship> getRelationships(RelationshipType... relationshipTypes) {
83-
return new FilteringIterable<>(rels, (r) -> isType(r, relationshipTypes));
84+
public ResourceIterable<Relationship> getRelationships(RelationshipType... relationshipTypes) {
85+
return Iterables.asResourceIterable(new FilteringIterable<>(rels, (r) -> isType(r, relationshipTypes)));
8486
}
8587

8688
private boolean isType(Relationship r, RelationshipType... relationshipTypes) {
@@ -93,10 +95,10 @@ private boolean isType(Relationship r, RelationshipType... relationshipTypes) {
9395
}
9496

9597
@Override
96-
public Iterable<Relationship> getRelationships(Direction direction,
98+
public ResourceIterable<Relationship> getRelationships(Direction direction,
9799
RelationshipType... relationshipTypes) {
98-
return new FilteringIterable<>(rels,
99-
(r) -> isType(r, relationshipTypes) && isDirection(r, direction));
100+
return Iterables.asResourceIterable(new FilteringIterable<>(rels,
101+
(r) -> isType(r, relationshipTypes) && isDirection(r, direction)));
100102
}
101103

102104
private boolean isDirection(Relationship r, Direction direction) {
@@ -115,8 +117,8 @@ public boolean hasRelationship(Direction direction, RelationshipType... relation
115117
}
116118

117119
@Override
118-
public Iterable<Relationship> getRelationships(Direction direction) {
119-
return new FilteringIterable<>(rels, (r) -> isDirection(r, direction));
120+
public ResourceIterable<Relationship> getRelationships(Direction direction) {
121+
return Iterables.asResourceIterable(new FilteringIterable<>(rels, (r) -> isDirection(r, direction)));
120122
}
121123

122124
@Override

src/main/java/n10s/result/VirtualRelationship.java

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public long getId() {
5454
return id;
5555
}
5656

57+
@Override
58+
public String getElementId()
59+
{
60+
return String.valueOf( id );
61+
}
62+
5763
@Override
5864
public void delete() {
5965
if (getStartNode() instanceof VirtualNode) {

src/main/java/n10s/validation/SHACLValidator.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ private String getViolationQuery(String queryId, boolean tx, String customWhere,
12721272
case "GetRangeLiteralKind":
12731273
query = getQuery((constraintType == CLASS_BASED_CONSTRAINT ? CYPHER_MATCH_WHERE : CYPHER_MATCH_ALL_WHERE),
12741274
tx, (constraintType == QUERY_BASED_CONSTRAINT ? customWhere + " and " : ""),
1275-
" exists(focus.`%s`) RETURN " + nodeIdFragment + nodeTypeFragment + shapeIdFragment
1275+
" focus.`%s` is not null RETURN " + nodeIdFragment + nodeTypeFragment + shapeIdFragment
12761276
+ "'" + SHACL.NODE_KIND_CONSTRAINT_COMPONENT
12771277
+ "' as propertyShape, null as offendingValue, "
12781278
+ propertyNameFragment + severityFragment
@@ -1297,7 +1297,7 @@ private String getViolationQuery(String queryId, boolean tx, String customWhere,
12971297
case "GetRangeType2":
12981298
query = getQuery((constraintType == CLASS_BASED_CONSTRAINT ? CYPHER_MATCH_WHERE : CYPHER_MATCH_ALL_WHERE),
12991299
tx, (constraintType == QUERY_BASED_CONSTRAINT ? customWhere + " and " : ""),
1300-
"exists(focus.`%s`) RETURN " + nodeIdFragment + nodeTypeFragment + shapeIdFragment
1300+
" focus.`%s` is not null RETURN " + nodeIdFragment + nodeTypeFragment + shapeIdFragment
13011301
+ "'" + SHACL.CLASS_CONSTRAINT_COMPONENT
13021302
+ "' as propertyShape, focus.`%s` as offendingValue, "
13031303
+ propertyNameFragment + severityFragment
@@ -1381,25 +1381,25 @@ private String getViolationQuery(String queryId, boolean tx, String customWhere,
13811381
case "TypeAsNodeMinCardinality":
13821382
query = getQuery((constraintType == CLASS_BASED_CONSTRAINT ? CYPHER_WITH_PARAMS_MATCH_WHERE : CYPHER_WITH_PARAMS_MATCH_ALL_WHERE),
13831383
tx, (constraintType == QUERY_BASED_CONSTRAINT ? customWhere + " and " : ""),
1384-
"NOT %s ( size((focus)-[:`%s`]->())) %s RETURN " + nodeIdFragment + nodeTypeFragment + shapeIdFragment
1385-
+ "'%s' as propertyShape, 'type cardinality (' + coalesce(size((focus)-[:`%s`]->()),0) + ') is outside the defined min-max limits' as message, "
1384+
"NOT %s ( size([(focus)-[rel:`%s`]->() | rel ])) %s RETURN " + nodeIdFragment + nodeTypeFragment + shapeIdFragment
1385+
+ "'%s' as propertyShape, 'type cardinality (' + coalesce(size([(focus)-[rel:`%s`]->() | rel ]),0) + ') is outside the defined min-max limits' as message, "
13861386
+ propertyNameFragment + severityFragment
13871387
+ " null as offendingValue , " + customMsgFragment);
13881388
break;
13891389
case "MinCardinality1":
13901390
query = getQuery((constraintType == CLASS_BASED_CONSTRAINT ? CYPHER_WITH_PARAMS_MATCH_WHERE : CYPHER_WITH_PARAMS_MATCH_ALL_WHERE),
13911391
tx, (constraintType == QUERY_BASED_CONSTRAINT ? customWhere + " and " : ""),
1392-
"NOT %s ( size((focus)-[:`%s`]->()) + size([] + coalesce(focus.`%s`, [])) ) %s RETURN "
1392+
"NOT %s ( size([(focus)-[rel:`%s`]->()| rel ]) + size([] + coalesce(focus.`%s`, [])) ) %s RETURN "
13931393
+ nodeIdFragment + nodeTypeFragment + shapeIdFragment
1394-
+ "'%s' as propertyShape, 'cardinality (' + (coalesce(size((focus)-[:`%s`]->()),0) + coalesce(size([] + focus.`%s`),0)) + ') is outside the defined min-max limits' as message, "
1394+
+ "'%s' as propertyShape, 'cardinality (' + (coalesce(size([(focus)-[rel:`%s`]->()| rel ]),0) + coalesce(size([] + focus.`%s`),0)) + ') is outside the defined min-max limits' as message, "
13951395
+ propertyNameFragment + severityFragment
13961396
+ "null as offendingValue , " + customMsgFragment);
13971397
break;
13981398
case "MinCardinality1Inverse":
13991399
query = getQuery((constraintType == CLASS_BASED_CONSTRAINT ? CYPHER_WITH_PARAMS_MATCH_WHERE : CYPHER_WITH_PARAMS_MATCH_ALL_WHERE),
14001400
tx, (constraintType == QUERY_BASED_CONSTRAINT ? customWhere + " and " : ""),
1401-
"NOT %s size((focus)<-[:`%s`]-()) %s RETURN " + nodeIdFragment + nodeTypeFragment + shapeIdFragment
1402-
+ "'%s' as propertyShape, 'incoming cardinality (' + coalesce(size((focus)<-[:`%s`]-()),0) +') is outside the defined min-max limits' as message, "
1401+
"NOT %s size([(focus)<-[rel:`%s`]-() | rel ]) %s RETURN " + nodeIdFragment + nodeTypeFragment + shapeIdFragment
1402+
+ "'%s' as propertyShape, 'incoming cardinality (' + coalesce(size([ (focus)<-[rel:`%s`]-()| rel ]),0) +') is outside the defined min-max limits' as message, "
14031403
+ propertyNameFragment + severityFragment
14041404
+ "null as offendingValue , " + customMsgFragment);
14051405
break;

src/test/java/DocsTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void generateDocs() {
8080
List<Row> rows = new ArrayList<>();
8181

8282
List<Row> procedureRows = db.defaultDatabaseService().executeTransactionally(
83-
"CALL dbms.procedures() YIELD signature, name, description WHERE name STARTS WITH 'n10s' RETURN 'procedure' AS type, name, description, signature ORDER BY signature",
83+
"show procedures YIELD signature, name, description WHERE name STARTS WITH 'n10s' RETURN 'procedure' AS type, name, description, signature ORDER BY signature",
8484
Collections.emptyMap(),
8585
result -> result.stream().map(record -> new Row(
8686
record.get("type").toString(),
@@ -91,7 +91,7 @@ public void generateDocs() {
9191
rows.addAll(procedureRows);
9292

9393
List<Row> functionRows = db.defaultDatabaseService().executeTransactionally(
94-
"CALL dbms.functions() YIELD signature, name, description WHERE name STARTS WITH 'n10s' RETURN 'function' AS type, name, description, signature ORDER BY signature",
94+
"show functions YIELD signature, name, description WHERE name STARTS WITH 'n10s' RETURN 'function' AS type, name, description, signature ORDER BY signature",
9595
Collections.emptyMap(),
9696
result -> result.stream().map(record -> new Row(
9797
record.get("type").toString(),

0 commit comments

Comments
 (0)