Manipulating the CentraSite Model (Registry)

The CentraSite model, also known as the CentraSite registry, is the collection of object type instances (also known as registry objects). As such, it is opposed to the CentraSite meta model, the collection of object types, which provide the model description, or schema.

The model accessor

To read or manipulate the CentraSite model, you need an instance of ROModelAccessor. This model accessor can be obtained with the following piece of code:

ConnectionProvider connProvider = new DefaultConnectionProvider(url, userName, password);
ModelDrivenRegistryFacade facade = new SimpleModelDrivenRegistryFacade(connProvider.getConnection());
ROMetaModelAccessor acc = facade.getMetaModelAccessor();

Reading the model

Reading the model is typically split into two phases:

Performing a query

Queries can be issued by using the standard BusinessQueryManager. To obtain a query manager, use the following snippet:

  acc.getRegistryFacade().getBusinessQueryManager()

However, the recommended method to perform a query is using the CentraSite Query Language with a snippet like the following:

  String query = "DECLARE NAMESPACE ns='SomeNamespace'"
               + "FROM ns:Organization AS o WHERE o.name() LIKE ?";
  List<RegistryObject> objects = acc.executeQuery(query, "abc%");

Reading object attributes

The model accessor provides a set of methods for reading an objects attributes. For example:

  String uniqueKey = acc.getSlotValue("uniqueKey", ro);
  RegistryObject employeeOf = acc.getRelationValue("EmployeeOf", ro);

These examples would read the value of the string attribute "uniqueKey", or the relation attribute "EmployeeOf", respectively. The example assumes that we have an attribute with multiplicity 1. If the attribute may have multiple values, then we should use the following methods:

  Collection<String> emailAddresses = acc.getSlotValues("emailAddress", ro);
  Collection<RegistryObject> orgs = acc.getRelationValues("EmployeeOf", ro);

Manipulating the model

Manipulating the model can mean a multitude of things, including

Creating new objects

The model accessor can be used to create new instances:

  RegistryObject org = acc.createInstance("{SomeNamespace}Organization");

Setting object attributes

Setting object attributes is as simple as reading them:

  RegistryObject ro;
  acc.setSlotValue("uniqueKey", ro, "3298798798");
  acc.setRelationValue("EmployeeOf", ro, targetOrganization);

Again, there are alternative implementations for attributes with multiple values:

  List<String> emailAddresses = Arrays.asList(new String[]{adr1, adr2, adr3});
  List<RegistryObject> orgs = Arrays.asList(new RegistryObject[]{ro1, ro2});
  RegistryObject ro;
  acc.setSlotValues("uniqueKey", ro, emailAddresses);
  acc.setRelationValues("EmployeeOf", ro, orgs);

Performance considerations

The methods presented so far are well suited for single use. In other words, you've got a single object that you would like to create or change one attribute. However, they are comparatively expensive, because any such method includes one or more lookups into the meta model.

For example, the following two lines of code are equivelant:

  acc.getSlotValue("uniqueKey", ro);
  acc.getSlotValue(acc.requireSlot(requireType(ro), "uniqueKey"), ro);

As you can see, the example contains no less that two lookups: The method ROType ROModelAccessor.requireType(RegistryObject) is used to determine the registry objects type in the meta model. Furthermore, the method ROSlot ROModelAccessor.requireSlot(ROType, String) is used to search for an attribute named "uniqueKey".

Multiple updates on a single object

With the above knowledge, have a look at the following snippet:

  String firstSlotValue = acc.getSlotValue("firstSlot", ro);
  String secondSlotValue = acc.getSlotValue("secondSlot", ro);
  String thirdSlotValue = acc.getSlotValue("thirdSlot", ro);

The example contains three lookups for the meta model type of the object ro. We can eliminate two lookups:

  ROType roType = acc.requireObjectType(ro);
  String firstSlotValue = acc.getSlotValue(roType, "firstSlot", ro);
  String secondSlotValue = acc.getSlotValue(roType, "secondSlot", ro);
  String thirdSlotValue = acc.getSlotValue(roType, "thirdSlot", ro);

Updates on a multiple objects

Another example are updates on multiple objects of the same type. Take this example:

  List<RegistryObject> ros;
  for (RegistryObject ro : ros) {
    acc.setSlotValue("firstSlot", ro, "foobar");
  }

The example allows us to eliminate most of the lookups for the object type as well:

  ROType type = acc.requireType(ros.get(0));
  ROSlot slot = acc.requireSlot(type, "firstSlot");
  List<RegistryObject> ros;
  for (RegistryObject ro : ros) {
    acc.setSlotValue(type, slot, ro, "foobar");
  }