Re: How to install my own DbAdapterDetector on 4.0.B2

2018-02-13 Thread Nikita Timofeev
Hi,

ServerModule.contributeAdapterDetectors(binder) actually uses
binder.bindList(DbAdapterDetector.class, SERVER_ADAPTER_DETECTORS_LIST),
so your binder.bindList(DbAdapterDetector.class) part was incorrect.

I think you better use insertBefore() instead of just add(), to be
sure that order remains correct.

On Tue, Feb 13, 2018 at 4:36 AM, Juan Manuel Diaz Lara
 wrote:
> I solved it,for 4.0.B2:
> ServerModule.contributeAdapterDetectors(binder).add(PcExpressPosPgDetector.class);
> I suppose this method add the new detector to the first place on the list, so 
> It is found as i want.
>
> Does  anybody knows why my first approach didn't worked ?
>
> Atte. Juan Manuel Díaz Lara
>
> On Monday, February 12, 2018, 7:06:42 PM CST, Juan Manuel Diaz Lara 
>  wrote:
>
>  My code was working on 4.0.M5, but I ca not figure out how to make it work 
> on B2, I think the problem is that I am not installing my DbAdapterDetector 
> properly.
>
> package com.ace.dba;
>
> import static 
> org.apache.cayenne.configuration.Constants.SERVER_ADAPTER_DETECTORS_LIST;
>
> import org.apache.cayenne.configuration.server.DbAdapterDetector;
> import org.apache.cayenne.dba.postgres.PostgresSniffer;
> import org.apache.cayenne.di.Binder;
> import org.apache.cayenne.di.Module;
>
> public class PcExpressPosModule implements Module {
>
> public void configure(Binder binder) {
> //4.0.m5:
> 
> //binder.bindList(SERVER_ADAPTER_DETECTORS_LIST).before(PostgresSniffer.class).add(PcExpressPosPgDetector.class);
> //4.0.b2:
> binder.bindList(DbAdapterDetector.class).insertBefore(PostgresSniffer.class, 
> PcExpressPosPgDetector.class );  //tryes param in reverse order nothing
> }
> }
>
> My PcExpressPosPgDetector:
>
> public class PcExpressPosPgDetector extends PostgresSniffer {
> public PcExpressPosPgDetector(@Inject AdhocObjectFactory objectFactory) {
> super(objectFactory);
>}
>
> @Override
> public DbAdapter createAdapter(DatabaseMetaData md) throws SQLException {
> PostgresAdapter db = (PostgresAdapter) super.createAdapter(md);
> db.setPkGenerator(new PcExpressPosUUIDPkGenerator(db));
> return db;
> }
> }
> PcExpressPosUUIDPkGenerator detects pk columns of type UUID and generates a 
> uuid for then,.. thats all.
>
>
>
> Atte. Juan Manuel Díaz Lara



-- 
Best regards,
Nikita Timofeev


Re: How to install my own DbAdapterDetector on 4.0.B2

2018-02-12 Thread Juan Manuel Diaz Lara
I solved it,for 4.0.B2:
ServerModule.contributeAdapterDetectors(binder).add(PcExpressPosPgDetector.class);
I suppose this method add the new detector to the first place on the list, so 
It is found as i want. 

Does  anybody knows why my first approach didn't worked ?

Atte. Juan Manuel Díaz Lara 

On Monday, February 12, 2018, 7:06:42 PM CST, Juan Manuel Diaz Lara 
 wrote:  
 
 My code was working on 4.0.M5, but I ca not figure out how to make it work on 
B2, I think the problem is that I am not installing my DbAdapterDetector 
properly.

package com.ace.dba;

import static 
org.apache.cayenne.configuration.Constants.SERVER_ADAPTER_DETECTORS_LIST;

import org.apache.cayenne.configuration.server.DbAdapterDetector;
import org.apache.cayenne.dba.postgres.PostgresSniffer;
import org.apache.cayenne.di.Binder;
import org.apache.cayenne.di.Module;

public class PcExpressPosModule implements Module {

    public void configure(Binder binder) {
    //4.0.m5: 
        
//binder.bindList(SERVER_ADAPTER_DETECTORS_LIST).before(PostgresSniffer.class).add(PcExpressPosPgDetector.class);
        //4.0.b2:        
binder.bindList(DbAdapterDetector.class).insertBefore(PostgresSniffer.class, 
PcExpressPosPgDetector.class );  //tryes param in reverse order nothing
    }
}

My PcExpressPosPgDetector:

public class PcExpressPosPgDetector extends PostgresSniffer {
    public PcExpressPosPgDetector(@Inject AdhocObjectFactory objectFactory) {
        super(objectFactory);
   }

    @Override
    public DbAdapter createAdapter(DatabaseMetaData md) throws SQLException {
    PostgresAdapter db = (PostgresAdapter) super.createAdapter(md);
        db.setPkGenerator(new PcExpressPosUUIDPkGenerator(db));
        return db;    
    }
}
PcExpressPosUUIDPkGenerator detects pk columns of type UUID and generates a 
uuid for then,.. thats all.



Atte. Juan Manuel Díaz Lara