From 6311342cbd79e0203fe5837dc647eaa059d36689 Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Fri, 7 Jan 2011 01:13:02 +0000 Subject: [PATCH] CSPACE-2496: Trivial cleanup in early Init Handler code and comments, including removing verbose log statements during init. --- .../services/common/init/AddIndices.java | 34 +++++++++---------- .../services/common/init/IInitHandler.java | 4 +-- .../services/common/init/InitHandler.java | 17 ++++++++-- .../common/init/MakeLargeTextFields.java | 18 +++------- 4 files changed, 37 insertions(+), 36 deletions(-) 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 d48ad84bd..018e7082b 100755 --- 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 @@ -35,27 +35,27 @@ import java.util.List; public class AddIndices extends InitHandler implements IInitHandler { final Logger logger = LoggerFactory.getLogger(AddIndices.class); + public void onRepositoryInitialized(ServiceBindingType sbt, List fields, List properties) throws Exception { - //todo: all post-init tasks for services, or delegate to services that override. - System.out.println("\r\n\r\n~~~~~~~~~~~~~ in AddIndices.onRepositoryInitialized with ServiceBindingType: "+sbt); + //todo: all post-init tasks for services, or delegate to services that override. // call something like this: - ResultSet rs = null; - try { - String addIndex_SQL = "UPDATE TABLE ADD KEY `tablename`.`id`..."; - rs = executeQuery(addIndex_SQL); - if (rs != null){ - // ..... + int rows = 0; + for (Field field : fields) { + try { + // MySQL + String addIndex_SQL = "CREATE INDEX " + field.getCol() + "_idx ON " + field.getTable() + " (" + field.getCol() + ")"; + rows = executeUpdate(addIndex_SQL); + } catch (Exception e) { + throw e; } - } catch (Exception e){ - throw e; - } finally { - closeResultSet(rs); - } - //call something like this: services.common.storage.DBUtils.addIndex(String tablename, String fields[]); - //for every field that has an authRef, do ... - // --> Connection conn = getConnection(); - //see parameter that you need for adding indices to SQL. + //call something like this: services.common.storage.DBUtils.addIndex(String tablename, String fields[]); + //for every field that has an authRef, do ... + // --> Connection conn = getConnection(); + //see parameter that you need for adding indices to SQL. + + } } + } diff --git a/services/common/src/main/java/org/collectionspace/services/common/init/IInitHandler.java b/services/common/src/main/java/org/collectionspace/services/common/init/IInitHandler.java index b4ee4ef39..7a7483e25 100755 --- a/services/common/src/main/java/org/collectionspace/services/common/init/IInitHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/common/init/IInitHandler.java @@ -1,6 +1,5 @@ package org.collectionspace.services.common.init; -import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.service.ServiceBindingType; import org.collectionspace.services.common.service.InitHandler.Params.Field; import org.collectionspace.services.common.service.InitHandler.Params.Property; @@ -12,6 +11,7 @@ import java.util.List; * $LastChangedRevision: $ * $LastChangedDate: $ */ + public interface IInitHandler { - public void onRepositoryInitialized(ServiceBindingType sbt, List fields, List property) throws Exception; + public void onRepositoryInitialized(ServiceBindingType sbt, List fields, List property) throws Exception; } diff --git a/services/common/src/main/java/org/collectionspace/services/common/init/InitHandler.java b/services/common/src/main/java/org/collectionspace/services/common/init/InitHandler.java index ce2fa4ff9..fc0f40880 100755 --- a/services/common/src/main/java/org/collectionspace/services/common/init/InitHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/common/init/InitHandler.java @@ -17,7 +17,6 @@ */ package org.collectionspace.services.common.init; -import org.collectionspace.services.common.ServiceMain; import org.collectionspace.services.common.storage.JDBCTools; import org.collectionspace.services.common.service.ServiceBindingType; import org.collectionspace.services.common.service.InitHandler.Params.Field; @@ -33,14 +32,26 @@ import java.util.List; * some action on the event onRepositoryInitialized(), such as sending JDBC * calls to the repository to add indices, etc. * @author Laramie + * $LastChangedRevision: $ + * $LastChangedDate: $ */ public class InitHandler implements IInitHandler { final Logger logger = LoggerFactory.getLogger(InitHandler.class); + /** + * Callback procedure for performing post-initialization actions. + * + * See org.collectionspace.services.common.init.AddIndices for an implementation example. + * + * @param sbt a service binding type. + * @param fields A list of fields and their attributes. + * @param properties A properties bag for additional properties. + * @throws Exception + */ + @Override public void onRepositoryInitialized(ServiceBindingType sbt, List fields, List properties) throws Exception { - // see org.collectionspace.services.common.init.AddIndices for a real implementation example. - System.out.println("\r\n\r\n~~~~~~~~~~~~~ in InitHandler.onRepositoryInitialized with ServiceBindingType: " + sbt); + for (Field field : fields) { System.out.println("InitHandler.fields:" + "\r\n col: " + field.getCol() diff --git a/services/common/src/main/java/org/collectionspace/services/common/init/MakeLargeTextFields.java b/services/common/src/main/java/org/collectionspace/services/common/init/MakeLargeTextFields.java index 22591e0a0..549106f7a 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/init/MakeLargeTextFields.java +++ b/services/common/src/main/java/org/collectionspace/services/common/init/MakeLargeTextFields.java @@ -40,30 +40,20 @@ public class MakeLargeTextFields extends InitHandler implements IInitHandler { final Logger logger = LoggerFactory.getLogger(MakeLargeTextFields.class); + @Override public void onRepositoryInitialized(ServiceBindingType sbt, List fields, List properties) throws Exception { - //todo: all post-init tasks for services, or delegate to services that override. - System.out.println("\r\n\r\n~~~~~~~~~~~~~ in MakeLargeTextFields.onRepositoryInitialized with ServiceBindingType: "+sbt); - - String tableName = "nuxeo.collectionobjects_common_comments"; - // String columnName = "item"; - String columnDataType = "TEXT"; - + //todo: all post-init tasks for services, or delegate to services that override. int rows = 0; try { for (Field field : fields) { // MySQL String sql = "ALTER TABLE " + field.getTable() + " MODIFY COLUMN " + field.getCol() + " " + field.getType(); // PostgreSQL - // String sql = "ALTER TABLE " + tableName + " ALTER COLUMN " + columnName + " TYPE " + columnDataType; + // String sql = "ALTER TABLE " + field.getTable() + " ALTER COLUMN " + field.getCol() + " " + field.getType(); rows = executeUpdate(sql); } - } catch (Exception e){ + } catch (Exception e) { throw e; } - //call something like this: services.common.storage.DBUtils.addIndex(String tablename, String fields[]); - //for every field that has an authRef, do ... - // --> Connection conn = getConnection(); - //see parameter that you need for adding indices to SQL. - } } -- 2.47.3