Discussion:
Trying to instanciate a datasource with setter injection and config
Vincent van Beveren
2010-02-11 11:33:14 UTC
Permalink
Hi everyone,

I'm new to pico-container, so bare with me :).
I'm trying to instantiate a PostgresSQL datasource, with PicoContainer 2.9. The datasource itself has methods like setUser, setServerName, etc... Also I wish this to be configurable. I've created the following code:

MutablePicoContainer pico = new DefaultPicoContainer();
pico.addConfig("serverName", "localhost");
pico.addConfig("databaseName", "mydb");
pico.addConfig("user", "user");

pico.change(Characteristics.USE_NAMES, Characteristics.SDI);
pico.addComponent(PGConnectionPoolDataSource.class);
PGConnectionPoolDataSource ds = pico.getComponent(PGConnectionPoolDataSource.class);
System.out.println(ds.getUser());
Exception in thread "main" org.picocontainer.injectors.AbstractInjector$AmbiguousComponentResolutionException: <no-component> needs a 'java.lang.String' injected, but there are too many choices to inject. These:[class java.lang.String, class java.lang.String, class java.lang.String], refer http://picocontainer.org/ambiguous-injectable-help.html

At the getComponent() call.

I tried to tell it that it needs to use the named version, but it doesn't seem to do it. What am I doing wrong? The next step would be to use properties loaded from a Properties file... I guess that should not be a problem once I get the above example working. Anyway, thanks for any help/examples!

Regards,
Vincent


___
Ing. V. van Beveren
Software Engineer, FOM Rijnhuizen
T: +31 (0) 30-6096769
E: V.vanBeveren-***@public.gmane.org<mailto:V.vanBeveren-***@public.gmane.org>
Paul Hammant
2010-02-11 14:24:59 UTC
Permalink
Can you share the source of PGConnectionPoolDataSource ?

Specifically, does it have methods setServerName(String serverName), setDatabaseName(String databaseName), setUser(String user) ?

Regards,

- Paul
Post by Vincent van Beveren
Hi everyone,
I’m new to pico-container, so bare with me :).
MutablePicoContainer pico = new DefaultPicoContainer();
pico.addConfig("serverName", "localhost");
pico.addConfig("databaseName", "mydb");
pico.addConfig("user", "user");
pico.change(Characteristics.USE_NAMES, Characteristics.SDI);
pico.addComponent(PGConnectionPoolDataSource.class);
PGConnectionPoolDataSource ds = pico.getComponent(PGConnectionPoolDataSource.class);
System.out.println(ds.getUser());
Exception in thread "main" org.picocontainer.injectors.AbstractInjector$AmbiguousComponentResolutionException: <no-component> needs a 'java.lang.String' injected, but there are too many choices to inject. These:[class java.lang.String, class java.lang.String, class java.lang.String], refer http://picocontainer.org/ambiguous-injectable-help.html
At the getComponent() call.
I tried to tell it that it needs to use the named version, but it doesn’t seem to do it. What am I doing wrong? The next step would be to use properties loaded from a Properties file... I guess that should not be a problem once I get the above example working. Anyway, thanks for any help/examples!
Regards,
Vincent
___
Ing. V. van Beveren
Software Engineer, FOM Rijnhuizen
T: +31 (0) 30-6096769
Vincent van Beveren
2010-02-11 14:27:30 UTC
Permalink
Hi Paul,

Yet is has. Its the datasource from Postgres SQL JDBC. Here is the link to the JavaDoc:

http://jdbc.postgresql.org/documentation/publicapi/index.html?org/postgresql/ds/PGConnectionPoolDataSource.html

But to answer your question, yes it does in the super class.

Regards,
Vincent

________________________________
From: Paul Hammant [mailto:paul-POq8DFUn+***@public.gmane.org]
Sent: donderdag 11 februari 2010 15:25
To: user-qxt/k92ZUMzOYGyH7mwfjrEhcVWVsK+***@public.gmane.org
Subject: Re: [picocontainer-user] Trying to instanciate a datasource with setter injection and config

Can you share the source of PGConnectionPoolDataSource ?

Specifically, does it have methods setServerName(String serverName), setDatabaseName(String databaseName), setUser(String user) ?

Regards,

- Paul

On Feb 11, 2010, at 5:33 AM, Vincent van Beveren wrote:


Hi everyone,

I'm new to pico-container, so bare with me :).
I'm trying to instantiate a PostgresSQL datasource, with PicoContainer 2.9. The datasource itself has methods like setUser, setServerName, etc... Also I wish this to be configurable. I've created the following code:

MutablePicoContainer pico = new DefaultPicoContainer();
pico.addConfig("serverName", "localhost");
pico.addConfig("databaseName", "mydb");
pico.addConfig("user", "user");

pico.change(Characteristics.USE_NAMES, Characteristics.SDI);
pico.addComponent(PGConnectionPoolDataSource.class);
PGConnectionPoolDataSource ds = pico.getComponent(PGConnectionPoolDataSource.class);
System.out.println(ds.getUser());
Exception in thread "main" org.picocontainer.injectors.AbstractInjector$AmbiguousComponentResolutionException: <no-component> needs a 'java.lang.String' injected, but there are too many choices to inject. These:[class java.lang.String, class java.lang.String, class java.lang.String], refer http://picocontainer.org/ambiguous-injectable-help.html

