Skip to content

Commit ab7560b

Browse files
committed
Port to Neo4j 4.2.3
The change to Neo4j 4.2 was more subtle. Mostly only internal API's around the use of `Path` instead of `File`. One change that could be noticed was the `IndexManager.IndexAccessMode` class. In the 0.27.0 and 0.27.1 versions we used `OverridenAccessMode` to take the users existing access mode and simply add on the rights to create tokens and indexes. In 0.27.2 we instead use `RestrictedAccessMode` to restrict the users access right to the built in `AccessModel.Static.SCHEMA` and then boost to enable index and token writes. The difference is subtle and should only be possible to notice in Enterprise Edition.
1 parent 84417b9 commit ab7560b

16 files changed

+50
-39
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ This has meant that the spatial library needed a major refactoring to work with
6868
objects to have been created in the current transaction.
6969
To work around this we added `.byId` versions of the `spatial.addNode` and `spatial.removeNode` procedures.
7070
We also changed the `spatial.removeNode` procedures to return `nodeId` instead of `node`.
71+
* The change to Neo4j 4.2 was more subtle. Mostly only internal API's around the use of `Path` instead of `File`.
72+
One change that could be noticed was the `IndexManager.IndexAccessMode` class.
73+
In the 0.27.0 and 0.27.1 versions we used `OverridenAccessMode` to take the users existing access mode
74+
and simply add on the rights to create tokens and indexes. In 0.27.2 we instead use `RestrictedAccessMode`
75+
to restrict the users access right to the built in `AccessModel.Static.SCHEMA` and then boost to enable
76+
index and token writes. The difference is subtle and should only be possible to notice in Enterprise Edition.
7177

7278
Consequences of the port to Neo4j 4.x:
7379

