]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5440: Create database indexes during startup within tables not associated...
authorAron Roberts <aron@socrates.berkeley.edu>
Tue, 7 Aug 2012 21:32:06 +0000 (14:32 -0700)
committerAron Roberts <aron@socrates.berkeley.edu>
Tue, 7 Aug 2012 21:32:06 +0000 (14:32 -0700)
services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml
services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceServiceContextListener.java
services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java
services/common/src/main/java/org/collectionspace/services/common/init/AddIndices.java

index 82019b13b9a988cb7f4ae14c9ede6d8fd8f5c90b..1455845659c78238026ed27e48279637aec8f173 100644 (file)
             <service:initHandler xmlns:service="http://collectionspace.org/services/config/service">
                 <service:classname>org.collectionspace.services.common.init.AddIndices</service:classname>
                 <service:params>
-                    <!-- The database index that is to be created for the ubiquitious updatedAt field -->
-                    <!-- in collectionspace_core is configured here in the Relation -->
-                    <!-- service, as it is a core service that will be reliably present. -->
-                    <service:field>
-                        <service:table>collectionspace_core</service:table>
-                        <service:col>updatedat</service:col>
-                    </service:field>
                     <service:field>
                         <service:table>relations_common</service:table>
                         <service:param>subjectcsid,objectcsid</service:param>
