<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>
@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
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
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
}\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
public TenantBindingConfigReaderImpl getTenantBindingConfigReader() {\r
return tenantBindingConfigReader;\r
}\r
+\r
+\r
}\r
</s:params>\r
</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
//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