12
12
import com .marklogic .mgmt .viewschemas .ViewSchemaManager ;
13
13
14
14
/**
15
- * So for a given view-schema resource, after it's been processed, we'll check for a (name)-views folder in the
16
- * view-schemas folder. If it exists, we'll process each file in the directory. We don't need to do anything on undeploy
17
- * fortunately.
15
+ * Processes each file in the view-schemas directory. For each one, then checks for a (view schema name)-views
16
+ * directory in the view-schemas directory. If it exists, each file in that directory is processed as a view.
17
+ *
18
+ * This command defaults to storing view schemas and views in the schemas database associated with the default
19
+ * content database. This can be overridden by setting the "databaseIdOrName" property. Unfortunately, this does
20
+ * not yet allow for multiple databases to have view schemas. But you can achieve that by using multiple instances
21
+ * of this class, each with a different view schemas path, which can be set via setViewSchemasPath.
18
22
*/
19
23
public class DeployViewSchemasCommand extends AbstractResourceCommand {
20
24
25
+ private String databaseIdOrName ;
26
+ private String viewSchemasPath = "view-schemas" ;
27
+
21
28
public DeployViewSchemasCommand () {
22
29
// Don't need to delete anything, as view-schemas all live in a database
23
30
setDeleteResourcesOnUndo (false );
@@ -26,12 +33,13 @@ public DeployViewSchemasCommand() {
26
33
27
34
@ Override
28
35
protected File [] getResourceDirs (CommandContext context ) {
29
- return new File [] { new File (context .getAppConfig ().getConfigDir ().getBaseDir (), "view-schemas" ) };
36
+ return new File [] { new File (context .getAppConfig ().getConfigDir ().getBaseDir (), viewSchemasPath ) };
30
37
}
31
38
32
39
@ Override
33
40
protected ResourceManager getResourceManager (CommandContext context ) {
34
- return new ViewSchemaManager (context .getManageClient (), context .getAppConfig ().getContentDatabaseName ());
41
+ String dbName = databaseIdOrName != null ? databaseIdOrName : context .getAppConfig ().getContentDatabaseName ();
42
+ return new ViewSchemaManager (context .getManageClient (), dbName );
35
43
}
36
44
37
45
@ Override
@@ -41,12 +49,19 @@ protected void afterResourceSaved(ResourceManager mgr, CommandContext context, F
41
49
String viewSchemaName = parser .getPayloadFieldValue (receipt .getPayload (), "view-schema-name" );
42
50
File viewDir = new File (resourceFile .getParentFile (), viewSchemaName + "-views" );
43
51
if (viewDir .exists ()) {
44
- ViewManager viewMgr = new ViewManager ( context .getManageClient (), context . getAppConfig ()
45
- . getContentDatabaseName () , viewSchemaName );
52
+ String dbName = databaseIdOrName != null ? databaseIdOrName : context .getAppConfig (). getContentDatabaseName ();
53
+ ViewManager viewMgr = new ViewManager ( context . getManageClient (), dbName , viewSchemaName );
46
54
for (File viewFile : listFilesInDirectory (viewDir )) {
47
55
saveResource (viewMgr , context , viewFile );
48
56
}
49
57
}
50
58
}
51
59
60
+ public void setDatabaseIdOrName (String databaseIdOrName ) {
61
+ this .databaseIdOrName = databaseIdOrName ;
62
+ }
63
+
64
+ public void setViewSchemasPath (String viewSchemasPath ) {
65
+ this .viewSchemasPath = viewSchemasPath ;
66
+ }
52
67
}
0 commit comments