XStreamDB is a native XML database: a database for storing, querying and manipulating XML documents. This reference manual is a specification of the external features of XStreamDB. You can read this manual from start to finish, but more typically you will use it as a reference through its table of contents or text search. If you are just starting out with XStreamDB you may want to look at the User Guide first as it contains more examples than this reference manual. Other documents in the XStreamDB documentation are available from the ReadMe.htm .
The following list contains the end user features of XStreamDB.
| Feature | Description | More Information |
|---|---|---|
| XQuery support | XQuery is an emerging W3C standard for querying databases. XStreamDB supports most of XQuery and also supports additional functionality not currently in the XQuery specification. |
|
| XQuery extensions |
The following list shows features supported in XStreamDB accomplished by extending the XQuery language.
|
|
| Full Text Search | Full text search allows you to search for words within element and attribute content. A full text index with automatic optimization speeds these searches up significantly. | |
| Indexing |
|
|
| Automatic optimization | One or more full text and value indexes are automatically used to optimize AND and OR selections of data. As well, joins, sorts and distinct operations are optimized through value indexes. | |
| Full-featured Java client API | XStreamDB supports multiple servers, each with configuration information and JDBC-like XConnection, XStatement and XResultSet objects. | |
| Concurrent transactional database | XStreamDB is built on a multi-transactional concurrent database storage engine. Transactional features include begin, commit, and rollback with deadlock detection. | |
| Client/Server architecture | The client can be deployed on a separate machine from the server. This allows multiple clients to access one server regardless of the location of clients. As well, clients can be started and stopped without influencing the server. | |
| Web server enabled | XStreamDB is enabled to work well with servlet enabled web and application servers. A simple servlet sample ships with the product. |
|
| User based Security |
XStreamDB has:
|
|
| Schema utilization and support |
Schema utilization and support includes:
|
|
| Product Components |
Describes each of the product components in the package that is released to the customer. |
|
| Remote server Explorer application | Included with XStreamDB is a stand alone explorer application which allows configuration and querying of any XStreamDB database on any server. |
|
| WebDav Server | On top of the XStreamDB resource system is a webdav server that allows you to store and retrieve any kind of content in XStreamDB. | � |
| Exposing Documents as Web Resources | XStreamDB has a resource subsystem which allows the exposure of documents as web resources and the access to these through either WebDav or the XdbWeb web applications. | � |
| Schedulable Hot Backup | Backup is a snapshot as of time T and can be concurrent with other transactions. As well, backup can be scheduled. | � |
XStreamDB is composed of a client side and a server side. The client is a set of Java class libraries (jars) that are accessed by a client application. A client application may be a Swing application, such as the XStreamDB Explorer, it may be a web application or it may be a command line Java application.
The server process, on the other hand, is a self sufficient Java application that can run on any machine. The server process performs all the work of processing XQuery statements, accessing the database and managing transactions, as well as most other XStreamDB features. Client applications communicate to the server through the client libraries which in turn use sockets to communicate to the server.
Described here is the notation used in this document.
This is the extended BNF used to show grammar rules:
These examples use nonterminals, literals and character sets.
Note The Name example below has a character set that is defined elsewhere, at the URL http://www.w3.org/TR/REC-xml-names/#NT-NCName.
RootId::= '/' DatabaseName '/' ShortRootName
DatabaseId ::= '/"Name
DatabaseName ::= Name
ShortRootName ::= Name
Name ::= [http://www.w3.org/TR/REC-xml-names/#NT-NCName]
StringLiteral ::=
('"' (PredefinedEntityRef | CharRef | ('"' '"') | [^"&])* '"') |
("'" (PredefinedEntityRef | CharRef | ("'" "'") | [^'&])* "'")
XStreamDB is an XML DBMS which manages a number of DBMSObjects . These objects are either Configuration Objects or Content Objects . The term DSObject (database system object), or sometimes just Object , is used to refer to these DBMSObjects. There are currently 11 ObjectTypes composed of 8 configuration object types and 3 content object types.
Configuration objects enable the database to contain content, enforce security and do other things a database is expected to do. The configuration objects in XStreamDB are:
The content objects are:
In many cases the binary object is accessed through its proxy Document , which is the document that gives the binary object its name and other meta data.
Each of the eight configuration object types and three content object types listed above make up all the types of DBMSObjects.
The following terms name the kinds of identifiers that refer to objects.
Every DBMSObject has an ObjectId that identifies it uniquely from other objects of the same ObjectType . This name is always a string literal. These ObjectIds are used throughout XStreamDb to refer to the object. Example ObjectIds are:
| Object Type | ObjectId | Local Name |
|---|---|---|
| Current Server | "/" | Not applicable |
| Database | "/MyDb | "MyDb" |
| Root | "/MyDb/MyRoot | "MyRoot" |
| Collection | "/ColRoot/MyCol1/MyCol2..." | "MyCol2" |
| Extent (virtual object) | RootId | CollectionId | Last step in path. |
| Index | "/MyDb/MyRoot/MyIndex" | "MyIndex" |
| Document |
Various Schemes:
|
� |
| Group | "/Doctors" | "Doctors" |
| User | "/Freddy" | "Freddy" |
| Trigger | "/MyDb/MyRoot/MyTrigger" | "MyTrigger" |
| Module | "http://www.bluestream.com/a/b" or "RefDoc". Note: the object ID form is parsable as URI as specified in the XQuery Language Specification. | "http://www.bluestream.com/a/b" |
| Binary | See Document ids above. | � |
| Schema | See Document ids above. | Most often uses the path form:Path: "/ColRo0t/a/b/FAQ.dtd |
The name of an object is not unique across that object type unless that object occurs directly under the server. The name of an object is a local name, which may be ambigous. For example, a root may be named MyRoot, although there may be multiple roots named "MyRoot" in multiple databases. Likewise, a content object may be named foo.xml which may be the same name as another object in another collection. It is the ObjectId that uniquely names an object of a given type.
Content object identity is much more sophiticated than configuration object identity. Some examples of Content object identifiers are above. Below is a table that describes the different identity schemes.
| Mechanism | Description | Notes |
|---|---|---|
| docNum | A system generated integer which is supported inside XStreamDB. | This number is relative to the root. DocNums may be re-used after deletion of the content object, so they are not always a good choice for long lived URIs, but they are OK for foreign key/primary key relationships within the database. |
| guid | A system generated identifier which is generated for each new insert. | This number is universally unique. It makes a good choice for distributed systems that need universal identity. A guid is longer and more expensive to support than a docNum. |
| counterId | A system generated integer which is sequentially generated. | This number is relative to the root. This number is not guaranteed to be sequential but counter at time b will be greater than counter assigned at time a, so the counter does represent a sequence in time, unlike DocNum. |
| fullPath | A string like /a/b/foo.xml. This string is configured by the user by setting a parent collection and a name for the content object. | This identifier is server unique. This identifier is setup by the user but the system ensures that it is unique. |
| docId/docVerId |
A string that qualifies a document according to its database and root as well as its version number. This identifier MUST NOT be persisted and used later as a foreign key or some other form. This is because a restore from backup changes the docId. For persistent keys, use one of the above types. DocNum can be extracted from a DocId, all of the other forms need to be generated and extracted using a function - see below. DocId is, however, used for replace and delete commands. |
For example, "1$BookDB:Book$1-0-0$2" |
Configuration objects are managed as described in the next section.
Document objects are managed through the XStreamDB command language which includes XQuery. This is decribed in further sections.
Binary objects are managed through the Binary management methods in the XConnection API.
The managment of Schema and Resource objects are described as follows:
The XStreamDB database server is configured for normal operations by creating, modifying and dropping the following configuration objects:
The above objects need to be defined and managed by a database administrator before normal production deployment operation of the server commences. The XDBExplorer GUI application offers a user interface to manage these objects. Many of these objects can be managed through the XStreamDB command language. In fact, triggers and stored modules are maintained through the command language only.
This section focuses on the lifecycle of creation, modification and destruction of the above objects, not the use of the objects. The use of the objects, once they are created, is covered in the Basic Command Language and other command language sections.
Configuration operations can only be performed if there are no users currently in an active XConnection transaction involving the database being modified. As well, the transaction doing the configuration statement must only do configuration statements, not mix them with other types of statements. More precisely, there can be no transactions open, including the current one, that have performed operations on the database being modified, where those operations have not been committed - excluding other configuration commands. For example, if a user has a noncommitted transaction which is querying database DB1, then drop database, create root, drop root, create index and drop index will not be possible on DB1 until that active transaction commits.
These BNF definitions are used below in the BNF for the configuration XStreamDB commands . As well, you can consult the machine generated XStreamDB Grammar File .
DatabaseIdStr ::= '"' DatabaseId '"'
RootIdStr ::= '"' RootId '"'
TriggerNameStr ::= '"' TriggerName '"'
TriggerIdStr ::= '"' TriggerId '"'
IndexNameStr ::= '"' IndexName '"'
RootId ::= '/' DatabaseName '/' ShortRootName
DatabaseId ::= '/' DatabaseName
TriggerId ::= '/' DatabaseName '/' RootName '/' TriggerName
DatabaseName ::= Name
RootName ::= Name
TriggerName ::= Name
IndexName ::= Name
SchemaSpec ::= '"' SchemaUri '"' /* basically a schema URI inside a string */
SchemaUri :: = "/SysData/SysSchema/" SchemaSubUri SchemaRootElementName
SchemaSubUri ::= (Name '/')* Name
SchemaRootElementName ::= QName
Name ::= [http://www.w3.org/TR/REC-xml-names/#NT-NCName]
StringLiteral ::=
('"' (PredefinedEntityRef | CharRef | ('"' '"') | [^"&])* '"') |
("'" (PredefinedEntityRef | CharRef | ("'" "'") | [^'&])* "'")
SetMetaData ::= SetMetaData ::= "set" "metadata" ElementExpr+
ElementExpr ::= /* Any expression that renders an XML element. */
Every configuration object has information associated with it - ConfigInfo. In XStreamDB this information has an XML form - a different form for each configuration object. This configuration information is extracted using a getConfigInfo function as described under the configuration functions section. The different ConfigInfo XML is defined in XdbConfigInfo.xsd . An example of much of the ConfigInfo within the containing DBTree is in ExampleDBTree.xml .
The objectType and objectId are defined in the identity section above.
CreateDatabaseStmt ::=
create database
DatabaseIdStr
DropDatabaseStmt ::=
drop database
DatabaseIdStr
Create database creates a named empty database. Drop database removes the named database from the server. Drop database also removes any documents, roots, indexes, resource definitions and triggers for a database.
For example:
create database "/MyDb"
Roots are collections of documents within a database. A root can be accessed in a query using the Root() or collection() functions. A root may or may not have an associated schema. If an alter root command has a SchemaURI and SchemaRootElement, then a Schema of that name must have been previously added to the XStreamDB server and the SchemaRootElement must exist as a global element in that schema. When a root is associated with a schema URI and schema root element, schema validation of documents at insert and replace time will take place automatically. The reason for specifying the schema root element as well as the schema URI is so multi-root element schemas can be restricted to just one schema element in that schema.
Associating a root with a schema URI and schema root element enables a number of schema based features discussed below in the schema section .
create root
RootIdStr (
with schema
SchemaUri)?
alter root
RootIdStr (
with schema
(SchemaUri |
none
))?
drop root
RootIdStr
For example,
create root "/MyDB/MyRoot" with schema /SysData/SysSchema/MySchema.xsd Person
This example creates a new root and associates the schema /SysData/SysSchema/MySchema.xsd and schema root element Person with that root.
Some of these root properties affect the space and performance of roots.
| Feature | Description | Notes |
| counter | Generate an incremental counter value for each document 1..n. This implicitly defines unique value index on the root supporting the counter. | � |
| guid | Generate a guid for each document. Define a unique value index on the root for this guid. Note: The guid must always be enabled before binary content objects can be stored in the root. | � |
Feature enablement will be stored as a propertyList and will be stored with the root collection. For example:
<propertyList> <property name="guid" value="true"/> </propertyList>
Functions to set and get root properties are:
SetRootProperty( $rootId as xs:string, $propName as xs:string, $onoff as xs:string)
GetRootProperty($rootId as xs:string) as element(xsdb:propertyList)
Example:
SetRootProperty("db:root","guid","true")
These functions are also described in the Configuration Functions section .
There are two kinds of indexes in XStreamDB: full text and path indexes. A full text index is associated with a root and automatically indexes every word in the content of every document inserted into that root. A path index, on the other hand, is more selective. You define a path index by specifying a path to specific data you want to index. For example, if you want to index all the FirstName values in a Person document you would construct a path like /Person/FirstName/data(). This indexes all the FirstName data values under a Person element, for all documents inserted into a root.
There is create index syntax for both kinds of index.
CreatePathIndex ::=
create
unique
?
index
IndexName
on
RootIdStr
path
Path
Path ::= '/'Name ('/'Name)* /
data()
CreateFullTextIndex ::=
create fulltext index on
RootIdStr
When a path index is created the namespaces in the underlying data are ignored. If the local names in the path match the local names in the data elements, then the data is indexed.
The drop index syntax for both types of index is similar:
DropPathIndex ::=
drop index
IndexNameStr
on
RootIdStr
DropFullTextIndex ::=
drop fulltext index on
RootIdStr
Triggers are used to define an XQuery statement to execute whenever root editing occurs. Root editing happens when documents are inserted into, updated on, or deleted from a root. Triggers are useful for enforcing rules on data, such as referential integrity, or for audit logging.
The requirement of triggers is that they must allow the user to:
CreateTrigger ::=
create trigger
TriggerNameStr
on
RootIdStr
priority
int (
before
|
after
)
(
insert
|
update
|
delete
)
DO
Expr
Here is an example that logs activity on MyDb:Invoice to MyDb:Log.
create trigger "Trig1" ON "/MyDb/Invoice"
after insert do
let $a :=
<LogEntry>
<Action>InsertOp</Action>
<id>{$SysDocAfter/id}</id>
<docid>{GetDocumentId($SysDocAfter)}</docid>
</LogEntry>
return insert document $a into "/st1/Log"
Create causes a trigger to be added to SysTrigger and causes that trigger to be activated for the root it is created on. Create Trigger is like other DDL commands, which must be done inside a transaction but cannot be rolled back.
If multiple triggers exist for root MyRoot, insert, then they are fired in order of priority with all the ones marked before fired first, and then all the ones marked after fired after the insert.
When a trigger is created the syntax of the DoExpr and WhenExpr is compiled to detect errors.
There are two built in variables in the context of trigger based XQuery. They are:
The trigger name has to be unique across the database.
drop trigger
TriggerIdStr
Removal of a trigger is done by name for a database since name is unique across the database. As well, when a root is dropped, all the triggers have to be deleted as well. Removal of a trigger causes that trigger to be removed from the "/SysData/SysTrigger" root.
One root per database, called SysTrigger, contains all the trigger descriptions.
XStreamDB data can be backed up and restored by directly using the API, by using command syntax, as described here, or by using the Explorer Configuration Tab for Server, Database and Root backup.
When a backup is created, the XStreamDB data goes into a zip archive file on the server. Each DB object in the zip file is given a path and a name, as is common to most zip files.
Below are the definitions of both the DB objects that can be backed up and the objects in the zip file.
DBObjectType ::= Server | Database | Root | Schema | User | Document
ZipObjectType ::= Schema | User | Document | ServerInfo | DatabaseInfo |
RootInfo
Individual documents cannot be be backed up. You can, however, backup:
The path of what can be backed up is defined as the DBObjectPath:
DBObjectPath ::= UserPath | SchemaPath |
DatabasePath | RootPath
UserPath ::= '/'
users
'/'username
SchemaPath ::= '/'
schema
'/'schemaname
DatabasePath ::= '/'dbname
RootPath ::= '/'dbname'/'rootname
Backup commands are the commands that can be sent to the XStreamDB command processor.
Syntax
BackupCmd ::=
backup item
'"' DBObjectPath '"' (
into
ZipFileName )?
Note The default directory for backups is {InstallDir}/Server/backup.
The following example backs up a database called SomeDB into a zip file named SomeZip.zip:
backup item "/SomeDB" into "SomeZip.zip"
Note If BackupDest specifies a file that already exists, it is overwritten. BackupDest is optional. If not specified, the system chooses a filename based on date and time. The statement returns a text node with the zip file name created.
Syntax
ListArchives ::=
List Archives
Returns a collection of text nodes, one for each zip file that exists at the {InstallDir}/Server/backup directory.
Syntax
Enumerate ::=
enumerate from
'"' ZipFileName '"'
Returns a collection of text nodes, one for each importable object in the named archive (same format as before), for example, ENUMERATE FROM "SomeZip.zip".
Syntax
Restore Item ::=
restore item
RestoreItem From
ArchiveName ( Into RestoreDest )?
RestoreItem ::= '"' DbObjectPath '"'
RestoreDest ::= '"' DbObjectPath '"'
The RestoreDest can optionally have different dbname and/or rootname. RestoreDest is optional. If not specified, it defaults to the same name as RestoreItem. RestoreItem and RestoreDest must be at the same level that is, if one specifies a DB then the other must as well. For example,
restore item "/SomeDB" from "SomeZip.zip" into "/SomeOtherDB"
A scheduled backup can be created, modified and deleted from the XDBExplorer configuration tab, as described in the User Guide. This section describes the low-level API-based method to create, modify and delete scheduled backups. Backup schedules are stored in the root SysData:SysBackup.
To create a new schedule for a backup insert the document following the structure below, into SysData:SysBackup and then issue a BackupSchedulesUpdated() command to notify the scheduler. For example, the following insert causes a database "/InvoiceDB" to be scheduled for backup weekly on Monday at 1:00 A.M.
insert document <BackupSchedule> <Weekday>2</Weekday> <Hour>1</Hour> <Minute>0</Minute> <BackupItem>/InvoiceDB</BackupItem> </BackupSchedule> into /SysData/SysBackup
For a daily backup every day at 1:00 P.M.:
insert document <BackupSchedule> <Weekday>every</Weekday> <Hour>1</Hour> <Minute>0</Minute> <BackupItem>/InvoiceDB</BackupItem> </BackupSchedule> into /SysData/SysBackup
For deleting and replacing a schedule use delete document and replace document commands and then use BackupSchedulesUpdated() to notify the scheduler.
If an object can be backed up and thus restored, it is shown across the top. A "Y" in the cell indicates objects and sub objects down the left side are also backed up. What sub objects are backed up is mostly determined by whether those objects are "contained" with the parent object. There is, however, exceptions to this with regard to:
| � | Server | DB | Root |
|---|---|---|---|
| Server | Y | � | � |
| DB | � | Y | � |
| Root | � | � | Y |
| Index | Y | Y | Y |
| Trigger | Y | Y | Y |
| Module | Y | � | � |
| Group | Y | � | � |
| User | Y | � | � |
| Document | Y | Y | Y |
| Binary | Y | Y | Y |
| Schemas | Y | Y | Y |
| Resources | Y | Y | Y (as referred to) |
| Categories | Y | Y | Y (as referred to) |
In XQuery, a module is either a library module or a main module. A library module is a collection of XQuery functions collected together into a module. A main module is a single XQuery expression. If a library module is defined, XStreamDB stores this module so it can be referenced later. XStreamDB supports the creation, replacement and deletion of library modules. Thus the user can create, modify and delete libraries of functions. As well, XStreamDB follows the XQuery standard for importing modules so that functions within that module can be employed in any other XQuery module, whether it be an XQuery expression or another collection of functions module. Modules are described in the W3C XQuery language document . For more particular discussion of Module Management note the sections below.
Create an XQuery library module to be stored in XStreamDB.
CreateModule ::=
create module
ModuleUri Prolog
ModuleUri ::= StringLiteral
Prolog ::= ( ( ContextDecl )* ( ImportModule )* ( DefineFunction )* )
A module is created using the syntax above. For example,
create module "MyModLib"
define function square(element $val) returns xsd:decimal {$val/data() * $val/data()}
define function wrap(element $nd) returns element {<dummy>{$nd}</dummy> }
The URI of the module is "MyModLib". This URI fills the roles of the name and the target namespace of the module. This URI, or name, can later be used to import the module, replace the module or delete the module. All of the names of the functions are defined in the target namespace defined by the ModuleURI. The ModuleURI is unique within a particular XStreamDB server. The body of the created module is composed of one or more declared functions.
QNames used in XQuery expressions such as XPaths in a library module will be bound to the namespace indicated by the prefix portion of the QName. For example:
create module "MyModLib"
namespace pre = "http://bluestream.com/myns"
define function foo(element $val) returns xsd:string {$val/pre:a/pre:b/data()}
When foo is later imported and executed it is not necessary to re-define "pre" since the XPaths are now bound to "http://bluestream.com/myns".
To replace the module identified by ModuleURI, use the following line:
ReplaceModule ::=
replace module
ModuleUri Prolog
To drop the module identified by ModuleURI, use the following line:
DropModule ::=
drop module
ModuleUri
The Import Module is used to import all the functions of a library module into the importing module. Once imported, all the functions in the module can be used if qualified by the correct namespace prefix. Importing is done as follows:
ImportModule ::=
import module
(
namespace
NCName '=' )? ModuleUri
A library module is imported using its ModuleURI, which is both a namespace for that module's functions and a name for the module. To use functions in a module a prefix must be bound to this ModuleURI, or the prefix must be defined in the module prolog namespace declarations in order to access functions in this URI. Consider the following example:
import module namespace chuck = "MyModLib" let $x := <s>20</s> return chuck:double($x)
Data is queried by using the XStreamDB command language. The command language is XQuery with some XStreamDB extensions. This section describes the XStreamDB implementation of XQuery with basic extensions noted as necessary.
As well as basic extensions, XStreamDB has made some advanced extensions to XQuery as decribed in the following sections on Update Commands and Full Text Search.
To see the exact BNF of the grammar click on this link Grammar
Other more detailed discussions of the XQuery grammar can be found at W3C XQuery Language .
The table below lists any key lexical differences between XSteramDB and the W3C XQuery Language .
| Rule | Production | XStreamDB | |
|---|---|---|---|
| StringLiteral | ::= | (["] [^"]* ["]) | (['] [^']* [']) |
Standard Escapes
The following escapes can be used in any XStreamDB string:
Like Literal Escapes For literals used in LIKE expressions use:
|
XStreamDB supports standard "LIKE operator" processing identical to that supported in SQL.
The escape sequences are:
|
Statement |
Meaning |
|---|---|
/book/[year like '199%] |
Returns all the books published in the 1990s. |
LET $d := "abc" WHERE $d LIKE "\u0061%" RETURN $d |
Returns "abc" since \u0061 is 'a'. |
When using XQuery, it is not always necessary to specify the data() accessor on the path of an element or attribute. data() is applied implicitly for:
data() is NOT implied for paths in:
In a predicate such as /Person/City = "Paris" spaces are stripped off the underlying data to match "Paris". For example, the underlying XML could show:
<Person>
<City>
Paris
</City>
</Person>
There is whitespace before and after "Paris", a newline and some spaces before "Paris" and a newline after. When XStreamDB evaluates predicates it trims the City text value to remove whitespace from the beginning and end. Xdb also trims path index keys, so that the behavior is consistent in predicate evaluation whether an index exists or not.
As well, Xdb evaluates predicates in a case insensitive way. So /Person/City = "paris" matches the same documents as /Person/City = "Paris".
Index optimization happens automatically when XStreamDB Queries and Updates are executed.
You can detect whether index optimization is taking place by examining the speed of execution of the query on large data sets or by turning on the QueryPlan setting in the {InstallDir}/Server/conf/XDBServer.prop file and restarting the server. A GoXMLDb_QryPlan.html file will then appear in the {InstallDir}/Server/bin directory. This file shows the query plan for each query executed.
Predicates can be expressed in XQuery in either path expressions or in the where clause of the FLWR expression. An example path expression using a predicate would be Root("/MyDB/MyRoot")/Person[City = "Paris"] .
An example where expression is:
for $p IN Root("/MyDB/MyRoot")/Person
where $p/City = "Paris"
return $p
Predicates are evaluated using available indexes. If a path index exists on path /Person/City/data() then the predicates in the above query expressions would be evaluated by seeking in the index. This index seeking can greatly reduce the number of documents the query engine has to consider when evaluating the query thus greatly improving performance.
The following comparison operators are optimized:
The types of path-index predicate optimizations done are described here. The examples use element values, but attribute values can be substituted where element names are used.
Single element, single index . As described above.
Single element, single index, multiple values . This is an " OR" list. For example, where $p/City = "Paris" or $p/City = "Toronto".
Multiple elements, multiple indexes, multiple values . AND and OR are supported. For example, where $p/City = "Paris" or $p/City = "Toronto" or $p/FirstName = "John" or $p/FirstName = "Frank".
Multiple elements, multiple path indexes, multiple . Values - parenthesis. For example, where ($p/City = "Paris" and $p/FirstName = "John") or ($p/City = "Paris" and $p/FirstName = "Frank").
Only some indexes . Many times some elements referenced in a predicate are indexed, whereas other are not. XStreamDB optimizes with indexes to reduce the set of possible documents and then uses the non-indexed element predicates on that smaller set of documents. However, by its nature, this yields no advantage for OR operations across an indexed element and another non-indexed element.
XQuery order by expressions order a sequence of XDMValues by the key expression in the sort by clause. For example,
for $a IN Root("/PersonsDB/persons")/Person order by $a/City Return $a
This example orders all the persons by city. If there is a path index on /Person/City/data(), then the order by expression uses this path index to order the sequence of /Person fragments.
As well, since the distinct optimization has to be able to eliminate duplicates, a path index can be used to accomplish this efficiently.
Note If a sort is formulated where there are multiple keys for each value being sorted, then the values being sorted will occur multiple times. In some uses, this error wouldn't be caught, and the error wouldn't be flagged.
When a query follows a certain pattern such as a nested for, multiple in clauses, or even a LET in the standard XQuery "group by pattern", then the join optimizer attempts to optimize the query using indexes.
The following table contains examples of some of the type of queries that are optimized:
| Example | Discussion |
|---|---|
FOR $c IN distinct(Root("/PersonDB/Person")/Person/City)
LET $CityGroup := Root("/PersonDB/Person")[Person/City = $c]
RETURN
<City name={$c} count={Count($CityGroup)} />
|
Self Join with Distinct.
Give the count of persons in each city. This optimization assumes an index on /Person/City/data(). The index is used to perform the sort as well as perform the [Person/City = $c] predicate optimization. |
Full text search optimization is discussed in the next section on full text search .
All function names are case sensitive. Functions that begin with an upper case letter are XStreamDB functions, functions that begin with a lower case letter are XQuery defined functions.
Functions are documented using the following form:
function-name($parameter-name as parameter-type, ...) as return-type
Notation for parameter-type and return-type in functions follows the XQuery standard for sequence types: Sequence Type Syntax which in turn relies on the XML Schema standard for data types schema data types.
The Sequence Type Syntax can be simplfied as:
SequenceType ::= KindType | AtomicType
KindType ::= KindTest "(" (optqualifiers)* ")"
AtomicType ::= QName // eg xs:string - taken from XML Schema
Kinds are things like element, attribute, item, node. opt qualifiers are names and XML schema types, either anySimpleType or complexType. For example:
element(po:shipto, po:address) - element named shipto of type address. element(*, po:address) // element any name of type address item()+ // sequence of one or more nodes or atomic values node()* // sequence of zero or more nodes of any kind
Kinds are:
| kind | description |
|---|---|
| document-node | document node |
| element | element node |
| attribute | attribute node |
| processing-instruction | pi node |
| comment | comment node |
| text | text node |
| node | any node |
| item | any node or atomic |
The following prefixes are used to for data types, as taken from XQuery Functions and Operators :
| prefix | description | uri |
|---|---|---|
| xs | XML Schema data types. | http://www.w3.org/2001/XMLSchema |
| xdt | Xpath/XQuery data types. These are defined in addition to XML Schema. | http://www.w3.org/2005/02/xpath-datatypes |
The following prefixes are sometimes used for functions:
| prefix | description | uri |
|---|---|---|
| fn | Built in XQuery functions | http://www.w3.org/2005/02/xpath-functions |
| xsfn | Built in xdb functions | http://www.bluestream.com/xstreamdb/functions |
Name . Name of function.
Prototype . Prototype of function.
| FunctionName | Prototype |
|---|---|
| AddGroup |
AddGroup($groupName as xs:string) |
| AddUserToGroup |
AddUserToGroup($groupName as xs:string,$userName as xs:string) |
| AttributeCtor |
AttributeCtor($attrName as xs:string,$value as xs:simpleType) as attribute() |
| avg |
avg($seq as xdt:anyAtomicType*) as xdt:anyAtomicType? |
| CDataCtor |
CDataCtor($cdata as xs:string) as cdataNode() |
| collection |
collection( $collectionId as xs:string, [$flag) as xs:string*]) as document-node()* |
| CommentCtor |
CommentCtor($commentText as xs:string) |
| concat |
concat( $a as xdt:anyAtomicType, $b as xdt:anyAtomicType,... ) as xs:string |
| count |
count($seq as item()*) as xs:integer |
| DatabaseExists |
DatabaseExists($databaseId as xs:string) as xs:boolean |
| Date |
Date() as xs:datetime |
| DeleteGroup |
DeleteGroup($groupName as xs:string) |
| DeleteUser |
DeleteUser($userName as xs:string) |
| DeleteUserFromGroup |
DeleteUserFromGroup($groupName as xs:string,$userName as xs:string) |
| distinct |
distinct($seq as xdt:anyAtomicType*) as xdt:anyAtomicType* |
| DocNumFromDocId |
DocNumFromDocId($docId as xs:string) as xs:integer |
| document |
document($url as xs:string) document-node() |
| DocumentByCounter |
DocumentByCounter($collectionId as xs:string, $counter as xs:integer,[flags as xs:string*]) as document-node() |
| DocumentByDocNum |
DocumentByDocNum( $collectionId as xs:string, $docNum as xs:integer, [$flags as xs:string*]) as document-node() |
| DocumentByGuid |
DocumentByGuid( $collectionId as xs:string, $guid as xs:string, [$flags as xs:string*]) as document-node() |
| DocumentById |
DocumentById( $documentId as xs:string, [$flags as xs:string*]) as document-node() |
| DocumentByPath |
DocumentByPath( $fullPath as xs:string, [$flags as xs:string*]) as document-node() |
| DocumentCtor |
DocumentCtor( $xmldecl as xs:string, $docType as xs:string, $tree as element(*)) as document-node() |
| DropBinaryObject |
DropBinaryObject( $collectionId as xs:string, $guidStr as xs:string) |
| empty |
empty($arg as item()*) as xs:boolean |
| exists |
exists($arg as item()*) as xs:boolean |
| GenValues |
GenValues($start as xs:integer, $end as xs:integer) as xs:integer* |
| GetACLSetting |
GetACLSetting( $thisObjectType as xs:string, $thisObjectId as xs:string, $actorType as xs:string, $actorName as xs:string) as element(xsdb:Acl) |
| GetConfigInfo |
getConfigInfo($objectType as xs:string,$objectId as xs:string) as element(*,ConfigInfoType) |
| GetDatabaseInfos |
GetDatabaseInfos() as element(xsdb:databaseInfo)* |
| GetDatabaseTree |
GetDatabaseTree() as element(xsdb:databaseTree) |
| GetDocId |
GetDocId($doc as document-node() as xs:string |
| GetDocumentId |
GetDocumentId($doc as document-node() as xs:string |
| GetDocVerId |
GetDocId($doc as document-node() as xs:string |
| GetEffectiveACL |
GetEffectiveACL( $thisObjectType as xs:string, $thisObjectId as xs:string, $actorType as xs:string, $actorName as xs:string) as element(xsdb:Acl) |
| GetFullTextIndexInfos |
GetFullTextIndexInfos($rootId as string) as element(fullTextIndexInfo) |
| GetGroupInfos |
GetGroupInfos() as element(xsdb:groupInfo)* |
| GetGroupMembers |
GetGroupMembers($groupId as xs:string) as element (xsdb:userInfo)* |
| GetModuleInfos |
GetModuleInfos() as element(xsdb:moduleInfo)* |
| GetRootInfos |
GetRootInfos(databaseId as xs:string) as element (xsdb:rootInfo)* |
| GetRootProperty |
GetRootProperty($rootId as xs:string) as element(xsdb:rootProperties) |
| GetTriggerInfos |
GetTriggerInfos($rootId as xs:string) as element(xsdb:triggerInfo)* |
| GetUserGroups |
GetUserGroups($userId as xs:string) as element(xsdb:groupInfo)+ |
| GetUserInfos |
GetUserInfos() as element(xsdb:userInfo)* |
| GetValueIndexInfos |
GetValueIndexInfos($rootId as xs:string) as element(xsdb:valueIndexInfo)* |
| GetVerNum |
GetVerNum($doc as document-node() as xs:string |
| GetXMLResourceText |
GetXMLResourceText( $path as xs:string, $name as xs:string, $contentDocId as xs:string, $length as xs:integer) as document-node() |
| IdDocId |
IdDocId($docVerId as xs:string) as xs:string |
| IdVerNum |
IdVerNum($docVerId as xs:string) as xs:string |
| JDBC |
sequence JDBC(String odbcDSN, String sqlQuery, String jdbcDriverName) JDBC( $odbcDSN as xs:string, $sqlQuery as xs:string, $jdbcDriverName as xs:string ) as element(*)* |
| max |
max($seq as xdt:anyAtomicType*) as xdt:anyAtomicType? |
| min |
min($seq as xdt:anyAtomicType*) as xdt:anyAtomicType? |
| namespace-uri |
namespace-uri($arg as node()?) as xs:anyURI |
| Newline |
Newline() as xs:string |
| not |
not($bool as item()*) as xs:boolean |
| PICtor |
PICtor($tag as xs:string, $value as xs:string) as processing-instruction() |
| RefreshSchemas |
RefreshSchemas() |
| ResourceContent |
ResourceContent( $resId as xs:string) as document-node() |
| Root |
Root($rootId as xs:string) as document-node()* |
| RootExists |
RootExists($databaseId as xs:string,$rootId as xs:string) as xs:boolean |
| SetObjectOwner |
SetOwner( $objectType as xs:string, $objectId as xs:string, $userName as xs:string) |
| SetRootProperty |
SetRootProperty( $rootId as xs:string, $propName as xs:string, $onoff as xs:string) |
| SetUserDescription |
SetUserDescription($userName as xs:string,$description as xs:string) |
| SetUserFullName |
SetUserFullName($userName as xs:string,$fullname as xs:string) |
| SetVar |
SetVar($var as variableName,$items as item()*) |
| Substring |
SubString($str as xs:string,$offset as xs:integer,$length as xs:integer) |
| sum |
sum($seq as xdt:anyAtomicType*) as xdt:anyAtomicType |
| TextLength |
TextLength($items as item()*) as xs:integer |
| translate |
translate($str as xs:string,$searchStr as xs:string,$replaceStr as xs:string) as xs:string |
| Trim |
Trim($strIn as xs:string) as xs:string |
| xdbm:CounterFromDocId |
xdbm:CounterFromDocId($docId as xs:string) as xs:integer |
| xdbm:GuidFromDocId |
xdbm:GuidFromDocId($docId as xs:string) as xs:string |
| XSLTransform |
XSLTransform ($xslTemplate as document-node(),$input as document-node()) as document-node() |
Aggregate functions are those that perform a computation on a set of values rather than on a single value.
Description:
Counts the number of items in a sequence and returns that count as a number.
Prototype:
count($seq as item()*) as xs:integer
Parameters:
Return:
Description:
(XQuery renamed to distinct-values) Compares values in a sequence and eliminates duplicates. If the sequence is a sequence of Nodes, then the nodes are compared for uniqueness recursively starting with element tag names, attribute names, attribute values, element values and so on as defined in the XQuery Functions and Operators document. On the other hand, if the sequence contains text a simple text compare is done to determine uniqueness.
Prototype:
distinct($seq as xdt:anyAtomicType*) as xdt:anyAtomicType*
Parameters:
Return:
Description:
Calculates average.
Prototype:
avg($seq as xdt:anyAtomicType*) as xdt:anyAtomicType?
Parameters:
Return:
Description:
Calculates maximum numeric value in a sequence of values.
Prototype:
max($seq as xdt:anyAtomicType*) as xdt:anyAtomicType?
Parameters:
Return:
Description:
Calculates minimum numeric value in a sequence of numeric values.
Prototype:
min($seq as xdt:anyAtomicType*) as xdt:anyAtomicType?
Parameters:
Return:
Description:
Calculates sum.
Prototype:
sum($seq as xdt:anyAtomicType*) as xdt:anyAtomicType
Parameters:
Return:
Functions that return boolean values.
Description:
Negates the passed boolean expression.
Prototype:
not($bool as item()*) as xs:boolean
Parameters:
Return:
Description:
Determines whether a sequence contains any nodes. Returns true for not empty, otherwise false.
Prototype:
exists($arg as item()*) as xs:boolean
Parameters:
Return:
Description:
Tests whether a sequence is empty or not.
Prototype:
empty($arg as item()*) as xs:boolean
Parameters:
Return:
This group contains functions that are used to setup or get information about the XStreamDB configuration objects.
Description:
Check to see if a database exists or not.
Prototype:
DatabaseExists($databaseId as xs:string) as xs:boolean
Parameters:
Return:
Example:
DatabaseExists("/PersonDB")
Description:
Determines if a root exists.
Prototype:
RootExists($databaseId as xs:string,$rootId as xs:string) as xs:boolean
Parameters:
Return:
Description:
Sets a property on a root.
Prototype:
SetRootProperty( $rootId as xs:string, $propName as xs:string, $onoff as xs:string)
Parameters:
Return:
Example:
SetRootProperty("/PersonDB/Person","guid","true")
SetRootProperty("/PersonDB/Person","counter","true")
Description:
Get the properties on a root.
Prototype:
GetRootProperty($rootId as xs:string) as element(xsdb:rootProperties)
Parameters:
Return:
Example:
<rootProperties>
<propertyList>
<property name='guid' value='true'>
</property>
</propertyList>
</rootProperties>
Description:
Obtain the information about one of the configuration objects.
Prototype:
getConfigInfo($objectType as xs:string,$objectId as xs:string) as element(*,ConfigInfoType)
Parameters:
Return:
Errors:
Description:
Returns a sequence of DatabaseInfos.
Prototype:
GetDatabaseInfos() as element(xsdb:databaseInfo)*
Parameters:
Return:
Errors:
Description:
Returns a sequence of RootInfos for the given database.
Prototype:
GetRootInfos(databaseId as xs:string) as element (xsdb:rootInfo)*
Parameters:
Return:
Errors:
Description:
Returns a sequence of ValueIndexInfos for the given root.
Prototype:
GetValueIndexInfos($rootId as xs:string) as element(xsdb:valueIndexInfo)*
Parameters:
Return:
Errors:
Description:
Returns a single fullTextIndexInfo for the given root if one exists.
Prototype:
GetFullTextIndexInfos($rootId as string) as element(fullTextIndexInfo)
Parameters:
Return:
Errors:
Description:
Returns a sequence of TriggerInfos for the given root.
Prototype:
GetTriggerInfos($rootId as xs:string) as element(xsdb:triggerInfo)*
Parameters:
Return:
Errors:
Description:
Returns a sequence of ModuleInfos for the current server.
Prototype:
GetModuleInfos() as element(xsdb:moduleInfo)*
Parameters:
Return:
Description:
Returns a sequence of all the security GroupInfo objects on a server. This includes built in groups .
Prototype:
GetGroupInfos() as element(xsdb:groupInfo)*
Parameters:
Return:
Errors:
Description:
Returns the UserInfos of all the users defined on the server.
Prototype:
GetUserInfos() as element(xsdb:userInfo)*
Parameters:
Return:
Errors:
Description:
Returns the groups for which the passed user is a member.
Prototype:
GetUserGroups($userId as xs:string) as element(xsdb:groupInfo)+
Parameters:
Return:
Errors:
Description:
Returns the user members for the given group.
Prototype:
GetGroupMembers($groupId as xs:string) as element (xsdb:userInfo)*
Parameters:
Return:
Errors:
Description:
Returns the DatabaseTree as defined in . The DatabaseTree is an XML "tree" composed of a list of all the databases on a server, each with its nested roots and each root with its nested indexes and nested triggers.
Prototype:
GetDatabaseTree() as element(xsdb:databaseTree)
Parameters:
Return:
Errors:
Use these functions to construct different kinds of nodes.
Description:
Creates a new XML document complete with a declaration and a document type.
Prototype:
DocumentCtor( $xmldecl as xs:string, $docType as xs:string, $tree as element(*)) as document-node()
Parameters:
Return:
Description:
Constructs an attribute node, which is placed as a child of an element.
Prototype:
AttributeCtor($attrName as xs:string,$value as xs:simpleType) as attribute()
Parameters:
Return:
Example:
for $p in Root('/PersonsDB/Person')/Person
where $p/@ID/data() = '12'
return
<llnode>{AttributeCtor("jack",$p/@ID/data())}</llnode><llnode jack = '12'></llnode>
Description:
Puts processing instructions into your XML.
Prototype:
PICtor($tag as xs:string, $value as xs:string) as processing-instruction()
Parameters:
Return:
Example:
PICtor("mytag","myvalue")
Description:
Puts comments into your XML.
Prototype:
CommentCtor($commentText as xs:string)
Parameters:
Return:
Description:
Use CDataCtor to put CData sections into your xml.
Prototype:
CDataCtor($cdata as xs:string) as cdataNode()
Parameters:
Return:
Example:
CDataCtor("here is some CData")
Content objects are either XML documents or binary objects. In XStreamDB it is possible to access content objects using a variety of identity schemes. Below are the functions that extract identifiers and convert from one kind of identifer to another. Accessing documents using these documents is handled in the section.
Description:
Get the DocId from the given document - without version.
Prototype:
GetDocId($doc as document-node() as xs:string
Parameters:
Return:
Example:<