Обсуждение: Connection pools with LOB?

Поиск
Список
Период
Сортировка

Connection pools with LOB?

От
"Ole Streicher"
Дата:
Hi,

I tried to use a connection pool my very first time, and unfortunately it
did not work at all. I could trace it down to the following sample:

import java.sql.Connection;
import org.postgresql.largeobject.LargeObjectManager;
import org.postgresql.PGConnection;
import org.postgresql.jdbc3.Jdbc3PoolingDataSource;

public class PoolLob {
  public static void main(String[] args) {
    try {
      Jdbc3PoolingDataSource source = new Jdbc3PoolingDataSource();
      source.setDataSourceName("test Pooling");
      source.setServerName("localhost");
      source.setDatabaseName("sample");
      source.setUser("foo");
      source.setPassword("bar");
      source.setMaxConnections(10);
      Connection conn = source.getConnection();
      LargeObjectManager lobj = ((PGConnection)conn).getLargeObjectAPI();
      int oid = lobj.create();
      System.out.println("Just created a sample Object Id: " + oid);
    } catch (Throwable e) {
      e.printStackTrace();
    }
  }
}

This code gives me a class cast exception when I try to get the
LargeObjectManager; it seems that the connection is not really a PGConnection.

So, how can I access a Large Object from a connection pool?

I use the pg73jdbc3.jar from the download page to access a Postgresql 7.3.4
database (SuSE 9.0).
BTW, the jdbc jars provided with the SuSE distrib and also the jdbc jars
from the Postgresql download site seem not to contain the connection pool
classes at all. Is this on purpose?

Best regards,

Ole

--
GMX ProMail (250 MB Mailbox, 50 FreeSMS, Virenschutz, 2,99 EUR/Monat...)
jetzt 3 Monate GRATIS + 3x DER SPIEGEL +++ http://www.gmx.net/derspiegel +++


Re: Connection pools with LOB?

От
Oliver Jowett
Дата:
Ole Streicher wrote:
> This code gives me a class cast exception when I try to get the
> LargeObjectManager; it seems that the connection is not really a PGConnection.
>
> So, how can I access a Large Object from a connection pool?

Use a more recent driver; the 7.3 drivers are quite old and newer
drivers are backwards-compatible. The connection casting problem was
fixed in CVS some time ago:

$ cvs log org/postgresql/jdbc2/optional/PooledConnectionImpl.java
[...]
----------------------------
revision 1.6
date: 2003/01/14 05:46:49;  author: barry;  state: Exp;  lines: +4 -3
Patch from Aaron Mulder to have pooled connections implement PGConnection

  Modified Files:
         jdbc/org/postgresql/jdbc2/optional/PooledConnectionImpl.java
         jdbc/org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java
----------------------------

Looks like this change didn't make it into the 7.3 branch (which I think
is no longer maintained, at least for JDBC purposes).

> I use the pg73jdbc3.jar from the download page to access a Postgresql 7.3.4
> database (SuSE 9.0).
> BTW, the jdbc jars provided with the SuSE distrib and also the jdbc jars
> from the Postgresql download site seem not to contain the connection pool
> classes at all. Is this on purpose?

I can't speak for SuSE, but you are mistaken about the
jdbc.postgresql.org drivers:

> $ ls -l pg73jdbc3.jar
> -rw-r--r--    1 oliver   oliver     184505 Aug  8  2003 pg73jdbc3.jar
> $ jar tvf pg73jdbc3.jar | grep -i pool
>   2164 Thu Aug 07 10:57:50 NZST 2003 org/postgresql/jdbc3/Jdbc3ConnectionPool.class
>    459 Thu Aug 07 10:57:50 NZST 2003 org/postgresql/jdbc3/Jdbc3PooledConnection.class
>   3005 Thu Aug 07 10:57:50 NZST 2003 org/postgresql/jdbc3/Jdbc3PoolingDataSource.class
>   1602 Thu Aug 07 10:57:50 NZST 2003 org/postgresql/jdbc2/optional/ConnectionPool.class
>   3338 Thu Aug 07 10:57:50 NZST 2003 org/postgresql/jdbc2/optional/PooledConnectionImpl$ConnectionHandler.class
>   4209 Thu Aug 07 10:57:50 NZST 2003 org/postgresql/jdbc2/optional/PooledConnectionImpl.class
>   1753 Thu Aug 07 10:57:50 NZST 2003 org/postgresql/jdbc2/optional/PoolingDataSource$1.class
>   7258 Thu Aug 07 10:57:50 NZST 2003 org/postgresql/jdbc2/optional/PoolingDataSource.class

-O