Skip to content

Consider adding database.beginTransaction(connection) - support case of external Connection provided #2232

@rbygrave

Description

@rbygrave

Query and query beans both have a method query.usingConnection(java.sql.Connection) ... so that is ok.

We should consider adding database.beginTransaction(connection) for the case where we have an external java.sql.Connection provided and want to use all Ebean functionality, not just queries.

Ebean has a method to turn a java.sql.Connection into a Transaction. Internally that is TransactionManager.wrapExternalConnection(Connection connection). Now, I thought that was exposed as public API but it is not.

We really should make the change to expose that method on Database. Something like:

// try with resources
try (Transaction t = database.beginTransaction(connection)) {

  // don't commit or rollback ...  end() as a no-op
}


// as the connection is provided the expectation is that the 
// commit() / rollback() is also external code 
connection.commit();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions