Class RetryingTransaction<R>

  • All Implemented Interfaces:
    Transaction<R>

    public abstract class RetryingTransaction<R>
    extends java.lang.Object
    implements Transaction<R>
    A simple transaction implementation for COPPER applications. Retrying means that the user's implementation of execute() will automatically be retried in case of technical failures.
    • Constructor Detail

      • RetryingTransaction

        public RetryingTransaction​(java.lang.String name,
                                   javax.sql.DataSource ds)
      • RetryingTransaction

        public RetryingTransaction​(javax.sql.DataSource ds)
      • RetryingTransaction

        public RetryingTransaction​(java.lang.String name,
                                   javax.sql.DataSource ds,
                                   boolean modificatory)
    • Method Detail

      • setDefaultSQLExceptionProcessor

        public static void setDefaultSQLExceptionProcessor​(SQLExceptionProcessor defaultSQLExceptionProcessor)
      • setSqlExceptionProcessor

        public void setSqlExceptionProcessor​(SQLExceptionProcessor sqlExceptionProcessor)
      • execute

        protected abstract R execute()
                              throws java.lang.Exception
        This function is to be implemented by anonymous inner classes. Usage should look like this: ... new RetryingTransaction<ReturnType>("TestTransaction") { protected ReturnType execute() { doSomething(); doAnotherThing(); return ...; } }.run();
        Returns:
        any type which shall be passed back after execution succeeded.
        Throws:
        java.lang.Exception - Any exception which could happen in an implementation of this method
      • getConnection

        public java.sql.Connection getConnection()
      • run

        public final R run()
                    throws java.lang.Exception
        This function implements error handling (i.e. transaction rollbacks in case of exceptions etc.), and automatic retries in case of deadlocks or timeouts.
        Specified by:
        run in interface Transaction<R>
        Throws:
        java.lang.Exception
      • check4retry

        protected RetryAction check4retry​(java.sql.SQLException e,
                                          int seqNr)
      • aquireConnection

        protected java.sql.Connection aquireConnection​(boolean validateNewConnection)
                                                throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • getMaxConnectRetries

        public int getMaxConnectRetries()
      • setMaxConnectRetries

        public Transaction<R> setMaxConnectRetries​(int maxConnectRetries)