From: "Jacopo Cappellato" <jacopo.cappell...@hotwaxmedia.com>

On May 23, 2012, at 7:34 PM, Adam Heath wrote:

On 05/23/2012 12:05 PM, Jacopo Cappellato wrote:

DBCPConnectionFactory is in framework/entity; having it require a
framework/entity/entitymodel seems the safest approach.

I agree; what if we use:

select count(testing_type_id) from testing_type where testing_type_id = 'ABC'

Actually, no, TestingType seems like it is an entity that would never
be installed in a production environment; I certainly would never want
to install testing-only things.

SequenceValueItem, EntityKeyStore always need to be in the *current*
datasource.  Tenant* might be in another datasource, so you can't test
for those.

count() also seems wrong, as it might be a heavy-weight operation.  Is
this particular thing going to run often?  That's an important thing
to consider if you switch the entity.

What about using DatabaseMetadata?  But that might have performance
issues.  What does this check actually hope to accomplish?  I haven't
read the code(sorry), and don't have time now to fully study it all.

Yeah, it is executed quite often (as far as I understand it) and we should use an efficient SQL that returns at least one record: the sql is used by DBCP to check if the connection is good and (I think) it is executed everytime the connection is borrowed/returned (but I don't remember exactly, it could be less often). I would also prefer to use one of SequenceValueItem or EntityKeyStore but I am worried that SequenceValueItem is a very used entity... EntityKeyStore may be a better choice. Using count() was simply a trick to be sure to get a record back even if the entity is empty... but if we use an entity that we are sure is populated we don't have to use it, of course. Of course if we use count(*) we have to use it in an entity with a very low number of rows... but I too would prefer to avoid it.

An entity in entity component seems a wise choice if ever someone wants to 
extract the entity engine (good luck).
But it seems to me that EntityKeyStore can be empty. I see it on trunk demo and in a the current project I'm working on (a large application). On the other hand I agree that SequenceValueItem is not a good choice (we have already SELECT FOR UPDATE there with SequenceBank.fillBank() method)
We could also rely on something external to entity component, but for the 
reason explained before it's less appealing.
I think that the select limited to 1 is a good idea, but maybe something else 
can be used on even a possible empty entity?

Ha no: http://commons.apache.org/dbcp/apidocs/org/apache/commons/dbcp/PoolableConnectionFactory.html#setValidationQuery%28java.lang.String%29 must returns 1 line...

Why not create a specific entity in entity component loaded with 1 line only 
used for that?

Jacques

Jacopo


that should always return one row with the 0 count; the entity is empty ootb (it is only used for automated tests) but the constraint on the pk should add an additional protection for efficiency.

Well, that proves it, it really shouldn't create the entity except
during a test run.  That's something I've been wanting to fix for
awhile now.


Reply via email to