index d9f857f5a36adfc1a0f894c813b3071fe079271b..bb9eb648956b20250f53c65915a9470dc77dc202 100644 (file)
@@ -15,21 +15,24 @@ public class CollectionSpaceServiceContextListener implements ServletContextList
 
     @Override
     public void contextInitialized(ServletContextEvent event) {
-        try {          
-               //
-               // Initialize/start the Nuxeo EP server instance and create/retrieve the service workspaces
-               //
-               ServletContext servletContext = event.getServletContext();
+        try {            
+            //
+            // Initialize/start the Nuxeo EP server instance and create/retrieve the service workspaces
+            //
+            ServletContext servletContext = event.getServletContext();
             ServiceMain svcMain = ServiceMain.getInstance(servletContext);
             
             svcMain.retrieveAllWorkspaceIds();
             
-               //
-               // Invoke all post-initialization handlers, passing in a DataSource instance of the Nuxeo db.
-               // Typically, these handlers modify column types and add indexes to the Nuxeo db schema.
-               //
-               svcMain.firePostInitHandlers();
-                       
+            // Create required indexes / indices in tables not associated
+            // with any specific tenant.
+            svcMain.createRequiredIndices();
+            //
+            // Invoke all post-initialization handlers, passing in a DataSource instance of the Nuxeo db.
+            // Typically, these handlers modify column types and add indexes to the Nuxeo db schema.
+            //
+            svcMain.firePostInitHandlers();
+                        
         } catch (Throwable e) {
             e.printStackTrace();
             //fail here
index 4fc06ff326e0181baec2d1d19af5eb6ec5132bd9..a952c592d46ab22c12235db92ec4dc1595da21af 100644 (file)
@@ -8,10 +8,7 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;\r
 import java.sql.SQLException;\r
 import java.sql.Statement;\r
-import java.util.ArrayList;\r
-import java.util.Hashtable;\r
-import java.util.List;\r
-import java.util.UUID;\r
+import java.util.*;\r
 \r
 import javax.naming.NamingException;\r
 import javax.servlet.ServletContext;\r
@@ -23,6 +20,8 @@ import org.collectionspace.services.config.service.InitHandler;
 import org.collectionspace.services.common.authorization_mgt.AuthorizationCommon;\r
 import org.collectionspace.services.common.config.ServicesConfigReaderImpl;\r
 import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;\r
+import org.collectionspace.services.common.init.AddIndices;\r
+import org.collectionspace.services.config.service.InitHandler.Params.Field;\r
 import org.collectionspace.services.common.init.IInitHandler;\r
 import org.collectionspace.services.common.security.SecurityUtils;\r
 import org.collectionspace.services.common.storage.JDBCTools;\r
@@ -206,6 +205,36 @@ public class ServiceMain {
             }\r
         }\r
     }\r
+    \r
+    /**\r
+     * Create required indices (aka indexes) in database tables not associated\r
+     * with any specific tenant.\r
+     * \r
+     * @throws Exception \r
+     */\r
+    void createRequiredIndices() throws Exception {\r
+         DataSource dataSource = JDBCTools.getDataSource(JDBCTools.NUXEO_REPOSITORY_NAME);\r
+                   \r
+         final String COLLECTIONSPACE_CORE_TABLE_NAME = "collectionspace_core";\r
+         final String NUXEO_FULLTEXT_TABLE_NAME = "fulltext";\r
+         final String NUXEO_HIERARCHY_TABLE_NAME = "hierarchy";\r
+         \r
+         Map<String,String> indexableFields = new HashMap<String,String>();\r
+         indexableFields.put("tenantid", COLLECTIONSPACE_CORE_TABLE_NAME);\r
+         indexableFields.put("updatedat", COLLECTIONSPACE_CORE_TABLE_NAME);\r
+         indexableFields.put("jobid", NUXEO_FULLTEXT_TABLE_NAME);\r
+         indexableFields.put("name", NUXEO_HIERARCHY_TABLE_NAME);\r
+       \r
+         AddIndices addindices = new AddIndices();\r
+         for (Map.Entry<String,String> entry : indexableFields.entrySet()) {\r
+             List<Field> fields = new ArrayList<Field>();\r
+             Field field = new Field();\r
+             field.setTable(entry.getValue());\r
+             field.setCol(entry.getKey());\r
+             fields.add(field);\r
+             addindices.onRepositoryInitialized(dataSource, null, fields, null);\r
+         }\r
+    }\r
 \r
     public void firePostInitHandlers() throws Exception {\r
        DataSource dataSource = JDBCTools.getDataSource(JDBCTools.NUXEO_REPOSITORY_NAME);\r
@@ -345,4 +374,6 @@ public class ServiceMain {
     public TenantBindingConfigReaderImpl getTenantBindingConfigReader() {\r
         return tenantBindingConfigReader;\r
     }\r
+\r
+\r
 }\r
index 6e62f1416f8b82db851d4c7a81bfb0509f3a544e..58b76e681635c7d9cf39bcf08903aedd8e94a5c3 100644 (file)
@@ -74,14 +74,15 @@ import org.slf4j.LoggerFactory;
                 &lt;/s:params>\r
             &lt;/s:initHandler>\r
  *\r
- * $LastChangedRevision$\r
+ * $LastChangedRevision$4\r
  * $LastChangedDate$\r
  */\r
 public class AddIndices extends InitHandler implements IInitHandler {\r
 \r
     final Logger logger = LoggerFactory.getLogger(AddIndices.class);\r
-    private final static String INDEX_SUFFIX = "_idx";\r
     private final static String INDEX_SEP = "_";\r
+    private final static String INDEX_SUFFIX = INDEX_SEP + "idx";\r
+\r
 \r
     /** See the class javadoc for this class: it shows the syntax supported in the configuration params.\r
      */\r
@@ -93,8 +94,10 @@ public class AddIndices extends InitHandler implements IInitHandler {
         //todo: all post-init tasks for services, or delegate to services that override.\r
         int rows = 0;\r
         String sql = "";\r
-        logger.info("Creating indicies, as needed, for designated fields in " + sbt.getName()\r
-                + " for repository domain " + sbt.getRepositoryDomain().trim() + "...");\r
+        if (logger.isInfoEnabled() && sbt != null) {\r
+            logger.info("Creating indicies, as needed, for designated fields in " + sbt.getName()\r
+                    + " for repository domain " + sbt.getRepositoryDomain().trim() + "...");\r
+        }\r
 \r
         for (Field field : fields) {\r
             String tableName = field.getTable();\r