At the getComponent() call.

I tried to tell it that it needs to use the named version, but it doesn't seem to do it. What am I doing wrong? The next step would be to use properties loaded from a Properties file... I guess that should not be a problem once I get the above example working. Anyway, thanks for any help/examples!

Regards,
Vincent


___
Ing. V. van Beveren
Software Engineer, FOM Rijnhuizen
T: +31 (0) 30-6096769
E: V.vanBeveren-***@public.gmane.org<mailto:V.vanBeveren-***@public.gmane.org>
Roman Kitko
2010-02-11 14:54:57 UTC
Permalink
Hi
I was trying to achieve something similar last week using Pico
XMLContainerBuilder.
I found out that SetterInjector uses just types when doing the DI.
But you can use PropertyApplicator to achieve your goal.

Your code could look something like this :

PropertyApplicator myAdapter = new PropertyApplicator(new
ConstructorInjector("myds",DSImpl.class);
myAdapter.setProperty("server","localhost");...
pico.addAdapter(myAdapter);

To Paul :
SetterInjector consider only types , nor names.
I think there should another SetterInjector that would consider
parameter types and names, adding the name also to
ConstantParameter class and adjust resolve method.

Roman
Post by Paul Hammant
Can you share the source of PGConnectionPoolDataSource ?
Specifically, does it have methods setServerName(String serverName),
setDatabaseName(String databaseName), setUser(String user) ?
Regards,
- Paul
Post by Vincent van Beveren
Hi everyone,
I’m new to pico-container, so bare with me :).
I’m trying to instantiate a PostgresSQL datasource, with
PicoContainer 2.9. The datasource itself has methods like setUser,
setServerName, etc... Also I wish this to be configurable. I’ve
MutablePicoContainer pico = new DefaultPicoContainer();
pico.addConfig("serverName", "localhost");
pico.addConfig("databaseName", "mydb");
pico.addConfig("user", "user");
pico.change(Characteristics.USE_NAMES, Characteristics.SDI);
pico.addComponent(PGConnectionPoolDataSource.class);
PGConnectionPoolDataSource ds =
pico.getComponent(PGConnectionPoolDataSource.class);
System.out.println(ds.getUser());
Exception in thread "main"
<no-component> needs a 'java.lang.String' injected, but there are too
many choices to inject. These:[class java.lang.String, class
java.lang.String, class java.lang.String],
refer http://picocontainer.org/ambiguous-injectable-help.html
At the getComponent() call.
I tried to tell it that it needs to use the named version, but it
doesn’t seem to do it. What am I doing wrong? The next step would be
to use properties loaded from a Properties file... I guess that
should not be a problem once I get the above example working. Anyway,
thanks for any help/examples!
Regards,
Vincent
___
Ing. V. van Beveren
Software Engineer, FOM Rijnhuizen
T: +31 (0) 30-6096769
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Paul Hammant
2010-02-11 23:06:32 UTC
Permalink
Its true, setter injection just uses types today.

However its easy to fix, in two ways:

setName(String anything)
^^^^

setAnything(String name)
^^^^

I'll code both of course, allow configuration so end users can specify.

Regards,

- Paul
Hi
I was trying to achieve something similar last week using Pico XMLContainerBuilder.
I found out that SetterInjector uses just types when doing the DI.
But you can use PropertyApplicator to achieve your goal.
PropertyApplicator myAdapter = new PropertyApplicator(new ConstructorInjector("myds",DSImpl.class);
myAdapter.setProperty("server","localhost");...
pico.addAdapter(myAdapter);
SetterInjector consider only types , nor names.
I think there should another SetterInjector that would consider parameter types and names, adding the name also to
ConstantParameter class and adjust resolve method.
Roman
Post by Paul Hammant
Can you share the source of PGConnectionPoolDataSource ?
Specifically, does it have methods setServerName(String serverName), setDatabaseName(String databaseName), setUser(String user) ?
Regards,
- Paul
Post by Vincent van Beveren
Hi everyone,
I’m new to pico-container, so bare with me :).
MutablePicoContainer pico = new DefaultPicoContainer();
pico.addConfig("serverName", "localhost");
pico.addConfig("databaseName", "mydb");
pico.addConfig("user", "user");
pico.change(Characteristics.USE_NAMES, Characteristics.SDI);
pico.addComponent(PGConnectionPoolDataSource.class);
PGConnectionPoolDataSource ds = pico.getComponent(PGConnectionPoolDataSource.class);
System.out.println(ds.getUser());
Exception in thread "main" org.picocontainer.injectors.AbstractInjector$AmbiguousComponentResolutionException: <no-component> needs a 'java.lang.String' injected, but there are too many choices to inject. These:[class java.lang.String, class java.lang.String, class java.lang.String], refer http://picocontainer.org/ambiguous-injectable-help.html
At the getComponent() call.
I tried to tell it that it needs to use the named version, but it doesn’t seem to do it. What am I doing wrong? The next step would be to use properties loaded from a Properties file... I guess that should not be a problem once I get the above example working. Anyway, thanks for any help/examples!
Regards,
Vincent
___
Ing. V. van Beveren
Software Engineer, FOM Rijnhuizen
T: +31 (0) 30-6096769
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
Vincent van Beveren
2010-02-12 07:25:17 UTC
Permalink
Hi Paul,

