Skip to content
This repository was archived by the owner on Apr 22, 2020. It is now read-only.

Commit d209bcb

Browse files
committed
Make neo4j-graph-algorithms work with 3.2 and all the Kernel-API changes
This creates a new "Kernel" class that wraps the API to make it behave like the old one Going forward we should rather change the code to not rely on Cursors during the loading but just use primitive values and iterators. Something that is also worse now in the new Kernel API is the massive use of (checked) Exceptions which is definitely not performance improving.
1 parent 689a434 commit d209bcb

File tree

14 files changed

+638
-90
lines changed

14 files changed

+638
-90
lines changed

algo/src/main/java/org/neo4j/graphalgo/exporter/SCCTarjanExporter.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import org.neo4j.kernel.api.exceptions.EntityNotFoundException;
1010
import org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException;
1111
import org.neo4j.kernel.api.exceptions.legacyindex.AutoIndexingKernelException;
12-
import org.neo4j.kernel.api.exceptions.schema.ConstraintValidationKernelException;
12+
import org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException;
1313
import org.neo4j.kernel.api.exceptions.schema.IllegalTokenNameException;
1414
import org.neo4j.kernel.api.properties.DefinedProperty;
1515
import org.neo4j.kernel.internal.GraphDatabaseAPI;
@@ -36,13 +36,7 @@ public SCCTarjanExporter withIdMapping(IdMapping idMapping) {
3636
}
3737

3838
public SCCTarjanExporter withWriteProperty(String writeProperty) {
39-
writeInTransaction(write -> {
40-
try {
41-
this.writePropertyId = write.propertyKeyGetOrCreateForName(writeProperty);
42-
} catch (IllegalTokenNameException e) {
43-
throw new RuntimeException(e);
44-
}
45-
});
39+
this.writePropertyId = getOrCreatePropertyId(writeProperty);
4640
return this;
4741
}
4842

@@ -57,7 +51,7 @@ public void write(ObjectArrayList<IntSet> data) {
5751
write.nodeSetProperty(idMapping.toOriginalNodeId(iCursor.value),
5852
property);
5953
} catch (EntityNotFoundException
60-
| ConstraintValidationKernelException
54+
| ConstraintValidationException
6155
| InvalidTransactionTypeKernelException
6256
| AutoIndexingKernelException e) {
6357
throw new RuntimeException(e);

algo/src/main/java/org/neo4j/graphalgo/impl/BetweennessCentrality.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
import org.neo4j.graphalgo.core.utils.TerminationFlag;
77
import org.neo4j.graphalgo.core.utils.container.Path;
88
import org.neo4j.graphdb.Direction;
9+
import org.neo4j.kernel.api.exceptions.EntityNotFoundException;
10+
import org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException;
11+
import org.neo4j.kernel.api.exceptions.legacyindex.AutoIndexingKernelException;
12+
import org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException;
13+
import org.neo4j.kernel.api.properties.Property;
14+
import org.neo4j.kernel.internal.GraphDatabaseAPI;
915

1016
import java.util.Arrays;
1117
import java.util.stream.IntStream;

algo/src/main/java/org/neo4j/graphalgo/impl/ShortestPathDijkstra.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import org.neo4j.kernel.api.exceptions.EntityNotFoundException;
1111
import org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException;
1212
import org.neo4j.kernel.api.exceptions.legacyindex.AutoIndexingKernelException;
13-
import org.neo4j.kernel.api.exceptions.schema.ConstraintValidationKernelException;
13+
import org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException;
1414
import org.neo4j.kernel.api.properties.DefinedProperty;
1515
import org.neo4j.kernel.impl.util.collection.SimpleBitSet;
1616
import org.neo4j.kernel.internal.GraphDatabaseAPI;
@@ -199,7 +199,7 @@ public void write(IntArrayDeque data) {
199199
try {
200200
writeOp.nodeSetProperty(idMapping.toOriginalNodeId(node),
201201
DefinedProperty.numberProperty(propertyId, distance++));
202-
} catch (EntityNotFoundException | ConstraintValidationKernelException | InvalidTransactionTypeKernelException | AutoIndexingKernelException e) {
202+
} catch (EntityNotFoundException | ConstraintValidationException | InvalidTransactionTypeKernelException | AutoIndexingKernelException e) {
203203
throw new RuntimeException(e);
204204
}
205205
}

core/src/main/java/org/neo4j/graphalgo/api/GraphFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import org.neo4j.graphalgo.core.utils.ProgressLogger;
44
import org.neo4j.graphalgo.core.utils.ProgressLoggerAdapter;
5+
import org.neo4j.graphalgo.core.Kernel;
56
import org.neo4j.graphdb.Transaction;
6-
import org.neo4j.kernel.api.ReadOperations;
77
import org.neo4j.kernel.api.Statement;
88
import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge;
99
import org.neo4j.kernel.internal.GraphDatabaseAPI;
@@ -46,10 +46,10 @@ public void setLog(Log log) {
4646
*
4747
* @param block the consumer
4848
*/
49-
protected final void withReadOps(Consumer<ReadOperations> block) {
49+
protected final void withReadOps(Consumer<Kernel> block) {
5050
try (final Transaction tx = api.beginTx();
5151
Statement statement = contextBridge.get()) {
52-
block.accept(statement.readOperations());
52+
block.accept(new Kernel(statement));
5353
tx.success();
5454
}
5555
}

0 commit comments

Comments
 (0)