Importing Items
You can import models and files into a Model Manager database from either the file system or another database. When importing a file from the file system, the source location can be specified using either a regular file system path or a file scheme path. You can also choose to either create a new item or update an existing item in the target database.
File Schemes and File Handling in the Application Builder Reference Manual
Examples
Import an MPH file as a new model in the database.
String filePath = "C:\\My Models\\my_model.mph";
String title = "My Model";
ModelItemVersion version = database
  .defaultRepository()
  .defaultBranch()
  .saveNewModel(filePath, title, "Imported a new model");
Update an existing model on some branch from an MPH file.
String filePath = "C:\\My Models\\my_model.mph";
UpdateModelItemParamGenerator p = DatabaseApiUtil.param()
  .forUpdateModel()
  .withSourceLocation(filePath);
 
// The itemKey variable is initialized elsewhere.
ModelItemVersion version = branch
  .modelByKey(itemKey)
  .update(p, "Updated model from MPH file.");
Import a whole sequence of MPH files as versions of the same model.
String[] paths = {"C:\\my-model\\v1.mph", "C:\\my-model\\v2.mph",
  "C:\\my-model\\v3.mph", "C:\\my-model\\v4.mph"};
 
ModelItemVersion firstVersion = branch
  .saveNewModel(paths[0], "My Model", null);
ItemKey itemKey = firstVersion.itemKey();
 
// Update the model item from the remaining MPH files.
for (int i = 1; i < paths.length; i++) {
  UpdateModelItemParamGenerator p = DatabaseApiUtil.param()
    .forUpdateModel()
    .withSourceLocation(paths[i])
    .withIgnoreConflicts();
  branch.modelByKey(itemKey).update(p, null);
}
If the source MPH files were exported from model versions in some other database, you can use the withIgnoreConflicts method on the parameter generator interface to ignore the inevitable save conflict with the latest version in the database.
Import a geometry stored in the COMSOL native CAD format mphbin.
String filePath = "C:\\my_geometry.mphbin";
 
// Pass null for the title argument to automatically infer the title
// from the filename.
FileItemVersion version = branch
  .saveNewFile(filePath, null, "Imported CAD data.");
Import a CAD assembly with external component files as a fileset by specifying a directory as the source.
String filepath = "C:\\My CAD files";
 
// The title is required since we are importing multiple file
// resources, in which case the choice of filename is ambiguous.
FileItemVersion version = branch
  .saveNewFile(filePath, "My CAD Assembly", null);
Import a file version from a source database to a target database.
// The sourceDatabaseKey and sourceItemVersionKey variables are
// initialized elsewhere.
SaveFileItemParamGenerator p = DatabaseApiUtil.param()
  .forSaveFile()
  .withSourceDatabaseKey(sourceDatabaseKey)
  .withSourceItemVersionKey(sourceItemVersionKey);
FileItemVersion version = branch.saveFile(p, null);
Save a file version using the temp file scheme.
DatabaseApiParamGenerators param = DatabaseApiUtil.param();
SourceFileParamGenerator p1 = param
  .forSourceFile()
  .withLocationModel(model.tag())
  .withLocation("temp:///my_table_data.txt");
SaveFileItemParamGenerator p2 = param
  .forSaveFile()
  .withSourceFiles(p1);
FileItemVersion version = branch.saveFile(p2, null);
The temp file scheme requires that the model tag identifier of a model is provided. That model implicitly specifies the root directory path for the temporary files on the file system.