Class TransactionContext


  • public final class TransactionContext
    extends java.lang.Object
    Manage transactions by making sure that the correct SecurityContext is applied.
    • Method Detail

      • of

        public static TransactionContext of​(org.neo4j.kernel.internal.GraphDatabaseAPI api,
                                            org.neo4j.graphdb.Transaction top)
        Creates a new TransactionContext with the same SecurityContext as the provided Transaction.
      • of

        public static TransactionContext of​(org.neo4j.kernel.internal.GraphDatabaseAPI api,
                                            org.neo4j.kernel.impl.coreapi.InternalTransaction top)
        Creates a new TransactionContext with the same SecurityContext as the provided InternalTransaction.
      • of

        public static TransactionContext of​(org.neo4j.kernel.internal.GraphDatabaseAPI api,
                                            org.neo4j.internal.kernel.api.security.SecurityContext securityContext)
        Creates a new TransactionContext with the provided SecurityContext.
      • 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 new Transaction under the managed SecurityContext. The new transaction is closed afterwards and any resource that is tied to the lifecycle of that transaction will throw a NotInTransactionException 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 new Transaction under the managed SecurityContext. 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 new TransactionContext restricted by the provided AccessMode. The mode only restricts but does not override the given SecurityContext, 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.