java.lang.Object
org.objectstyle.cayenne.conf.Configuration
org.objectstyle.cayenne.conf.DefaultConfiguration
org.objectstyle.cayenne.conf.BasicServletConfiguration
org.objectstyle.cayenne.conf.ServletConfiguration
- All Implemented Interfaces:
- java.util.EventListener, javax.servlet.http.HttpSessionListener, javax.servlet.ServletContextListener
- public class ServletConfiguration
- extends BasicServletConfiguration
- implements javax.servlet.http.HttpSessionListener, javax.servlet.ServletContextListener
ServletConfiguration is a Configuration that uses ServletContext to locate resources.
This class can only be used in a context of a servlet/jsp container.
It resolves configuration file paths relative to the web application
"WEB-INF" directory.
It performs the following tasks:
- Loads Cayenne configuration when the application is started within container.
- Assigns new DataContext to every new session created within the application.
ServletConfiguration must be configured in web.xml deployment
descriptor as a listener of context and session events:
<listener>
<listener-class>org.objectstyle.cayenne.conf.ServletConfiguration</listener-class>
</listener>
Note that to set ServletConfiguration as a listener of web application events,
you must use servlet containers
compatible with Servlet Specification 2.3 (such as Tomcat 4.0). Listeners were only added
to servlet specification in 2.3. If you are using an older container. You will need
to configure Cayenne in you code.
| Nested classes inherited from class org.objectstyle.cayenne.conf.Configuration |
|
| Fields inherited from class org.objectstyle.cayenne.conf.Configuration |
configurationShutdownHook, dataDomains, dataDomainsRef, DEFAULT_CONFIGURATION_CLASS, DEFAULT_DOMAIN_FILE, DEFAULT_LOGGING_PROPS_FILE, domainConfigurationName, ignoringLoadFailures, loadStatus, overrideFactory, resourceLoader, sharedConfiguration |
| Methods inherited from class org.objectstyle.cayenne.conf.Configuration |
addDomain, bootstrapSharedConfiguration, configureCommonLogging, configureCommonLogging, configureLogging, getDataSourceFactory, getDomain, getDomain, getDomainConfigurationName, getDomains, getLoaderDelegate, getLoadStatus, getLoggingLevel, getResourceLoader, getSharedConfiguration, initializeSharedConfiguration, initializeSharedConfiguration, initializeSharedConfiguration, installConfigurationShutdownHook, isIgnoringLoadFailures, isLoggingConfigured, removeDomain, setDataSourceFactory, setDomainConfigurationName, setIgnoringLoadFailures, setLoadStatus, setLoggingConfigured, setLoggingLevel, shutdown, uninstallConfigurationShutdownHook |
DATA_CONTEXT_KEY
public static final java.lang.String DATA_CONTEXT_KEY
- See Also:
- Constant Field Values
ServletConfiguration
public ServletConfiguration()
ServletConfiguration
public ServletConfiguration(javax.servlet.ServletContext context)
getDefaultContext
public static org.objectstyle.cayenne.access.DataContext getDefaultContext(javax.servlet.http.HttpSession s)
- Returns default Cayenne DataContext associated with session
s.
contextInitialized
public void contextInitialized(javax.servlet.ServletContextEvent sce)
- Sets itself as a Cayenne shared Configuration object that can later
be obtained by calling
Configuration.getSharedConfig().
This method is a part of ServletContextListener interface and is called
on application startup.
- Specified by:
contextInitialized in interface javax.servlet.ServletContextListener
contextDestroyed
public void contextDestroyed(javax.servlet.ServletContextEvent sce)
- Currently does nothing. In the future it should close down
any database connections if they wheren't obtained via JNDI.
This method is a part of ServletContextListener interface and is called
on application shutdown.
- Specified by:
contextDestroyed in interface javax.servlet.ServletContextListener
sessionCreated
public void sessionCreated(javax.servlet.http.HttpSessionEvent se)
- Creates and assigns a new data context based on default domain
to the session object associated with this event. This method
is a part of HttpSessionListener interface and is called every time
when a new session is created.
- Specified by:
sessionCreated in interface javax.servlet.http.HttpSessionListener
sessionDestroyed
public void sessionDestroyed(javax.servlet.http.HttpSessionEvent se)
- Does nothing. This method
is a part of HttpSessionListener interface and is called every time
when a session is destroyed.
- Specified by:
sessionDestroyed in interface javax.servlet.http.HttpSessionListener