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. For more information, read about Configuring a property extension repository in a federated repository configuration in the WebSphere Application Server information center.
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.
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 above 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. For more information about using this command, see the topic IdMgrDBSetup command group for the AdminTask object in the WebSphere Application Server information center.
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>