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

Nikita Timofeev <[email protected]>
Newsgroups gmane.comp.java.cayenne.user
Message-ID <CAMi+qzCqwM5jpKXU5+S7VqN874bhOSnik7uyJ2Us4rNW85LLhw@mail.gmail.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
<[email protected]> 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.