cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: Controlling Cayennes JDBC connection usage
Date Mon, 09 Oct 2017 06:29:22 GMT
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 <dlatt@alqualonde.de> 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?


Mime
View raw message