@@ -340,6 +346,7 @@ The Neo4j Spatial Plugin is available for inclusion in the server version of Neo
340346
* Using GeoTools 24.2 (for GeoServer 2.18.x):
341347
* [v0.27.0 for Neo4j 4.0.3](https://github.com/neo4j-contrib/m2/blob/master/releases/org/neo4j/neo4j-spatial/0.27.0-neo4j-4.0.3/neo4j-spatial-0.27.0-neo4j-4.0.3-server-plugin.jar?raw=true)
342348
* [v0.27.1 for Neo4j 4.1.7](https://github.com/neo4j-contrib/m2/blob/master/releases/org/neo4j/neo4j-spatial/0.27.1-neo4j-4.1.7/neo4j-spatial-0.27.1-neo4j-4.1.7-server-plugin.jar?raw=true)
349+
* [v0.27.2 for Neo4j 4.2.3](https://github.com/neo4j-contrib/m2/blob/master/releases/org/neo4j/neo4j-spatial/0.27.2-neo4j-4.2.3/neo4j-spatial-0.27.2-neo4j-4.2.3-server-plugin.jar?raw=true)
343350

344351
For versions up to 0.15-neo4j-2.3.4:
345352

@@ -456,7 +463,7 @@ Add the following repositories and dependency to your project's pom.xml:
456463
<dependency>
457464
<groupId>org.neo4j</groupId>
458465
<artifactId>neo4j-spatial</artifactId>
459-
<version>0.27.1-neo4j-4.1.7</version>
466+
<version>0.27.2-neo4j-4.2.3</version>
460467
</dependency>
461468
~~~
462469

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
33
<properties>
4-
<neo4j.version>4.1.7</neo4j.version>
4+
<neo4j.version>4.2.3</neo4j.version>
55
<lucene.version>8.2.0</lucene.version>
66
<!-- make sure lucene version is the same as the one the current neo4j depends on -->
77
<neo4j.java.version>11</neo4j.java.version>
@@ -23,7 +23,7 @@
2323
<modelVersion>4.0.0</modelVersion>
2424
<artifactId>neo4j-spatial</artifactId>
2525
<groupId>org.neo4j</groupId>
26-
<version>0.27.1-neo4j-4.1.7</version>
26+
<version>0.27.2-neo4j-4.2.3</version>
2727
<name>Neo4j - Spatial Components</name>
2828
<description>Spatial utilities and components for Neo4j</description>
2929
<url>http://components.neo4j.org/${project.artifactId}/${project.version}</url>

src/main/java/org/neo4j/gis/spatial/index/IndexManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.neo4j.internal.kernel.api.security.PrivilegeAction;
77
import org.neo4j.internal.kernel.api.security.SecurityContext;
88
import org.neo4j.kernel.api.KernelTransaction;
9-
import org.neo4j.kernel.impl.api.security.OverriddenAccessMode;
9+
import org.neo4j.kernel.impl.api.security.RestrictedAccessMode;
1010
import org.neo4j.kernel.internal.GraphDatabaseAPI;
1111

1212
import java.util.List;
@@ -17,13 +17,13 @@ public class IndexManager {
1717
private final GraphDatabaseAPI db;
1818
private final SecurityContext securityContext;
1919

20-
public static class IndexAccessMode extends OverriddenAccessMode {
20+
public static class IndexAccessMode extends RestrictedAccessMode {
2121
public static SecurityContext withIndexCreate(SecurityContext securityContext) {
2222
return securityContext.withMode(new IndexAccessMode(securityContext));
2323
}
2424

2525
private IndexAccessMode(SecurityContext securityContext) {
26-
super(Static.ACCESS, securityContext.mode());
26+
super(securityContext.mode(), Static.SCHEMA);
2727
}
2828

2929
@Override

src/main/java/org/neo4j/gis/spatial/index/LayerSpaceFillingCurvePointIndex.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.neo4j.kernel.api.KernelTransaction;
4040
import org.neo4j.kernel.impl.core.NodeEntity;
4141
import org.neo4j.kernel.impl.coreapi.internal.NodeCursorResourceIterator;
42+
import org.neo4j.memory.EmptyMemoryTracker;
4243
import org.opengis.referencing.crs.CoordinateReferenceSystem;
4344
import org.opengis.referencing.cs.CoordinateSystemAxis;
4445

@@ -145,7 +146,7 @@ private ResourceIterator<Node> nodesByLabelAndProperty(KernelTransaction transac
145146
// Ha! We found an index - let's use it to find matching nodes
146147
try
147148
{
148-
NodeValueIndexCursor cursor = transaction.cursors().allocateNodeValueIndexCursor(PageCursorTracer.NULL);
149+
NodeValueIndexCursor cursor = transaction.cursors().allocateNodeValueIndexCursor(PageCursorTracer.NULL, EmptyMemoryTracker.INSTANCE);
149150
IndexReadSession indexSession = read.indexReadSession( index );
150151
read.nodeIndexSeek( indexSession, cursor, IndexQueryConstraints.unordered(false), query );
151152

src/main/java/org/neo4j/gis/spatial/osm/OSMImporter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,19 +1635,19 @@ private void loadTestOsmData(String layerName, int commitInterval) throws Except
16351635
}
16361636

16371637
private DatabaseLayout prepareLayout(boolean delete) throws IOException {
1638-
Neo4jLayout homeLayout = Neo4jLayout.of(dbPath);
1638+
Neo4jLayout homeLayout = Neo4jLayout.of(dbPath.toPath());
16391639
DatabaseLayout databaseLayout = homeLayout.databaseLayout(databaseName);
16401640
if (delete) {
1641-
FileUtils.deleteRecursively(databaseLayout.databaseDirectory());
1642-
FileUtils.deleteRecursively(databaseLayout.getTransactionLogsDirectory());
1641+
FileUtils.deleteDirectory(databaseLayout.databaseDirectory());
1642+
FileUtils.deleteDirectory(databaseLayout.getTransactionLogsDirectory());
16431643
}
16441644
return databaseLayout;
16451645
}
16461646

16471647
private void prepareDatabase(boolean delete) throws IOException {
16481648
shutdown();
16491649
prepareLayout(delete);
1650-
databases = new DatabaseManagementServiceBuilder(dbPath).build();
1650+
databases = new DatabaseManagementServiceBuilder(dbPath.toPath()).build();
16511651
graphDb = databases.database(databaseName);
16521652
}
16531653

src/test/java/org/neo4j/gis/spatial/LayersTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class LayersTest {
6363

6464
@Before
6565
public void setup() throws KernelException {
66-
databases = new TestDatabaseManagementServiceBuilder(new File("target/layers")).impermanent().build();
66+
databases = new TestDatabaseManagementServiceBuilder(new File("target/layers").toPath()).impermanent().build();
6767
graphDb = databases.database(DEFAULT_DATABASE_NAME);
6868
((GraphDatabaseAPI) graphDb).getDependencyResolver().resolveDependency(GlobalProcedures.class).registerProcedure(SpatialProcedures.class);
6969
}

src/test/java/org/neo4j/gis/spatial/Neo4jSpatialDataStoreTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
import org.opengis.feature.simple.SimpleFeatureType;
1919

2020
import javax.xml.stream.XMLStreamException;
21-
import java.io.File;
2221
import java.io.IOException;
2322
import java.nio.charset.StandardCharsets;
23+
import java.nio.file.Path;
2424
import java.util.HashSet;
2525
import java.util.Set;
2626

@@ -36,7 +36,7 @@ public class Neo4jSpatialDataStoreTest {
3636

3737
@Before
3838
public void setup() throws IOException, XMLStreamException {
39-
this.databases = new TestDatabaseManagementServiceBuilder(new File("target/test")).impermanent().build();
39+
this.databases = new TestDatabaseManagementServiceBuilder(Path.of("target", "test")).impermanent().build();
4040
this.graph = databases.database(DEFAULT_DATABASE_NAME);
4141
OSMImporter importer = new OSMImporter("map", new ConsoleListener());
4242
importer.setCharset(StandardCharsets.UTF_8);
@@ -65,7 +65,7 @@ public void shouldOpenDataStore() {
6565
public void shouldOpenDataStoreOnNonSpatialDatabase() {
6666
DatabaseManagementService otherDatabases = null;
6767
try {
68-
otherDatabases = new TestDatabaseManagementServiceBuilder(new File("target/other-db")).impermanent().build();
68+
otherDatabases = new TestDatabaseManagementServiceBuilder(Path.of("target", "other-db")).impermanent().build();
6969
GraphDatabaseService otherGraph = otherDatabases.database(DEFAULT_DATABASE_NAME);
7070
Neo4jSpatialDataStore store = new Neo4jSpatialDataStore(otherGraph);
7171
ReferencedEnvelope bounds = store.getBounds("map");

src/test/java/org/neo4j/gis/spatial/Neo4jTestCase.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import java.io.File;
3939
import java.io.IOException;
40+
import java.nio.file.Path;
4041
import java.util.HashMap;
4142
import java.util.Map;
4243
import java.util.Objects;
@@ -70,7 +71,7 @@ public abstract class Neo4jTestCase {
7071
}
7172

7273
private static final File basePath = new File("target/var");
73-
private static final File dbPath = new File(basePath, "neo4j-db");
74+
private static final Path dbPath = new File(basePath, "neo4j-db").toPath();
7475
private DatabaseManagementService databases;
7576
private GraphDatabaseService graphDb;
7677

@@ -124,8 +125,8 @@ private DatabaseLayout prepareLayout(boolean delete) throws IOException {
124125
Neo4jLayout homeLayout = Neo4jLayout.of(dbPath);
125126
DatabaseLayout databaseLayout = homeLayout.databaseLayout(DEFAULT_DATABASE_NAME);
126127
if (delete) {
127-
FileUtils.deleteRecursively(databaseLayout.databaseDirectory());
128-
FileUtils.deleteRecursively(databaseLayout.getTransactionLogsDirectory());
128+
FileUtils.deleteDirectory(databaseLayout.databaseDirectory());
129+
FileUtils.deleteDirectory(databaseLayout.getTransactionLogsDirectory());
129130
}
130131
return databaseLayout;
131132
}
@@ -141,7 +142,7 @@ private Config makeConfig(Map<String, String> config) {
141142

142143
@Before
143144
public void before() throws Exception {
144-
fileSystemRule.get().mkdirs(new File("target"));
145+
fileSystemRule.get().mkdirs(new File("target").toPath());
145146
}
146147

147148
@After
@@ -152,17 +153,17 @@ public void tearDown() {
152153
private void beforeShutdown() {
153154
}
154155

155-
File getNeoPath() {
156-
return new File(dbPath.getAbsolutePath());
156+
Path getNeoPath() {
157+
return dbPath.toAbsolutePath();
157158
}
158159

159-
File getDbPath() {
160-
return new File(dbPath.getAbsolutePath(), "test-" + storePrefix);
160+
Path getDbPath() {
161+
return dbPath.toAbsolutePath().resolve("test-" + storePrefix);
161162
}
162163

163164
private void deleteDatabase() {
164165
try {
165-
FileUtils.deleteRecursively(getNeoPath());
166+
FileUtils.deleteDirectory(getNeoPath());
166167
} catch (IOException e) {
167168
// TODO Auto-generated catch block
168169
e.printStackTrace();
@@ -189,7 +190,7 @@ private static void deleteFileOrDirectory(File file) {
189190
}
190191

191192
void printDatabaseStats() {
192-
Neo4jTestUtils.printDatabaseStats(graphDb(), getDbPath());
193+
Neo4jTestUtils.printDatabaseStats(graphDb(), getDbPath().toFile());
193194
}
194195

195196
protected GraphDatabaseService graphDb() {

src/test/java/org/neo4j/gis/spatial/OsmAnalysisTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ protected SpatialDatabaseService setDataset(String dataset) {
138138
System.out.println("Failed to delete previous database directory '" + dbDir + "': " + e.getMessage());
139139
}
140140
}
141-
databases = new TestDatabaseManagementServiceBuilder(dbDir).impermanent().build();
141+
databases = new TestDatabaseManagementServiceBuilder(dbDir.toPath()).impermanent().build();
142142
db = databases.database(DEFAULT_DATABASE_NAME);
143143
return new SpatialDatabaseService(new IndexManager((GraphDatabaseAPI) db, SecurityContext.AUTH_DISABLED));
144144
}

src/test/java/org/neo4j/gis/spatial/RTreeBulkInsertTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1582,7 +1582,7 @@ private void restart() throws IOException {
15821582
FileUtils.deleteDirectory(storeDir);
15831583
}
15841584
FileUtils.forceMkdir(storeDir);
1585-
databases = new TestDatabaseManagementServiceBuilder(storeDir).impermanent().build();
1585+
databases = new TestDatabaseManagementServiceBuilder(storeDir.toPath()).impermanent().build();
15861586
db = databases.database(DEFAULT_DATABASE_NAME);
15871587
}
15881588

0 commit comments

Comments
 (0)