cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: Set DB Adapter in code
Date Thu, 15 Dec 2016 17:39:16 GMT

> On Oct 18, 2016, at 7:26 PM, Hugi Thordarson <hugi@karlmenn.is> wrote:
> 
> Hi all,
> when running tests I need to switch the DB adapter to H2Adapter (my DataNode has a Customer
adaptor). How would this be easiest to do?
> 
> Cheers,
> - hugi


I am a bit late to the game here, but a general customization advice (with a few exceptions)
is to go to ServerModule and see what you can redefine there. In this case DbAdapterFactory
is the best candidate.

Also an alternative solution. Instead of defining your custom adapter explicitly in the Model,
let your app guess it automatically based on what DB you connect:

  binder.bindList(Constants.SERVER_ADAPTER_DETECTORS_LIST).add(MyAdapterDetector.class).before(FirebirdSniffer.class);

"MyAdapterDetector" is a class that implements DbAdapterDetector. Look for existing implementations
for an example. It should return a non-null value when it detects that DB signature matches
your real DB. 

"FirebirdSniffer" is just a marker .. Our standard detector list starts with it. So your custom
detector will be the first one consulted by Cayenne, as it will go *before* FirebirdSniffer.

So when the DB is your real DB, your own adapter will be installed. When the DB is H2, Cayenne
will skip MyAdapterDetector, and will eventually find detector for H2 and install the corresponding
adapter.

Andrus
Mime
View raw message