io::zorba::api::xqj::ZorbaXQPreparedExpressionThis class describes an expression that can be prepared for multiple subsequent executions. A prepared expression can be created from the connection.The preparation of the expression does the static analysis of the expression using the static context information.The dynamic context information, such as values for bind variables, can then be set using the setter methods. When setting values for bind variables, these variables should be present as external variables in the prolog of the prepared expression.The static type information of the query can also be retrieved if the XQuery implementation provides it using the getStaticResultType method.When the expression is executed using the executeQuery method, if the execution is successful, then an ZorbaXQResultSequence object is returned. The ZorbaXQResultSequence object is tied to the ZorbaXQPreparedExpression from which it was prepared and is closed implicitly if that expression is either closed or if re-executed.The ZorbaXQPreparedExpression object is dependent on the ZorbaXQConnection object from which it was created and is only valid for the duration of that object. Thus, if the ZorbaXQConnection object is closed then this ZorbaXQPreparedExpression object will be implicitly closed and it can no longer be used.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 ZorbaXQPreparedExpression is closed any ZorbaXQResultSequence object obtained from it is also implicitly closed.Example -{.java} ZorbaXQConnection conn = XQDataSource.getconnection(); ZorbaXQPreparedExpression expr = conn.prepareExpression ("for $i in (1) return 'abc' "); // get the sequence type out.. This would be something like xs:string * ZorbaXQSequenceType type = expr.getStaticResultType(); XQSequence result1 = expr.executeQuery(); // process the result.. result1.next(); System.out.println(" First result1 "+ result1.getAtomicValue()); ZorbaXQResultSequence result2 = expr.executeQuery(); // result1 is implicitly closed // recommended to close the result sequences explicitly. // process the result.. while (result2.next()) System.out.println(" result is "+ result2.getAtomicValue()); result2.close(); expr.close(); // closing expression implicitly closes all result sequence or // items obtained from this expression. conn.close(); // closing connections will close expressions and results. Private Attributes
Public Functions
Private Functions
Private Attributesclosedboolean closed
connectionXQConnection connection
dynamicContextDynamicContext dynamicContext
itemsBoundedCollection< String > itemsBounded
queryXQuery query
resultSequencesCollection< XQResultSequence > resultSequences
staticContextXQStaticContext staticContext
xmlDataManagerXmlDataManager xmlDataManager
Public FunctionsbindAtomicValuevoid bindAtomicValue(QName varName, String value, XQItemType type) Binds a value to the given external variable or the context item. The value is converted into an instance of the specified type according to the casting from xs:string rules outlined in 17.1.1 Casting from xs:string and xs:untypedAtomic, XQuery 1.0 and XPath 2.0 Functions and Operators. If the cast fails, or if there is a mismatch between the static and dynamic types, an XQException is thrown either by this method or during query evaluation. Parameters
Parameters
bindBooleanvoid bindBoolean(QName varName, boolean value, XQItemType type) Binds a value to the given external variable or the context item. The value is converted into an instance of the specified type according to the rule defined in 14.2 Mapping a Java Data Type to an XQuery Data Type, XQuery API for Java (XQJ) 1.0. If the conversion fails, or if there is a mismatch between the static and dynamic types, an XQException is raised either by this method, or during query evaluation. Parameters
Parameters
bindBytevoid bindByte(QName varName, byte value, XQItemType type) Binds a value to the given external variable or the context item. The value is converted into an instance of the specified type according to the rule defined in 14.2 Mapping a Java Data Type to an XQuery Data Type, XQuery API for Java (XQJ) 1.0. If the conversion fails, or if there is a mismatch between the static and dynamic types, an XQException is raised either by this method, or during query evaluation. Parameters
Parameters
bindDocumentvoid bindDocument(QName varName, String value, String baseURI, XQItemType type) Binds a value to the given external variable or the context item. If the value represents a well-formed XML document, it will be parsed and results in a document node. The kind of the input type must be null, XQITEMKIND_DOCUMENT_ELEMENT, or XQITEMKIND_DOCUMENT_SCHEMA_ELEMENT.The value is converted into an instance of the specified type according to the rules defined in 14.3 Mapping a Java XML document to an XQuery document node, XQuery API for Java (XQJ) 1.0.If the conversion fails, or if there is a mismatch between the static and dynamic types, an XQException is raised either by this method, or during query evaluation. If the value is not well formed, or if a kind of the input type other than the values list above is specified, behavior is implementation defined and may raise an exception. Parameters
Parameters
bindDocumentvoid bindDocument(QName varName, Reader value, String baseURI, XQItemType type) Binds a value to the given external variable or the context item. If the value represents a well-formed XML document, it will be parsed and results in a document node. The kind of the input type must be null, XQITEMKIND_DOCUMENT_ELEMENT, or XQITEMKIND_DOCUMENT_SCHEMA_ELEMENT.The value is converted into an instance of the specified type according to the rules defined in 14.3 Mapping a Java XML document to an XQuery document node, XQuery API for Java (XQJ) 1.0.If the conversion fails, or if there is a mismatch between the static and dynamic types, an XQException is raised either by this method, or during query evaluation. If the value is not well formed, or if a kind of the input type other than the values list above is specified, behavior is implementation defined and may raise an exception. Parameters
Parameters
bindDocumentvoid bindDocument(QName varName, InputStream value, String baseURI, XQItemType type) Binds a value to the given external variable or the context item. If the value represents a well-formed XML document, it will be parsed and results in a document node. The kind of the input type must be null, XQITEMKIND_DOCUMENT_ELEMENT, or XQITEMKIND_DOCUMENT_SCHEMA_ELEMENT.The value is converted into an instance of the specified type according to the rules defined in 14.3 Mapping a Java XML document to an XQuery document node, XQuery API for Java (XQJ) 1.0.If the conversion fails, or if there is a mismatch between the static and dynamic types, an XQException is raised either by this method, or during query evaluation. If the value is not well formed, or if a kind of the input type other than the values list above is specified, behavior is implementation defined and may raise an exception. Parameters
Parameters
bindDocumentvoid bindDocument(QName varName, XMLStreamReader value, XQItemType type) Binds a value to the given external variable or the context item. If the value represents a well-formed XML document, it will be parsed and results in a document node. The kind of the input type must be null, XQITEMKIND_DOCUMENT_ELEMENT, or XQITEMKIND_DOCUMENT_SCHEMA_ELEMENT.The value is converted into an instance of the specified type according to the rules defined in 14.3 Mapping a Java XML document to an XQuery document node, XQuery API for Java (XQJ) 1.0.If the conversion fails, or if there is a mismatch between the static and dynamic types, an XQException is raised either by this method, or during query evaluation. If the value is not well formed, or if a kind of the input type other than the values list above is specified, behavior is implementation defined and may raise an exception. Parameters
Parameters
bindDocumentvoid bindDocument(QName varName, Source value, XQItemType type) Binds a value to the given external variable or the context item. Binds a value to the given external variable or the context item from the given Source. An XQJ implementation must at least support the following implementations:
Parameters
Parameters
bindDoublevoid bindDouble(QName varName, double value, XQItemType type) Binds a value to the given external variable or the context item. The value is converted into an instance of the specified type according to the rule defined in 14.2 Mapping a Java Data Type to an XQuery Data Type, XQuery API for Java (XQJ) 1.0. If the conversion fails, or if there is a mismatch between the static and dynamic types, an XQException is raised either by this method, or during query evaluation. Parameters
Parameters
bindFloatvoid bindFloat(QName varName, float value, XQItemType type) Binds a value to the given external variable or the context item. The value is converted into an instance of the specified type according to the rule defined in 14.2 Mapping a Java Data Type to an XQuery Data Type, XQuery API for Java (XQJ) 1.0. If the conversion fails, or if there is a mismatch between the static and dynamic types, an XQException is raised either by this method, or during query evaluation. Parameters
Parameters
bindIntvoid bindInt(QName varName, int value, XQItemType type) Binds a value to the given external variable or the context item. The value is converted into an instance of the specified type according to the rule defined in 14.2 Mapping a Java Data Type to an XQuery Data Type, XQuery API for Java (XQJ) 1.0. If the conversion fails, or if there is a mismatch between the static and dynamic types, an XQException is raised either by this method, or during query evaluation. Parameters
Parameters
bindItemvoid bindItem(QName varName, XQItem value) Binds a value to the given external variable. The dynamic type of the value is derived from the ZorbaXQItem. In case of a mismatch between the static and dynamic types, an XQException is raised either by this method, or during query evaluation. Parameters
Parameters
bindLongvoid bindLong(QName varName, long value, XQItemType type) Binds a value to the given external variable or the context item. The value is converted into an instance of the specified type according to the rule defined in 14.2 Mapping a Java Data Type to an XQuery Data Type, XQuery API for Java (XQJ) 1.0. If the conversion fails, or if there is a mismatch between the static and dynamic types, an XQException is raised either by this method, or during query evaluation. Parameters
Parameters
bindNodevoid bindNode(QName varName, Node value, XQItemType type) Binds a value to the given external variable or the context item. The value is converted into an instance of the specified type according to the rule defined in 14.2 Mapping a Java Data Type to an XQuery Data Type, XQuery API for Java (XQJ) 1.0. If the conversion fails, or if there is a mismatch between the static and dynamic types, an XQException is raised either by this method, or during query evaluation. Parameters
Parameters
bindObjectvoid bindObject(QName varName, Object value, XQItemType type) Binds a value to the given external variable or the context item. The value is converted into an instance of the specified type according to the rule defined in 14.2 Mapping a Java Data Type to an XQuery Data Type, XQuery API for Java (XQJ) 1.0. If the conversion fails, or if there is a mismatch between the static and dynamic types, an XQException is raised either by this method, or during query evaluation. Parameters
Parameters
bindSequencevoid bindSequence(QName varName, XQSequence value) Binds a value to the given external variable or the context item. The input sequence is consumed from its current position to the end, after which the input sequence's position will be set to point after the last item. The dynamic type of the value is derived from the items in the sequence. In case of a mismatch between the static and dynamic types, an XQException is be raised either by this method, or during query evaluation. Parameters
Parameters
bindShortvoid bindShort(QName varName, short value, XQItemType type) Binds a value to the given external variable or the context item. The value is converted into an instance of the specified type according to the rule defined in 14.2 Mapping a Java Data Type to an XQuery Data Type, XQuery API for Java (XQJ) 1.0. If the conversion fails, or if there is a mismatch between the static and dynamic types, an XQException is raised either by this method, or during query evaluation. Parameters
Parameters
bindStringvoid bindString(QName varName, String value, XQItemType type) Binds a value to the given external variable or the context item. The value is converted into an instance of the specified type, which must represent an xs:string or a type derived by restriction from xs:string. If the specified type is null, it defaults to xs:string. Subsequently the value is converted into an instance of the specified type according to the rule defined in 14.2 Mapping a Java Data Type to an XQuery Data Type, XQuery API for Java (XQJ) 1.0,. If the conversion fails, or if there is a mismatch between the static and dynamic types, an XQException is raised either by this method, or during query evaluation. Parameters
Parameters
cancelvoid cancel() Attempts to cancel the execution if both the XQuery engine and XQJ driver support aborting the execution of an ZorbaXQPreparedExpression. This method can be used by one thread to cancel an ZorbaXQPreparedExpression, that is being executed in another thread. If cancellation is not supported or the attempt to cancel the execution was not successful, the method returns without any error. If the cancellation is successful, an XQException is thrown, to indicate that it has been aborted, by executeQuery, executeCommand or any method accessing the ZorbaXQResultSequence returned by executeQuery. If applicable, any open ZorbaXQResultSequence and XQResultItem objects will also be implicitly closed in this case. Parameters
closevoid close() Closes the expression object and release all resources associated with this prepared expression. This also closes any result sequences obtained from this expression. Once the expression is closed, all methods on this object other than the close or isClosed will raise exceptions. Calling close on an XQExpression object that is already closed has no effect. Parameters
executeQueryXQResultSequence executeQuery() Executes the prepared query expression. Calling this method implicitly closes any previous result sequence obtained from this expression. Returnsthe xquery sequence object containing the result of the query executionParameters
getAllExternalVariablesQName[] getAllExternalVariables() Retrieves all the external variables defined in the prolog of the prepared expression.
Returnsan array of QName objects for all the external variables defined in the prolog of a prepared expression. Empty array if there are no external variables present.Parameters
getAllUnboundExternalVariablesQName[] getAllUnboundExternalVariables() Retrieves the names of all unbound external variables. Gets the static type information of the result sequence. If an implementation does not do static typing of the query, then this method must return an ZorbaXQSequenceType object corresponding to the XQuery sequence type item()*. ReturnsZorbaXQSequenceType containing the static result information.Parameters
getImplicitTimeZoneTimeZone getImplicitTimeZone() Gets the implicit timezone.
Returnsthe implicit timezone. This may have been set by an application using the setImplicitTimeZone method or provided by the implementationParameters
getStaticContextXQStaticContext getStaticContext() Gets an ZorbaXQStaticContext representing the values for all expression properties. Note that these properties cannot be changed; in order to change, a new ZorbaXQPreparedExpression needs to be created. Returnsan ZorbaXQStaticContext representing the values for all expression propertiesParameters
getStaticResultTypeXQSequenceType getStaticResultType() Gets the static type information of the result sequence. If an implementation does not do static typing of the query, then this method must return an ZorbaXQSequenceType object corresponding to the XQuery sequence type item()*. ReturnsZorbaXQSequenceType containing the static result information.Parameters
getStaticVariableTypeXQSequenceType getStaticVariableType(QName varName) Retrieves the static type of a given external variable.
Parameters
Returnsthe static type information of the variable as defined in the prolog of the prepared expressionParameters
isClosedboolean isClosed() Checks if the prepared expression in a closed state.
Returnstrue if the prepared expression is in a closed state, false otherwise.setImplicitTimeZonevoid setImplicitTimeZone(TimeZone value) Sets the implicit timezone.
Parameters
Parameters
ZorbaXQPreparedExpression ZorbaXQPreparedExpression(XQConnection conn, String string)
ZorbaXQPreparedExpression ZorbaXQPreparedExpression(XQConnection conn, Reader reader)
ZorbaXQPreparedExpression ZorbaXQPreparedExpression(XQConnection conn, InputStream input)
ZorbaXQPreparedExpression ZorbaXQPreparedExpression(XQConnection conn, String string, XQStaticContext sc)
ZorbaXQPreparedExpression ZorbaXQPreparedExpression(XQConnection conn, Reader reader, XQStaticContext sc)
ZorbaXQPreparedExpression ZorbaXQPreparedExpression(XQConnection conn, InputStream input, XQStaticContext sc)
Private FunctionsisClosedXQExceptionvoid isClosedXQException()
isExternalboolean isExternal(String varName)
isNullXQExceptionvoid isNullXQException(Object value)
nodeToStringString nodeToString(Node node)
|