The issue is that I have not written then class. I have nothing to say about the naming it uses for its parameters, or what type of injection it uses. However, it seems they did a tidy job. setServerName(String serverName). However, this only works if debugging information is retained, which I think probably is not, since it doesn't work for me.

Regards,
Vincent

________________________________
From: Paul Hammant [mailto:paul-POq8DFUn+***@public.gmane.org]
Sent: vrijdag 12 februari 2010 0:07
To: user-qxt/k92ZUMzOYGyH7mwfjrEhcVWVsK+***@public.gmane.org
Subject: Re: [picocontainer-user] Trying to instanciate a datasource with setter injection and config

Its true, setter injection just uses types today.

However its easy to fix, in two ways:

setName(String anything)
^^^^

setAnything(String name)
^^^^

I'll code both of course, allow configuration so end users can specify.

Regards,

- Paul

On Feb 11, 2010, at 8:54 AM, Roman Kitko wrote:


Hi
I was trying to achieve something similar last week using Pico XMLContainerBuilder.
I found out that SetterInjector uses just types when doing the DI.
But you can use PropertyApplicator to achieve your goal.

Your code could look something like this :

PropertyApplicator myAdapter = new PropertyApplicator(new ConstructorInjector("myds",DSImpl.class);
myAdapter.setProperty("server","localhost");...
pico.addAdapter(myAdapter);

To Paul :
SetterInjector consider only types , nor names.
I think there should another SetterInjector that would consider parameter types and names, adding the name also to
ConstantParameter class and adjust resolve method.

Roman


Paul Hammant wrote:

Can you share the source of PGConnectionPoolDataSource ?

Specifically, does it have methods setServerName(String serverName), setDatabaseName(String databaseName), setUser(String user) ?
Regards,

- Paul

On Feb 11, 2010, at 5:33 AM, Vincent van Beveren wrote:

Hi everyone,
I'm new to pico-container, so bare with me :).
I'm trying to instantiate a PostgresSQL datasource, with PicoContainer 2.9. The datasource itself has methods like setUser, setServerName, etc... Also I wish this to be configurable. I've created the following code:
MutablePicoContainer pico = new DefaultPicoContainer();
pico.addConfig("serverName", "localhost");
pico.addConfig("databaseName", "mydb");
pico.addConfig("user", "user");
pico.change(Characteristics.USE_NAMES, Characteristics.SDI);
pico.addComponent(PGConnectionPoolDataSource.class);
PGConnectionPoolDataSource ds = pico.getComponent(PGConnectionPoolDataSource.class);
System.out.println(ds.getUser());
From the documentation I thought this should work, but it gives me a:
Exception in thread "main" org.picocontainer.injectors.AbstractInjector$AmbiguousComponentResolutionException: <no-component> needs a 'java.lang.String' injected, but there are too many choices to inject. These:[class java.lang.String, class java.lang.String, class java.lang.String], refer http://picocontainer.org/ambiguous-injectable-help.html
At the getComponent() call.
I tried to tell it that it needs to use the named version, but it doesn't seem to do it. What am I doing wrong? The next step would be to use properties loaded from a Properties file... I guess that should not be a problem once I get the above example working. Anyway, thanks for any help/examples!
Regards,
Vincent
___
Ing. V. van Beveren
Software Engineer, FOM Rijnhuizen
T: +31 (0) 30-6096769
E: V.vanBeveren-***@public.gmane.org<mailto:V.vanBeveren-***@public.gmane.org> <mailto:V.vanBeveren-***@public.gmane.org>




---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Paul Hammant
2010-02-13 02:13:32 UTC
Permalink
Vincent, Roman,

What I'm saying is there is more than one to skin a cat. In the latest PicoContainer 2.10-SNAPSHOT (just deployed to )

You can do ..

pico = new DefaultPicoContainer(new NamedMethodInjection());
pico.addConfig("serverName", serverName);
pico.addComponent(PGConnectionPoolDataSource.class);

.. and it should just work with or without debug tables as this one is matching on the method name 'set[sS]erverName'. Paranamer is not used for this one.

Tell me what you think....

Regards,

- Paul
Post by Vincent van Beveren
Hi Paul,
The issue is that I have not written then class. I have nothing to say about the naming it uses for its parameters, or what type of injection it uses. However, it seems they did a tidy job. setServerName(String serverName). However, this only works if debugging information is retained, which I think probably is not, since it doesn’t work for me.
Regards,
Vincent
Sent: vrijdag 12 februari 2010 0:07
Subject: Re: [picocontainer-user] Trying to instanciate a datasource with setter injection and config
Its true, setter injection just uses types today.
setName(String anything)
^^^^
setAnything(String name)
^^^^
I'll code both of course, allow configuration so end users can specify.
Regards,
- Paul
Hi
I was trying to achieve something similar last week using Pico XMLContainerBuilder.
I found out that SetterInjector uses just types when doing the DI.
But you can use PropertyApplicator to achieve your goal.
PropertyApplicator myAdapter = new PropertyApplicator(new ConstructorInjector("myds",DSImpl.class);
myAdapter.setProperty("server","localhost");...
pico.addAdapter(myAdapter);
SetterInjector consider only types , nor names.
I think there should another SetterInjector that would consider parameter types and names, adding the name also to
ConstantParameter class and adjust resolve method.
Roman
Can you share the source of PGConnectionPoolDataSource ?
Post by Paul Hammant
Specifically, does it have methods setServerName(String serverName), setDatabaseName(String databaseName), setUser(String user) ?
Regards,
- Paul
Post by Vincent van Beveren
Hi everyone,
I’m new to pico-container, so bare with me :).
MutablePicoContainer pico = new DefaultPicoContainer();
pico.addConfig("serverName", "localhost");
pico.addConfig("databaseName", "mydb");
pico.addConfig("user", "user");
pico.change(Characteristics.USE_NAMES, Characteristics.SDI);
pico.addComponent(PGConnectionPoolDataSource.class);
PGConnectionPoolDataSource ds = pico.getComponent(PGConnectionPoolDataSource.class);
System.out.println(ds.getUser());
Exception in thread "main" org.picocontainer.injectors.AbstractInjector$AmbiguousComponentResolutionException: <no-component> needs a 'java.lang.String' injected, but there are too many choices to inject. These:[class java.lang.String, class java.lang.String, class java.lang.String], refer http://picocontainer.org/ambiguous-injectable-help.html
At the getComponent() call.
I tried to tell it that it needs to use the named version, but it doesn’t seem to do it. What am I doing wrong? The next step would be to use properties loaded from a Properties file... I guess that should not be a problem once I get the above example working. Anyway, thanks for any help/examples!
Regards,
Vincent
___
Ing. V. van Beveren
Software Engineer, FOM Rijnhuizen
T: +31 (0) 30-6096769
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
Vincent van Beveren
2010-02-15 07:22:03 UTC
Permalink
Hi Paul,

I've tried it, but the cat still won't budge ;). I have the following code:

