Skip to content

Commit

Permalink
Add 5.16 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jjaderberg committed Jan 11, 2024
1 parent 1445d48 commit eee6473
Show file tree
Hide file tree
Showing 33 changed files with 3,668 additions and 2 deletions.
65 changes: 65 additions & 0 deletions compatibility/5.16/neo4j-kernel-adapter/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
apply plugin: 'java-library'
apply plugin: 'me.champeau.mrjar'

description = 'Neo4j Graph Data Science :: Neo4j Kernel Adapter 5.16'

group = 'org.neo4j.gds'

// for all 5.x versions
if (ver.'neo4j'.startsWith('5.')) {
sourceSets {
main {
java {
srcDirs = ['src/main/java17']
}
}
}

dependencies {
annotationProcessor project(':annotations')
annotationProcessor group: 'org.immutables', name: 'value', version: ver.'immutables'
annotationProcessor group: 'org.neo4j', name: 'annotations', version: neos.'5.16'

compileOnly project(':annotations')
compileOnly group: 'org.immutables', name: 'value-annotations', version: ver.'immutables'
compileOnly group: 'org.neo4j', name: 'annotations', version: neos.'5.16'
compileOnly group: 'org.neo4j', name: 'neo4j', version: neos.'5.16'
compileOnly group: 'org.neo4j', name: 'neo4j-record-storage-engine', version: neos.'5.16'
compileOnly group: 'org.neo4j.community', name: 'it-test-support', version: neos.'5.16'

implementation project(':neo4j-kernel-adapter-api')
implementation project(':neo4j-kernel-adapter-5-common')
}
} else {
multiRelease {
targetVersions 11, 17
}

if (!project.hasProperty('no-forbidden-apis')) {
forbiddenApisJava17 {
exclude('**')
}
}

dependencies {
annotationProcessor group: 'org.neo4j', name: 'annotations', version: ver.'neo4j'

compileOnly project(':annotations')
compileOnly group: 'org.neo4j', name: 'annotations', version: ver.'neo4j'

implementation project(':neo4j-kernel-adapter-api')

java17AnnotationProcessor project(':annotations')
java17AnnotationProcessor group: 'org.immutables', name: 'value', version: ver.'immutables'
java17AnnotationProcessor group: 'org.neo4j', name: 'annotations', version: neos.'5.16'

java17CompileOnly project(':annotations')
java17CompileOnly group: 'org.immutables', name: 'value-annotations', version: ver.'immutables'
java17CompileOnly group: 'org.neo4j', name: 'neo4j', version: neos.'5.16'
java17CompileOnly group: 'org.neo4j', name: 'neo4j-record-storage-engine', version: neos.'5.16'
java17CompileOnly group: 'org.neo4j.community', name: 'it-test-support', version: neos.'5.16'

java17Implementation project(':neo4j-kernel-adapter-api')
java17Implementation project(':neo4j-kernel-adapter-5-common')
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.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.gds.compat._516;

import org.neo4j.annotations.service.ServiceProvider;
import org.neo4j.gds.compat.Neo4jProxyApi;
import org.neo4j.gds.compat.Neo4jProxyFactory;
import org.neo4j.gds.compat.Neo4jVersion;

@ServiceProvider
public final class Neo4jProxyFactoryImpl implements Neo4jProxyFactory {

@Override
public boolean canLoad(Neo4jVersion version) {
return false;
}

@Override
public Neo4jProxyApi load() {
throw new UnsupportedOperationException("5.16 compatibility requires JDK17");
}

@Override
public String description() {
return "Neo4j 5.16 (placeholder)";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.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.gds.compat._516;

import org.neo4j.bolt.dbapi.BoltGraphDatabaseServiceSPI;
import org.neo4j.bolt.dbapi.BoltTransaction;
import org.neo4j.bolt.protocol.common.message.AccessMode;
import org.neo4j.bolt.protocol.common.message.request.connection.RoutingContext;
import org.neo4j.bolt.tx.statement.StatementQuerySubscriber;
import org.neo4j.exceptions.KernelException;
import org.neo4j.gds.compat.BoltQuerySubscriber;
import org.neo4j.gds.compat.BoltTransactionRunner;
import org.neo4j.graphdb.QueryStatistics;
import org.neo4j.internal.kernel.api.connectioninfo.ClientConnectionInfo;
import org.neo4j.internal.kernel.api.security.LoginContext;
import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.impl.query.QueryExecutionConfiguration;
import org.neo4j.kernel.impl.query.QueryExecutionKernelException;
import org.neo4j.values.virtual.MapValue;

import java.time.Duration;
import java.util.List;
import java.util.Map;

public class BoltTransactionRunnerImpl extends BoltTransactionRunner<StatementQuerySubscriber, String> {

@Override
protected BoltQuerySubscriber<StatementQuerySubscriber> boltQuerySubscriber() {
var subscriber = new StatementQuerySubscriber();
return new BoltQuerySubscriber<>() {
@Override
public void assertSucceeded() throws KernelException {
subscriber.assertSuccess();
}

@Override
public QueryStatistics queryStatistics() {
return subscriber.getStatistics();
}

@Override
public StatementQuerySubscriber innerSubscriber() {
return subscriber;
}
};
}

@Override
protected void executeQuery(
BoltTransaction boltTransaction,
String query,
MapValue parameters,
StatementQuerySubscriber querySubscriber
) throws QueryExecutionKernelException {
try {
boltTransaction.executeQuery(query, parameters, true, querySubscriber)
.queryExecution() // This fella here is quite lazy
.consumeAll(); // We need to do this in order to trigger the query execution.
} catch (Exception e) {
throw new RuntimeException(e);
}
}

@Override
protected BoltTransaction beginBoltWriteTransaction(
BoltGraphDatabaseServiceSPI fabricDb,
LoginContext loginContext,
KernelTransaction.Type kernelTransactionType,
ClientConnectionInfo clientConnectionInfo,
List<String> bookmarks,
Duration txTimeout,
Map<String, Object> txMetadata
) {
return fabricDb.beginTransaction(
kernelTransactionType,
loginContext,
clientConnectionInfo,
bookmarks,
txTimeout,
AccessMode.WRITE,
txMetadata,
new RoutingContext(true, Map.of()),
QueryExecutionConfiguration.DEFAULT_CONFIG
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.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.gds.compat._516;

import org.neo4j.annotations.service.ServiceProvider;
import org.neo4j.gds.compat.Neo4jProxyApi;
import org.neo4j.gds.compat.Neo4jProxyFactory;
import org.neo4j.gds.compat.Neo4jVersion;

@ServiceProvider
public final class Neo4jProxyFactoryImpl implements Neo4jProxyFactory {

@Override
public boolean canLoad(Neo4jVersion version) {
return version == Neo4jVersion.V_5_16;
}

@Override
public Neo4jProxyApi load() {
return new Neo4jProxyImpl();
}

@Override
public String description() {
return "Neo4j 5.16";
}
}
Loading

0 comments on commit eee6473

Please sign in to comment.