Managing the model

Model methods manage objects in the Common Data Model. You can use the model methods to add, delete, and update objects within the Common Data Model. You can also use the methods to compare objects, and to rebuild the derived data, such as dependencies, relationships and data consolidation.

Table 1 describes the model methods you can use.

Table 1. Model management methods
Method Description

add(ModelObject[] obj, Guid mss)

Add a new object to the database.

Note: This method cannot be used to add GroupingPattern or Selector model objects. It throws ApiException when any of the provided objects is of the GroupingPattern or Selector type. Use GroupingPattern API for all operations on GroupingPatterns or selectors.

addArrayElements(Guid object, String attrName, Guid[] elements, Guid mss)

Add the elements to the named array of the specified object without fetching either the object or the array.

compare(ModelObject left, ModelObject[] right, CompareOptions opts)

compare(ObjectRef obj1, ObjectRef[] objs, CompareOptions opts)

Compare a model object (or golden master) against a set of objects.

delete(Guid[] guids, Guid mss)

delete(ModelObject[] obj, Guid mss)

Delete the objects specified by the GUID from the database and cascade delete all objects contained within the objects in either of the following cases:

  • No Management Software System (MSS) is provided.
  • The object is owned exclusively by the specified MSS.

The object is not deleted when an MMS is provided and the object is owned by another MSS. Instead, the association between the object and MSS is deleted.

When an object is deleted from the TADDM database, all relationships and collection memberships associated with the object are also deleted.

If the specified object is a top-level model object, all contained objects are also removed. For example, when a computer system is removed, the operating system and IP interfaces contained within the object, along with the relationships between the computer system and IP interfaces, are also removed.

Note: This method cannot be used to delete GroupingPattern or Selector model objects. It throws ApiException when any of the provided objects is of the GroupingPattern or Selector type. Use GroupingPattern API for all operations on GroupingPatterns or selectors.

deleteStale(Guid mss, long date)

Note: This method is deprecated.

Delete managed elements and relationships that have not been touched since a specified date. The managed elements and relationships that have an update time stamp less than or equal to the specified date are deleted.

If a stale managed element or relationship is owned by more than one management software system, the managed element or relationship is not deleted from the database. Only the association is deleted between the managed element or relationship and the specified management software system. However, if a stale managed element or relationship is owned only by the specified management software system, the managed element or relationship is deleted from the database. All relationships and collection memberships associated with a deleted managed element are also deleted.

If the specified object is a top-level model object, all contained objects are also removed. For example, when a computer system is removed, the operating system and IP interfaces contained in the object, along with the relationships between the computer system and IP interfaces, are also removed.

Fix Pack
2 refresh(Guid mss, long date)

Delete managed elements and relationships that have not been stored since a specified date. The managed elements and relationships that have an update time stamp less than the specified date are deleted.

If a stale managed element or relationship is owned by more than one management software system, the managed element or relationship is still deleted from the database. All relationships and collection memberships associated with a deleted managed element are also deleted.

If the specified object is a top-level model object, all contained objects are also removed. For example, when a computer system is removed, the operating system and IP interfaces contained in the object, along with the relationships between the computer system and IP interfaces, are also removed.

endBulkload(long bulkloadId)

Mark the end of a bulkload operation. Each caller that calls the startBulkload() method must call endBulkload() to release the lock on the storage subsystem.

exportData(File directoryToWriteTo, long maxFileSize, Guid mss)

Export all objects in the TADDM database to the specified directory, creating files for each object class using the find() method with infinite depth. When maxFileSize bytes are exceeded, a new file is created using a .N extension, with N incremented as required. The format of the output adheres to the XML schema format.

importData(URI source, boolean rebuildTopo, Guid mss)

Convert XML data from the specified source into model objects which are updated within the TADDM database, according to the following rules:

  • When the source is a file, the contents of the single file are read and inserted.
  • When the source is a directory, each file in the directory is imported.
  • When the source is a remote object, such as an HTTP address, each update operates within its own transaction.