MutablePicoContainer pico = new DefaultPicoContainer(new NamedMethodInjection());
pico.addConfig("serverName", "localhost");
pico.addConfig("databaseName", "mydb");
pico.addConfig("user", "postgres");

pico.addComponent(PGConnectionPoolDataSource.class);
PGConnectionPoolDataSource ds = pico.getComponent(PGConnectionPoolDataSource.class);
System.out.println(ds.getUser());

However, it gives me another exception:

Exception in thread "main" org.picocontainer.injectors.AbstractInjector$AmbiguousComponentResolutionException: <no-component> needs a 'java.lang.String' injected, but there are too many choices to inject. These:[class java.lang.String, class java.lang.String, class java.lang.String], refer http://picocontainer.org/ambiguous-injectable-help.html
at org.picocontainer.parameters.BasicComponentParameter.tooManyMatchingAdaptersFound(BasicComponentParameter.java:249)
at org.picocontainer.parameters.BasicComponentParameter.resolveAdapter(BasicComponentParameter.java:208)
at org.picocontainer.parameters.BasicComponentParameter.resolve(BasicComponentParameter.java:87)
etc...

I tried using the pico.change(...), but it doesn't seem to matter (or given an error).

Regards,
Vincent

________________________________
From: Paul Hammant [mailto:paul-POq8DFUn+***@public.gmane.org]
Sent: zaterdag 13 februari 2010 3:14
To: user-qxt/k92ZUMzOYGyH7mwfjrEhcVWVsK+***@public.gmane.org
Subject: Re: [picocontainer-user] Trying to instanciate a datasource with setter injection and config

Vincent, Roman,

What I'm saying is there is more than one to skin a cat. In the latest PicoContainer 2.10-SNAPSHOT (just deployed to )

You can do ..

pico = new DefaultPicoContainer(new NamedMethodInjection());
pico.addConfig("serverName", serverName);
pico.addComponent(PGConnectionPoolDataSource.class);

.. and it should just work with or without debug tables as this one is matching on the method name 'set[sS]erverName'. Paranamer is not used for this one.

Tell me what you think....

Regards,

- Paul

On Feb 12, 2010, at 1:25 AM, Vincent van Beveren wrote:


Hi Paul,

The issue is that I have not written then class. I have nothing to say about the naming it uses for its parameters, or what type of injection it uses. However, it seems they did a tidy job. setServerName(String serverName). However, this only works if debugging information is retained, which I think probably is not, since it doesn't work for me.

Regards,
Vincent

________________________________
From: Paul Hammant [mailto:paul-POq8DFUn+***@public.gmane.org]
Sent: vrijdag 12 februari 2010 0:07
To: user-qxt/k92ZUMzOYGyH7mwfjrEhcVWVsK+***@public.gmane.org<mailto:user-qxt/k92ZUMzOYGyH7mwfjrEhcVWVsK+***@public.gmane.org>
Subject: Re: [picocontainer-user] Trying to instanciate a datasource with setter injection and config

Its true, setter injection just uses types today.

However its easy to fix, in two ways:

setName(String anything)
^^^^

setAnything(String name)
^^^^

I'll code both of course, allow configuration so end users can specify.

Regards,

- Paul

On Feb 11, 2010, at 8:54 AM, Roman Kitko wrote:



Hi
I was trying to achieve something similar last week using Pico XMLContainerBuilder.
I found out that SetterInjector uses just types when doing the DI.
But you can use PropertyApplicator to achieve your goal.

