Re: Transactions
Ricardo Parada <[email protected]> Sat, 4 Oct 2025 20:16:23 -0400
| Newsgroups | gmane.comp.java.cayenne.user |
|---|---|
| Message-ID | <[email protected]> |
This looks close to what I need. It was suggested by ChatGPT.=20
import org.apache.cayenne.tx.BaseTransaction;
import org.apache.cayenne.tx.Transaction;
import java.sql.Connection;
runtime.performInTransaction(() -> {
BaseTransaction tx =3D (BaseTransaction) BaseTransaction.getThreadTransa=
ction();
if (tx !=3D null) {
// Iterate over all connections (key =3D DataNode name)
tx.getConnections().forEach((nodeName, connection) -> {
System.out.println("Node: " + nodeName + ", Connection: " + conn=
ection);
});
// Or, if you know the node name:
Connection conn =3D tx.getConnection("mynode");
// Now you can use the JDBC Connection directly (careful =E2=80=94 t=
his bypasses Cayenne!)
}
return null;
});
>=20
> On Oct 4, 2025, at 6:20=E2=80=AFPM, Andrus Adamchik <[email protected]> w=
rote:
>=20
> BaseTransaction.getThreadTransaction()