Hi Andrus, thanks for your indications. I'll investigate if all that can lead to a solution that does what I need. I already pondered if Cayenne's transaction management and SchemaUpdateStrategies might work out. Since my approach with Hibernate works even with several transactions in a Session (thus a Connection), I was/am a bit in doubt. But maybe the restriction to a single transaction is sufficient.
Further, I'll try and implement a SchemaUpdateStrategy based on Liquibase. I'll post my findings. Thanks again, Dirk Am Mon, 9 Oct 2017 09:29:22 +0300 schrieb Andrus Adamchik <[email protected]>: > Hi Dirk, > > When using explicit transactions [1], the connection is always the > same within the transaction. "runtime.performInTransaction(..)" [2] > can also take TransactionListener as a second argument that you may > implement to set connection properties. > > Unrelated to the above, specifically for schema generation purposes > you can bind SchemaUpdateStrategyFactory [3] when you start your > runtime, that creates SchemaUpdateStrategy (either one of the > standard choices like CreateIfNoSchemaStrategy, or your custom > version). Cayenne is guaranteed to invoke the strategy before any of > the app code can access the DB. > > Hopefully it will point you in the right direction. > > Andrus > > [1] > http://cayenne.apache.org/docs/4.0/cayenne-guide/persistent-objects-objectcontext.html#transactions > [2] > https://cayenne.apache.org/docs/4.0/api/index.html?org/apache/cayenne/configuration/server/ServerRuntime.html > [3] > https://cayenne.apache.org/docs/4.0/api/org/apache/cayenne/access/dbsync/SchemaUpdateStrategyFactory.html > > > > On Oct 8, 2017, at 12:39 PM, Dirk Lattermann <[email protected]> > > wrote: > > > > Hello, > > > > is it possible to control which database connection is used when > > committing an ObjectContext? > > > > For example, when using an explicit transaction, the database > > connection used in the thread starting the exception must always be > > the same. > > > > Now, I have a use case where I want to obtain a PostgresQL advisory > > exclusive session lock and do some DDL to create a db schema. Then I > > want to write something into that schema using Cayenne, and after > > that, release the lock. That's to somewhat atomically initialize a > > db schema. > > > > For normal schema usage, I want to obtain an advisory shared lock > > in the db connection and use that connection with Cayenne. > > > > That mechanism can also be used to manipulate portions of the > > database that must be done without concurrent access. > > > > It's how I solved the problem with Hibernate, where a Hibernate > > session represents a JDBC Connection. It is bound to the current > > thread and used for all Hibernate DB accesses during the session. > > That worked quite well. > > > > Would it be possible to do something similar with Cayenne? >
