Package org.neo4j.gds.core
Class TransactionContext
- java.lang.Object
-
- org.neo4j.gds.core.TransactionContext
-
public final class TransactionContext extends java.lang.Object
Manage transactions by making sure that the correctSecurityContext
is applied.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TransactionContext.SecureTransaction
static interface
TransactionContext.TxConsumer<E extends java.lang.Exception>
static interface
TransactionContext.TxFunction<T,E extends java.lang.Exception>
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <E extends java.lang.Exception>
voidaccept(TransactionContext.TxConsumer<E> block)
Run some code within a newTransaction
under the managedSecurityContext
.<T,E extends java.lang.Exception>
Tapply(TransactionContext.TxFunction<T,E> block)
Run some code within a newTransaction
under the managedSecurityContext
.TransactionContext.SecureTransaction
fork()
Return a newTransactionContext.SecureTransaction
that owns a newly created top-levelTransaction
.static TransactionContext
of(org.neo4j.kernel.internal.GraphDatabaseAPI api, org.neo4j.graphdb.Transaction top)
Creates a newTransactionContext
with the sameSecurityContext
as the providedTransaction
.static TransactionContext
of(org.neo4j.kernel.internal.GraphDatabaseAPI api, org.neo4j.internal.kernel.api.security.SecurityContext securityContext)
Creates a newTransactionContext
with the providedSecurityContext
.static TransactionContext
of(org.neo4j.kernel.internal.GraphDatabaseAPI api, org.neo4j.kernel.impl.coreapi.InternalTransaction top)
Creates a newTransactionContext
with the sameSecurityContext
as the providedInternalTransaction
.java.lang.String
username()
TransactionContext
withRestrictedAccess(org.neo4j.internal.kernel.api.security.AccessMode.Static accessMode)
Returns a newTransactionContext
restricted by the providedAccessMode
.
-
-
-
Method Detail
-
of
public static TransactionContext of(org.neo4j.kernel.internal.GraphDatabaseAPI api, org.neo4j.graphdb.Transaction top)
Creates a newTransactionContext
with the sameSecurityContext
as the providedTransaction
.
-
of
public static TransactionContext of(org.neo4j.kernel.internal.GraphDatabaseAPI api, org.neo4j.kernel.impl.coreapi.InternalTransaction top)
Creates a newTransactionContext
with the sameSecurityContext
as the providedInternalTransaction
.
-
of
public static TransactionContext of(org.neo4j.kernel.internal.GraphDatabaseAPI api, org.neo4j.internal.kernel.api.security.SecurityContext securityContext)
Creates a newTransactionContext
with the providedSecurityContext
.
-
username
public java.lang.String username()
- Returns:
- The username associated with the current
SecurityContext
.
-
apply
public <T,E extends java.lang.Exception> T apply(TransactionContext.TxFunction<T,E> block) throws E extends java.lang.Exception
Run some code within a newTransaction
under the managedSecurityContext
. The new transaction is closed afterwards and any resource that is tied to the lifecycle of that transaction will throw aNotInTransactionException
upon access.- Throws:
E extends java.lang.Exception
-
accept
public <E extends java.lang.Exception> void accept(TransactionContext.TxConsumer<E> block) throws E extends java.lang.Exception
Run some code within a newTransaction
under the managedSecurityContext
. The new transaction is closed afterwards.- Throws:
E extends java.lang.Exception
-
withRestrictedAccess
public TransactionContext withRestrictedAccess(org.neo4j.internal.kernel.api.security.AccessMode.Static accessMode)
Returns a newTransactionContext
restricted by the providedAccessMode
. The mode only restricts but does not override the givenSecurityContext
, i.e. you cannot grant more access.One use-case is to restrict the access to
AccessMode.Static.READ
to make sure that only read-only queries can be executed.A new instance is returned,
this
instance remains untouched.
-
fork
public TransactionContext.SecureTransaction fork()
Return a newTransactionContext.SecureTransaction
that owns a newly created top-levelTransaction
. The returned instance will operate under theSecurityContext
as provided by thisTransactionContext
.For shorter tasks, consider using
accept(TransactionContext.TxConsumer)
orapply(TransactionContext.TxFunction)
which make sure that the created transaction is closed.This is intended for when you need to keep track of a new transaction for a longer time, in which case you can use
TransactionContext.SecureTransaction.kernelTransaction()
to get the underlying transaction.
-
-