public class XmlIndexSpecification
extends java.lang.Object
XmlContainer.getIndexSpecification()
method, and modified using the
XmlContainer.setIndexSpecification(com.sleepycat.dbxml.XmlIndexSpecification)
method.
Note that adding an index to a container results in re-indexing all of
the documents in that container, which can take a very long time. It
is good practice to design an application to add useful indices before
populating a container. Automatic indexing
(setAutoIndexing(boolean)
) results in implicit addition
of indexes for leaf elements and attributes of newly-inserted content, resulting
in reindexing as such new content is added. This behavior is on by default
in order to provide simpler "hands-off" index addition. Applications that
need to assert finer control over indexes should disable this behavior using
setAutoIndexing(boolean)
and explicitly add indexes.
The class is implemented using a handle-body idiom. When a handle is copied both handles maintain a reference to the same body.
This object is not thread-safe, and can only be safely used by one thread at a time in an application.
Modifier and Type | Field and Description |
---|---|
static int |
KEY_EQUALITY
Equality key type.
|
static int |
KEY_NONE
No key type.
|
static int |
KEY_PRESENCE
Presence key type.
|
static int |
KEY_SUBSTRING
Substring key type.
|
static int |
NODE_ATTRIBUTE
Attribute node type.
|
static int |
NODE_ELEMENT
Element node type.
|
static int |
NODE_METADATA
Metadata node type.
|
static int |
NODE_NONE
No node type.
|
static int |
PATH_EDGE
Edge path type.
|
static int |
PATH_NODE
Node path type.
|
static int |
PATH_NONE
No path type.
|
static int |
UNIQUE_OFF
The indexed value need not be unique container-wide
|
static int |
UNIQUE_ON
The indexed value must be unique container-wide
|
Constructor and Description |
---|
XmlIndexSpecification() |
Modifier and Type | Method and Description |
---|---|
void |
addDefaultIndex(int type,
int syntax)
Adds an indexing strategy to the default index specification.
|
void |
addDefaultIndex(java.lang.String index)
Adds a single indexing strategy to the default index.
|
void |
addIndex(java.lang.String uri,
java.lang.String name,
int type,
int syntax)
Identifies an indexing strategy to set for the identified node.
|
void |
addIndex(java.lang.String uri,
java.lang.String name,
java.lang.String index)
Adds an index to the index specification.
|
void |
delete()
Free the native resources associated with this object.
|
void |
deleteDefaultIndex(int type,
int syntax)
Delete the identified index from the default index specification.
|
void |
deleteDefaultIndex(java.lang.String index)
Deletes one or more indexing strategies to the default index.
|
void |
deleteIndex(java.lang.String uri,
java.lang.String name,
int type,
int syntax)
Deletes a single index strategy from the identified node.
|
void |
deleteIndex(java.lang.String uri,
java.lang.String name,
java.lang.String index)
Deletes indexing strategies for a named document or metadata node.
|
XmlIndexDeclaration |
find(java.lang.String uri,
java.lang.String name)
Returns the indexing strategies for a named document or metadata node.
|
boolean |
getAutoIndexing()
Retrieves the current state of automatic indexing.
|
java.lang.String |
getDefaultIndex()
Retrieves the default index.
|
static int |
getValueType(java.lang.String index)
Gets the
XmlValue type specified in the given index string. |
XmlIndexDeclaration |
next()
Obtains the next index in the
XmlIndexSpecification . |
void |
replaceDefaultIndex(int type,
int syntax)
Replaces the default indexing strategy for the container.
|
void |
replaceDefaultIndex(java.lang.String index)
Identifies one or more indexing strategies to set for the default index.
|
void |
replaceIndex(java.lang.String uri,
java.lang.String name,
int type,
int syntax)
Replaces the indexing strategies for a named document or metadata node.
|
void |
replaceIndex(java.lang.String uri,
java.lang.String name,
java.lang.String index)
Replaces the indexing strategies for a named document or metadata node.
|
void |
reset()
Resets the index specification iterator to the beginning of the index
list.
|
void |
setAutoIndexing(boolean value)
Sets the state of automatic indexing to the specified value.
|
public static final int UNIQUE_OFF
public static final int UNIQUE_ON
public static final int PATH_NONE
public static final int PATH_NODE
public static final int PATH_EDGE
public static final int NODE_NONE
public static final int NODE_ELEMENT
public static final int NODE_ATTRIBUTE
public static final int NODE_METADATA
public static final int KEY_NONE
public static final int KEY_PRESENCE
public static final int KEY_EQUALITY
public static final int KEY_SUBSTRING
public void delete()
public void addIndex(java.lang.String uri, java.lang.String name, int type, int syntax) throws XmlException
uri
- The namespace of the node to be indexed. The default namespace is selected by passing an empty string for the namespace.name
- The name of the element or attribute node to be indexed.type
- A series of values bitwise OR'd together to form the index strategy.
To indicate whether the indexed value must be unique container-wide, use one of the following, or leave the value out entirely:
To identify the path type, use one of the following:
To identify the node type, use one of the following:
Note that if NODE_METADATA
is used, then PATH_NODE
must also be used as well.
To identify the key type, use one of the following:
For example:
XmlIndexSpecification.PATH_NODE | XmlIndexSpecification.NODE_ELEMENT | XmlIndexSpecification.KEY_SUBSTRING
syntax
- Identifies the type of information being indexed. The value must be one of the XmlValue enumerated types:
XmlValue.NONE
XmlValue.BASE_64_BINARY
XmlValue.BOOLEAN
XmlValue.DATE
XmlValue.DATE_TIME
XmlValue.DECIMAL
XmlValue.DOUBLE
XmlValue.DURATION
XmlValue.FLOAT
XmlValue.G_DAY
XmlValue.G_MONTH
XmlValue.G_MONTH_DAY
XmlValue.G_YEAR
XmlValue.G_YEAR_MONTH
XmlValue.HEX_BINARY
XmlValue.STRING
XmlValue.TIME
Note that if KEY_PRESENCE
is specified for type
,
then this parameter must be XmlValue.NONE
.
XmlException
public void addIndex(java.lang.String uri, java.lang.String name, java.lang.String index) throws XmlException
XmlContainer.setIndexSpecification(com.sleepycat.dbxml.XmlIndexSpecification)
.
You identify the indexing strategy that you want to add to the index specification in one of two ways. The first way is to provide a string that identifies the desired indexing strategy. The second is to use XmlIndexSpecification and XmlValue class constants to identify the same information.
Either way, an index strategy is set by providing the name of a node and one or more indexing strategies for that node. The node name can be either that of an element, attribute, or metadata node. Metadata nodes are used only for indexing metadata. Element and attribute nodes are used for indexing XML document content. For example, in the XML fragment:
there are two node names that index strategies could be specified for, the element node name is 'art', and the attribute node name is 'title'."<art title='...'/>"
When specifying indexing strategies, you must provide the following information:
there is an edge at <a><b> and another one at <b><c>."<a><b><c>foo</c>o</b></a>"
In addition to setting index strategies for specified nodes, applications can also specify a default indexing strategy for all nodes in a container by using addDefaultIndex(int, int)
. When a container is first created the default indexing strategy is 'unique-node-metadata-equality-string'.
For more information on designing an indexing strategy for your application, see the Berkeley DB XML Getting Started Guide.
uri
- The namespace of the node to be indexed. The default namespace is
selected by passing an empty string for the namespace.name
- The name of the element or attribute node to be indexed.index
- A comma-separated list of strings that represent the indexing strategy.
The strings must contain the following information in the following order:
unique-{path type}-{node type}-{key type}-{syntax}
where:
unique indicates that the indexed value is unique in the container. If this keyword does not appear on the index string, then the indexed value is not required to be unique in the container.
{path type} is either node or edge.
{node type} is one of element, attribute, or metadata. If metadata is specified, then {path type} must be node.
{key type} is one of presence, equality, or substring.
{syntax} identifies the type of information being indexed. It must be one of the following values:
Note that if {key type} is presence, then {syntax} must be none or simply not specified.
For example, examples index strings are:
unique-node-element-presence
node-element-equality-string
edge-element-presence-none
node-element-equality-float
XmlException
public void deleteIndex(java.lang.String uri, java.lang.String name, int type, int syntax) throws XmlException
uri
- The namespace of the node for which you want the index deleted. The default namespace is selected by passing an empty string for the
namespace.name
- The name of the element or attribute node to be indexed.type
- A series of values bitwise OR'd
together to form the index strategy. See addIndex(String, String, int, int)
for a complete description.syntax
- Identifies the type of information being indexed. See addIndex(String, String, int, int)
for a complete description.
XmlException
public void deleteIndex(java.lang.String uri, java.lang.String name, java.lang.String index) throws XmlException
uri
- The namespace of the node for which you want the index deleted. The default namespace is selected by passing an empty string for the
namespace.name
- The name of the element or attribute node to be indexed.index
- A comma-separated list of strings that represent the indexing strategy. See addIndex(String, String, String)
for a complete description.XmlException
public void replaceIndex(java.lang.String uri, java.lang.String name, int type, int syntax) throws XmlException
uri
- The namespace of the node for which you want the index replaced. The default namespace is selected by passing an empty string for the
namespace.name
- The name of the element or attribute node to be indexed.type
- A series of values bitwise OR'd
together to form the index strategy. See addIndex(String, String, int, int)
for a complete description.syntax
- Identifies the type of information being indexed. See addIndex(String, String, int, int)
for a complete description.
XmlException
public void replaceIndex(java.lang.String uri, java.lang.String name, java.lang.String index) throws XmlException
Identifies one or more indexing strategies to set for the identified node. The strategies are identified using a space-separated listing of strings.
uri
- The namespace of the node for which you want the index replaces. The default namespace is selected by passing an empty string for the
namespace.name
- The name of the element or attribute node to be indexed.index
- A comma-separated list of strings that represent the indexing strategy. See addIndex(String, String, String)
for a complete description.XmlException
public void addDefaultIndex(int type, int syntax) throws XmlException
type
- A series of values bitwise OR'd
together to form the index strategy. See addIndex(String, String, int, int)
for a complete description.syntax
- Identifies the type of information being indexed. See addIndex(String, String, int, int)
for a complete description.XmlException
public void addDefaultIndex(java.lang.String index) throws XmlException
index
- A comma-separated list of strings that represent the indexing strategy. See addIndex(String, String, String)
for a complete description.XmlException
public void deleteDefaultIndex(int type, int syntax) throws XmlException
addDefaultIndex(int, int)
.type
- A series of values bitwise OR'd
together to form the index strategy. See addIndex(String, String, int, int)
for a complete description.syntax
- Identifies the type of information being indexed. See addIndex(String, String, int, int)
for a complete description.
XmlException
public void deleteDefaultIndex(java.lang.String index) throws XmlException
index
- A comma-separated list of strings that represent the indexing strategy. See addIndex(String, String, String)
for a complete description.XmlException
public void replaceDefaultIndex(int type, int syntax) throws XmlException
addIndex(java.lang.String, java.lang.String, int, int)
.type
- A series of values bitwise OR'd
together to form the index strategy. See addIndex(String, String, int, int)
for a complete description.syntax
- Identifies the type of information being indexed. See addIndex(String, String, int, int)
for a complete description.
XmlException
public void replaceDefaultIndex(java.lang.String index) throws XmlException
index
- A comma-separated list of strings that represent the indexing strategy. See addIndex(String, String, String)
for a complete description.XmlException
public void reset() throws XmlException
next()
to iterate through the
indices contained in the index specification.XmlException
public XmlIndexDeclaration find(java.lang.String uri, java.lang.String name) throws XmlException
XmlIndexDeclaration
object if an index for the node is found; otherwise it returns null
.uri
- The namespace of the node to be indexed. The default namespace is selected by passing an empty string for the namespace.name
- The name of the element or attribute node to be indexed.XmlException
public XmlIndexDeclaration next() throws XmlException
XmlIndexSpecification
. Use
reset()
to reset this iterator.
This method returns null
if no additional indices exist in the index list.
XmlException
public java.lang.String getDefaultIndex() throws XmlException
XmlException
public void setAutoIndexing(boolean value)
XmlContainer.setIndexSpecification(com.sleepycat.dbxml.XmlIndexSpecification)
is called with this object.value
- set to true to enable automatic index additionpublic static int getValueType(java.lang.String index) throws XmlException
XmlValue
type specified in the given index string.index
- The index string.XmlValue
type, which consists of
XmlException
public boolean getAutoIndexing()
Copyright (c) 2004,2014 Oracle. All rights reserved.