On Sat, 20 Mar 2004 20:15:11 +0100, Emir Causevic wrote:

>
>
>Bruce,
>Thank you for your info.
>I want to test if the database is up.
>Please see my code and propose a better solution if you see one.
>
>I did something like this:
>
>    try
>    {
>      db = (DatabaseImpl) jdo.getDatabase();
>      db.begin();
>      conn = (java.sql.Connection) db.getConnection(); // it will throw
>:-)        
>      db.commit();
>      db.close();
>    }
>    catch(DatabaseNotFoundException e) {/*...*/} 
>    catch(PersistenceException e) {/* I get an exception here if the
>database is shut down. It is some useful message from the DBSM, e.g.
>ORA-xxx. */}
>
>
>As I can see, the transaction must be in progress to open a connection (
>_ctx attribute in DatabaseImpl must not be null). BTW, there a way to
>open connection without opening a transaction?
>
>The main reason for these probably annoying questions of mine is that
>I'm creating a step-by-step introduction to Castor. My intention was
>first to show obtaining a connection to database and then in the next
>step a simple transaction example. Nevertheless, if this is the "castor
>way", I'll accept it as it is. :-) 

Eric,

whilst I've got no problem with your approach per se, here's a couple of small 
comments re: the step-by-step instructions. I think that obtaining a 
connection in the context of Castor is different from obtaining a JDBC connection, 
hence testing for the existence of a JDBC connection is kind of 
wrong. Why ? Well, this test is based on assumptions about the availability, the 
timeliness, etc, things that should be opaque to the user as per design. 
Just imagine that with JDBC release 4.0 the standard mechanism to obtain connections 
will be replaced with a new mechanism, not based on the 
DriverManager or DataSources. If we were to follow this, you won't be able to test 
whether a JDBC Connection has been created as Castor will not be 
using JDBC anymore but a new replacement mechanism or e.g. the Connector API.

In general, Castor offers a contract to the user such as the Database object, and your 
tests should focus on testing this contract offered, not some 
implementation details that might disappear in the future.

Just my 0.02 cents 
Werner

>
>Regards,
>Emir
>
>P.S. Regarding the documentation... I was looking under the "API" link,
>and overlooked "Full javadoc" link at the bottom of page. I apologize
>for that. :$
>
>
>
>-----Original Message-----
>From: Bruce Snyder [mailto:[EMAIL PROTECTED] 
>Sent: 19. oᅵujak 2004 20:35
>To: [EMAIL PROTECTED]
>Subject: Re: [castor-dev] Re: you? - getDatabase() again
>
>
>I'm not exactly sure what you're trying to achieve, maybe you want
>to test that the java.sql.Connection is alive. If this is what
>you're trying to achieve, this can certainly be accomplished via
>the DatabaseImpl class.
>
>There is most certainly Javadoc for the DatabaseImpl class available
>here:
>
> 
>http://www.castor.org/javadoc/org/exolab/castor/jdo/engine/DatabaseImpl.
>html
>
>Bruce
>--
>perl -e 'print
>unpack("u30","<0G)[EMAIL PROTECTED]&5R\"F9E<G)E=\$\!F<FEI+F-O;0\`\`");'
>
>The Castor Project
>http://www.castor.org/
>
>Apache Geronimo
>http://incubator.apache.org/projects/geronimo.html
>
>----------------------------------------------------------- 
>If you wish to unsubscribe from this mailing, send mail to
>[EMAIL PROTECTED] with a subject of:
>        unsubscribe castor-dev
>
>----------------------------------------------------------- 
>If you wish to unsubscribe from this mailing, send mail to
>[EMAIL PROTECTED] with a subject of:
>        unsubscribe castor-dev
>

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to