Class SqlLeaseContextBuilder


  • public class SqlLeaseContextBuilder
    extends java.lang.Object
    Utility class to assemble a SqlLeaseContext and execute operations on it using a Connection. The intended use is to create the SqlLeaseContextBuilder once and set the connection many times:
      //in ctor:
      lc = SqlLeaseContextconfiguration.with( .... );
    
      //in method 1
      void method1(){
          var connection = ...;
          lc.withConnection(connection).acquireLease(...);
          //or
          lc.withConnection(connection).breakLease(...);
      }
     

    Please do NOT keep references to the SqlLeaseContext, as this would keep the underlying connection open!

    • Method Detail

      • with

        public static SqlLeaseContextBuilder with​(org.eclipse.dataspaceconnector.spi.transaction.TransactionContext trxContext,
                                                  java.lang.String leaseHolder,
                                                  LeaseStatements statements,
                                                  java.time.Clock clock)
      • by

        public SqlLeaseContextBuilder by​(java.lang.String leaseHolder)
        Sets the name which is used when acquiring a lease.
      • forTime

        public SqlLeaseContextBuilder forTime​(java.time.Duration duration)
        configures the duration for which the lease is acquired. Has no effect when breaking or getting the lease
      • withConnection

        public SqlLeaseContext withConnection​(java.sql.Connection connection)
        sets the Connection on which the next DB statement is executed.

        Storing references to the SqlLeaseContext is strongly discouraged, as this would keep the database Connection open!