Re: Unable to set loginTimeout on data sources defined in context.xml

2010-01-28 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Jorge,

On 1/27/2010 5:40 PM, Jorge Medina wrote:
 I have the following Resource defined in context.xml
 
 Resource name=jdbc/MasterDB
   auth=Container
   driverClassName=oracle.jdbc.driver.OracleDriver
   type=oracle.jdbc.pool.OracleDataSource
   factory=oracle.jdbc.pool.OracleDataSourceFactory
   description=Database Master DB Instance
   maxActive=100
   maxIdle=30
   maxWait=5000
   user=@@ORACLE_USER@@
   password=@@ORACLE_USER_PASSWORD@@
 
   loginTimeout=10

I don't see any documentation that shows loginTimeout as being a valid
parameter for the Resource element.

http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html
http://tomcat.apache.org/tomcat-6.0-doc/config/globalresources.html
http://commons.apache.org/dbcp/configuration.html

Is this some OracleDataSourceFactory-specific parameter?

Looks like it:
http://www.oracle.com/technology/docs/tech/java/sqlj_jdbc/doc_library/javadoc/oracle.jdbc.pool.oracledatasource.html#setLoginTimeout%28int%29

(They're using the javadoc that shipped with Java 1.0 or something like
that... how delightful!)

 While the database is up an running, everything works fine in my web app
 (webservices implemented with Spring framework)
 But when the database is down, my clients timeout because my application
 takes a lot of time to realize that the database is down (several minutes).
 
 I want my web app to fail quickly if the DB is down (and either return some
 useful error to the user)
 I have been tried setting the property loginTimeout in my Resource, but it
 seems that Tomcat is ignoring the property.

Try something like this in a test JSP:

%
  InitialContext ctx = new InitialContext();
  OracleDataSource ds =
(OracleDataSource)ctx.lookup(java:/comp/env/jdbc/MasterDB);
%
DataSource loginTimeout = %= ds.getLoginTimeout() % seconds

If it says 10 seconds then the property is being set on your
connection, and your problem is elsewhere.

 Originally I was using javax.sql.Datasource and the datasource factory was
 defaulting to the DBCP BasicDataSourceFactory in my Resource declaration.
 If I specified the loginTimeout property in the Resource with this
 factory, the application was just unable to get a connection.

Probably because the loginTimeout property doesn't exist for
BasicDataSourceFactory.

 (I forgot the
 details, but this prompted me to use the
 oracle.jdbc.pool.OracleDataSourceFactory and the corresponding data source,
 oracle.jdbc.pool.OracleDataSource ).

Try setting type=javax.jdbc.DataSource. By using the Oracle-specific
factory, I don't think it matters about the type, but it's tough for me
to understand the code for
org/apache/naming/factory/ResourceFactory.java out of context.

 Is Tomcat ignoring the loginTimeout property?

Most likely not. Tomcat's job is to pass that information on to the
DataSource that gets created by the Factory. Try the above code and see
what you get.

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkth8j8ACgkQ9CaO5/Lv0PAexwCgo3uXG7uwwvXwVQDE/IklYjjj
qJgAn3gKqVdyHZ7s3BmuXUFu6qNO2NYh
=9zfV
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Unable to set loginTimeout on data sources defined in context.xml

2010-01-27 Thread Jorge Medina
Hi,

I have the following Resource defined in context.xml

Resource name=jdbc/MasterDB
  auth=Container
  driverClassName=oracle.jdbc.driver.OracleDriver
  type=oracle.jdbc.pool.OracleDataSource
  factory=oracle.jdbc.pool.OracleDataSourceFactory
  description=Database Master DB Instance
  maxActive=100
  maxIdle=30
  maxWait=5000
  user=@@ORACLE_USER@@
  password=@@ORACLE_USER_PASSWORD@@

  loginTimeout=10

  defaultAutoCommit=true
  url=@@ORACLE_URL@@
  validationQuery=select sysdate from dual
  testOnBorrow=true
  testWhileIdle=true
  timeBetweenEvictionRunsMillis=30
  minEvictableIdleTimeMillis=180
  /

where the user, password and url are all defined at install time and are not
important for this issue.

I use Hibernate on my application,  and define my hibernate.master.cfg.xml
as

hibernate-configuration
  session-factory
!-- The JNDI resource name for the Data Source defined in
tomcat/conf/context.xml --
property
name=hibernate.connection.datasourcejava:/comp/env/jdbc/MasterDB/property
!-- The Hibernate Properties for this data source --
property
name=hibernate.dialectorg.hibernate.dialect.Oracle10gDialect/property
property name=hibernate.connection.autocommittrue/property
property name=hibernate.cache.use_query_cachefalse/property
!-- property name=hibernate.hbm2ddl.autovalidate/property --
property name=hibernate.jdbc.batch_size0/property
property name=hibernate.cache.use_second_level_cachetrue/property
property
name=hibernate.current_session_context_classthread/property
property
name=hibernate.cache.provider_classnet.sf.ehcache.hibernate.EhCacheProvider/property
property
name=net.sf.ehcache.configurationResourceNameehcache.xml/property
  /session-factory
/hibernate-configuration

While the database is up an running, everything works fine in my web app
(webservices implemented with Spring framework)
But when the database is down, my clients timeout because my application
takes a lot of time to realize that the database is down (several minutes).

I want my web app to fail quickly if the DB is down (and either return some
useful error to the user)
I have been tried setting the property loginTimeout in my Resource, but it
seems that Tomcat is ignoring the property.

Originally I was using javax.sql.Datasource and the datasource factory was
defaulting to the DBCP BasicDataSourceFactory in my Resource declaration.
If I specified the loginTimeout property in the Resource with this
factory, the application was just unable to get a connection. (I forgot the
details, but this prompted me to use the
oracle.jdbc.pool.OracleDataSourceFactory and the corresponding data source,
oracle.jdbc.pool.OracleDataSource ).

Is Tomcat ignoring the loginTimeout property?


-Jorge