You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by cr...@apache.org on 2002/06/10 12:34:10 UTC
cvs commit: jakarta-avalon-excalibur/datasource/src/java/org/apache/avalon/excalibur/datasource InformixDataSource.java
crafterm 2002/06/10 03:34:09
Modified: datasource/src/java/org/apache/avalon/excalibur/datasource
InformixDataSource.java
Log:
Fixed InformixDataSource class so that it returns pooled connections by
default. Also removed the requirement for javax.naming.* classes by using
Informix's IfxConnectionPoolDataSource class directly.
Revision Changes Path
1.10 +28 -60 jakarta-avalon-excalibur/datasource/src/java/org/apache/avalon/excalibur/datasource/InformixDataSource.java
Index: InformixDataSource.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/datasource/src/java/org/apache/avalon/excalibur/datasource/InformixDataSource.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- InformixDataSource.java 16 May 2002 11:55:19 -0000 1.9
+++ InformixDataSource.java 10 Jun 2002 10:34:08 -0000 1.10
@@ -8,11 +8,9 @@
package org.apache.avalon.excalibur.datasource;
import com.informix.jdbcx.IfxConnectionPoolDataSource;
-import com.informix.jdbcx.IfxDataSource;
import java.sql.Connection;
import java.sql.SQLException;
-import javax.naming.Context;
-import javax.naming.InitialContext;
+import javax.sql.PooledConnection;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
@@ -48,8 +46,9 @@
* <p>
* You must have Informix's JDBC 2.2 or higher jar file, as well as the
* extensions jar file (<code>ifxjdbc.jar</code> and <code>ifxjdbcx.jar</code>).
- * Also, this DataSource requires the Avalon Cadastre package because it uses
- * the MemoryContext.
+ * You will also need the JDBC 2.0 Optional Pacakge
+ * (<code>jdbc2_0-stdext.jar</code>) available from
+ * http://java.sun.com/products/jdbc/download.html.
* </p>
*
* <p>
@@ -73,30 +72,16 @@
*
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
* @author <a href="mailto:crafterm@apache.org">Marcus Crafter</a>
- * @version CVS $Revision: 1.9 $ $Date: 2002/05/16 11:55:19 $
+ * @version CVS $Revision: 1.10 $ $Date: 2002/06/10 10:34:08 $
* @since 4.0
*/
public class InformixDataSource
extends AbstractLogEnabled
implements DataSourceComponent, Loggable
{
- private IfxDataSource m_dataSource;
+ private IfxConnectionPoolDataSource m_dataSource;
+ private PooledConnection m_pooledConnection;
private boolean m_autocommit;
- private static boolean INIT_FACTORY = false;
-
- /**
- * Set up the system property for the context factory if it hasn't been
- * done already. This is not done in a static initializer due to the
- * existence of the J2eeDataSource.
- */
- public InformixDataSource()
- {
- if( !InformixDataSource.INIT_FACTORY )
- {
- System.setProperty( Context.INITIAL_CONTEXT_FACTORY,
- "org.apache.avalon.excalibur.naming.memory.MemoryInitialContextFactory" );
- }
- }
public void setLogger( final org.apache.log.Logger logger )
{
@@ -108,7 +93,15 @@
*/
public Connection getConnection() throws SQLException
{
- Connection conn = m_dataSource.getConnection();
+ synchronized (this)
+ {
+ if (m_pooledConnection == null)
+ {
+ m_pooledConnection = m_dataSource.getPooledConnection();
+ }
+ }
+
+ Connection conn = m_pooledConnection.getConnection();
if( conn.getAutoCommit() != m_autocommit )
{
@@ -125,46 +118,21 @@
{
Configuration poolController = conf.getChild( "pool-controller" );
String dbname = conf.getChild( "dbname" ).getValue( "ifx" );
- IfxConnectionPoolDataSource pooledDataSource = new IfxConnectionPoolDataSource();
+ m_dataSource = new IfxConnectionPoolDataSource();
m_autocommit = conf.getChild( "autocommit" ).getValueAsBoolean( true );
- pooledDataSource.setIfxCPMInitPoolSize( poolController.getAttributeAsInteger( "init", 5 ) );
- pooledDataSource.setIfxCPMMinPoolSize( poolController.getAttributeAsInteger( "min", 5 ) );
- pooledDataSource.setIfxCPMMaxPoolSize( poolController.getAttributeAsInteger( "max", 10 ) );
- pooledDataSource.setIfxCPMServiceInterval( 100 );
- pooledDataSource.setServerName( conf.getChild( "servername" ).getValue() );
- pooledDataSource.setDatabaseName( conf.getChild( "dbname" ).getValue() );
- pooledDataSource.setIfxIFXHOST( conf.getChild( "host" ).getValue() );
- pooledDataSource.setPortNumber( conf.getChild( "host" ).getAttributeAsInteger( "port" ) );
- pooledDataSource.setUser( conf.getChild( "user" ).getValue() );
- pooledDataSource.setPassword( conf.getChild( "password" ).getValue() );
-
- try
- {
- Context context = new InitialContext();
-
- context.bind( dbname + "pool", pooledDataSource );
-
- m_dataSource = new IfxDataSource();
- m_dataSource.setDataSourceName( dbname + "pool" );
- m_dataSource.setServerName( conf.getChild( "servername" ).getValue() );
- m_dataSource.setDatabaseName( conf.getChild( "dbname" ).getValue() );
- m_dataSource.setIfxIFXHOST( conf.getChild( "host" ).getValue() );
- m_dataSource.setPortNumber( conf.getChild( "host" ).getAttributeAsInteger( "port" ) );
- m_dataSource.setUser( conf.getChild( "user" ).getValue() );
- m_dataSource.setPassword( conf.getChild( "password" ).getValue() );
- configureTracing( conf.getChild( "tracing", false ) );
+ m_dataSource.setIfxCPMInitPoolSize( poolController.getAttributeAsInteger( "init", 5 ) );
+ m_dataSource.setIfxCPMMinPoolSize( poolController.getAttributeAsInteger( "min", 5 ) );
+ m_dataSource.setIfxCPMMaxPoolSize( poolController.getAttributeAsInteger( "max", 10 ) );
+ m_dataSource.setIfxCPMServiceInterval( 100 );
+ m_dataSource.setServerName( conf.getChild( "servername" ).getValue() );
+ m_dataSource.setDatabaseName( conf.getChild( "dbname" ).getValue() );
+ m_dataSource.setIfxIFXHOST( conf.getChild( "host" ).getValue() );
+ m_dataSource.setPortNumber( conf.getChild( "host" ).getAttributeAsInteger( "port" ) );
+ m_dataSource.setUser( conf.getChild( "user" ).getValue() );
+ m_dataSource.setPassword( conf.getChild( "password" ).getValue() );
- context.bind( dbname, m_dataSource );
- }
- catch( Exception e )
- {
- if( getLogger().isErrorEnabled() )
- {
- getLogger().error( "There was an error trying to bind the connection pool", e );
- }
- throw new ConfigurationException( "There was an error trying to bind the connection pool", e );
- }
+ configureTracing( conf.getChild( "tracing", false ) );
}
/**
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>