Advanced Database Operations Using Parameter Objects
The Model Manager API enables you to take further control over database operations using so-called parameter objects. These are objects that specify all available input options governing the corresponding database operation. This is useful, for example, when you want to stray from default settings when creating or updating database objects, or when you need to perform other advanced operations that would be unwieldy to code by providing a long list of disparate arguments to an API method.
The parameter objects are created using a utility returned from the method param on DatabaseApiUtil. For each advanced database operation in the Model Manager API, there is a corresponding method on this utility that returns a so-called parameter generator for the parameter object. This generator has a dual purpose: it is used for specifying all input options and for being passed as argument to the corresponding API method as the parameter object itself.
Syntax
DatabaseApiParamGenerators param = DatabaseApiUtil.param();
 
<method>ParamGenerator generator = param.for<method>();
 
<method>ParamGenerator parameterObject = generator
  .with<parameter-option1>(<parameter-value1>)
  .with<parameter-option2>(<parameter-value2>)
  .with<parameter-option3>(<parameter-value3>);
with <method> corresponding to a method in the Model Manager API, <parameter-optionX> the name of a parameter option, and <parameter-valueX> the value for the parameter option. The parameter generator interface extends the parameter object interface. The parameterObject variable can therefore be passed directly to a method in the API.
Examples
Create a new repository with a custom name for the repository’s initial, default, branch.
CreateRepositoryParamGenerator p = DatabaseApiUtil.param()
  .forCreateRepository()
  .withName("My Repository")
  .withDefaultBranchName("My Main Branch")
  .withCommitComment("Created a new repository.");
 
Repository repository = database.createRepository(p);
Create a new branch from the specific commit that a model version was saved in.
// The modelLocationUri string could have been obtained, for
// example, using Copy Location in the Model Manager workspace.
ModelItemVersion version = api
  .modelVersionByLocationUri(modelLocationUri);
 
CreateBranchParamGenerator p = DatabaseApiUtil.param()
  .forCreateBranch()
  .withName("My Branch")
  .withSourceCommitKey(version.commitKey());
 
Branch branch = version.repository().createBranch(p);
The model version itself is used as an anchor to access the repository in which to create the new branch — see also Navigating a Model Manager Database.
Update settings for the latest version of a model on a branch.
BranchModelItem branchModelItem = version.branchItem();
UpdateModelItemParamGenerator p = DatabaseApiUtil.param()
  .forUpdateModel()
  .withDescription("My model description.")
  .withFilename("my_model.mph");
 
// Passing null for the optional commit comment is allowed.
ModelItemVersion newVersion = branchModelItem.update(p, null);