Errors roll back the update of the current object only, and the import then proceeds.

rebuildTopology()

Rebuild the TADDM database derived data, such as dependencies, relationships and data consolidation. During this operation, the entire database is locked against updates.

removeArrayElements(Guid object, String attrName, Guid[] elements, Guid mss)

Remove the specified elements of the given object from the named array in the TADDM database without fetching either the object or the array to the client.

startBulkload(long timeoutInSeconds)

Lock the storage subsystem from other changes to the database, including discoveries and synchronizations. You must call this method before performing major updates. The lock remains until the endBulkload() method is called.

update(ModelObject obj, mss)

update(ModelObject[] obj, mss)

Update or insert a model object into the database. Attributes which are set in the source object are merged in the destination, while attributes which are not set are not updated. When an object with the specified type and key does not exist, a new object is created within the database.

Note the following details:

  • The new object must have either its GUID or a key set. When a key refers to a parent object, the parent object must exist. An empty object with only the GUID set is enough to identify a parent.
  • When the source object directly references a GUID, it is the developer's responsibility that the GUID exists in the TADDM database.
  • When the mss GUID is null, the objects are inserted or updated in the TADDM database and no MSS-Object link is updated. When the mss GUID is not null, the MSS-Object link is updated.
  • It might be necessary to rebuild the topology to automatically infer dependencies and explicit relationships for the new object.
  • Arrays are replaced in their entirety.
Note: This method cannot be used to update GroupingPattern or Selector model objects. It throws ApiException when any of the provided objects is of the GroupingPattern or Selector type. Use GroupingPattern API for all operations on GroupingPatterns or selectors.

updateXML(String xml, Guid mss)

Same as update(ModelObject[] obj, mss) except that the objects are represented as an XML string.

Note: This method cannot be used to update GroupingPattern or Selector model objects. It throws ApiException when any of the provided objects is of the GroupingPattern or Selector type. Use GroupingPattern API for all operations on GroupingPatterns or selectors.

Example

This example illustrates how to compare objects.

//Find two comparable objects to compare first.

ModelObject mo[] = api.find(
      "SELECT * FROM SunSPARCUnitaryComputerSystem", 3, null, null);

if (mo != null) {
   if (mo.length > 1) {
      ModelObject mo1 = mo[0];
      ModelObject mo2 = mo[1];

      try {
         System.out.println("Comparing " + mo1.getDisplayName() + 
            " to " + mo2.getDisplayName()); 
      } catch (Exception e) {
         e.printStackTrace();
      }
                    
      // ObjectRef is a simple data structure that contains the GUID and the 
      // version of the object to be compared.

      ObjectRef objectRef2 = new ObjectRef(mo2.getGuid(), 0);
      ComparisonResult result = api.compare(new ObjectRef(mo1.getGuid(), 0),
         new ObjectRef[]{objectRef2},
         new CompareOptions(true));
         handleModel((TreeTableModel)result);
   }
}

public void handleModel(TreeTableModel model) {
   CompareResultRow row = model.getRoot();
   handleRow(model, row, "");
}

private void handleRow(
      TreeTableModel model, CompareResultRow row, String attributeName){
   System.out.println("Handling row " + row);

   int nColumns = model.getColumnCount();

   for (int i = 0; i < nColumns; i++) {
      String columnName = model.getColumnName(i);
      Object value = model.getValueAt(row, i);
      System.out.println("Col Name " + columnName + " value " + value);

      //First column, this is the attributeName
      if (i == 0) {
         if (!"".equals(attributeName)) {
            attributeName = attributeName + ":" + String.valueOf(value);
         } else {
            attributeName = String.valueOf(value);
         }
      }

      // Calculate the column name and persist to db here.
   }

   List children = row.getChildren();

   if (children != null) {
      Iterator it = children.iterator();
      while (it.hasNext()) {
         CompareResultRow resultRow = (CompareResultRow) it.next();  //recurse
         handleRow(model, resultRow, attributeName);
      }
   }
}