You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Phil Steitz <ph...@gmail.com> on 2011/06/16 18:25:10 UTC

[pool][dbcp] Ongoing saga of setFactory

Yesterday I fixed some [dbcp] "problems" caused by the new [pool]
requirement that setFactory can only be called once.  The quotes are
because most of the problems were redundant calls to setFactory. 
The reason that we left setFactory in [pool] is that [dbcp]'s
connection factory constructors call setFactory on the pool passed
to them.  It is an easy "mistake" to create a pool, then create a
connection factory and then do pool.setFactory(factory).  I
eliminated all of these usages from within [dbcp], but I bet a fair
amount of user code will similarly blow up when people upgrade.  I
hate to keep backsliding here, but maybe we should to this in GOP
setFactory:

             synchronized (factoryLock) {
                 if (this.factory == null) {
                     this.factory = factory;
-                } else {
+                } else if (this.factory != factory) {
                     throw new IllegalStateException("Factory
already set");
                 }
             }

Phil


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [pool][dbcp] Ongoing saga of setFactory

Posted by Phil Steitz <ph...@gmail.com>.
On 6/16/11 9:32 AM, sebb wrote:
> On 16 June 2011 17:25, Phil Steitz <ph...@gmail.com> wrote:
>> Yesterday I fixed some [dbcp] "problems" caused by the new [pool]
>> requirement that setFactory can only be called once.  The quotes are
>> because most of the problems were redundant calls to setFactory.
>> The reason that we left setFactory in [pool] is that [dbcp]'s
>> connection factory constructors call setFactory on the pool passed
>> to them.  It is an easy "mistake" to create a pool, then create a
>> connection factory and then do pool.setFactory(factory).  I
>> eliminated all of these usages from within [dbcp], but I bet a fair
>> amount of user code will similarly blow up when people upgrade.
> AIUI, the upgrade does require code to be changed because of the package rename?

No question the upgrade is going to require changes.  I just want to
make those changes as transparent as possible and if possible avoid
gotchas like what happened above.
> If so, can we not drop the setFactory method and provide it as a
> constructor parameter?

We have already decided to keep the setFactory method, basically
because the [dbcp] use case above would be very hard to meet without
it, but we now use double-checked locking and do not allow it to be
reset, once it is set initially.  My proposal below is to be more
forgiving if an invocation when it is already set passes a
reference-equal factory as actual parameter.

Phil
> That would produce a compile-time error, rather than failing at run-time.
>
>>  I hate to keep backsliding here, but maybe we should to this in GOP
>> setFactory:
>>
>>             synchronized (factoryLock) {
>>                 if (this.factory == null) {
>>                     this.factory = factory;
>> -                } else {
>> +                } else if (this.factory != factory) {
>>                     throw new IllegalStateException("Factory
>> already set");
>>                 }
>>             }
>>
>> Phil
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [pool][dbcp] Ongoing saga of setFactory

Posted by Mark Thomas <ma...@apache.org>.
On 03/07/2011 22:43, Phil Steitz wrote:
> On 7/3/11 12:32 PM, Mark Thomas wrote:
>> On 26/06/2011 01:05, Phil Steitz wrote:
>>> On 6/25/11 4:28 PM, Mark Thomas wrote:
>>>> On 17/06/2011 09:02, Mark Thomas wrote:
>>>>> On 17/06/2011 00:32, Gary Gregory wrote:
>>>>>> I think 2.0 is the opportunity to do this right. Almost like we were
>>>>>> designing this from scratch.
>>>>>>
>>>>>> Making the factory an invariant of the pool sounds good.
>>>>>>
>>>>>> Otoh If a setFactory method exists it should be implemented fully. The
>>>>>> throw an exception impl is pretty "smelly".
>>>>> I agree that it is smelly. I'm not sure we can change this without a
>>>>> huge amount of work in DBCP.
>>>> I think largely due to the clean-up Phil has already done in DBCP, this
>>>> is now manageable. I have just done this for GOP and will do the same
>>>> for GKOP next (exact timing TBD).
>>> +1 - definitely better.  Will test and review and if I get to if
>>> before you, handle GKOP.   Thanks for doing this.
>> Looking at this, I can't see a way of doing this without introducing a
>> new interface StatementPoolFactory that extends KeyedObjectPoolFactory
>> and adds a setPoolingConnection() method (or something along those lines
>> anyway).
>>
>> The names may well change as the refactoring evolves and we add generics
>> support to DBCP but this should do for now.
> 
> Sorry I have not gotten to this.  I was thinking something a little
> different.  What needs to be set is the GKOP factory, which is part
> of its config.  The current BDS setup is arguably smelly, since it
> creates a partial config for the KeyedObjectPoolFactory (omitting
> the factory).  Extending as you have above works around this split. 
> Setting the pooling connection is really setting the factory.  That
> will work, but so might the following:
> 
> 0) Get rid of the partially configured KeyedObjectPoolFactory in BDS
> altogether.  The only variable part of the config is
> maxOpenPreparedStatements.  Pass this along to PCF (and a
> poolStatements flag).
> 1) Create the full config for the statement pool GKOP in PCF makeObject.
> 2) Add a setStatementPool method to PoolingConnection, so this can
> be constructed without the statement pool.
> 3) Include the factory ( = the newly constructed PC) in the config
> used to create the statement pool in PCF makeObject
> 
> So makeObject in PCF looks something like:
> 
> Connection conn = _connFactory.createConnection();
> if (conn == null) {
>     throw new IllegalStateException("Connection factory returned
> null from createConnection");
> }
> initializeConnection(conn);
> if(poolStatements) {
>     conn = new PoolingConnection(conn);
>     GenericKeyedObjectPoolConfig config =
>                     new GenericKeyedObjectPoolConfig();
>     config.setMaxTotalPerKey(-1);
>     config.setWhenExhaustedAction(WhenExhaustedAction.FAIL);
>     config.setMaxWait(0);
>     config.setMaxIdlePerKey(1);
>     config.setMaxTotal(maxOpenPreparedStatements);
>     config.setFactory((PoolingConnection)conn);
>     KeyedObjectPool stmtPool = new GenericKeyedObjectPool(config);
>     conn.setStatementPool(stmtPool);
>  }
> return new PoolableConnection(conn,_pool,_config);
> 
> I have not tested the above setup, but it has the advantage that the
> pool configuration is defined fully in one place and it is similar
> to what we now have for PCs vis a vis the GOP.

Yep, that works. Changes committed.

Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [pool][dbcp] Ongoing saga of setFactory

Posted by Phil Steitz <ph...@gmail.com>.
On 7/3/11 12:32 PM, Mark Thomas wrote:
> On 26/06/2011 01:05, Phil Steitz wrote:
>> On 6/25/11 4:28 PM, Mark Thomas wrote:
>>> On 17/06/2011 09:02, Mark Thomas wrote:
>>>> On 17/06/2011 00:32, Gary Gregory wrote:
>>>>> I think 2.0 is the opportunity to do this right. Almost like we were
>>>>> designing this from scratch.
>>>>>
>>>>> Making the factory an invariant of the pool sounds good.
>>>>>
>>>>> Otoh If a setFactory method exists it should be implemented fully. The
>>>>> throw an exception impl is pretty "smelly".
>>>> I agree that it is smelly. I'm not sure we can change this without a
>>>> huge amount of work in DBCP.
>>> I think largely due to the clean-up Phil has already done in DBCP, this
>>> is now manageable. I have just done this for GOP and will do the same
>>> for GKOP next (exact timing TBD).
>> +1 - definitely better.  Will test and review and if I get to if
>> before you, handle GKOP.   Thanks for doing this.
> Looking at this, I can't see a way of doing this without introducing a
> new interface StatementPoolFactory that extends KeyedObjectPoolFactory
> and adds a setPoolingConnection() method (or something along those lines
> anyway).
>
> The names may well change as the refactoring evolves and we add generics
> support to DBCP but this should do for now.

Sorry I have not gotten to this.  I was thinking something a little
different.  What needs to be set is the GKOP factory, which is part
of its config.  The current BDS setup is arguably smelly, since it
creates a partial config for the KeyedObjectPoolFactory (omitting
the factory).  Extending as you have above works around this split. 
Setting the pooling connection is really setting the factory.  That
will work, but so might the following:

0) Get rid of the partially configured KeyedObjectPoolFactory in BDS
altogether.  The only variable part of the config is
maxOpenPreparedStatements.  Pass this along to PCF (and a
poolStatements flag).
1) Create the full config for the statement pool GKOP in PCF makeObject.
2) Add a setStatementPool method to PoolingConnection, so this can
be constructed without the statement pool.
3) Include the factory ( = the newly constructed PC) in the config
used to create the statement pool in PCF makeObject

