You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by John Hauf <j...@hauf.org> on 2006/09/07 15:59:04 UTC

GetConnection

Hello,

I have a problem with the method Torque.getConnection(). I use Torque 
with SharedPoolDataSourceFactory.
I try to do the following - as suggested on the dbcp-configuration page:
Connection conn = Torque.getConnection();
Connection dconn = ((org.apache.commons.dbcp.DelegatingConnection) 
conn).getInnermostDelegate();

I have also set this in my torque-configuration: 
torque.dsfactory.spatial.pool.accessToUnderlyingConnectionAllowed = true

But I always get a ClassCastException back when I try to cast the 
connection to "DelegatingConnection".

I need to do this, because I need to add some datatypes to the 
underlaying postgres-connection:
((org.postgresql.PGConnection) conn).addDataType("geometry", 
PGgeometry.class);

Has anybody a solution for this problem?

Thank you!

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Re: GetConnection

Posted by John Hauf <j...@hauf.org>.
Hello,

thank you for your help. It seems that I have found a solution that 
works for my problem with the Postgis-geometry-datatype.
The solution was quite simple: I patched the 
com.workingdogs.village.Value-class and can now get access to the 
underlying object of each value in my records.

But I still have a small question: The datatype of my postgis-geometry 
is Types.OTHER and this datatype is returned as String from the 
om.workingdogs.village.Value-class. Is there any possibility to access 
the underlying objets of a record without patching the value class?
I tried with the dataset()-method in the Result-class, but the recordSet 
is always empty.

John






Greg Monroe wrote:
> Hmm, did some code spelunking and found that the accessTo...
> parameter in dbcp only works for BasicDataSources.  Torque's 
> SharedPoolDataSourceFactory uses DBCP's SharedPoolDataSource
> which does not support this option.  So the class of connection 
> object you get will be: 
> 
>   org.apache.commons.dbcp.cpdsadapter.ConnectionImpl
> 
> and this doesn't allow access to the real connection.
> 
> That said, one thing to try is subclassing the PostGres JDBC
> Driver class and overriding the connect method to add your
> 'geometries' type.  Then use this subclass in your Torque
> settings.
> 
> 
>> Johannes Hauf said:
>>
>> Thank you. I tried with your suggestion and I think this 
>> would work if the database wouldn't be Postgres.
>> In the postgres-jdbc driver, the typeMap-mechanism seems not 
>> to be implemented yet.
>>
>> Has anyone another idea?
>>
>> John
>>
>> Greg Monroe wrote:
>>> Can you use the standard Connection interface TypeMap support to do 
>>> the same thing rather than the PostGres extension?  E.g.
>>>
>>> Map map = conn.getTypeMap();
>>> map.put("geometry", Pggeometry.class); conn.setTypeMap(map);
>>>
> 
> Duke CE Privacy Statement
> Please be advised that this e-mail and any files transmitted with it are confidential communication or may otherwise be privileged or confidential and are intended solely for the individual or entity to whom they are addressed.  If you are not the intended recipient you may not rely on the contents of this email or any attachments, and we ask that you  please not read, copy or retransmit this communication, but reply to the sender and destroy the email, its contents, and all copies thereof immediately.  Any unauthorized dissemination, distribution or copying of this communication is strictly prohibited.
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: GetConnection

Posted by Greg Monroe <Gr...@DukeCE.com>.
Hmm, did some code spelunking and found that the accessTo...
parameter in dbcp only works for BasicDataSources.  Torque's 
SharedPoolDataSourceFactory uses DBCP's SharedPoolDataSource
which does not support this option.  So the class of connection 
object you get will be: 

  org.apache.commons.dbcp.cpdsadapter.ConnectionImpl

and this doesn't allow access to the real connection.

That said, one thing to try is subclassing the PostGres JDBC
Driver class and overriding the connect method to add your
'geometries' type.  Then use this subclass in your Torque
settings.


> Johannes Hauf said:
> 
> Thank you. I tried with your suggestion and I think this 
> would work if the database wouldn't be Postgres.
> In the postgres-jdbc driver, the typeMap-mechanism seems not 
> to be implemented yet.
> 
> Has anyone another idea?
> 
> John
> 
> Greg Monroe wrote:
> > Can you use the standard Connection interface TypeMap support to do 
> > the same thing rather than the PostGres extension?  E.g.
> > 
> > Map map = conn.getTypeMap();
> > map.put("geometry", Pggeometry.class); conn.setTypeMap(map);
> > 

Duke CE Privacy Statement
Please be advised that this e-mail and any files transmitted with it are confidential communication or may otherwise be privileged or confidential and are intended solely for the individual or entity to whom they are addressed.  If you are not the intended recipient you may not rely on the contents of this email or any attachments, and we ask that you  please not read, copy or retransmit this communication, but reply to the sender and destroy the email, its contents, and all copies thereof immediately.  Any unauthorized dissemination, distribution or copying of this communication is strictly prohibited.



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Re: GetConnection

