Package org.neo4j.gds.transaction
Class TransactionContext
- java.lang.Object
-
- org.neo4j.gds.transaction.TransactionContext
-
public final class TransactionContext extends java.lang.ObjectManage transactions by making sure that the correctSecurityContextis applied.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTransactionContext.SecureTransactionstatic interfaceTransactionContext.TxConsumer<E extends java.lang.Exception>static interfaceTransactionContext.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 newTransactionunder the managedSecurityContext.<T,E extends java.lang.Exception>
Tapply(TransactionContext.TxFunction<T,E> block)Run some code within a newTransactionunder the managedSecurityContext.TransactionContext.SecureTransactionfork()Return a newTransactionContext.SecureTransactionthat owns a newly created top-levelTransaction.static TransactionContextof(org.neo4j.graphdb.GraphDatabaseService databaseService, org.neo4j.graphdb.Transaction top)Creates a newTransactionContextwith the sameSecurityContextas the providedTransaction.static TransactionContextof(org.neo4j.graphdb.GraphDatabaseService databaseService, org.neo4j.internal.kernel.api.security.SecurityContext securityContext)Creates a newTransactionContextwith the providedSecurityContext.static TransactionContextof(org.neo4j.graphdb.GraphDatabaseService databaseService, org.neo4j.kernel.impl.coreapi.InternalTransaction top)Creates a newTransactionContextwith the sameSecurityContextas the providedInternalTransaction.java.lang.Stringusername()TransactionContextwithRestrictedAccess(org.neo4j.internal.kernel.api.security.AccessMode.Static accessMode)Returns a newTransactionContextrestricted by the providedAccessMode.
-
-
-
Method Detail
-
of
public static TransactionContext of(org.neo4j.graphdb.GraphDatabaseService databaseService, org.neo4j.graphdb.Transaction top)
Creates a newTransactionContextwith the sameSecurityContextas the providedTransaction.
-
of
public static TransactionContext of(org.neo4j.graphdb.GraphDatabaseService databaseService, org.neo4j.kernel.impl.coreapi.InternalTransaction top)
Creates a newTransactionContextwith the sameSecurityContextas the providedInternalTransaction.
-
of
public static TransactionContext of(org.neo4j.graphdb.GraphDatabaseService databaseService, org.neo4j.internal.kernel.api.security.SecurityContext securityContext)
Creates a newTransactionContextwith 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 newTransactionunder the managedSecurityContext. The new transaction is closed afterwards and any resource that is tied to the lifecycle of that transaction will throw aNotInTransactionExceptionupon 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 newTransactionunder 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 newTransactionContextrestricted 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.READto make sure that only read-only queries can be executed.A new instance is returned,
thisinstance remains untouched.
-
fork
public TransactionContext.SecureTransaction fork()
Return a newTransactionContext.SecureTransactionthat owns a newly created top-levelTransaction. The returned instance will operate under theSecurityContextas 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.
-
-