> On Oct 18, 2016, at 7:26 PM, Hugi Thordarson <h...@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

Reply via email to