From: Aron Roberts Date: Tue, 7 Aug 2012 21:32:06 +0000 (-0700) Subject: CSPACE-5440: Create database indexes during startup within tables not associated... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=25e6b355efc4df1373d57649af057457fbf3c8d1;p=tmp%2Fjakarta-migration.git CSPACE-5440: Create database indexes during startup within tables not associated with any specific tenant. --- diff --git a/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml b/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml index 82019b13b..145584565 100644 --- a/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml +++ b/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml @@ -2813,13 +2813,6 @@ org.collectionspace.services.common.init.AddIndices - - - - - collectionspace_core - updatedat - relations_common subjectcsid,objectcsid diff --git a/services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceServiceContextListener.java b/services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceServiceContextListener.java index d9f857f5a..bb9eb6489 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceServiceContextListener.java +++ b/services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceServiceContextListener.java @@ -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 diff --git a/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java b/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java index 4fc06ff32..a952c592d 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java +++ b/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java @@ -8,10 +8,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.List; -import java.util.UUID; +import java.util.*; import javax.naming.NamingException; import javax.servlet.ServletContext; @@ -23,6 +20,8 @@ import org.collectionspace.services.config.service.InitHandler; import org.collectionspace.services.common.authorization_mgt.AuthorizationCommon; import org.collectionspace.services.common.config.ServicesConfigReaderImpl; import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl; +import org.collectionspace.services.common.init.AddIndices; +import org.collectionspace.services.config.service.InitHandler.Params.Field; import org.collectionspace.services.common.init.IInitHandler; import org.collectionspace.services.common.security.SecurityUtils; import org.collectionspace.services.common.storage.JDBCTools; @@ -206,6 +205,36 @@ public class ServiceMain { } } } + + /** + * Create required indices (aka indexes) in database tables not associated + * with any specific tenant. + * + * @throws Exception + */ + void createRequiredIndices() throws Exception { + DataSource dataSource = JDBCTools.getDataSource(JDBCTools.NUXEO_REPOSITORY_NAME); + + final String COLLECTIONSPACE_CORE_TABLE_NAME = "collectionspace_core"; + final String NUXEO_FULLTEXT_TABLE_NAME = "fulltext"; + final String NUXEO_HIERARCHY_TABLE_NAME = "hierarchy"; + + Map indexableFields = new HashMap(); + indexableFields.put("tenantid", COLLECTIONSPACE_CORE_TABLE_NAME); + indexableFields.put("updatedat", COLLECTIONSPACE_CORE_TABLE_NAME); + indexableFields.put("jobid", NUXEO_FULLTEXT_TABLE_NAME); + indexableFields.put("name", NUXEO_HIERARCHY_TABLE_NAME); + + AddIndices addindices = new AddIndices(); + for (Map.Entry entry : indexableFields.entrySet()) { + List fields = new ArrayList(); + Field field = new Field(); + field.setTable(entry.getValue()); + field.setCol(entry.getKey()); + fields.add(field); + addindices.onRepositoryInitialized(dataSource, null, fields, null); + } + } public void firePostInitHandlers() throws Exception { DataSource dataSource = JDBCTools.getDataSource(JDBCTools.NUXEO_REPOSITORY_NAME); @@ -345,4 +374,6 @@ public class ServiceMain { public TenantBindingConfigReaderImpl getTenantBindingConfigReader() { return tenantBindingConfigReader; } + + } diff --git a/services/common/src/main/java/org/collectionspace/services/common/init/AddIndices.java b/services/common/src/main/java/org/collectionspace/services/common/init/AddIndices.java index 6e62f1416..58b76e681 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/init/AddIndices.java +++ b/services/common/src/main/java/org/collectionspace/services/common/init/AddIndices.java @@ -74,14 +74,15 @@ import org.slf4j.LoggerFactory; </s:params> </s:initHandler> * - * $LastChangedRevision$ + * $LastChangedRevision$4 * $LastChangedDate$ */ public class AddIndices extends InitHandler implements IInitHandler { final Logger logger = LoggerFactory.getLogger(AddIndices.class); - private final static String INDEX_SUFFIX = "_idx"; private final static String INDEX_SEP = "_"; + private final static String INDEX_SUFFIX = INDEX_SEP + "idx"; + /** See the class javadoc for this class: it shows the syntax supported in the configuration params. */ @@ -93,8 +94,10 @@ public class AddIndices extends InitHandler implements IInitHandler { //todo: all post-init tasks for services, or delegate to services that override. int rows = 0; String sql = ""; - logger.info("Creating indicies, as needed, for designated fields in " + sbt.getName() - + " for repository domain " + sbt.getRepositoryDomain().trim() + "..."); + if (logger.isInfoEnabled() && sbt != null) { + logger.info("Creating indicies, as needed, for designated fields in " + sbt.getName() + + " for repository domain " + sbt.getRepositoryDomain().trim() + "..."); + } for (Field field : fields) { String tableName = field.getTable();