Skip to content

Explicitly close connections? #19

Closed

Description

@hansgru

Is it possible to explicitly close DB connections?

There seems to be lazy-init="true" that helps when doing something else before the DB operations, but the same problem still remains after the DB operations :(.

Thank you.

Activity

  1. aadrian commented on May 30, 2015

    @aadrian

    I haven't found a way to achieve this :(.

    What you can do is to create another etl.xml file to execute based on certain conditions after the other one with the DB operations (in case it does not depend on query logic).

    Of course, this is quite annoying since it does not allow to logically group operations, and the logic is moved from the etl.xml to the shell file starting Scriptella, and also reduces the scenarios where Scriptella can be used.

  2. mrdanpsmith commented on Jun 10, 2015

    @mrdanpsmith

    Has any thought been given to allowing "include" to be a top level element so that you can include etl files, or creating a new element to allow including of sub etls? That way there would be a boundary around which Scriptella could automatically open / close declared connections.

    I could give it a shot if anyone else thinks it's a good idea. I found the most confusing thing about Scriptella to be that there did not seem to be a way to break apart my ETL scripts into smaller (and more maintainable) chunks.

    I did wind up breaking them apart anyway, but I'm using a wildcard in the launcher which does not typically have a guaranteed call order and therefore seems kinda code-smellish to me.

  3. trombosestrumpf commented on Feb 14, 2022

    @trombosestrumpf

    For testing something I actually made some changes based on version 1.2 allowing closing connections early. Probably I will ask to merge my changes to the trunk, if there is interest in that. It is quite simple and does not break the concepts.

  4. trombosestrumpf commented on Feb 14, 2022

    @trombosestrumpf

    @mrdanpsmith
    Breaking ETL scripts into chunks could be problematic for the scope of ETL variables, and a lot of other referencing stuff i am afraid.

  5. mrdanpsmith commented on Feb 14, 2022

    @mrdanpsmith

    @trombosestrumpf I no longer use this project, but scoping everything globally or heavy reliance on globally scoped variables is in general a bad practice and is one of the biggest categorical causes of software defects. I would assume if includes were added that you would add more / better scopes at the same time.

    I don't remember much about it unfortunately as this thread was dormant for so long and I no longer remember any of the details.

    It was useful when I was using it, but it was a former employer that was using it and I wouldn't be shocked to find that they too have moved on from it. But I could be wrong.

    Cheers!

  6. ejboy commented on Oct 21, 2026

    @ejboy
    Member

    After eleven years, this might be a contender for the slowest fix ever 🙂 I’ve finally found time to return to working on Scriptella this year, and I’m targeting this enhancement for 1.7.

    The scope is to allow explicitly closing a connection once its work is complete, while the remaining ETL continues. We’ll need clear semantics for pending transactions, active queries, and subsequent references to a closed connection.

    The implementation will define how pending transactions are handled, prevent closure while a query is still using the connection, and provide clear behavior when a later script references a closed connection. Final cleanup will also account for connections that have already been closed.

    Sub-ETL inclusion is outside the scope of this change.

  7. added this to the 1.7.0 milestone on Oct 21, 2026
  8. ejboy commented on Oct 25, 2026

    @ejboy
    Member

    Implemented in 73b0138 for the upcoming 1.7.0 release; not yet released.

    The delivered interface is opt-in automatic closure after final use, rather than an explicit close command: connection property close.after.use, execution-wide default scriptella.close.after.use, built-in default false. Explicit connection settings override the global default.

    Conservative analysis retires connections after their final potentially referencing top-level subtree completes, including nested queries, inherited references and error handlers. Owned new-tx connections are handled together; unopened lazy connections remain unopened. Statistics and progress counters survive retirement, and retired connections cannot reopen.

    Enabling this feature introduces an early commit boundary: pending work is committed before closure, and later ETL failure/cancellation cannot roll it back. Default lifecycle behavior is unchanged.

    Focused tests cover configuration precedence, repeated/nested execution, lazy/new-tx connections, failure/cancellation, commit failures, final JDBC batches, retained counters and conditional elements. Maven and Ant regression suites passed locally; CI passed on the implementation commit.

    Repository documentation: docs/connection-lifecycle.md. Public website guide/reference publication, release notes and link verification are tracked in #70. Closing as implemented while retaining the 1.7.0 milestone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions