Sample code for extending the schema in the property extension repository

Use the sample code snippet and data graphs to extend the schema in the property extension repository.

The following sample code snippet and data graphs show how to add the property, age, to the PersonAccount entity type, and extend the schema in the property extension repository, by using the extensionPropertySchema data object. The property extension repository must be configured before you can use extensionPropertySchema.

Prerequisites

Ensure that you have read the information and completed the steps described in the topic, Programming prerequisites, including the section, Extending property schema, which has information about propertySchema and extensionPropertySchema data objects and lists the valid syntax for property data types.

Sample code

Add the following code snippet to your application code and replace the variables with the actual values that you want to use.

// Get a root data object. The rest of the object tree would be built under it
DataObject root = SDOHelper.createRootDataObject();
// Create a new "schema" object under root
// This object will contain the details of the schema modifications that need to be made
DataObject schema = root.createDataObject(SchemaConstants.DO_SCHEMA);
// Create a property schema data object under the schema object created earlier
// Note: To ensure that the property is also added into the extension repository
// use the Extension Property Schema instead of the simple Property Schema
DataObject propertySchema = schema.createDataObject(SchemaConstants.DO_EXTENSION_PROPERTY_SCHEMA);
// Set the value for the property name
propertySchema.setString(SchemaConstants.PROP_PROPERTY_NAME, "age");
// Set the namespace for the property
// As here we are defining the property in the default namespace, 
// we do not need to define the namespace prefix
// Note: Adding of property in default namespace is only possible when the VMM is using "dynamicModel"
propertySchema.setString(SchemaConstants.PROP_NS_URI, SchemaConstants.WIM_NS_URI);
// Specify if the property is multi-valued (if it is multi-valued, its type must be List)
propertySchema.setBoolean(SchemaConstants.PROP_MULTI_VALUED, false);
// Specify the data type of the property
// Data types can be simple like boolean, int, float, double, String
// or special like Address, Person, Group, etc.
propertySchema.setString(SchemaConstants.PROP_DATA_TYPE, SchemaConstants.DATA_TYPE_INT);
// Get the list of entity types to which this property needs to be added and
// add the applicable entity type names (here "PersonAccount") to the list fetched previously
propertySchema.getList(SchemaConstants.PROP_APPLICABLE_ENTITY_TYPE_NAMES).add(Service.DO_PERSON_ACCOUNT);
// Invoke the create schema
root = service.createSchema(root);

You can use the deleteIdMgrPropertyExtensionEntityData wsadmin command to delete property data from the property extension repository.

Input and output data graphs

Input data graph for adding property:

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:sdo="commonj.sdo"
    xmlns:wim="http://www.ibm.com/websphere/wim">
  <wim:Root>
    <wim:schema>
      <wim:extensionPropertySchema nsURI="http://www.ibm.com/websphere/wim" dataType="Int"
          multiValued="false" propertyName="age">
        <wim:applicableEntityTypeNames>PersonAccount</wim:applicableEntityTypeNames>
      </wim:extensionPropertySchema>
    </wim:schema>
  </wim:Root>
</sdo:datagraph>

Output data graph after adding property:

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:sdo="commonj.sdo"
    xmlns:wim="http://www.ibm.com/websphere/wim">
  <wim:Root>
    <wim:schema>
      <wim:extensionPropertySchema nsURI="http://www.ibm.com/websphere/wim" dataType="Int"
          multiValued="false" propertyName="age">
        <wim:applicableEntityTypeNames>PersonAccount</wim:applicableEntityTypeNames>
      </wim:extensionPropertySchema>
    </wim:schema>
  </wim:Root>
</sdo:datagraph>

Icon that indicates the type of topic Reference topic



Timestamp icon Last updated: March 6, 2017 0:20
File name: samplecodeforextendingtheschemainpropertyextensionrepository.html