Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit d4776b6

Browse files
committed
#314 Added factory to abstract how a DeployDatabaseCommand is constructed
1 parent ff51b1f commit d4776b6

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.marklogic.appdeployer.command.databases;
2+
3+
import java.io.File;
4+
5+
public class DefaultDeployDatabaseCommandFactory implements DeployDatabaseCommandFactory {
6+
7+
@Override
8+
public DeployDatabaseCommand newDeployDatabaseCommand(File databaseFile) {
9+
return new DeployDatabaseCommand(databaseFile);
10+
}
11+
12+
}

src/main/java/com/marklogic/appdeployer/command/databases/DeployDatabaseCommand.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ public class DeployDatabaseCommand extends AbstractCommand implements UndoableCo
8484
*/
8585
private Set<String> databasesToNotUndeploy;
8686

87+
private DeployDatabaseCommandFactory deployDatabaseCommandFactory = new DefaultDeployDatabaseCommandFactory();
88+
8789
public DeployDatabaseCommand() {
8890
setExecuteSortOrder(SortOrderConstants.DEPLOY_OTHER_DATABASES);
8991
setUndoSortOrder(SortOrderConstants.DELETE_OTHER_DATABASES);
@@ -169,7 +171,7 @@ protected void addSubDatabases(DatabaseManager dbMgr, CommandContext context, St
169171
List<String> subDbNames = new ArrayList<String>();
170172
for (File f : listFilesInDirectory(subdbDir)) {
171173
logger.info(format("Will process sub database for %s found in file: %s", superDatabaseName, f.getAbsolutePath()));
172-
DeployDatabaseCommand subDbCommand = new DeployDatabaseCommand();
174+
DeployDatabaseCommand subDbCommand = this.deployDatabaseCommandFactory.newDeployDatabaseCommand(null);
173175
subDbCommand.setDatabaseFile(f);
174176
subDbCommand.setSuperDatabaseName(superDatabaseName);
175177
subDbCommand.setSubDatabase(true);
@@ -198,7 +200,7 @@ protected void removeSubDatabases(DatabaseManager dbMgr, CommandContext context,
198200
logger.info("Removing all subdatabases from database: " + superDatabaseName);
199201
dbMgr.detachSubDatabases(superDatabaseName);
200202
for (File f : listFilesInDirectory(subdbDir)) {
201-
DeployDatabaseCommand subDbCommand = new DeployDatabaseCommand();
203+
DeployDatabaseCommand subDbCommand = this.deployDatabaseCommandFactory.newDeployDatabaseCommand(null);
202204
subDbCommand.setDatabaseFile(f);
203205
subDbCommand.setSuperDatabaseName(superDatabaseName);
204206
subDbCommand.setSubDatabase(true);
@@ -445,4 +447,8 @@ public Set<String> getDatabasesToNotUndeploy() {
445447
public void setDatabasesToNotUndeploy(Set<String> databasesToNotUndeploy) {
446448
this.databasesToNotUndeploy = databasesToNotUndeploy;
447449
}
450+
451+
public void setDeployDatabaseCommandFactory(DeployDatabaseCommandFactory deployDatabaseCommandFactory) {
452+
this.deployDatabaseCommandFactory = deployDatabaseCommandFactory;
453+
}
448454
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.marklogic.appdeployer.command.databases;
2+
3+
import java.io.File;
4+
5+
/**
6+
* Abstracts how a DeployDatabaseCommand is instantiated so that Data Hub Framework can provide in its
7+
* own implementation with DHF-specific functionality in it.
8+
*/
9+
public interface DeployDatabaseCommandFactory {
10+
11+
/**
12+
* @param databaseFile can be null
13+
* @return
14+
*/
15+
DeployDatabaseCommand newDeployDatabaseCommand(File databaseFile);
16+
17+
}

src/main/java/com/marklogic/appdeployer/command/databases/DeployOtherDatabasesCommand.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public class DeployOtherDatabasesCommand extends AbstractUndoableCommand {
3636
*/
3737
private Set<String> defaultDatabasesToNotUndeploy = new HashSet<>();
3838

39+
private DeployDatabaseCommandFactory deployDatabaseCommandFactory = new DefaultDeployDatabaseCommandFactory();
40+
3941
public DeployOtherDatabasesCommand() {
4042
this(1);
4143
}
@@ -113,7 +115,7 @@ protected List<DeployDatabaseCommand> buildDatabaseCommands(CommandContext conte
113115
}
114116

115117
protected DeployDatabaseCommand buildDeployDatabaseCommand(File file) {
116-
DeployDatabaseCommand c = new DeployDatabaseCommand(file);
118+
DeployDatabaseCommand c = this.deployDatabaseCommandFactory.newDeployDatabaseCommand(file);
117119
c.setForestsPerHost(getForestsPerHost());
118120
c.setCheckForCustomForests(isCheckForCustomForests());
119121
c.setForestFilename(getForestFilename());
@@ -181,4 +183,8 @@ public Set<String> getDefaultDatabasesToNotUndeploy() {
181183
public void setDefaultDatabasesToNotUndeploy(Set<String> defaultDatabasesToNotUndeploy) {
182184
this.defaultDatabasesToNotUndeploy = defaultDatabasesToNotUndeploy;
183185
}
186+
187+
public void setDeployDatabaseCommandFactory(DeployDatabaseCommandFactory deployDatabaseCommandFactory) {
188+
this.deployDatabaseCommandFactory = deployDatabaseCommandFactory;
189+
}
184190
}

0 commit comments

Comments
 (0)