io::zorba::api::xqj::ZorbaXQResultSequenceThis class represents a sequence of items obtained as a result of evaluation XQuery expressions. The result sequence is tied to the XQconnection object on which the expression was evaluated.This sequence can be obtained by performing an executeQuery on the expression object. It represents a cursor-like class.The ZorbaXQResultSequence object is dependent on the connection and the expression from which it was created and is only valid for the duration of those objects. Thus, if any one of those objects is closed, this ZorbaXQResultSequence object will be implicitly closed and it can no longer be used. Similarly re-executing the expression also implicitly closes the associated result sequences.An XQJ driver is not required to provide finalizer methods for the connection and other objects. Hence it is strongly recommended that users call close method explicitly to free any resources. It is also recommended that they do so under a final block to ensure that the object is closed even when there are exceptions. Not closing this object implicitly or explicitly might result in serious memory leaks.When the ZorbaXQResultSequence is closed any ZorbaXQResultItem objects obtained from it are also implicitly closed.Example -{.java} XQPreparedExpression expr = conn.prepareExpression("for $i .."); ZorbaXQResultSequence result = expr.executeQuery(); // create the ItemTypes for string and integer XQItemType strType = conn.createAtomicType(XQItemType.XQBASETYPE_STRING); XQItemType intType = conn.createAtomicType(XQItemType.XQBASETYPE_INT); // posititioned before the first item while (result.next()) { XQItemType type = result.getItemType(); // If string, then get the string value out if (type.equals(strType)) String str = result.getAtomicValue(); else if (type.equals(intType)) // if it is an integer.. int intval = result.getInt(); ... } result.close(); // explicitly close the result sequence Private Attributes
Public Functions
Private Functions
Private Attributesclosedboolean closed
connectionXQConnection connection
consumedItemboolean consumedItem
deliveredboolean delivered
iterIterator iter
iterDeletedboolean iterDeleted
lQueryio.zorba.api.XQuery lQuery
preparedExpressionboolean preparedExpression
Public Functionsabsoluteboolean absolute(int i) Moves the XQSequence's position to the given item number in this object. If the item number is positive, the XQSequence moves to the given item number with respect to the beginning of the XQSequence. The first item is item 1, the second is item 2, and so on.If the given item number is negative, the XQSequence positions itself on an absolute item position with respect to the end of the sequence.For example, calling the method absolute(-1) positions the XQSequence on the last item; calling the method absolute(-2) moves the XQSequence to the next-to-last item, and so on. absolute(0) will position the sequence before the first item.An attempt to position the sequence beyond the first/last item set leaves the current position to be before the first item or after the last item.Calling this method on an empty sequence will return false. Parameters
Returnstrue if the current position is within the sequence, false otherwiseParameters
afterLastvoid afterLast() Move to the position after the last item.
Parameters
beforeFirstvoid beforeFirst() Moves to the position before the first item.
Parameters
closevoid close() Closes the sequence and frees all resources associated with this sequence. Closing an XQSequence object also implicitly closes all XQItem objects obtained from it. All methods other than the isClosed or close method will raise exceptions when invoked after closing the sequence. Calling close on an XQSequence object that is already closed has no effect. Parameters
countint count() Returns a number indicating the number of items in the sequence.
Returnsthe number of items in this sequenceParameters
firstboolean first() Moves to the first item in the sequence. The method returns true, if it was able to move to the first item in the sequence false, otherwise. Calling this method on an empty sequence will return false. Returnstrue if the sequence was positioned on the first item, false otherwiseParameters
getAtomicValueString getAtomicValue() Gets the current item as a Java String. The current item must be an atomic value. This function casts the current item to an xs:string value according to the casting rules defined in 17.1.2 Casting to xs:string and xs:untypedAtomic, XQuery 1.0 and XPath 2.0 Functions and Operators, and then returns the value as a Java String. Returnsthe string representation of the itemParameters
getBooleanboolean getBoolean() Gets the current item as a boolean. The current item must be an atomic value of type xs:boolean or a subtype. Returnsa boolean representing the current itemParameters
getBytebyte getByte() Gets the current item as a byte. The current item must be an atomic value of type xs:decimal or a subtype, and its value must be in the value space of byte. Returnsa byte representing the current itemParameters
getConnectionXQConnection getConnection() Gets the XQuery connection associated with this result sequence.
Returnsthe connection associated with this result sequenceParameters
getDoubledouble getDouble() Gets the current item as a double. The current item must be an atomic value of type xs:double or a subtype. Returnsa double representing the current itemParameters
getFloatfloat getFloat() Gets the current item as a float. The current item must be an atomic value of type xs:float or a subtype. Returnsa float representing the current itemParameters
getIntint getInt() Gets the current item as an int. The current item must be an atomic value of type xs:decimal or a subtype, and its value must be in the value space of int. Returnsan int representing the current itemParameters
getItemXQItem getItem() Get the current item as an immutable XQItem object. In case of an ZorbaXQResultSequence, the item is an ZorbaXQResultItem. In the case of forward only sequences, this method or any other get or write method may only be called once on the curent item.The XQItem object is dependent on the sequence from which it was created and is only valid for the duration of XQSequence lifetime. Thus, the XQSequence is closed, this XQItem object will be implicitly closed and it can no longer be used. Returnsan XQItem objectParameters
getItemAsStreamXMLStreamReader getItemAsStream() Read the current item as an XMLStreamReader object. Read the current item as an XMLStreamReader object, as described in Section 12.1 Serializing an XDM instance into a StAX event stream (XMLStreamReader), XQuery API for Java (XQJ) 1.0. Note that the serialization process might fail, in which case a XQException is thrown. While the stream is being read, the application MUST NOT do any other concurrent operations on the underlying item or sequence. The operation on the stream is undefined if the underlying sequence is repositioned or the state of the underlying item or sequence is changed by concurrent operations. Returnsan XML reader object as XMLStreamReaderParameters
getItemAsStringString getItemAsString(Properties prprts) Serializes the current item according to the XSLT 2.0 and XQuery 1.0 serialization. Serialization parameters, which influence how serialization is performed, can be specified. Refer to the XSLT 2.0 and XQuery 1.0 serialization and Section 12 Serialization, XQuery API for Java (XQJ) 1.0 for more information. Parameters
Returnsthe serialized representation of the itemParameters
getItemTypeXQItemType getItemType() Gets the type of the item. On a forward only sequence this method can be called independent of any other get or write method. It will not raise an error if such method has been called already, nor will it affect subsequent invocations of any other get or write method. Returnsthe type of the itemParameters
getLonglong getLong() Gets the current item as a long. The current item must be an atomic value of type xs:decimal or a subtype, and its value must be in the value space of long. Returnsa long representing the current itemParameters
getNodeNode getNode() Gets the item as a DOM node. The current item must be a node. The type of the returned DOM node is governed by Table 7 - XQuery Node Types and Corresponding Java Object Types XQuery API for Java (XQJ) 1.0 The instance of the returned node is implementation dependent. The node may be a reference or a copy of the internal state of the item. It is advisable to make a copy of the node if the application plans to modify it. Returnsa DOM node representing the current itemParameters
getNodeUriURI getNodeUri() Returns the URI for this item. If the item is a document node, then this method returns the absolute URI of the resource from which the document node was constructed. If the document URI is not available, then the empty string is returned. If the document URI is available, the returned value is the same as if fn:document-uri were evaluated on this document node. If the item is of a node kind other than document node, then the returned URI is implementation-defined. On a forward only sequence this method can be called independent of any other get or write method. It will not raise an error if such method has been called already, nor will it affect subsequent invocations of any other get or write method on the current item. Returnsthe document URI for this document node or the empty string if not available. For other node kinds, the result is implementation-definedParameters
getObjectObject getObject() Gets the current item as an Object. The data type of the returned object will be the Java Object type as specified in 14.4 Mapping an XQuery Atomic Value to a Java Object Type and 14.5 Mapping an XQuery Node to a Java Object Type, XQuery API for Java (XQJ) 1.0. Returnsan object representing the current itemParameters
getPositionint getPosition() Gets the current cursor position. 0 indicates that the position is before the first item and count() + 1 indicates position after the last item. A specific position indicates that the cursor is positioned on the item at that position. Use the isOnItem method to verify if the cursor is positioned on the item.Calling this method on an empty sequence will return 0. Parameters
getSequenceAsStreamXMLStreamReader getSequenceAsStream() Read the entire sequence starting from the current position as an XMLStreamReader object. Read the entire sequence starting from the current position as an XMLStreamReader object, as described in Section 12.1 Serializing an XDM instance into a StAX event stream (XMLStreamReader), XQuery API for Java (XQJ) 1.0. Note that the serialization process might fail, in which case a XQException is thrown. While the stream is being read, the application MUST NOT do any other concurrent operations on the sequence. The operation on the stream is undefined if the underlying sequence position or state is changed by concurrent operations. After all items are written to the stream, the current position of the cursor is set to point after the last item. Also, in the case of forward only sequences, this method may only be called if the current item has not yet been read through any of the get or write methods. Returnsan XML reader object as XMLStreamReaderParameters
getSequenceAsStringString getSequenceAsString(Properties prprts) Serializes the sequence starting from the current position to a String. Serializes the sequence starting from the current position to a String according to the XSLT 2.0 and XQuery 1.0 serialization. Serialization parameters, which influence how serialization is performed, can be specified. Refer to the XSLT 2.0 and XQuery 1.0 serialization and Section 12 Serialization, XQuery API for Java (XQJ) 1.0 for more information. Reading the sequence during the serialization process performs implicit next operations to read the items. After all items are written to the stream, the current position of the cursor is set to point after the last item. Also, in the case of forward only sequences, this method may only be called if the current item has not yet been read through any of the get or write methods. Parameters
Returnsthe serialized representation of the sequenceParameters
getShortshort getShort() Gets the current item as a short. The current item must be an atomic value of type xs:decimal or a subtype, and its value must be in the value space of short. Returnsa short representing the current itemParameters
getStaticCollectionManagerZorbaXQStaticCollectionManager getStaticCollectionManager() Returns a StaticCollectionManager. Returns a CollectionManager responsible for all collections which are statically declared in the static context of this query (main module) or any transitively imported library module. The collection manager provides a set of functions for managing collections and their contents. ReturnsZorbaXQStaticCollectionManager The collection manager responsible for managing collections of this Sequence.Parameters
instanceOfboolean instanceOf(XQItemType xqit) Checks if the item "matches" an item type. Checks if the item "matches" an item type, as defined in 2.5.4.2 Matching an Item Type and an Item, XQuery 1.0: An XML Query Language. You can use this method to first check the type of the result before calling the specific get methods.Example - {.java} ... XQItemType strType = conn.createAtomicType(XQItemType.XQBASETYPE_STRING); XQItemType nodeType = conn.createNodeType(); XQSequence result = preparedExpr.executeQuery(); while (result.next()) { // Generic check for node.. if (result.instanceOf(nodeType)) org.w3.dom.Node node = result.getNode(); else if (result.instanceOf(strType)) String str = result.getAtomicValue(); } If either the type of the XQItemAccessor or the input XQItemType is not a built-in type, then this method is allowed to raise exception if it can NOT determine the instanceOf relationship due to the lack of the access of the XML schema that defines the user defined schema types if the XQMetaData.isUserDefinedXMLSchemaTypeSupported() method returns false. Otherwise, this method must determine if the type of the XQItemAccessor is an instance of the input XQItemType. Note even if isUserDefinedXMLSchemaTypeSupported() returns false, an XQJ implementation may still be able to determine the instanceOf relationship for certain cases involving user defined schema type. For example, if the type of an XQItemAccessor is of mySchema:hatSize sequence type and the input parameter XQItemType is of item() sequence type, the return value for instanceOf relationship should always be true even though the XQJ implementation does not know the precise type information of mySchema:hatSize type defined in XML schema 'mySchema'. Parameters
Returnstrue if this item matches the input item type as defined in 2.5.4.2 Matching an Item Type and an Item, XQuery 1.0: An XML Query Language, and false if it does notParameters
isAfterLastboolean isAfterLast() Checks if the current position is after the last item in the sequence. Calling this method on an empty sequence will return false. Returnstrue if the current position is after the last item, false otherwiseParameters
isBeforeFirstboolean isBeforeFirst() Checks if the current position before the first item in the sequence. Calling this method on an empty sequence will return false. Returnstrue if the current position is before the first item, false otherwiseParameters
isClosedboolean isClosed() Checks if the sequence is closed.
Returnstrue if the sequence is in a closed state, false otherwiseisFirstboolean isFirst() Checks if the current position at the first item in the sequence. Calling this method on an empty sequence will return false. Returnstrue if the current position is at the first item, false otherwiseParameters
isLastboolean isLast() Checks if the current position at the last item in the sequence. Calling this method on an empty sequence will return false. Returnstrue if the current position is at the last item, false otherwiseParameters
isOnItemboolean isOnItem() Check if the sequence is positioned on an item or not. Calling this method on an empty sequence will return false. Returnstrue if the sequence is currently positioned on an item, false if sequence is positioned before the first item, or after the last itemParameters
isScrollableboolean isScrollable() Checks if the sequence is scrollable.
Returnstrue if the sequence can be scrolled backward or forward, false otherwiseParameters
lastboolean last() Moves to the last item in the sequence. This method returns true, if it was able to move to the last item in the sequence false, otherwise. Calling this method on an empty sequence will return false. Returnstrue if the sequence was positioned on the last item, false otherwiseParameters
nextboolean next() Moves to the next item in the sequence. Calling this method on an empty sequence will return false. Returnstrue if the new item is valid, false if there are no more itemsParameters
previousboolean previous() Moves to the previous item in the sequence. Calling this method on an empty sequence will return false. Returnstrue if the new current position is within the sequence, (i.e., not before first); false otherwise.Parameters
relativeboolean relative(int i) Moves the cursor a relative number of items. Moves the cursor a relative number of items, either positive or negative. Attempting to move beyond the first/last item in the sequence positions the sequence before/after the the first/last item. Calling relative(0) is valid, but does not change the cursor position. Note: Calling the method relative(1) is identical to calling the method next and calling the method relative(-1) is identical to calling the method previous(). Calling this method on an empty sequence will return false. Parameters
Returnstrue if the new current position is within the sequence (i.e., not before first or after last); false otherwise.Parameters
writeItemvoid writeItem(OutputStream out, Properties prprts) Serializes the current item to a Writer. Serializes the current item to a Writer according to XSLT 2.0 and XQuery 1.0 serialization. Serialization parameters, which influence how serialization is performed, can be specified. Refer to the XSLT 2.0 and XQuery 1.0 serialization and Section 12 Serialization, XQuery API for Java (XQJ) 1.0 for more information. Parameters
Parameters
writeItemvoid writeItem(Writer writer, Properties prprts) Serializes the current item to a Writer. Serializes the current item to a Writer according to XSLT 2.0 and XQuery 1.0 serialization. Serialization parameters, which influence how serialization is performed, can be specified. Refer to the XSLT 2.0 and XQuery 1.0 serialization and Section 12 Serialization, XQuery API for Java (XQJ) 1.0 for more information.Warning: When outputting to a Writer, make sure the writer's encoding matches the encoding parameter if specified as a property or the default encoding. Parameters
Parameters
writeItemToResultvoid writeItemToResult(Result result) Writes the current item to a Result. First the item is normalized as described in XSLT 2.0 and XQuery 1.0 serialization. Subsequently it is serialized to the Result object. Note that the normalization process can fail, in which case an XQException is thrown. An XQJ implementation must at least support the following implementations:
Parameters
Parameters
writeItemToSAXvoid writeItemToSAX(ContentHandler ch) Writes the current item to a SAX handler. Writes the current item to a SAX handler, as described in in Section 12.2 Serializing an XDM instance into a SAX event stream, XQuery API for Java (XQJ) 1.0. Note that the serialization process might fail, in which case a XQException is thrown. The specified org.xml.sax.ContentHandler can optionally implement the org.xml.sax.LexicalHandler interface. An implementation must check if the specified ContentHandler implements LexicalHandler. If the handler is a LexicalHandler comment nodes are reported, otherwise they will be silently ignored. Parameters
Parameters
writeSequencevoid writeSequence(OutputStream out, Properties prprts) Serializes the sequence starting from the current position to an OutputStream. Serializes the sequence starting from the current position to an OutputStream according to the XSLT 2.0 and XQuery 1.0 serialization. Serialization parameters, which influence how serialization is performed, can be specified. Refer to the XSLT 2.0 and XQuery 1.0 serialization and Section 12 Serialization, XQuery API for Java (XQJ) 1.0 for more information. Reading the sequence during the serialization process performs implicit next operations to read the items. After all items are written to the stream, the current position of the cursor is set to point after the last item. Also, in the case of forward only sequences, this method may only be called if the current item has not yet been read through any of the get or write methods. Parameters
Parameters
writeSequencevoid writeSequence(Writer writer, Properties prprts) Serializes the sequence starting from the current position to a Writer. Serializes the sequence starting from the current position to a Writer according to the XSLT 2.0 and XQuery 1.0 serialization. Serialization parameters, which influence how serialization is performed, can be specified. Refer to the XSLT 2.0 and XQuery 1.0 serialization and Section 12 Serialization, XQuery API for Java (XQJ) 1.0 for more information.Warning: When outputting to a Writer, make sure the writer's encoding matches the encoding parameter if specified as a property or the default encoding.Reading the sequence during the serialization process performs implicit next operations to read the items. After all items are written to the stream, the current position of the cursor is set to point after the last item. Also, in the case of forward only sequences, this method may only be called if the current item has not yet been read through any of the get or write methods. Parameters
Parameters
writeSequenceToResultvoid writeSequenceToResult(Result result) Writes the entire sequence starting from the current position to a Result. First the sequence is normalized as described in XSLT 2.0 and XQuery 1.0 serialization. Subsequently it is serialized to the Result object. Note that the normalization process can fail, in which case an XQException is thrown. An XQJ implementation must at least support the following implementations:
Parameters
Parameters
writeSequenceToSAXvoid writeSequenceToSAX(ContentHandler ch) Writes the entire sequence starting from the current position to a SAX handler. Writes the entire sequence starting from the current position to a SAX handler, as described in Section 12.2 Serializing an XDM instance into a SAX event stream, XQuery API for Java (XQJ) 1.0. Note that the serialization process might fail, in which case a XQException is thrown. After all items are written to the stream, the current position of the cursor is set to point after the last item. Also, in the case of forward only sequences, this method may only be called if the current item has not yet been read through any of the get or write methods. The specified org.xml.sax.ContentHandler can optionally implement the org.xml.sax.LexicalHandler interface. An implementation must check if the specified ContentHandler implements LexicalHandler. If the handler is a LexicalHandler comment nodes are reported, otherwise they will be silently ignored. Parameters
Parameters
ZorbaXQResultSequence ZorbaXQResultSequence(XQConnection conn, io.zorba.api.XQuery query, boolean prepared)
Private FunctionsisClosedXQExceptionvoid isClosedXQException()
isConsumedXQExceptionvoid isConsumedXQException()
isItemDeliveredXQExceptionvoid isItemDeliveredXQException()
isNullXQExceptionvoid isNullXQException(Object value)
isOnItemXQExceptionvoid isOnItemXQException()
|