So makeObject in PCF looks something like:

Connection conn = _connFactory.createConnection();
if (conn == null) {
    throw new IllegalStateException("Connection factory returned
null from createConnection");
}
initializeConnection(conn);
if(poolStatements) {
    conn = new PoolingConnection(conn);
    GenericKeyedObjectPoolConfig config =
                    new GenericKeyedObjectPoolConfig();
    config.setMaxTotalPerKey(-1);
    config.setWhenExhaustedAction(WhenExhaustedAction.FAIL);
    config.setMaxWait(0);
    config.setMaxIdlePerKey(1);
    config.setMaxTotal(maxOpenPreparedStatements);
    config.setFactory((PoolingConnection)conn);
    KeyedObjectPool stmtPool = new GenericKeyedObjectPool(config);
    conn.setStatementPool(stmtPool);
 }
return new PoolableConnection(conn,_pool,_config);

I have not tested the above setup, but it has the advantage that the
pool configuration is defined fully in one place and it is similar
to what we now have for PCs vis a vis the GOP.

Phil



> Mark
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [pool][dbcp] Ongoing saga of setFactory

Posted by Mark Thomas <ma...@apache.org>.
On 26/06/2011 01:05, Phil Steitz wrote:
> On 6/25/11 4:28 PM, Mark Thomas wrote:
>> On 17/06/2011 09:02, Mark Thomas wrote:
>>> On 17/06/2011 00:32, Gary Gregory wrote:
>>>> I think 2.0 is the opportunity to do this right. Almost like we were
>>>> designing this from scratch.
>>>>
>>>> Making the factory an invariant of the pool sounds good.
>>>>
>>>> Otoh If a setFactory method exists it should be implemented fully. The
>>>> throw an exception impl is pretty "smelly".
>>> I agree that it is smelly. I'm not sure we can change this without a
>>> huge amount of work in DBCP.
>> I think largely due to the clean-up Phil has already done in DBCP, this
>> is now manageable. I have just done this for GOP and will do the same
>> for GKOP next (exact timing TBD).
> 
> +1 - definitely better.  Will test and review and if I get to if
> before you, handle GKOP.   Thanks for doing this.

Looking at this, I can't see a way of doing this without introducing a
new interface StatementPoolFactory that extends KeyedObjectPoolFactory
and adds a setPoolingConnection() method (or something along those lines
anyway).

The names may well change as the refactoring evolves and we add generics
support to DBCP but this should do for now.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [pool][dbcp] Ongoing saga of setFactory

Posted by Phil Steitz <ph...@gmail.com>.
On 6/25/11 4:28 PM, Mark Thomas wrote:
> On 17/06/2011 09:02, Mark Thomas wrote:
>> On 17/06/2011 00:32, Gary Gregory wrote:
>>> I think 2.0 is the opportunity to do this right. Almost like we were
>>> designing this from scratch.
>>>
>>> Making the factory an invariant of the pool sounds good.
>>>
>>> Otoh If a setFactory method exists it should be implemented fully. The
>>> throw an exception impl is pretty "smelly".
>> I agree that it is smelly. I'm not sure we can change this without a
>> huge amount of work in DBCP.
> I think largely due to the clean-up Phil has already done in DBCP, this
> is now manageable. I have just done this for GOP and will do the same
> for GKOP next (exact timing TBD).

+1 - definitely better.  Will test and review and if I get to if
before you, handle GKOP.   Thanks for doing this.

Phil
> Mark
>
>> Mark
>>
>>> Gary
>>>
>>> On Jun 16, 2011, at 13:39, Phil Steitz <ph...@gmail.com> wrote:
>>>
>>>> On 6/16/11 10:19 AM, Mark Thomas wrote:
>>>>> On 16/06/2011 17:32, sebb wrote:
>>>>>> On 16 June 2011 17:25, Phil Steitz <ph...@gmail.com> wrote:
>>>>>>> Yesterday I fixed some [dbcp] "problems" caused by the new [pool]
>>>>>>> requirement that setFactory can only be called once.  The quotes are
>>>>>>> because most of the problems were redundant calls to setFactory.
>>>>>>> The reason that we left setFactory in [pool] is that [dbcp]'s
>>>>>>> connection factory constructors call setFactory on the pool passed
>>>>>>> to them.  It is an easy "mistake" to create a pool, then create a
>>>>>>> connection factory and then do pool.setFactory(factory).  I
>>>>>>> eliminated all of these usages from within [dbcp], but I bet a fair
>>>>>>> amount of user code will similarly blow up when people upgrade.
>>>>>> AIUI, the upgrade does require code to be changed because of the package rename?
>>>>> It does, but that is just a search and replace and compilation will fail
>>>>> until it is fixed.
>>>>>> If so, can we not drop the setFactory method and provide it as a
>>>>>> constructor parameter?
>>>>> I don't think so. We have been around this buoy already.
>>>>>
>>>>> To quote Phil's summary:
>>>>> <quote>
>>>>> I think it is more natural to have
>>>>> pool = new GKOP(factory,...) have factory.setPool(this) as a side
>>>>> effect than
>>>>> factory = new KPOF(...,pool...) have pool.setFactory(this) as a side
>>>>> effect
>>>>> </quote>
>>>>>
>>>>> I disagree with Phil on this. Since a pool only has one factory whereas
>>>>> a factory may support multiple pools,
>>>> I had not thought about it that way before.  What is humorous is
>>>> that that logic makes it questionable to pass the pool to the
>>>> factory constructor (or at least just one pool).  In the case of
>>>> [dbcp]'s PoolableConnectionFactory,  it is hard-wired 1-1 to the
>>>> pool because it needs to provide the PoolableConnections that it
>>>> sources a reference to their owning pool.  I guess a generalized PCF
>>>> could source objects for multiple pools, in which case the
>>>> constructor could take a collection of pools.  I now see your
>>>> point.  In any case, from my perspective, the requirement to be able
>>>> to set the factory is understood and I am fine with keeping the code
>>>> as it is, possibly with the small patch below.
>>>>
>>>> Phil
>>>>
>>>>
>>>>> I think it is wrong for for "new
>>>>> GKOP(factory,...)" to have "factory.setPool(this)" as a side-effect. I
>>>>> think "new KPOF(...,pool...)" having "pool.setFactory(this)" as a side
>>>>> effect is the more natural choice (as per the current code).
>>>>>
>>>>>>> I hate to keep backsliding here, but maybe we should to this in GOP
>>>>>>> setFactory:
>>>>>>>
>>>>>>>            synchronized (factoryLock) {
>>>>>>>                if (this.factory == null) {
>>>>>>>                    this.factory = factory;
>>>>>>> -                } else {
>>>>>>> +                } else if (this.factory != factory) {
>>>>>>>                    throw new IllegalStateException("Factory
>>>>>>> already set");
>>>>>>>                }
>>>>>>>            }
>>>>> I'd be OK with that. If we sort out logging we can log it at INFO as
>>>>> unnecessary.
>>>>>
>>>>> Mark
>>>>>
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [pool][dbcp] Ongoing saga of setFactory

Posted by Mark Thomas <ma...@apache.org>.
On 17/06/2011 09:02, Mark Thomas wrote:
> On 17/06/2011 00:32, Gary Gregory wrote:
>> I think 2.0 is the opportunity to do this right. Almost like we were
>> designing this from scratch.
>>
>> Making the factory an invariant of the pool sounds good.
>>
>> Otoh If a setFactory method exists it should be implemented fully. The
>> throw an exception impl is pretty "smelly".
> 
> I agree that it is smelly. I'm not sure we can change this without a
> huge amount of work in DBCP.

I think largely due to the clean-up Phil has already done in DBCP, this
is now manageable. I have just done this for GOP and will do the same
for GKOP next (exact timing TBD).

Mark

> 
> Mark
> 
>>
>> Gary
>>
>> On Jun 16, 2011, at 13:39, Phil Steitz <ph...@gmail.com> wrote:
>>
>>> On 6/16/11 10:19 AM, Mark Thomas wrote:
>>>> On 16/06/2011 17:32, sebb wrote:
>>>>> On 16 June 2011 17:25, Phil Steitz <ph...@gmail.com> wrote:
>>>>>> Yesterday I fixed some [dbcp] "problems" caused by the new [pool]
>>>>>> requirement that setFactory can only be called once.  The quotes are
>>>>>> because most of the problems were redundant calls to setFactory.
>>>>>> The reason that we left setFactory in [pool] is that [dbcp]'s
>>>>>> connection factory constructors call setFactory on the pool passed
>>>>>> to them.  It is an easy "mistake" to create a pool, then create a
>>>>>> connection factory and then do pool.setFactory(factory).  I
>>>>>> eliminated all of these usages from within [dbcp], but I bet a fair
>>>>>> amount of user code will similarly blow up when people upgrade.
>>>>> AIUI, the upgrade does require code to be changed because of the package rename?
>>>> It does, but that is just a search and replace and compilation will fail
>>>> until it is fixed.
>>>>> If so, can we not drop the setFactory method and provide it as a
>>>>> constructor parameter?
>>>> I don't think so. We have been around this buoy already.
>>>>
>>>> To quote Phil's summary:
>>>> <quote>
>>>> I think it is more natural to have
>>>> pool = new GKOP(factory,...) have factory.setPool(this) as a side
>>>> effect than
>>>> factory = new KPOF(...,pool...) have pool.setFactory(this) as a side
>>>> effect
>>>> </quote>
>>>>
>>>> I disagree with Phil on this. Since a pool only has one factory whereas
>>>> a factory may support multiple pools,
>>>
>>> I had not thought about it that way before.  What is humorous is
>>> that that logic makes it questionable to pass the pool to the
>>> factory constructor (or at least just one pool).  In the case of
>>> [dbcp]'s PoolableConnectionFactory,  it is hard-wired 1-1 to the
>>> pool because it needs to provide the PoolableConnections that it
>>> sources a reference to their owning pool.  I guess a generalized PCF
>>> could source objects for multiple pools, in which case the
>>> constructor could take a collection of pools.  I now see your
>>> point.  In any case, from my perspective, the requirement to be able
>>> to set the factory is understood and I am fine with keeping the code
>>> as it is, possibly with the small patch below.
>>>
>>> Phil
>>>
>>>
>>>> I think it is wrong for for "new
>>>> GKOP(factory,...)" to have "factory.setPool(this)" as a side-effect. I
>>>> think "new KPOF(...,pool...)" having "pool.setFactory(this)" as a side
>>>> effect is the more natural choice (as per the current code).
>>>>
>>>>>> I hate to keep backsliding here, but maybe we should to this in GOP
>>>>>> setFactory:
>>>>>>
>>>>>>            synchronized (factoryLock) {
>>>>>>                if (this.factory == null) {
>>>>>>                    this.factory = factory;
>>>>>> -                } else {
>>>>>> +                } else if (this.factory != factory) {
>>>>>>                    throw new IllegalStateException("Factory
>>>>>> already set");
>>>>>>                }
>>>>>>            }
>>>> I'd be OK with that. If we sort out logging we can log it at INFO as
>>>> unnecessary.
>>>>
>>>> Mark
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [pool][dbcp] Ongoing saga of setFactory

Posted by Mark Thomas <ma...@apache.org>.
On 17/06/2011 00:32, Gary Gregory wrote:
> I think 2.0 is the opportunity to do this right. Almost like we were
> designing this from scratch.
> 
> Making the factory an invariant of the pool sounds good.
> 
> Otoh If a setFactory method exists it should be implemented fully. The
> throw an exception impl is pretty "smelly".

I agree that it is smelly. I'm not sure we can change this without a
huge amount of work in DBCP.

Mark

> 
> Gary
> 
> On Jun 16, 2011, at 13:39, Phil Steitz <ph...@gmail.com> wrote:
> 
>> On 6/16/11 10:19 AM, Mark Thomas wrote:
>>> On 16/06/2011 17:32, sebb wrote:
>>>> On 16 June 2011 17:25, Phil Steitz <ph...@gmail.com> wrote:
>>>>> Yesterday I fixed some [dbcp] "problems" caused by the new [pool]
>>>>> requirement that setFactory can only be called once.  The quotes are
>>>>> because most of the problems were redundant calls to setFactory.
>>>>> The reason that we left setFactory in [pool] is that [dbcp]'s
>>>>> connection factory constructors call setFactory on the pool passed
>>>>> to them.  It is an easy "mistake" to create a pool, then create a
>>>>> connection factory and then do pool.setFactory(factory).  I
>>>>> eliminated all of these usages from within [dbcp], but I bet a fair
>>>>> amount of user code will similarly blow up when people upgrade.
>>>> AIUI, the upgrade does require code to be changed because of the package rename?
>>> It does, but that is just a search and replace and compilation will fail
>>> until it is fixed.
>>>> If so, can we not drop the setFactory method and provide it as a
>>>> constructor parameter?
>>> I don't think so. We have been around this buoy already.
>>>
>>> To quote Phil's summary:
>>> <quote>
>>> I think it is more natural to have
>>> pool = new GKOP(factory,...) have factory.setPool(this) as a side
>>> effect than
>>> factory = new KPOF(...,pool...) have pool.setFactory(this) as a side
>>> effect
>>> </quote>
>>>
>>> I disagree with Phil on this. Since a pool only has one factory whereas
>>> a factory may support multiple pools,
>>
>> I had not thought about it that way before.  What is humorous is
>> that that logic makes it questionable to pass the pool to the
>> factory constructor (or at least just one pool).  In the case of
>> [dbcp]'s PoolableConnectionFactory,  it is hard-wired 1-1 to the
>> pool because it needs to provide the PoolableConnections that it
>> sources a reference to their owning pool.  I guess a generalized PCF
>> could source objects for multiple pools, in which case the
>> constructor could take a collection of pools.  I now see your
>> point.  In any case, from my perspective, the requirement to be able
>> to set the factory is understood and I am fine with keeping the code
>> as it is, possibly with the small patch below.
>>
>> Phil
>>
>>
>>> I think it is wrong for for "new
>>> GKOP(factory,...)" to have "factory.setPool(this)" as a side-effect. I
>>> think "new KPOF(...,pool...)" having "pool.setFactory(this)" as a side
>>> effect is the more natural choice (as per the current code).
>>>
>>>>> I hate to keep backsliding here, but maybe we should to this in GOP
>>>>> setFactory:
>>>>>
>>>>>            synchronized (factoryLock) {
>>>>>                if (this.factory == null) {
>>>>>                    this.factory = factory;
>>>>> -                } else {
>>>>> +                } else if (this.factory != factory) {
>>>>>                    throw new IllegalStateException("Factory
>>>>> already set");
>>>>>                }
>>>>>            }
>>> I'd be OK with that. If we sort out logging we can log it at INFO as
>>> unnecessary.
>>>
>>> Mark
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [pool][dbcp] Ongoing saga of setFactory

Posted by Gary Gregory <ga...@gmail.com>.
I think 2.0 is the opportunity to do this right. Almost like we were
designing this from scratch.

Making the factory an invariant of the pool sounds good.

Otoh If a setFactory method exists it should be implemented fully. The
throw an exception impl is pretty "smelly".

Gary

On Jun 16, 2011, at 13:39, Phil Steitz <ph...@gmail.com> wrote:

> On 6/16/11 10:19 AM, Mark Thomas wrote:
>> On 16/06/2011 17:32, sebb wrote:
>>> On 16 June 2011 17:25, Phil Steitz <ph...@gmail.com> wrote:
>>>> Yesterday I fixed some [dbcp] "problems" caused by the new [pool]
>>>> requirement that setFactory can only be called once.  The quotes are
>>>> because most of the problems were redundant calls to setFactory.
>>>> The reason that we left setFactory in [pool] is that [dbcp]'s
>>>> connection factory constructors call setFactory on the pool passed
>>>> to them.  It is an easy "mistake" to create a pool, then create a
>>>> connection factory and then do pool.setFactory(factory).  I
>>>> eliminated all of these usages from within [dbcp], but I bet a fair
>>>> amount of user code will similarly blow up when people upgrade.
>>> AIUI, the upgrade does require code to be changed because of the package rename?
>> It does, but that is just a search and replace and compilation will fail
>> until it is fixed.
>>> If so, can we not drop the setFactory method and provide it as a
>>> constructor parameter?
>> I don't think so. We have been around this buoy already.
>>
>> To quote Phil's summary:
>> <quote>
>> I think it is more natural to have
>> pool = new GKOP(factory,...) have factory.setPool(this) as a side
>> effect than
>> factory = new KPOF(...,pool...) have pool.setFactory(this) as a side
>> effect
>> </quote>
>>
>> I disagree with Phil on this. Since a pool only has one factory whereas
>> a factory may support multiple pools,
>
> I had not thought about it that way before.  What is humorous is
> that that logic makes it questionable to pass the pool to the
> factory constructor (or at least just one pool).  In the case of
> [dbcp]'s PoolableConnectionFactory,  it is hard-wired 1-1 to the
> pool because it needs to provide the PoolableConnections that it
> sources a reference to their owning pool.  I guess a generalized PCF
> could source objects for multiple pools, in which case the
> constructor could take a collection of pools.  I now see your
> point.  In any case, from my perspective, the requirement to be able
> to set the factory is understood and I am fine with keeping the code
> as it is, possibly with the small patch below.
>
> Phil
>
>
>> I think it is wrong for for "new
>> GKOP(factory,...)" to have "factory.setPool(this)" as a side-effect. I
>> think "new KPOF(...,pool...)" having "pool.setFactory(this)" as a side
>> effect is the more natural choice (as per the current code).
>>
>>>> I hate to keep backsliding here, but maybe we should to this in GOP
>>>> setFactory:
>>>>
>>>>            synchronized (factoryLock) {
>>>>                if (this.factory == null) {
>>>>                    this.factory = factory;
>>>> -                } else {
>>>> +                } else if (this.factory != factory) {
>>>>                    throw new IllegalStateException("Factory
>>>> already set");
>>>>                }
>>>>            }
>> I'd be OK with that. If we sort out logging we can log it at INFO as
>> unnecessary.
>>
>> Mark
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [pool][dbcp] Ongoing saga of setFactory

Posted by Phil Steitz <ph...@gmail.com>.
On 6/16/11 10:19 AM, Mark Thomas wrote:
> On 16/06/2011 17:32, sebb wrote:
>> On 16 June 2011 17:25, Phil Steitz <ph...@gmail.com> wrote:
>>> Yesterday I fixed some [dbcp] "problems" caused by the new [pool]
>>> requirement that setFactory can only be called once.  The quotes are
>>> because most of the problems were redundant calls to setFactory.
>>> The reason that we left setFactory in [pool] is that [dbcp]'s
>>> connection factory constructors call setFactory on the pool passed
>>> to them.  It is an easy "mistake" to create a pool, then create a
>>> connection factory and then do pool.setFactory(factory).  I
>>> eliminated all of these usages from within [dbcp], but I bet a fair
>>> amount of user code will similarly blow up when people upgrade.
>> AIUI, the upgrade does require code to be changed because of the package rename?
> It does, but that is just a search and replace and compilation will fail
> until it is fixed.
>> If so, can we not drop the setFactory method and provide it as a
>> constructor parameter?
> I don't think so. We have been around this buoy already.
>
> To quote Phil's summary:
> <quote>
> I think it is more natural to have
> pool = new GKOP(factory,...) have factory.setPool(this) as a side
> effect than
> factory = new KPOF(...,pool...) have pool.setFactory(this) as a side
> effect
> </quote>
>
> I disagree with Phil on this. Since a pool only has one factory whereas
> a factory may support multiple pools,

I had not thought about it that way before.  What is humorous is
that that logic makes it questionable to pass the pool to the
factory constructor (or at least just one pool).  In the case of
[dbcp]'s PoolableConnectionFactory,  it is hard-wired 1-1 to the
pool because it needs to provide the PoolableConnections that it
sources a reference to their owning pool.  I guess a generalized PCF
could source objects for multiple pools, in which case the
constructor could take a collection of pools.  I now see your
point.  In any case, from my perspective, the requirement to be able
to set the factory is understood and I am fine with keeping the code
as it is, possibly with the small patch below.

Phil


>  I think it is wrong for for "new
> GKOP(factory,...)" to have "factory.setPool(this)" as a side-effect. I
> think "new KPOF(...,pool...)" having "pool.setFactory(this)" as a side
> effect is the more natural choice (as per the current code).
>
>>>  I hate to keep backsliding here, but maybe we should to this in GOP
>>> setFactory:
>>>
>>>             synchronized (factoryLock) {
>>>                 if (this.factory == null) {
>>>                     this.factory = factory;
>>> -                } else {
>>> +                } else if (this.factory != factory) {
>>>                     throw new IllegalStateException("Factory
>>> already set");
>>>                 }
>>>             }
> I'd be OK with that. If we sort out logging we can log it at INFO as
> unnecessary.
>
> Mark
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [pool][dbcp] Ongoing saga of setFactory

Posted by Mark Thomas <ma...@apache.org>.
On 16/06/2011 17:32, sebb wrote:
> On 16 June 2011 17:25, Phil Steitz <ph...@gmail.com> wrote:
>> Yesterday I fixed some [dbcp] "problems" caused by the new [pool]
>> requirement that setFactory can only be called once.  The quotes are
>> because most of the problems were redundant calls to setFactory.
>> The reason that we left setFactory in [pool] is that [dbcp]'s
>> connection factory constructors call setFactory on the pool passed
>> to them.  It is an easy "mistake" to create a pool, then create a
>> connection factory and then do pool.setFactory(factory).  I
>> eliminated all of these usages from within [dbcp], but I bet a fair
>> amount of user code will similarly blow up when people upgrade.
> 
> AIUI, the upgrade does require code to be changed because of the package rename?

It does, but that is just a search and replace and compilation will fail
until it is fixed.
> 
> If so, can we not drop the setFactory method and provide it as a
> constructor parameter?

I don't think so. We have been around this buoy already.

To quote Phil's summary:
<quote>
I think it is more natural to have
pool = new GKOP(factory,...) have factory.setPool(this) as a side
effect than
factory = new KPOF(...,pool...) have pool.setFactory(this) as a side
effect
</quote>

I disagree with Phil on this. Since a pool only has one factory whereas
a factory may support multiple pools, I think it is wrong for for "new
GKOP(factory,...)" to have "factory.setPool(this)" as a side-effect. I
think "new KPOF(...,pool...)" having "pool.setFactory(this)" as a side
effect is the more natural choice (as per the current code).

>>  I hate to keep backsliding here, but maybe we should to this in GOP
>> setFactory:
>>
>>             synchronized (factoryLock) {
>>                 if (this.factory == null) {
>>                     this.factory = factory;
>> -                } else {
>> +                } else if (this.factory != factory) {
>>                     throw new IllegalStateException("Factory
>> already set");
>>                 }
>>             }

I'd be OK with that. If we sort out logging we can log it at INFO as
unnecessary.

Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [pool][dbcp] Ongoing saga of setFactory

Posted by sebb <se...@gmail.com>.
On 16 June 2011 17:25, Phil Steitz <ph...@gmail.com> wrote:
> Yesterday I fixed some [dbcp] "problems" caused by the new [pool]
> requirement that setFactory can only be called once.  The quotes are
> because most of the problems were redundant calls to setFactory.
> The reason that we left setFactory in [pool] is that [dbcp]'s
> connection factory constructors call setFactory on the pool passed
> to them.  It is an easy "mistake" to create a pool, then create a
> connection factory and then do pool.setFactory(factory).  I
> eliminated all of these usages from within [dbcp], but I bet a fair
> amount of user code will similarly blow up when people upgrade.

AIUI, the upgrade does require code to be changed because of the package rename?

If so, can we not drop the setFactory method and provide it as a
constructor parameter?

That would produce a compile-time error, rather than failing at run-time.

> I hate to keep backsliding here, but maybe we should to this in GOP
> setFactory:
>
>             synchronized (factoryLock) {
>                 if (this.factory == null) {
>                     this.factory = factory;
> -                } else {
> +                } else if (this.factory != factory) {
>                     throw new IllegalStateException("Factory
> already set");
>                 }
>             }
>
> Phil
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org