用于在属性扩展存储库中扩展模式的样本代码

使用样本代码片段和数据图在属性扩展存储库中扩展模式。

以下样本代码片段和数据图显示如何将属性 age 添加到 PersonAccount 实体类型,并使用 extensionPropertySchema 数据对象在属性扩展存储库中扩展模式。必须首先配置属性扩展存储库,然后您才能使用 extensionPropertySchema。有关更多信息,请阅读 WebSphere Application Server 信息中心中的在联合存储库配置中配置属性扩展存储库

必备条件

确保您已阅读了“编程先决条件”主题(包括“扩展属性模式”部分,其中包含有关 propertySchema 和 extensionPropertySchema 数据对象的信息并列出了属性数据类型的有效语法)中的信息,并完成了其中描述的步骤。

样本代码

请将以下代码片段添加到您的应用程序代码,并将变量替换为您要使用的实际值。

// 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);

您可以使用 deleteIdMgrPropertyExtensionEntityData wsadmin 命令从属性扩展存储库中删除属性数据。有关使用此命令的更多信息,请参阅 WebSphere Application Server 信息中心内的主题 AdminTask 对象的 IdMgrDBSetup 命令组

输入和输出数据图

用于添加属性的输入数据图:

<?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>

添加属性之后的输出数据图:

<?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>


使用条款 | 反馈