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();