XQueries for Retrieving Primary Objects
Primary objects include services, organizations, classificationSchemes, concepts, packages, externalLinks, and instances of user-defined object-types. There are a number of primary object types in the JAXR data model representation of CentraSite database. Also, instances of the user-defined object types become primary objects, since when you add a new type to CentraSite, a respective schema is created that defines the new type as a new doctype to the CentraSite database. Instances of the primary object types are represented as XML documents in the CentraSite database collection.
The sample XQuery to find all organizations in CentraSite, for example, is:
for $organization in collection("CentraSite")/*:organization
return $organization
The document element name pattern *:organization finds all documents with a local-name organization in any namespace. A proper namespace allows the XQuery processor more means of optimization (index utilization, for example), and therefore we enhance the XQuery definition as:
declare namespace jaxr = "http://namespaces.CentraSite.com/Schema/jaxr"
for $organization in collection("CentraSite")/jaxr:organization
return $organization
To find a specific organization, we include a where clause in the above XQuery definition. Note that most of the elements to be retrieved (as the key element holding the unique UDDI key) are also in the JAXR namespace.
declare namespace jaxr = "http://namespaces.CentraSite.com/Schema/jaxr";
for $organization in collection("CentraSite")/jaxr:organization
where $organization/jaxr:key = "uddi:4299de0d-51a4-11de-9115-99700cdcef42"
return $organization
To return a more sophisticated result than just the retrieved element as it is contained in the CentraSite database, define a result structure as the XQuery result and insert the data taken from the element. The next XQuery returns a generated element organization containing the organization's name and its owner . The owner is identified as a user (another primary object type) and is defined by the organization's sub-element owner .
declare namespace jaxr = "http://namespaces.CentraSite.com/Schema/jaxr";
for $organization in collection("CentraSite")/jaxr:organization
where $organization/jaxr:key = "uddi:4299de0d-51a4-11de-9115-99700cdcef42"
return
<organization>
<name> { string(($organization/jaxr:name/jaxr:localString)[1]) } </name>
<owner> {
let $owner := collection("CentraSite")/*:user
[jaxr:key = $organization/jaxr:owner]
return string(($owner/jaxr:name/jaxr:localString)[1])
} </owner>
</organization>
This results in a newly generated element node containing elements for the organization's name and owner as below:
<xq:result xmlns:xq="http://namespaces.softwareag.com/tamino/XQuery/result">
<organization>
<name>Mozart Music GmbH</name>
<owner>INTERNAL\Administrator</owner>
</organization>
</xq:result>
To find a primary object's name, we declare and use a user-defined XQuery function:
declare namespace jaxr = "http://namespaces.CentraSite.com/Schema/jaxr";
declare function local:getName($node as node()) as xs:string {
string(($node/jaxr:name/jaxr:localString)[1])
};
for $organization in collection("CentraSite")/jaxr:organization
where $organization/jaxr:key = "uddi:4299de0d-51a4-11de-9115-99700cdcef42"
return
<organization>
<name> { local:getName($organization) } </name>
<owner> {
let $owner := collection("CentraSite")/*:user
[jaxr:key = $organization/jaxr:owner]
return local:getName($owner)
} </owner>
</organization>