]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
794aa11e42fa8edca3fb9f1417b9dcc048f9a2c7
[tmp/jakarta-migration.git] /
1 /**
2  * Copyright 2009 University of California at Berkeley
3  */
4 package org.collectionspace.services.common;
5
6 import javax.servlet.ServletContext;
7 import javax.servlet.ServletContextEvent;
8 import javax.servlet.ServletContextListener;
9
10 import org.collectionspace.services.common.storage.jpa.JpaStorageUtils;
11
12 /**
13  * CollectionSpaceServiceContextListener is a ServletContextListener that helps initialize
14  * the services layer at deployment and undeployment times
15  */
16 public class CollectionSpaceServiceContextListener implements ServletContextListener {
17
18     @Override
19     public void contextInitialized(ServletContextEvent event) {
20         try {            
21             //
22             // Initialize/start the Nuxeo EP server instance and create/retrieve the service workspaces
23             //
24             ServletContext servletContext = event.getServletContext();
25             ServiceMain svcMain = ServiceMain.getInstance(servletContext);
26             
27             svcMain.retrieveAllWorkspaceIds();
28             
29             // Create required indexes (aka indices) in tables not associated
30             // with any specific tenant.
31             svcMain.createRequiredIndices();
32             //
33             // Invoke all post-initialization handlers, passing in a DataSource instance of the Nuxeo db.
34             // Typically, these handlers modify column types and add indexes to the Nuxeo db schema.
35             //
36             svcMain.firePostInitHandlers();
37                         
38         } catch (Throwable e) {
39             e.printStackTrace();
40             //fail here
41             System.err.println("[ERROR] The CollectionSpace Services could not initialize.  Please see the log files for details.");
42             throw new RuntimeException(e);
43         }
44     }
45
46     @Override
47     public void contextDestroyed(ServletContextEvent event) {
48         //ServiceMain.getInstance().release();
49         JpaStorageUtils.releaseEntityManagerFactories();
50     }
51 }