Skip to content

Commit

Permalink
Fixes #3640: Custom procedures declaration fails in 5.x (#3647) (#3677)
Browse files Browse the repository at this point in the history
  • Loading branch information
vga91 authored Jul 24, 2023
1 parent 36abce1 commit e075004
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@ private ProcedureDescriptor procedureDescriptor(Node node) {
Mode.valueOf((String) node.getProperty(ExtendedSystemPropertyKeys.mode.name())),
false,
null,
new String[0],
description,
null,
false,
false,
false,
false,
false,
false), statement);
}

Expand Down
81 changes: 17 additions & 64 deletions extended/src/main/java/apoc/custom/Signatures.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.neo4j.internal.kernel.api.procs.*;
import org.neo4j.procedure.Mode;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -85,11 +84,10 @@ public ProcedureSignature toProcedureSignature(SignatureParser.ProcedureContext
List<FieldSignature> inputSignatures = signature.parameter().stream().map(p -> getInputField(name(p.name()), type(p.type()), defaultValue(p.defaultValue(), type(p.type())))).collect(Collectors.toList());
boolean admin = false;
String deprecated = "";
String[] allowed = new String[0];
String warning = null; // "todo warning";
boolean eager = false;
boolean caseInsensitive = true;
return createProcedureSignature(name, inputSignatures, outputSignature, mode, admin, deprecated, allowed, description, warning, eager, caseInsensitive, false, false, false);
return createProcedureSignature(name, inputSignatures, outputSignature, mode, admin, deprecated, description, warning, eager, caseInsensitive, false, false, false, false);
}

public List<String> namespace(SignatureParser.NamespaceContext namespaceContext) {
Expand Down Expand Up @@ -237,72 +235,27 @@ public static ProcedureSignature createProcedureSignature(QualifiedName name,
Mode mode,
boolean admin,
String deprecated,
String[] allowed,
String description,
String warning,
boolean eager,
boolean caseInsensitive,
boolean systemProcedure,
boolean internal,
boolean allowExpiredCredentials) {
try {
// in Neo4j 4.0.5 org.neo4j.internal.kernel.api.procs.ProcedureSignature
// changed the signature adding a boolean at the end and without leaving the old signature
// in order to maintain the backwards compatibility with version prior to 4.0.5 we use the
// reflection to create a new instance of the class
// in Neo4j 4.3 another boolean was added
final Class<?> clazz = Class.forName("org.neo4j.internal.kernel.api.procs.ProcedureSignature");
final Constructor<?>[] constructors = clazz.getConstructors();
for (int i = 0; i < constructors.length; i++) {
final Constructor<?> constructor = constructors[i];
switch (constructor.getParameterCount()) {
case 14:
return (ProcedureSignature) constructor.newInstance(name,
inputSignature,
outputSignature,
mode,
admin,
deprecated,
allowed,
description,
warning,
eager,
caseInsensitive,
systemProcedure,
internal,
allowExpiredCredentials);
case 13:
return (ProcedureSignature) constructor.newInstance(name,
inputSignature,
outputSignature,
mode,
admin,
deprecated,
allowed,
description,
warning,
eager,
caseInsensitive,
systemProcedure,
internal);
case 12:
return (ProcedureSignature) constructor.newInstance(name,
inputSignature,
outputSignature,
mode,
admin,
deprecated,
allowed,
description,
warning,
eager,
caseInsensitive,
systemProcedure);
}
}
throw new RuntimeException("Constructor of org.neo4j.internal.kernel.api.procs.ProcedureSignature not found");
} catch (Exception e) {
throw new RuntimeException(e);
}
boolean allowExpiredCredentials,
boolean threadSafe) {
return new ProcedureSignature(name,
inputSignature,
outputSignature,
mode,
admin,
deprecated,
description,
warning,
eager,
caseInsensitive,
systemProcedure,
internal,
allowExpiredCredentials,
threadSafe);
}
}

0 comments on commit e075004

Please sign in to comment.