Search in sources :

Example 26 with BasicContext

use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.

the class ReflectiveProcedureTest method shouldRunSimpleReadOnlyProcedure.

@Test
public void shouldRunSimpleReadOnlyProcedure() throws Throwable {
    // Given
    CallableProcedure proc = compile(SingleReadOnlyProcedure.class).get(0);
    // When
    RawIterator<Object[], ProcedureException> out = proc.apply(new BasicContext(), new Object[0]);
    // Then
    assertThat(asList(out), contains(new Object[] { "Bonnie" }, new Object[] { "Clyde" }));
}
Also used : BasicContext(org.neo4j.kernel.api.proc.BasicContext) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Test(org.junit.Test)

Example 27 with BasicContext

use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.

the class OperationsFacade method callProcedure.

private RawIterator<Object[], ProcedureException> callProcedure(QualifiedName name, Object[] input, final AccessMode override) throws ProcedureException {
    statement.assertOpen();
    final SecurityContext procedureSecurityContext = tx.securityContext().withMode(override);
    final RawIterator<Object[], ProcedureException> procedureCall;
    try (KernelTransaction.Revertable ignore = tx.overrideWith(procedureSecurityContext)) {
        BasicContext ctx = new BasicContext();
        ctx.put(Context.KERNEL_TRANSACTION, tx);
        ctx.put(Context.THREAD, Thread.currentThread());
        ctx.put(Context.SECURITY_CONTEXT, procedureSecurityContext);
        procedureCall = procedures.callProcedure(ctx, name, input);
    }
    return new RawIterator<Object[], ProcedureException>() {

        @Override
        public boolean hasNext() throws ProcedureException {
            try (KernelTransaction.Revertable ignore = tx.overrideWith(procedureSecurityContext)) {
                return procedureCall.hasNext();
            }
        }

        @Override
        public Object[] next() throws ProcedureException {
            try (KernelTransaction.Revertable ignore = tx.overrideWith(procedureSecurityContext)) {
                return procedureCall.next();
            }
        }
    };
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) BasicContext(org.neo4j.kernel.api.proc.BasicContext) SecurityContext(org.neo4j.kernel.api.security.SecurityContext) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) RawIterator(org.neo4j.collection.RawIterator)

Example 28 with BasicContext

use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.

the class OperationsFacade method callFunction.

private Object callFunction(QualifiedName name, Object[] input, final AccessMode mode) throws ProcedureException {
    statement.assertOpen();
    try (KernelTransaction.Revertable ignore = tx.overrideWith(tx.securityContext().withMode(mode))) {
        BasicContext ctx = new BasicContext();
        ctx.put(Context.KERNEL_TRANSACTION, tx);
        ctx.put(Context.THREAD, Thread.currentThread());
        return procedures.callFunction(ctx, name, input);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) BasicContext(org.neo4j.kernel.api.proc.BasicContext)

Example 29 with BasicContext

use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.

the class OperationsFacade method aggregationFunction.

private CallableUserAggregationFunction.Aggregator aggregationFunction(QualifiedName name, final AccessMode mode) throws ProcedureException {
    statement.assertOpen();
    try (KernelTransaction.Revertable ignore = tx.overrideWith(tx.securityContext().withMode(mode))) {
        BasicContext ctx = new BasicContext();
        ctx.put(Context.KERNEL_TRANSACTION, tx);
        ctx.put(Context.THREAD, Thread.currentThread());
        return procedures.createAggregationFunction(ctx, name);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) BasicContext(org.neo4j.kernel.api.proc.BasicContext)

Example 30 with BasicContext

use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.

the class NonTransactionalDbmsOperations method functionCallDbms.

@Override
public Object functionCallDbms(QualifiedName name, Object[] input, SecurityContext securityContext) throws ProcedureException {
    BasicContext ctx = new BasicContext();
    ctx.put(Context.SECURITY_CONTEXT, securityContext);
    return procedures.callFunction(ctx, name, input);
}
Also used : BasicContext(org.neo4j.kernel.api.proc.BasicContext)

Aggregations

BasicContext (org.neo4j.kernel.api.proc.BasicContext)42 Test (org.junit.Test)36 CallableProcedure (org.neo4j.kernel.api.proc.CallableProcedure)16 ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)12 CallableUserFunction (org.neo4j.kernel.api.proc.CallableUserFunction)10 Log (org.neo4j.logging.Log)8 NullLog (org.neo4j.logging.NullLog)8 CallableUserAggregationFunction (org.neo4j.kernel.api.proc.CallableUserAggregationFunction)7 URL (java.net.URL)3 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)3 ProcedureSignature (org.neo4j.kernel.api.proc.ProcedureSignature)3 RawIterator (org.neo4j.collection.RawIterator)2 Context (org.neo4j.kernel.api.proc.Context)2 NTString (org.neo4j.kernel.api.proc.Neo4jTypes.NTString)1 UserFunctionSignature (org.neo4j.kernel.api.proc.UserFunctionSignature)1 SecurityContext (org.neo4j.kernel.api.security.SecurityContext)1