public class AddIndices extends InitHandler implements IInitHandler {\r
\r
final Logger logger = LoggerFactory.getLogger(AddIndices.class);\r
+\r
public void onRepositoryInitialized(ServiceBindingType sbt, List<Field> fields, List<Property> properties) throws Exception {\r
- //todo: all post-init tasks for services, or delegate to services that override.\r
- System.out.println("\r\n\r\n~~~~~~~~~~~~~ in AddIndices.onRepositoryInitialized with ServiceBindingType: "+sbt);\r
+ //todo: all post-init tasks for services, or delegate to services that override.\r
\r
// call something like this:\r
- ResultSet rs = null;\r
- try {\r
- String addIndex_SQL = "UPDATE TABLE ADD KEY `tablename`.`id`...";\r
- rs = executeQuery(addIndex_SQL);\r
- if (rs != null){\r
- // .....\r
+ int rows = 0;\r
+ for (Field field : fields) {\r
+ try {\r
+ // MySQL\r
+ String addIndex_SQL = "CREATE INDEX " + field.getCol() + "_idx ON " + field.getTable() + " (" + field.getCol() + ")";\r
+ rows = executeUpdate(addIndex_SQL);\r
+ } catch (Exception e) {\r
+ throw e;\r
}\r
- } catch (Exception e){\r
- throw e;\r
- } finally {\r
- closeResultSet(rs);\r
- }\r
- //call something like this: services.common.storage.DBUtils.addIndex(String tablename, String fields[]);\r
- //for every field that has an authRef, do ...\r
- // --> Connection conn = getConnection();\r
- //see parameter that you need for adding indices to SQL.\r
\r
+ //call something like this: services.common.storage.DBUtils.addIndex(String tablename, String fields[]);\r
+ //for every field that has an authRef, do ...\r
+ // --> Connection conn = getConnection();\r
+ //see parameter that you need for adding indices to SQL.\r
+\r
+ }\r
}\r
+\r
}\r
package org.collectionspace.services.common.init;\r
\r
-import org.collectionspace.services.common.context.ServiceContext;\r
import org.collectionspace.services.common.service.ServiceBindingType;\r
import org.collectionspace.services.common.service.InitHandler.Params.Field;\r
import org.collectionspace.services.common.service.InitHandler.Params.Property;\r
* $LastChangedRevision: $\r
* $LastChangedDate: $\r
*/\r
+\r
public interface IInitHandler {\r
- public void onRepositoryInitialized(ServiceBindingType sbt, List<Field> fields, List<Property> property) throws Exception;\r
+ public void onRepositoryInitialized(ServiceBindingType sbt, List<Field> fields, List<Property> property) throws Exception;\r
}\r
*/\r
package org.collectionspace.services.common.init;\r
\r
-import org.collectionspace.services.common.ServiceMain;\r
import org.collectionspace.services.common.storage.JDBCTools;\r
import org.collectionspace.services.common.service.ServiceBindingType;\r
import org.collectionspace.services.common.service.InitHandler.Params.Field;\r
* some action on the event onRepositoryInitialized(), such as sending JDBC\r
* calls to the repository to add indices, etc.\r
* @author Laramie\r
+ * $LastChangedRevision: $\r
+ * $LastChangedDate: $\r
*/\r
public class InitHandler implements IInitHandler {\r
\r
final Logger logger = LoggerFactory.getLogger(InitHandler.class);\r
\r
+ /**\r
+ * Callback procedure for performing post-initialization actions.\r
+ *\r
+ * See org.collectionspace.services.common.init.AddIndices for an implementation example.\r
+ *\r
+ * @param sbt a service binding type.\r
+ * @param fields A list of fields and their attributes.\r
+ * @param properties A properties bag for additional properties.\r
+ * @throws Exception\r
+ */\r
+ @Override\r
public void onRepositoryInitialized(ServiceBindingType sbt, List<Field> fields, List<Property> properties) throws Exception {\r
- // see org.collectionspace.services.common.init.AddIndices for a real implementation example.\r
- System.out.println("\r\n\r\n~~~~~~~~~~~~~ in InitHandler.onRepositoryInitialized with ServiceBindingType: " + sbt);\r
+\r
for (Field field : fields) {\r
System.out.println("InitHandler.fields:"\r
+ "\r\n col: " + field.getCol()\r
final Logger logger = LoggerFactory.getLogger(MakeLargeTextFields.class);
+ @Override
public void onRepositoryInitialized(ServiceBindingType sbt, List<Field> fields, List<Property> 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.
-
}
}