1212import com .marklogic .mgmt .viewschemas .ViewSchemaManager ;
1313
1414/**
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.
1822 */
1923public class DeployViewSchemasCommand extends AbstractResourceCommand {
2024
25+ private String databaseIdOrName ;
26+ private String viewSchemasPath = "view-schemas" ;
27+
2128 public DeployViewSchemasCommand () {
2229 // Don't need to delete anything, as view-schemas all live in a database
2330 setDeleteResourcesOnUndo (false );
@@ -26,12 +33,13 @@ public DeployViewSchemasCommand() {
2633
2734 @ Override
2835 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 ) };
3037 }
3138
3239 @ Override
3340 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 );
3543 }
3644
3745 @ Override
@@ -41,12 +49,19 @@ protected void afterResourceSaved(ResourceManager mgr, CommandContext context, F
4149 String viewSchemaName = parser .getPayloadFieldValue (receipt .getPayload (), "view-schema-name" );
4250 File viewDir = new File (resourceFile .getParentFile (), viewSchemaName + "-views" );
4351 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 );
4654 for (File viewFile : listFilesInDirectory (viewDir )) {
4755 saveResource (viewMgr , context , viewFile );
4856 }
4957 }
5058 }
5159
60+ public void setDatabaseIdOrName (String databaseIdOrName ) {
61+ this .databaseIdOrName = databaseIdOrName ;
62+ }
63+
64+ public void setViewSchemasPath (String viewSchemasPath ) {
65+ this .viewSchemasPath = viewSchemasPath ;
66+ }
5267}
0 commit comments