Skip to content

Commit

Permalink
Support lazy loading
Browse files Browse the repository at this point in the history
  • Loading branch information
loveleif committed Dec 8, 2024
1 parent 14a8392 commit a64f320
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 347 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ apply from: "licenses-source-header.gradle"

ext {
publicDir = "${project.rootDir}"
neo4jVersionEffective = project.hasProperty("neo4jVersionOverride") ? project.getProperty("neo4jVersionOverride") : "2024.12.0-SNAPSHOT"
neo4jVersionEffective = project.hasProperty("neo4jVersionOverride") ? project.getProperty("neo4jVersionOverride") : "2024.12.0"
testContainersVersion = '1.20.2'
apacheArrowVersion = '15.0.0'
}
14 changes: 0 additions & 14 deletions procedure-collector/build.gradle

This file was deleted.

This file was deleted.

This file was deleted.

67 changes: 11 additions & 56 deletions processor/src/main/java/apoc/processor/ApocProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,27 @@
package apoc.processor;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
import org.neo4j.kernel.api.QueryLanguage;
import org.neo4j.procedure.Procedure;
import org.neo4j.procedure.UserAggregationFunction;
import org.neo4j.procedure.UserFunction;

@SupportedSourceVersion(SourceVersion.RELEASE_21)
public class ApocProcessor extends AbstractProcessor {

private List<Map<String, List<QueryLanguage>>> procedureSignatures;
private List<Map<String, List<QueryLanguage>>> userFunctionSignatures;
private Set<String> procedureClassNames;
private List<Signature> signatures;

private SignatureVisitor signatureVisitor;

private ExtensionClassWriter extensionClassWriter;
private ProcedureServiceWriter procedureServiceWriter;

@Override
public Set<String> getSupportedAnnotationTypes() {
Expand All @@ -52,65 +48,24 @@ public Set<String> getSupportedAnnotationTypes() {

@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
procedureSignatures = new ArrayList<>();
userFunctionSignatures = new ArrayList<>();
procedureClassNames = new HashSet<>();
signatures = new ArrayList<>();
extensionClassWriter = new ExtensionClassWriter(processingEnv.getFiler());
procedureServiceWriter = new ProcedureServiceWriter(processingEnv.getFiler());
signatureVisitor = new SignatureVisitor(processingEnv.getElementUtils(), processingEnv.getMessager());
}

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
annotations.forEach(annotation -> extractSignature(annotation, roundEnv));
annotations.forEach(annotation -> procedureClassNames.add(annotation.getQualifiedName().toString()));

List<String> procedureSignaturesCypher5 = new ArrayList<>();
List<String> userFunctionSignaturesCypher5 = new ArrayList<>();
List<String> procedureSignaturesCypher25 = new ArrayList<>();
List<String> userFunctionSignaturesCypher25 = new ArrayList<>();

separateKeysByQueryLanguage(procedureSignatures, procedureSignaturesCypher5, procedureSignaturesCypher25);
separateKeysByQueryLanguage(
userFunctionSignatures, userFunctionSignaturesCypher5, userFunctionSignaturesCypher25);
for (final var annotation : annotations) {
for (final var method : roundEnv.getElementsAnnotatedWith(annotation)) {
signatures.add(signatureVisitor.visit(method));
}
}

if (roundEnv.processingOver()) {
extensionClassWriter.write(
procedureSignaturesCypher5,
userFunctionSignaturesCypher5,
procedureSignaturesCypher25,
userFunctionSignaturesCypher25);

extensionClassWriter.write(signatures);
procedureServiceWriter.write(signatures);
}
return false;
}

private void extractSignature(TypeElement annotation, RoundEnvironment roundEnv) {
List<Map<String, List<QueryLanguage>>> signatures = accumulator(annotation);
roundEnv.getElementsAnnotatedWith(annotation)
.forEach(annotatedElement -> signatures.add(signatureVisitor.visit(annotatedElement)));
}

private List<Map<String, List<QueryLanguage>>> accumulator(TypeElement annotation) {
if (annotation.getQualifiedName().contentEquals(Procedure.class.getName())) {
return procedureSignatures;
}
return userFunctionSignatures;
}

public static void separateKeysByQueryLanguage(
List<Map<String, List<QueryLanguage>>> list, List<String> c5Keys, List<String> c6Keys) {
for (Map<String, List<QueryLanguage>> map : list) {
for (Map.Entry<String, List<QueryLanguage>> entry : map.entrySet()) {
String key = entry.getKey();
List<QueryLanguage> values = entry.getValue();

if (values.contains(QueryLanguage.CYPHER_5)) {
c5Keys.add(key);
}
if (values.contains(QueryLanguage.CYPHER_25)) {
c6Keys.add(key);
}
}
}
}
}
Loading

0 comments on commit a64f320

Please sign in to comment.