You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Juan Manuel Diaz Lara <jm...@yahoo.com.INVALID> on 2020/01/28 01:28:35 UTC

In 4.1.RC2, how to contribute/replace PKGenerator

My DB is postgres, how can I contribute/replace de PostgresPkGenerator with my own implementation to genera UUID's as PK's:
public class PcExpressPosUUIDPkGenerator extends PostgresPkGenerator {
    public PcExpressPosUUIDPkGenerator(@Inject PostgresAdapter adapter) {
        super(adapter);
    }

    @Override
    public Object generatePk(DataNode arg0, DbAttribute attribute) throws Exception {
        if (    attribute.getType() == java.sql.Types.OTHER)
            return java.util.UUID.randomUUID();
        else if (attribute.getType() == java.sql.Types.VARCHAR)
            return java.util.UUID.randomUUID().toString();
        else 
            return super.generatePk(arg0, attribute);
    }
}
I tryied this in a new Module:

ServerModule.contributePkGenerators(binder).put(PostgresAdapter.class.getName(), PcExpressPosUUIDPkGenerator.class);
But when trying to create my first context get this error:
org.apache.cayenne.di.DIRuntimeException: DI container has no binding for key <BindingKey: org.apache.cayenne.dba.postgres.PostgresAdapter>

Atte. Juan Manuel Díaz Lara

Re: In 4.1.RC2, how to contribute/replace PKGenerator

Posted by "jmdiazlr@yahoo.com.INVALID" <jm...@yahoo.com.INVALID>.
Thanks. You are great. 


   El martes, 28 de enero de 2020 7:44:42 GMT-6, Nikita Timofeev <nt...@objectstyle.com> escribió:  
 
 Hi,

You shouldn't inject an adapter in the constructor, it's not in DI
container directly. Try to define only default constructor:

public PcExpressPosUUIDPkGenerator() {
    super();
}

On Tue, Jan 28, 2020 at 4:28 AM Juan Manuel Diaz Lara
<jm...@yahoo.com.invalid> wrote:
>
> My DB is postgres, how can I contribute/replace de PostgresPkGenerator with my own implementation to genera UUID's as PK's:
> public class PcExpressPosUUIDPkGenerator extends PostgresPkGenerator {
>    public PcExpressPosUUIDPkGenerator(@Inject PostgresAdapter adapter) {
>        super(adapter);
>    }
>
>    @Override
>    public Object generatePk(DataNode arg0, DbAttribute attribute) throws Exception {
>        if (    attribute.getType() == java.sql.Types.OTHER)
>            return java.util.UUID.randomUUID();
>        else if (attribute.getType() == java.sql.Types.VARCHAR)
>            return java.util.UUID.randomUUID().toString();
>        else
>            return super.generatePk(arg0, attribute);
>    }
> }
> I tryied this in a new Module:
>
> ServerModule.contributePkGenerators(binder).put(PostgresAdapter.class.getName(), PcExpressPosUUIDPkGenerator.class);
> But when trying to create my first context get this error:
> org.apache.cayenne.di.DIRuntimeException: DI container has no binding for key <BindingKey: org.apache.cayenne.dba.postgres.PostgresAdapter>
>
> Atte. Juan Manuel Díaz Lara



-- 
Best regards,
Nikita Timofeev  

Re: In 4.1.RC2, how to contribute/replace PKGenerator

Posted by Nikita Timofeev <nt...@objectstyle.com>.
Hi,

You shouldn't inject an adapter in the constructor, it's not in DI
container directly. Try to define only default constructor:

public PcExpressPosUUIDPkGenerator() {
    super();
}

On Tue, Jan 28, 2020 at 4:28 AM Juan Manuel Diaz Lara
<jm...@yahoo.com.invalid> wrote:
>
> My DB is postgres, how can I contribute/replace de PostgresPkGenerator with my own implementation to genera UUID's as PK's:
> public class PcExpressPosUUIDPkGenerator extends PostgresPkGenerator {
>     public PcExpressPosUUIDPkGenerator(@Inject PostgresAdapter adapter) {
>         super(adapter);
>     }
>
>     @Override
>     public Object generatePk(DataNode arg0, DbAttribute attribute) throws Exception {
>         if (    attribute.getType() == java.sql.Types.OTHER)
>             return java.util.UUID.randomUUID();
>         else if (attribute.getType() == java.sql.Types.VARCHAR)
>             return java.util.UUID.randomUUID().toString();
>         else
>             return super.generatePk(arg0, attribute);
>     }
> }
> I tryied this in a new Module:
>
> ServerModule.contributePkGenerators(binder).put(PostgresAdapter.class.getName(), PcExpressPosUUIDPkGenerator.class);
> But when trying to create my first context get this error:
> org.apache.cayenne.di.DIRuntimeException: DI container has no binding for key <BindingKey: org.apache.cayenne.dba.postgres.PostgresAdapter>
>
> Atte. Juan Manuel Díaz Lara



-- 
Best regards,
Nikita Timofeev