Posted by Johannes Hauf <ha...@arsnavigandi.de>.
Thank you. I tried with your suggestion and I think this would work if 
the database wouldn't be Postgres.
In the postgres-jdbc driver, the typeMap-mechanism seems not to be 
implemented yet.

Has anyone another idea?

John

Greg Monroe wrote:
> Can you use the standard Connection interface TypeMap
> support to do the same thing rather than the PostGres
> extension?  E.g.
> 
> Map map = conn.getTypeMap();
> map.put("geometry", Pggeometry.class);
> conn.setTypeMap(map); 
> 
>> -----Original Message-----
>> From: John Hauf [mailto:j@hauf.org] 
>> Sent: Thursday, September 07, 2006 9:59 AM
>> To: torque-user@db.apache.org
>> Subject: GetConnection
>>
>> Hello,
>>
>> I have a problem with the method Torque.getConnection(). I 
>> use Torque with SharedPoolDataSourceFactory.
>> I try to do the following - as suggested on the 
>> dbcp-configuration page:
>> Connection conn = Torque.getConnection(); Connection dconn = 
>> ((org.apache.commons.dbcp.DelegatingConnection)
>> conn).getInnermostDelegate();
>>
>> I have also set this in my torque-configuration: 
>> torque.dsfactory.spatial.pool.accessToUnderlyingConnectionAllo
>> wed = true
>>
>> But I always get a ClassCastException back when I try to cast 
>> the connection to "DelegatingConnection".
>>
>> I need to do this, because I need to add some datatypes to 
>> the underlaying postgres-connection:
>> ((org.postgresql.PGConnection) conn).addDataType("geometry", 
>> PGgeometry.class);
>>
>> Has anybody a solution for this problem?
>>
>> Thank you!
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: torque-user-help@db.apache.org
>>
>>
> 
> Duke CE Privacy Statement
> Please be advised that this e-mail and any files transmitted with it are confidential communication or may otherwise be privileged or confidential and are intended solely for the individual or entity to whom they are addressed.  If you are not the intended recipient you may not rely on the contents of this email or any attachments, and we ask that you  please not read, copy or retransmit this communication, but reply to the sender and destroy the email, its contents, and all copies thereof immediately.  Any unauthorized dissemination, distribution or copying of this communication is strictly prohibited.
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
> 
> 
> 

-- 
--------------------------------------------------------------
ars navigandi [lat. die Kunst zu navigieren]

Johannes Hauf M.A.                         ars navigandi GmbH
Telefon: +49 (0)89 82989164                Spiegelstr. 4
FAX:     +49 (0)89 244325475               81241 Muenchen
http://www.arsnavigandi.de                 Germany
mailto:hauf@arsnavigandi.de

Internet-Agentur - Software-Lösungen - E-Learning - Design
--------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: GetConnection

Posted by Greg Monroe <Gr...@DukeCE.com>.
Can you use the standard Connection interface TypeMap
support to do the same thing rather than the PostGres
extension?  E.g.

Map map = conn.getTypeMap();
map.put("geometry", Pggeometry.class);
conn.setTypeMap(map); 

> -----Original Message-----
> From: John Hauf [mailto:j@hauf.org] 
> Sent: Thursday, September 07, 2006 9:59 AM
> To: torque-user@db.apache.org
> Subject: GetConnection
> 
> Hello,
> 
> I have a problem with the method Torque.getConnection(). I 
> use Torque with SharedPoolDataSourceFactory.
> I try to do the following - as suggested on the 
> dbcp-configuration page:
> Connection conn = Torque.getConnection(); Connection dconn = 
> ((org.apache.commons.dbcp.DelegatingConnection)
> conn).getInnermostDelegate();
> 
> I have also set this in my torque-configuration: 
> torque.dsfactory.spatial.pool.accessToUnderlyingConnectionAllo
> wed = true
> 
> But I always get a ClassCastException back when I try to cast 
> the connection to "DelegatingConnection".
> 
> I need to do this, because I need to add some datatypes to 
> the underlaying postgres-connection:
> ((org.postgresql.PGConnection) conn).addDataType("geometry", 
> PGgeometry.class);
> 
> Has anybody a solution for this problem?
> 
> Thank you!
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
> 
> 

Duke CE Privacy Statement
Please be advised that this e-mail and any files transmitted with it are confidential communication or may otherwise be privileged or confidential and are intended solely for the individual or entity to whom they are addressed.  If you are not the intended recipient you may not rely on the contents of this email or any attachments, and we ask that you  please not read, copy or retransmit this communication, but reply to the sender and destroy the email, its contents, and all copies thereof immediately.  Any unauthorized dissemination, distribution or copying of this communication is strictly prohibited.



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org