RE: How i can read at runtime datasource info?

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Apr 14 2005 - 09:38:08 EDT

  • Next message: Emre Yilmaz: "Re: 'cayenne.xml' is not found"

    The whole idea of JNDI (for better or for worse) is to externalize
    configuration details from code. So in theory a server administrator can
    replace one implementation of DataSource with another, based on a
    different provider, and application should still run. So you application
    can only rely on the methods provided by DataSource interface, which
    doesn't give you a URL.

    However nothing prevents you from creating a custom runtime property
    (separate from Cayenne) configured to store database URL.

    Andrus

    > Hi Andrus,
    > i use both the configuration...(DriverDataSourceFactory /
    > container-provided DataSource JNDI) one for production and one for
    > develop.
    > There is a unique way to retrive this infomation?
    > I need at least the JDBC URL.
    > Thank's
    > Davide
    >
    > -----Original Message-----
    > From: Andrus Adamchik [mailto:andru..bjectstyle.org]
    > Sent: giovedì 14 aprile 2005 15.03
    > To: cayenne-use..bjectstyle.org
    > Subject: Re: How i can read at runtime datasource info?
    >
    >
    >> Hi,
    >> i want to read dasource info at runtime. I see that "DatasourceInfo"
    >> class have all the property that i need. How i can obtain an instance
    >> of this class?
    >> From a "Configuration" oject?
    >> From a "DataDomain" object?
    >>
    >> Thank's
    >> Davide
    >
    > Hi Davide,
    >
    > You are on the right track, but go even lower down the stack. You need
    > to obtain DataNod, then call getDataSource, casting the result to
    > org.objectstyle.cayenne.conn.PoolManager. Pool manager has al the info
    > you need.
    >
    > Of course the cast to PoolManager is valid only if you configured
    > DriverDataSourceFactory for the DataNode in the Modeler. If it is a
    > container-provided DataSource (i.e. obtained via JNDI), this won't work.
    >
    > Andrus



    This archive was generated by hypermail 2.0.0 : Thu Apr 14 2005 - 09:38:10 EDT