use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class IndexProcedures method createIndex.
private Stream<BuiltInProcedures.SchemaIndexInfo> createIndex(String name, List<String> labels, List<String> properties, IndexProviderDescriptor indexProviderDescriptor, Map<String, Object> configMap, String statusMessage, IndexCreator indexCreator) throws ProcedureException {
IndexConfig indexConfig = IndexSettingUtil.toIndexConfigFromStringObjectMap(configMap);
assertSingleLabel(labels);
assertValidIndexProvider(indexProviderDescriptor);
int labelId = getOrCreateLabelId(labels.get(0));
int[] propertyKeyIds = getOrCreatePropertyIds(properties);
try {
SchemaWrite schemaWrite = ktx.schemaWrite();
LabelSchemaDescriptor labelSchemaDescriptor = SchemaDescriptor.forLabel(labelId, propertyKeyIds);
indexCreator.create(schemaWrite, name, labelSchemaDescriptor, indexProviderDescriptor, indexConfig);
return Stream.of(new BuiltInProcedures.SchemaIndexInfo(name, labels, properties, indexProviderDescriptor.name(), statusMessage));
} catch (KernelException e) {
throw new ProcedureException(e.status(), e, e.getMessage());
}
}
use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class ProcedureRegistry method register.
/**
* Register a new procedure.
*
* @param proc the procedure.
*/
public void register(CallableProcedure proc, boolean overrideCurrentImplementation) throws ProcedureException {
ProcedureSignature signature = proc.signature();
QualifiedName name = signature.name();
String descriptiveName = signature.toString();
validateSignature(descriptiveName, signature.inputSignature(), "input");
validateSignature(descriptiveName, signature.outputSignature(), "output");
if (!signature.isVoid() && signature.outputSignature().isEmpty()) {
throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "Procedures with zero output fields must be declared as VOID");
}
CallableProcedure oldImplementation = procedures.get(name);
if (oldImplementation == null) {
procedures.put(name, proc, signature.caseInsensitive());
} else {
if (overrideCurrentImplementation) {
procedures.put(name, proc, signature.caseInsensitive());
} else {
throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "Unable to register procedure, because the name `%s` is already in use.", name);
}
}
}
use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class FieldInjections method setters.
/**
* For each annotated field in the provided class, creates a `FieldSetter`.
* @param cls The class where injection should happen.
* @return A list of `FieldSetters`
* @throws ProcedureException if the type of the injected field does not match what has been registered.
*/
List<FieldSetter> setters(Class<?> cls) throws ProcedureException {
List<FieldSetter> setters = new LinkedList<>();
Class<?> currentClass = cls;
do {
for (Field field : currentClass.getDeclaredFields()) {
// ignore synthetic fields
if (field.isSynthetic()) {
continue;
}
if (Modifier.isStatic(field.getModifiers())) {
if (field.isAnnotationPresent(Context.class)) {
throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "The field `%s` in the class named `%s` is annotated as a @Context field,%n" + "but it is static. @Context fields must be public, non-final and non-static,%n" + "because they are reset each time a procedure is invoked.", field.getName(), cls.getSimpleName());
}
continue;
}
assertValidForInjection(cls, field);
setters.add(createInjector(cls, field));
}
} while ((currentClass = currentClass.getSuperclass()) != null);
return setters;
}
use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class BoltKeepAliveSchedulingIT method installSleepProcedure.
private static void installSleepProcedure(GraphDatabaseService db) throws ProcedureException {
GraphDatabaseAPI dbApi = (GraphDatabaseAPI) db;
dbApi.getDependencyResolver().resolveDependency(GlobalProcedures.class).register(new CallableProcedure.BasicProcedure(procedureSignature("boltissue", "sleep").out(ProcedureSignature.VOID).build()) {
@Override
public RawIterator<AnyValue[], ProcedureException> apply(Context context, AnyValue[] objects, ResourceTracker resourceTracker) throws ProcedureException {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
throw new ProcedureException(Status.General.UnknownError, e, "Interrupted");
}
return RawIterator.empty();
}
});
}
use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class CommunityProcedureITBase method listProcedures.
@Test
void listProcedures() throws Throwable {
// When
ProcedureHandle procedures = procs().procedureGet(procedureName("dbms", "procedures"));
RawIterator<AnyValue[], ProcedureException> stream = procs().procedureCallRead(procedures.id(), new AnyValue[0], ProcedureCallContext.EMPTY);
// Then
List<AnyValue[]> actual = asList(stream);
List<Object[]> expected = getExpectedCommunityProcs();
Map<String, AnyValue[]> resultMap = actual.stream().collect(toMap(row -> ((StringValue) row[0]).stringValue(), Function.identity()));
Map<String, Object[]> expectedMap = expected.stream().collect(toMap(row -> ((StringValue) row[0]).stringValue(), Function.identity()));
assertThat(resultMap.keySet(), containsInAnyOrder(expectedMap.keySet().toArray()));
for (String procName : resultMap.keySet()) {
AnyValue[] actualArray = resultMap.get(procName);
Object[] expectedArray = expectedMap.get(procName);
assertNotNull(expectedArray, "Got an unexpected entry for " + procName + " =>\n" + printElementsOfArray(actualArray));
assertEquals(expectedArray.length, actualArray.length, "Count of columns for " + procName + " does not match");
for (int i = 1; i < actualArray.length; i++) {
Matcher matcher;
if (expectedArray[i] instanceof TextArray) {
// this has to be a list of roles, we ignore those in community and expect a null here
matcher = equalTo(NO_VALUE);
} else if (expectedArray[i] instanceof Matcher) {
matcher = (Matcher) expectedArray[i];
} else {
matcher = equalTo(expectedArray[i]);
}
assertThat("Column " + i + " for " + procName + " does not match", actualArray[i], matcher);
}
}
commit();
}
Aggregations