Class UCPServletContextListener
- java.lang.Object
-
- oracle.ucp.jdbc.UCPServletContextListener
-
- All Implemented Interfaces:
java.util.EventListener
,javax.servlet.ServletContextListener
public class UCPServletContextListener extends java.lang.Object implements javax.servlet.ServletContextListener
This ServletContextListener implementation creates a UCP DataSource by reading context initialization parameters and binds it to JNDI and to an ApplicationScoped object (same object) to be able to be retrieved (via JNDI or Injection) by other components in the container.
The listener creates the datasource on container startup. If the JNDI name is specified it registers the created datasource with JNDI. On container shutdown it destroys the datasource and removes JNDI binding. To use this listener configure it in web.xml as follows:<listener> <listener-class>oracle.ucp.jdbc.UCPServletContextListener</listener-class> </listener>
The listener wraps the UCP datasource instance in an Application scoped object called UCPDataSourceResource and puts it in the JNDI context. A wrapper over UCP datasource is needed because putting UCP PoolDataSource instance directly into the JNDI context creates a new pool each time we lookup the datasource in JNDI context. It is because UCP PoolDataSource implements the Referenceable interface.
The UCP datasource can be configured either by setting pool properties in web.xml file as context initialization parameters or through UCP XML configuration file.
In order to create the datasource using XML config file you must set the System property oracle.ucp.jdbc.xmlConfigFile and specify the datasource name in web.xml file as context initialization parameter using property - ucp.dataSourceNameFromXMLConfig. The value of this property must match with the datasource name defined in XML configuration file. Below is the list of supported UCP pool properties in web.xml file as context initialization parameters:- ucp.URL
- ucp.user
- ucp.password
- ucp.connectionFactoryClassName
- ucp.initialPoolSize
- ucp.maxPoolSize
- ucp.minPoolSize,
- ucp.connectionPoolName
- ucp.connectionWaitTimeout
- ucp.validateConnectionOnBorrow
- ucp.fastConnectionFailoverEnabled
- ucp.maxStatements
- ucp.sqlForValidateConnection
- ucp.onsConfiguration
- ucp.maxIdleTime
- ucp.propertyCycle
- ucp.timeoutCheckInterval
- ucp.inactiveConnectionTimeout
- ucp.timeToLiveConnectionTimeout
- ucp.abandonedConnectionTimeout
- ucp.highCostConnectionReuseThreshold
- ucp.connectionLabelingHighCost
- ucp.maxConnectionReuseTime
- ucp.description
- ucp.roleName
- ucp.secondsToTrustIdleConnection
- ucp.dataSourceName
- ucp.connectionValidationTimeout
- ucp.connectionRepurposeThreshold
- ucp.connectionHarvestMaxCount
- ucp.connectionHarvestTriggerCount
- ucp.maxConnectionReuseCount
- ucp.maxConnectionsPerShard
- ucp.shardingMode
- ucp.serverName
- ucp.databaseName
- ucp.networkProtocol
- ucp.portNumber
- ucp.dataSourceNameFromXMLConfig
- ucp.jndiName
The application can access the above configured UCP datasource wrapper instance either via Injection if underlying server supports CDI feature or via JNDI lookup if the ucp.jndiName property is set in web.xml file as context initialization parameter.
Option-1 Using Context and Dependency Injection(CDI)
@Inject @UCPResource private javax.sql.DataSource ds;
Option-2 Using JNDI lookupInitialContext initContext = new InitialContext(); // ucp.jndiName_value is the value of ucp.jndiName context init param in web descriptor file. javax.sql.DataSource ds = (DataSource) initContext.lookup(ucp.jndiName_value);
-
-
Constructor Summary
Constructors Constructor Description UCPServletContextListener()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
contextDestroyed(javax.servlet.ServletContextEvent servletContextEvent)
void
contextInitialized(javax.servlet.ServletContextEvent servletContextEvent)
-
-
-
Method Detail
-
contextInitialized
public void contextInitialized(javax.servlet.ServletContextEvent servletContextEvent)
- Specified by:
contextInitialized
in interfacejavax.servlet.ServletContextListener
-
contextDestroyed
public void contextDestroyed(javax.servlet.ServletContextEvent servletContextEvent)
- Specified by:
contextDestroyed
in interfacejavax.servlet.ServletContextListener
-
-