Your code could look something like this :

PropertyApplicator myAdapter = new PropertyApplicator(new ConstructorInjector("myds",DSImpl.class);
myAdapter.setProperty("server","localhost");...
pico.addAdapter(myAdapter);

To Paul :
SetterInjector consider only types , nor names.
I think there should another SetterInjector that would consider parameter types and names, adding the name also to
ConstantParameter class and adjust resolve method.

Roman


Paul Hammant wrote:


Can you share the source of PGConnectionPoolDataSource ?

Specifically, does it have methods setServerName(String serverName), setDatabaseName(String databaseName), setUser(String user) ?
Regards,

- Paul

On Feb 11, 2010, at 5:33 AM, Vincent van Beveren wrote:

Hi everyone,
I'm new to pico-container, so bare with me :).
I'm trying to instantiate a PostgresSQL datasource, with PicoContainer 2.9. The datasource itself has methods like setUser, setServerName, etc... Also I wish this to be configurable. I've created the following code:
MutablePicoContainer pico = new DefaultPicoContainer();
pico.addConfig("serverName", "localhost");
pico.addConfig("databaseName", "mydb");
pico.addConfig("user", "user");
pico.change(Characteristics.USE_NAMES, Characteristics.SDI);
pico.addComponent(PGConnectionPoolDataSource.class);
PGConnectionPoolDataSource ds = pico.getComponent(PGConnectionPoolDataSource.class);
System.out.println(ds.getUser());
From the documentation I thought this should work, but it gives me a:
Exception in thread "main" org.picocontainer.injectors.AbstractInjector$AmbiguousComponentResolutionException: <no-component> needs a 'java.lang.String' injected, but there are too many choices to inject. These:[class java.lang.String, class java.lang.String, class java.lang.String], refer http://picocontainer.org/ambiguous-injectable-help.html
At the getComponent() call.
I tried to tell it that it needs to use the named version, but it doesn't seem to do it. What am I doing wrong? The next step would be to use properties loaded from a Properties file... I guess that should not be a problem once I get the above example working. Anyway, thanks for any help/examples!
Regards,
Vincent
___
Ing. V. van Beveren
Software Engineer, FOM Rijnhuizen
T: +31 (0) 30-6096769
E: V.vanBeveren-***@public.gmane.org<mailto:V.vanBeveren-***@public.gmane.org> <mailto:V.vanBeveren-***@public.gmane.org>




---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Konstantin Priblouda
2010-02-15 11:24:45 UTC
Permalink
Well, that's self explaining. There is definitely more than one string available for injection - so pico needs a hint what to inject where.


I'm affraid you will have to specify params explicitely on datasource being registered.

regards,
----[ Konstantin Pribluda http://www.pribluda.de ]----------------
JTec quality components: http://www.pribluda.de/projects/
Subject: RE: [picocontainer-user] Trying to instanciate a datasource with setter injection and config
Date: Monday, February 15, 2010, 9:22 AM
Hi Paul,
 
I’ve tried it, but the cat still won’t
 
      MutablePicoContainer
pico = new
DefaultPicoContainer(new
NamedMethodInjection());
     
pico.addConfig("serverName",
"localhost");
pico.addConfig("databaseName",
"mydb");
     
pico.addConfig("user",
"postgres");
           
     
pico.addComponent(PGConnectionPoolDataSource.class);
     
PGConnectionPoolDataSource
ds = pico.getComponent(PGConnectionPoolDataSource.class);
      System.out.println(ds.getUser());
 
However, it gives me another
 
Exception in thread
"main"
<no-component> needs a 'java.lang.String'
injected, but there are too
many choices to inject. These:[class java.lang.String,
class java.lang.String,
class java.lang.String], refer
http://picocontainer.org/ambiguous-injectable-help.html
      at
org.picocontainer.parameters.BasicComponentParameter.tooManyMatchingAdaptersFound(BasicComponentParameter.java:249)
      at
org.picocontainer.parameters.BasicComponentParameter.resolveAdapter(BasicComponentParameter.java:208)
      at
org.picocontainer.parameters.BasicComponentParameter.resolve(BasicComponentParameter.java:87)
etc...
 
I tried using the pico.change(...), but it
doesn’t
seem to matter (or given an error).
 
Regards,
Vincent
 
zaterdag 13 februari 2010
3:14
[picocontainer-user]
Trying to instanciate a datasource with setter injection
and config
 
Vincent, Roman,
 
What I'm saying is there is more
than one to skin a cat.  In the
latest PicoContainer 2.10-SNAPSHOT (just deployed to
)
 
You can do ..
 
  pico = new
DefaultPicoContainer(new
NamedMethodInjection());
  pico.addConfig("serverName",
serverName);
  pico.addComponent(PGConnectionPoolDataSource.class);
 
.. and it should just work with or
without debug tables as this one is
matching on the method name 'set[sS]erverName'.
 Paranamer is not used for
this one.
 
Tell me what you
think....
 
Regards,
 
-
Paul
 
On Feb 12, 2010, at 1:25 AM, Vincent van
Hi
Paul,
 
The issue
is that I have not written then
class. I have nothing to say about the naming it uses for
its parameters, or what
type of injection it uses. However, it seems they did a
tidy job.
setServerName(String serverName). However, this only works
if debugging
information is retained, which I think probably is not,
since it doesn’t
work for me.
 
Regards,
Vincent
 
Sent: vrijdag
12 februari 2010
0:07
[picocontainer-user]
Trying to instanciate a datasource with setter injection
and config
 
Its true, setter injection just uses
types today.
 
However its easy to fix, in two
 
  
setName(String anything)
    
 ^^^^
 
   setAnything(String
name)
          
         
 ^^^^
    
  
I'll code both of course, allow
configuration so end users can specify.
 
Regards,
 
-
Paul
 
On Feb 11, 2010, at 8:54 AM, Roman Kitko
Hi
I was trying to achieve something similar last week using
Pico
XMLContainerBuilder.
I found out that SetterInjector uses just types when doing
the DI.
But you can use PropertyApplicator to achieve your goal.
PropertyApplicator myAdapter = new PropertyApplicator(new
ConstructorInjector("myds",DSImpl.class);
myAdapter.setProperty("server","localhost");...
pico.addAdapter(myAdapter);
SetterInjector consider only types , nor names.
I think there should another SetterInjector that would
consider parameter types
and names, adding the name also to
ConstantParameter class and adjust resolve method.
Roman
Can you share the source of
PGConnectionPoolDataSource ?
 
Specifically, does it have methods
setServerName(String serverName),
setDatabaseName(String databaseName), setUser(String user)
?
Regards,
 
- Paul
 
On Feb 11, 2010, at 5:33 AM, Vincent van
 
Hi everyone,
I’m new to pico-container, so bare
with me :).
I’m trying to instantiate a
PostgresSQL datasource, with
PicoContainer 2.9. The datasource itself has methods like
setUser,
setServerName, etc... Also I wish this to be configurable.
I’ve created
            MutablePicoContainer
pico = new DefaultPicoContainer();
           pico.addConfig("serverName",
"localhost");
           pico.addConfig("databaseName",
"mydb");
           pico.addConfig("user",
"user");
                      pico.change(Characteristics.USE_NAMES,
Characteristics.SDI);
           pico.addComponent(PGConnectionPoolDataSource.class);
           PGConnectionPoolDataSource
ds =
pico.getComponent(PGConnectionPoolDataSource.class);
           System.out.println(ds.getUser());
From the documentation I thought this
Exception in thread "main"
<no-component> needs a 'java.lang.String'
injected, but there are too
many choices to inject. These:[class java.lang.String,
class java.lang.String,
class java.lang.String], refer http://picocontainer.org/ambiguous-injectable-help.html
At the getComponent()
call.
I tried to tell it that it needs to use
the named version, but it
doesn’t seem to do it. What am I doing wrong? The
next step would be to
use properties loaded from a Properties file... I guess
that should not be a
problem once I get the above example working. Anyway,
thanks for any
help/examples!
Regards,
Vincent
 ___
Ing. V. van Beveren
Software Engineer, FOM
Rijnhuizen
T: +31 (0) 30-6096769
 
 
---------------------------------------------------------------------
  http://xircles.codehaus.org/manage_email
 
 
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Vincent van Beveren
2010-02-15 11:27:01 UTC
Permalink
Hi Konstantin,

I thought the names of the configuration parameters where enough, since it matches the method setters. According to Paul this should work with the latest installment of Picocontainer.

Regards,
Vincent

-----Original Message-----
From: Konstantin Priblouda [mailto:kpriblouda-/***@public.gmane.org]
Sent: maandag 15 februari 2010 12:25
To: user-qxt/k92ZUMzOYGyH7mwfjrEhcVWVsK+***@public.gmane.org
Subject: RE: [picocontainer-user] Trying to instanciate a datasource with setter injection and config

Well, that's self explaining. There is definitely more than one string available for injection - so pico needs a hint what to inject where.


I'm affraid you will have to specify params explicitely on datasource being registered.

regards,
----[ Konstantin Pribluda http://www.pribluda.de ]----------------
JTec quality components: http://www.pribluda.de/projects/
Subject: RE: [picocontainer-user] Trying to instanciate a datasource with setter injection and config
Date: Monday, February 15, 2010, 9:22 AM
Hi Paul,
 
I've tried it, but the cat still won't
 
      MutablePicoContainer
pico = new
DefaultPicoContainer(new
NamedMethodInjection());
     
pico.addConfig("serverName",
"localhost");
pico.addConfig("databaseName",
"mydb");
     
pico.addConfig("user",
"postgres");
           
     
pico.addComponent(PGConnectionPoolDataSource.class);
     
PGConnectionPoolDataSource
ds = pico.getComponent(PGConnectionPoolDataSource.class);
      System.out.println(ds.getUser());
 
However, it gives me another
 
Exception in thread
"main"
<no-component> needs a 'java.lang.String'
injected, but there are too
many choices to inject. These:[class java.lang.String,
class java.lang.String,
class java.lang.String], refer
http://picocontainer.org/ambiguous-injectable-help.html
      at
org.picocontainer.parameters.BasicComponentParameter.tooManyMatchingAdaptersFound(BasicComponentParameter.java:249)
      at
org.picocontainer.parameters.BasicComponentParameter.resolveAdapter(BasicComponentParameter.java:208)
      at
org.picocontainer.parameters.BasicComponentParameter.resolve(BasicComponentParameter.java:87)
etc...
 
I tried using the pico.change(...), but it
doesn't
seem to matter (or given an error).
 
Regards,
Vincent
 
zaterdag 13 februari 2010
3:14
[picocontainer-user]
Trying to instanciate a datasource with setter injection
and config
 
Vincent, Roman,
 
What I'm saying is there is more
than one to skin a cat.  In the
latest PicoContainer 2.10-SNAPSHOT (just deployed to
)
 
You can do ..
 
  pico = new
DefaultPicoContainer(new
NamedMethodInjection());
  pico.addConfig("serverName",
serverName);
  pico.addComponent(PGConnectionPoolDataSource.class);
 
.. and it should just work with or
without debug tables as this one is
matching on the method name 'set[sS]erverName'.
 Paranamer is not used for
this one.
 
Tell me what you
think....
 
Regards,
 
-
Paul
 
On Feb 12, 2010, at 1:25 AM, Vincent van
Hi
Paul,
 
The issue
is that I have not written then
class. I have nothing to say about the naming it uses for
its parameters, or what
type of injection it uses. However, it seems they did a
tidy job.
setServerName(String serverName). However, this only works
if debugging
information is retained, which I think probably is not,
since it doesn't
work for me.
 
Regards,
Vincent
 
Sent: vrijdag
12 februari 2010
0:07
[picocontainer-user]
Trying to instanciate a datasource with setter injection
and config
 
Its true, setter injection just uses
types today.
 
However its easy to fix, in two
 
  
setName(String anything)
    
 ^^^^
 
   setAnything(String
name)
          
         
 ^^^^
    
  
I'll code both of course, allow
configuration so end users can specify.
 
Regards,
 
-
Paul
 
On Feb 11, 2010, at 8:54 AM, Roman Kitko
Hi
I was trying to achieve something similar last week using
Pico
XMLContainerBuilder.
I found out that SetterInjector uses just types when doing
the DI.
But you can use PropertyApplicator to achieve your goal.
PropertyApplicator myAdapter = new PropertyApplicator(new
ConstructorInjector("myds",DSImpl.class);
myAdapter.setProperty("server","localhost");...
pico.addAdapter(myAdapter);
SetterInjector consider only types , nor names.
I think there should another SetterInjector that would
consider parameter types
and names, adding the name also to
ConstantParameter class and adjust resolve method.
Roman
Can you share the source of
PGConnectionPoolDataSource ?
 
Specifically, does it have methods
setServerName(String serverName),
setDatabaseName(String databaseName), setUser(String user)
?
Regards,
 
- Paul
 
On Feb 11, 2010, at 5:33 AM, Vincent van
 
Hi everyone,
I'm new to pico-container, so bare
with me :).
I'm trying to instantiate a
PostgresSQL datasource, with
PicoContainer 2.9. The datasource itself has methods like
setUser,
setServerName, etc... Also I wish this to be configurable.
I've created
            MutablePicoContainer
pico = new DefaultPicoContainer();
           pico.addConfig("serverName",
"localhost");
           pico.addConfig("databaseName",
"mydb");
           pico.addConfig("user",
"user");
                      pico.change(Characteristics.USE_NAMES,
Characteristics.SDI);
           pico.addComponent(PGConnectionPoolDataSource.class);
           PGConnectionPoolDataSource
ds =
pico.getComponent(PGConnectionPoolDataSource.class);
           System.out.println(ds.getUser());
From the documentation I thought this
Exception in thread "main"
<no-component> needs a 'java.lang.String'
injected, but there are too
many choices to inject. These:[class java.lang.String,
class java.lang.String,
class java.lang.String], refer http://picocontainer.org/ambiguous-injectable-help.html
At the getComponent()
call.
I tried to tell it that it needs to use
the named version, but it
doesn't seem to do it. What am I doing wrong? The
next step would be to
use properties loaded from a Properties file... I guess
that should not be a
problem once I get the above example working. Anyway,
thanks for any
help/examples!
Regards,
Vincent
 ___
Ing. V. van Beveren
Software Engineer, FOM
Rijnhuizen
T: +31 (0) 30-6096769
 
 
---------------------------------------------------------------------
  http://xircles.codehaus.org/manage_email
 
 
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Paul Hammant
2010-02-15 15:46:03 UTC
Permalink
Yeah, it should work.

Take a look at the last test in http://svn.codehaus.org/picocontainer/java/2.x/trunk/pico/container/src/test/org/picocontainer/injectors/NamedMethodInjectionTestCase.java and tell me what I have done wrong to simulate your case.

Regards,

- Paul
Post by Vincent van Beveren
Hi Konstantin,
I thought the names of the configuration parameters where enough, since it matches the method setters. According to Paul this should work with the latest installment of Picocontainer.
Regards,
Vincent
-----Original Message-----
Sent: maandag 15 februari 2010 12:25
Subject: RE: [picocontainer-user] Trying to instanciate a datasource with setter injection and config
Well, that's self explaining. There is definitely more than one string available for injection - so pico needs a hint what to inject where.
I'm affraid you will have to specify params explicitely on datasource being registered.
regards,
----[ Konstantin Pribluda http://www.pribluda.de ]----------------
JTec quality components: http://www.pribluda.de/projects/
Subject: RE: [picocontainer-user] Trying to instanciate a datasource with setter injection and config
Date: Monday, February 15, 2010, 9:22 AM
Hi Paul,
I've tried it, but the cat still won't
MutablePicoContainer
pico = new
DefaultPicoContainer(new
NamedMethodInjection());
pico.addConfig("serverName",
"localhost");
pico.addConfig("databaseName",
"mydb");
pico.addConfig("user",
"postgres");
pico.addComponent(PGConnectionPoolDataSource.class);
PGConnectionPoolDataSource
ds = pico.getComponent(PGConnectionPoolDataSource.class);
System.out.println(ds.getUser());
However, it gives me another
Exception in thread
"main"
<no-component> needs a 'java.lang.String'
injected, but there are too
many choices to inject. These:[class java.lang.String,
class java.lang.String,
class java.lang.String], refer
http://picocontainer.org/ambiguous-injectable-help.html
at
org.picocontainer.parameters.BasicComponentParameter.tooManyMatchingAdaptersFound(BasicComponentParameter.java:249)
at
org.picocontainer.parameters.BasicComponentParameter.resolveAdapter(BasicComponentParameter.java:208)
at
org.picocontainer.parameters.BasicComponentParameter.resolve(BasicComponentParameter.java:87)
etc...
I tried using the pico.change(...), but it
doesn't
seem to matter (or given an error).
Regards,
Vincent
zaterdag 13 februari 2010
3:14
[picocontainer-user]
Trying to instanciate a datasource with setter injection
and config
Vincent, Roman,
What I'm saying is there is more
than one to skin a cat. In the
latest PicoContainer 2.10-SNAPSHOT (just deployed to
)
You can do ..
pico = new
DefaultPicoContainer(new
NamedMethodInjection());
pico.addConfig("serverName",
serverName);
pico.addComponent(PGConnectionPoolDataSource.class);
.. and it should just work with or
without debug tables as this one is
matching on the method name 'set[sS]erverName'.
Paranamer is not used for
this one.
Tell me what you
think....
Regards,
-
Paul
On Feb 12, 2010, at 1:25 AM, Vincent van
Hi
Paul,
The issue
is that I have not written then
class. I have nothing to say about the naming it uses for
its parameters, or what
type of injection it uses. However, it seems they did a
tidy job.
setServerName(String serverName). However, this only works
if debugging
information is retained, which I think probably is not,
since it doesn't
work for me.
Regards,
Vincent
Sent: vrijdag
12 februari 2010
0:07
[picocontainer-user]
Trying to instanciate a datasource with setter injection
and config
Its true, setter injection just uses
types today.
However its easy to fix, in two
setName(String anything)
^^^^
setAnything(String
name)
^^^^
I'll code both of course, allow
configuration so end users can specify.
Regards,
-
Paul
On Feb 11, 2010, at 8:54 AM, Roman Kitko
Hi
I was trying to achieve something similar last week using
Pico
XMLContainerBuilder.
I found out that SetterInjector uses just types when doing
the DI.
But you can use PropertyApplicator to achieve your goal.
PropertyApplicator myAdapter = new PropertyApplicator(new
ConstructorInjector("myds",DSImpl.class);
myAdapter.setProperty("server","localhost");...
pico.addAdapter(myAdapter);
SetterInjector consider only types , nor names.
I think there should another SetterInjector that would
consider parameter types
and names, adding the name also to
ConstantParameter class and adjust resolve method.
Roman
Can you share the source of
PGConnectionPoolDataSource ?
Specifically, does it have methods
setServerName(String serverName),
setDatabaseName(String databaseName), setUser(String user)
?
Regards,
- Paul
On Feb 11, 2010, at 5:33 AM, Vincent van
Hi everyone,
I'm new to pico-container, so bare
with me :).
I'm trying to instantiate a
PostgresSQL datasource, with
PicoContainer 2.9. The datasource itself has methods like
setUser,
setServerName, etc... Also I wish this to be configurable.
I've created
MutablePicoContainer
pico = new DefaultPicoContainer();
pico.addConfig("serverName",
"localhost");
pico.addConfig("databaseName",
"mydb");
pico.addConfig("user",
"user");
pico.change(Characteristics.USE_NAMES,
Characteristics.SDI);
pico.addComponent(PGConnectionPoolDataSource.class);
PGConnectionPoolDataSource
ds =
pico.getComponent(PGConnectionPoolDataSource.class);
System.out.println(ds.getUser());
From the documentation I thought this
Exception in thread "main"
<no-component> needs a 'java.lang.String'
injected, but there are too
many choices to inject. These:[class java.lang.String,
class java.lang.String,
class java.lang.String], refer http://picocontainer.org/ambiguous-injectable-help.html
At the getComponent()
call.
I tried to tell it that it needs to use
the named version, but it
doesn't seem to do it. What am I doing wrong? The
next step would be to
use properties loaded from a Properties file... I guess
that should not be a
problem once I get the above example working. Anyway,
thanks for any
help/examples!
Regards,
Vincent
___
Ing. V. van Beveren
Software Engineer, FOM
Rijnhuizen
T: +31 (0) 30-6096769
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Loading...