<service:key>sqlScriptName</service:key>
<service:value>create_id_generators_table.sql</service:value>
</service:property>
+ <service:property>
+ <service:key>sqlScriptName</service:key>
+ <service:value>load_id_generators.sql</service:value>
+ </service:property>
</service:params>
</service:initHandler>
</tenant:serviceBindings>
</service:uriPath>
-->
<service:repositoryDomain xmlns:service="http://collectionspace.org/services/config/service">default-domain</service:repositoryDomain>
- <!-- The following initHandler config block is placed here, rather than in the -->
- <!-- idgenerators service, above, as it appears that we currently can only run -->
- <!-- one initHandler per service - ADR 2012-12-13 -->
- <service:initHandler xmlns:service="http://collectionspace.org/services/config/service">
- <service:classname>org.collectionspace.services.common.init.RunSqlScript</service:classname>
- <service:params>
- <service:property>
- <service:key>sqlScriptName</service:key>
- <service:value>load_id_generators.sql</service:value>
- </service:property>
- </service:params>
- </service:initHandler>
</tenant:serviceBindings>
<!-- end id service meta-data -->
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
+import java.util.ArrayList;
import java.util.List;
import org.collectionspace.services.common.api.Tools;
import org.collectionspace.services.common.storage.JDBCTools;
*/
@Override
public void onRepositoryInitialized(String dataSourceName,
- String repositoryName,
- ServiceBindingType sbt,
- List<Field> fields,
- List<Property> properties) throws Exception {
-
- /*
- if (logger.isInfoEnabled() && sbt != null) {
- logger.info("Running SQL script in " + sbt.getName()
- + " for repository domain " + sbt.getRepositoryDomain().trim() + "...");
- }
- */
+ String repositoryName,
+ ServiceBindingType sbt,
+ List<Field> fields,
+ List<Property> properties) throws Exception {
if (properties == null || properties.isEmpty()) {
logger.warn("No properties were provided to the RunSqlScript init handler.");
logger.warn(CANNOT_PERFORM_TASKS_MESSAGE);
return;
}
-
- String scriptName = getSqlScriptName(properties);
- if (Tools.isBlank(scriptName)) {
- logger.warn("Could not get SQL script name.");
- logger.warn(CANNOT_PERFORM_TASKS_MESSAGE);
- return;
- }
-
- String scriptPath = getSqlScriptPath(dataSourceName, repositoryName, scriptName);
- if (Tools.isBlank(scriptPath)) {
- logger.warn("Could not get path to SQL script.");
+ List<String> scriptNames = getSqlScriptNames(properties);
+ if (scriptNames == null || scriptNames.isEmpty()) {
+ logger.warn("Could not obtain the name of any SQL script to run.");
logger.warn(CANNOT_PERFORM_TASKS_MESSAGE);
return;
}
-
- String scriptContents = getSqlScriptContents(scriptPath);
- if (Tools.isBlank(scriptContents)) {
- logger.warn("Could not get contents of SQL script.");
- logger.warn(CANNOT_PERFORM_TASKS_MESSAGE);
- return;
+ for (String scriptName : scriptNames) {
+ String scriptPath = getSqlScriptPath(dataSourceName, repositoryName, scriptName);
+ if (Tools.isBlank(scriptPath)) {
+ logger.warn("Could not get path to SQL script.");
+ logger.warn(CANNOT_PERFORM_TASKS_MESSAGE);
+ continue;
+ }
+ String scriptContents = getSqlScriptContents(scriptPath);
+ if (Tools.isBlank(scriptContents)) {
+ logger.warn("Could not get contents of SQL script.");
+ logger.warn(CANNOT_PERFORM_TASKS_MESSAGE);
+ continue;
+ }
+ runScript(dataSourceName, repositoryName, scriptContents, scriptPath);
}
-
- runScript(dataSourceName, repositoryName, scriptContents, scriptPath);
}
- private String getSqlScriptName(List<Property> properties) {
+ private List<String> getSqlScriptNames(List<Property> properties) {
String scriptName = "";
+ List<String> scriptNames = new ArrayList<String>();
for (Property property : properties) {
if (property.getKey().equals(SQL_SCRIPT_NAME_PROPERTY)) {
scriptName = property.getValue();
if (Tools.notBlank(scriptName)) {
- break;
+ scriptNames.add(scriptName);
}
}
}
- return scriptName;
+ return scriptNames;
}
private String getSqlScriptPath(String dataSourceName, String repositoryName, String scriptName) throws Exception {