Class UCPServletContextListener
- All Implemented Interfaces:
jakarta.servlet.ServletContextListener,EventListener
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 lookup
InitialContext 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 -
Method Summary
Modifier and TypeMethodDescriptionvoidcontextDestroyed(jakarta.servlet.ServletContextEvent servletContextEvent) voidcontextInitialized(jakarta.servlet.ServletContextEvent servletContextEvent)
-
Constructor Details
-
UCPServletContextListener
public UCPServletContextListener()
-
-
Method Details
-
contextInitialized
public void contextInitialized(jakarta.servlet.ServletContextEvent servletContextEvent) - Specified by:
contextInitializedin interfacejakarta.servlet.ServletContextListener
-
contextDestroyed
public void contextDestroyed(jakarta.servlet.ServletContextEvent servletContextEvent) - Specified by:
contextDestroyedin interfacejakarta.servlet.ServletContextListener
-