ZorbaXQStaticContext.java
Go to the documentation of this file.
1 /*
2  * Copyright 2006-2012 The FLWOR Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.zorbaxquery.api.xqj;
17 
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.HashMap;
21 import java.util.Map;
22 import javax.xml.xquery.XQConstants;
23 import javax.xml.xquery.XQException;
24 import javax.xml.xquery.XQItemType;
25 import org.zorbaxquery.api.*;
26 import org.zorbaxquery.api.ZorbaConstants.BoundarySpaceMode;
27 import org.zorbaxquery.api.ZorbaConstants.ConstructionMode;
28 import org.zorbaxquery.api.ZorbaConstants.InheritMode;
29 import org.zorbaxquery.api.ZorbaConstants.OrderEmptyMode;
30 import org.zorbaxquery.api.ZorbaConstants.OrderingMode;
31 import org.zorbaxquery.api.ZorbaConstants.PreserveMode;
32 
33  /** \brief
34  *
35  * An ZorbaXQStaticContext represents default values for various XQuery Static Context Components. Further it includes the static XQJ properties for an XQExpression or XQPreparedExpression object.
36  *
37  * The following XQuery Static Context Components are supported through the ZorbaXQStaticContext interface:
38  *
39  * - Statically known namespaces
40  * - Default element/type namespace
41  * - Default function namespace
42  * - Context item static type
43  * - Default collation
44  * - Construction mode
45  * - Ordering mode
46  * - Default order for empty sequences
47  * - Boundary-space policy
48  * - Copy-namespaces mode
49  * - Base URI
50  *
51  * As described in the XQuery specification, each of these default values can be overridden or augmented in the query prolog.
52  * In addition ZorbaXQStaticContext includes the static XQJ properties for an XQExpression or XQPreparedExpression object:
53  *
54  * - Binding mode
55  * - Holdability of the result sequences
56  * - Scrollability of the result sequences
57  * - Query language
58  * - Query timeout
59  *
60  * Note that ZorbaXQStaticContext is a value object, changing attributes in such object doesn't affect any existing XQExpression or XQPreparedExpression object.
61  * In order to take effect, the application needs to explicitly change the XQConnection default values, or specify an ZorbaXQStaticContext object when creating an XQExpression or XQPreparedExpression.
62  * \code{.java}
63  * XQConnection conn = XQDatasource.getConnection();
64  * // get the default values from the implementation
65  * ZorbaXQStaticContext cntxt = conn.getStaticContext();
66  * // change the base uri
67  * cntxt.setBaseURI("http://www.foo.com/xml/");
68  * // change the implementation defaults
69  * conn.setStaticContext(cntxt);
70  *
71  * // create an XQExpression using the new defaults
72  * XQExpression expr1 = conn.createExpression();
73  *
74  * // creat an XQExpression, using BaseURI "file:///root/user/john/"
75  * cntxt.setBaseURI("file:///root/user/john/");
76  * XQExpression expr2 = conn.createExpression(cntxt);
77  * ...
78  * \endcode
79  */
80 public class ZorbaXQStaticContext implements javax.xml.xquery.XQStaticContext {
81 
82 
83  private StaticContext staticContext;
84  private int scrollability = XQConstants.SCROLLTYPE_FORWARD_ONLY;
85  private int holdability = XQConstants.HOLDTYPE_CLOSE_CURSORS_AT_COMMIT;
86  private int queryLang = XQConstants.LANGTYPE_XQUERY;
87  private int binding = XQConstants.BINDING_MODE_IMMEDIATE;
88  Map<String, String> namespaces = new HashMap<String, String>();
89  private StringVector uriPaths;
90  private StringVector libPaths;
91  private StringVector modulePaths;
92 
93  private Zorba zorba;
94  private XQuery query;
95  private ZorbaXQStaticCollectionManager lStaticCollectionManager;
96 
97  String baseURI = null; //Patch for Zorba, bug filed on https://bugs.launchpad.net/zorba/+bug/905028
98  XQItemType contextItemStaticType = null; //Patch for Zorba, TypeIdentifier is not complete
99  protected StaticContext getZorbaStaticContext() {
100  return staticContext;
101  }
102 
103  public ZorbaXQStaticContext(Zorba aZorba) {
104  zorba = aZorba;
105  staticContext = zorba.createStaticContext();
106  if (uriPaths!=null) {
107  staticContext.setURIPath(uriPaths);
108  }
109  }
110  public ZorbaXQStaticContext(XQuery aQuery) {
111  query = aQuery;
112  staticContext = query.getStaticContext();
113  if (uriPaths!=null) {
114  staticContext.setURIPath(uriPaths);
115  }
116  }
117 
118  protected void setURIPaths(StringVector aURIPath) {
119  uriPaths = aURIPath;
120  if (staticContext!=null) {
121  staticContext.setURIPath(uriPaths);
122  }
123  }
124  protected void setLIBPaths(StringVector aLIBPath) {
125  libPaths = aLIBPath;
126  if (staticContext!=null) {
127  staticContext.setLIBPath(libPaths);
128  }
129  }
130  protected void setMODPaths(StringVector aMODPath) {
131  modulePaths = aMODPath;
132  if (staticContext!=null) {
133  staticContext.setModulePath(modulePaths);
134  }
135  }
136 
137  /** \brief Returns the prefixes of all the statically known namespaces.
138  * Use the getNamespaceURI method to look up the namespace URI corresponding to a specific prefix.
139  *
140  * @return String array containing the namespace prefixes. Cannot be null
141  */
142  @Override
143  public String[] getNamespacePrefixes() {
144 
145  StringPairVector bindings = staticContext.getNamespaceBindings();
146  Collection<String> stringBindings = new ArrayList<String>();
147  int size= (int) bindings.size();
148  for (int i=0; i<size; i++) {
149  StringPair pair = bindings.get(i);
150  stringBindings.add(pair.getFirst());
151  }
152  return stringBindings.toArray(new String[0]);
153  }
154 
155  /** \brief Retrieves the namespace URI associated with a prefix.
156  * An XQException is thrown if an unknown prefix is specified, i.e. a prefix not returned by the getInScopeNamespacePrefixes method.
157  *
158  * @param prefix - the prefix for which the namespace URI is sought. Cannot be null
159  * @return the namespace URI. Cannot be null
160  * @throw XQException - if a null prefix is specified or if the prefix is unknown
161  */
162  @Override
163  public String getNamespaceURI(String prefix) throws XQException {
164  isNullXQException(prefix);
165  String result = null;
166  try {
167  result = staticContext.getNamespaceURIByPrefix(prefix);
168  } catch (Exception e) {
169  throw new XQException("Error getting Namespace URI" + e.getLocalizedMessage());
170  }
171  return result;
172  }
173 
174  /** \brief Declares a namespace prefix and associates it with a namespace URI.
175  * If the namespace URI is the empty string, the prefix is removed from the in-scope namespace definitions.
176  *
177  * @param prefix - the prefix for the namespace URI
178  * @param URI - the namespace URI. An empty string undeclares the specific prefix. Cannot be null
179  * @throw XQException - if (1) a null prefix, or (2) a null namespace URI is specified
180  */
181  @Override
182  public void declareNamespace(String prefix, String URI) throws XQException {
183  isNullXQException(prefix);
184  isNullXQException(URI);
185  try {
186  if ((URI.isEmpty()) && (namespaces.containsKey(prefix))) {
187  namespaces.remove(prefix);
188  StaticContext sc = null;
189  if (zorba==null) {
190  sc = query.getStaticContext();
191  } else {
192  sc = zorba.createStaticContext();
193  }
194  StringPairVector scNamespaces = sc.getNamespaceBindings();
195  int scNamespacesSize = (int) scNamespaces.size();
196 
197  for (String key: namespaces.keySet()) {
198  Boolean found = false;
199  for (int i = 0; i<scNamespacesSize; i++) {
200  StringPair pair = scNamespaces.get(i);
201  if (key.equalsIgnoreCase(pair.getFirst())) {
202  found = true;
203  }
204  }
205  if (!found) {
206  sc.addNamespace(key, namespaces.get(key));
207  }
208  }
209  staticContext = sc;
210 
211  } else {
212  staticContext.addNamespace(prefix, URI);
213  namespaces.put(prefix, URI);
214  }
215  } catch (Exception e) {
216  throw new XQException("Error declaring namespace on static context:" + e.getLocalizedMessage());
217  }
218  }
219 
220  /** \brief Gets the URI of the default element/type namespace, the empty string if not set.
221  *
222  * @return the URI of the default element/type namespace, if set, else the empty string. Cannot be null
223  */
224  @Override
226  return staticContext.getDefaultElementAndTypeNamespace();
227  }
228 
229  /** \brief Sets the URI of the default element/type namespace, the empty string to make it unspecified.
230  *
231  * @param URI - the namespace URI of the default element/type namespace, the empty string to make it unspecified. Cannot be null.
232  * @throw XQException - if a null uri is specified
233  */
234  @Override
235  public void setDefaultElementTypeNamespace(String URI) throws XQException {
236  isNullXQException(URI);
237  staticContext.setDefaultElementAndTypeNamespace(URI);
238  }
239 
240  /** \brief Gets the URI of the default function namespace, the empty string if not set.
241  *
242  * @return the URI of the default function namespace, if set, else the empty string. Cannot be null
243  */
244  @Override
245  public String getDefaultFunctionNamespace() {
246  return staticContext.getDefaultFunctionNamespace();
247  }
248 
249  /** \brief Sets the URI of the default function namespace, the empty string to make it unspecified.
250  *
251  * @param URI - the namespace URI of the default function namespace, the empty string to make it unspecified. Cannot be null.
252  * @throw XQException - if a null URI is specified
253  */
254  @Override
255  public void setDefaultFunctionNamespace(String URI) throws XQException {
256  isNullXQException(URI);
257  staticContext.setDefaultFunctionNamespace(URI);
258  }
259 
260  /** \brief Gets the static type of the context item. null if unspecified.
261  *
262  * @return the static type of the context item, if set, else null
263  */
264  @Override
265  public XQItemType getContextItemStaticType() {
266  //not very complete implementation
267  //TypeIdentifier type = staticContext.getContextItemStaticType();
268  return contextItemStaticType;
269  }
270 
271  /** \brief Sets the static type of the context item, specify null to make it unspecified.
272  *
273  * @param xqit - the static type of the context item; null if unspecified.
274  * @throw XQException - if the contextItemType is not a valid ZorbaXQItemType
275  */
276  @Override
277  public void setContextItemStaticType(XQItemType xqit) throws XQException {
278  contextItemStaticType = xqit;
279  if (xqit instanceof XQItemType) {
280  org.zorbaxquery.api.xqj.ZorbaXQItemType wrapper = (org.zorbaxquery.api.xqj.ZorbaXQItemType) xqit;
281  staticContext.setContextItemStaticType(wrapper.getTypeIdentifier());
282  }
283  }
284 
285  /** \brief Gets the URI of the default collation.
286  *
287  * @return the URI of the default collation. Cannot be null.
288  */
289  @Override
290  public String getDefaultCollation() {
291  return staticContext.getDefaultCollation();
292  }
293 
294  /** \brief Sets the URI of the default collation.
295  *
296  * @param URI - the namespace URI of the default collation. Cannot be null.
297  * @throw XQException - if a null URI is specified
298  */
299  @Override
300  public void setDefaultCollation(String URI) throws XQException {
301  isNullXQException(URI);
302  staticContext.setDefaultCollation(URI);
303  }
304 
305  /** \brief Gets the construction mode defined in the static context.
306  *
307  * @return construction mode value. One of: XQConstants.CONSTRUCTION_MODE_PRESERVE, XQConstants.CONSTRUCTION_MODE_STRIP
308  */
309  @Override
310  public int getConstructionMode() {
311  int result = XQConstants.CONSTRUCTION_MODE_PRESERVE;
312  int mode = staticContext.getConstructionMode();
313  if (mode == ConstructionMode.STRIP_CONSTRUCTION) {
314  result = XQConstants.CONSTRUCTION_MODE_STRIP;
315  }
316  return result;
317  }
318 
319  /** \brief Sets the construction mode in the static context.
320  *
321  * @param i - construction mode value. One of: XQConstants.CONSTRUCTION_MODE_PRESERVE, XQConstants.CONSTRUCTION_MODE_STRIP.
322  * @throw XQException - the specified mode is different from XQConstants.CONSTRUCTION_MODE_PRESERVE, XQConstants.CONSTRUCTION_MODE_STRIP
323  */
324  @Override
325  public void setConstructionMode(int i) throws XQException {
326  if (!((i==XQConstants.CONSTRUCTION_MODE_PRESERVE) || (i==XQConstants.CONSTRUCTION_MODE_STRIP))) {
327  throw new XQException("Invalid construction mode.");
328  }
329  int mode = ConstructionMode.STRIP_CONSTRUCTION;
330  if (i==XQConstants.CONSTRUCTION_MODE_PRESERVE) {
331  mode = ConstructionMode.PRESERVE_CONSTRUCTION;
332  }
333  staticContext.setConstructionMode(mode);
334  }
335 
336  /** \brief Gets the ordering mode defined in the static context.
337  *
338  * @return ordering mode value. One of: XQConstants.ORDERING_MODE_ORDERED, XQConstants.ORDERING_MODE_UNORDERED.
339  */
340  @Override
341  public int getOrderingMode() {
342  int result = XQConstants.ORDERING_MODE_ORDERED;
343  int mode = staticContext.getOrderingMode();
344  if (mode == OrderingMode.UNORDERED) {
345  result = XQConstants.ORDERING_MODE_UNORDERED;
346  }
347  return result;
348  }
349 
350  /** \brief Sets the ordering mode in the static context.
351  *
352  * @param i - ordering mode value. One of: XQConstants.ORDERING_MODE_ORDERED, XQConstants.ORDERING_MODE_UNORDERED.
353  * @throw XQException - the specified mode is different from XQConstants.ORDERING_MODE_ORDERED, XQConstants.ORDERING_MODE_UNORDERED
354  */
355  @Override
356  public void setOrderingMode(int i) throws XQException {
357  if (!((i==XQConstants.ORDERING_MODE_ORDERED) || (i==XQConstants.ORDERING_MODE_UNORDERED))) {
358  throw new XQException("Invalid ordering mode.");
359  }
360  int mode = OrderingMode.ORDERED;
361  if (i==XQConstants.ORDERING_MODE_UNORDERED) {
362  mode = OrderingMode.UNORDERED;
363  }
364  staticContext.setOrderingMode(mode);
365  }
366 
367  /** \brief Gets the default order for empty sequences defined in the static context.
368  *
369  * @return default order for empty sequences value. One of: XQConstants.DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_GREATEST, XQConstants.DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_LEAST.
370  */
371  @Override
373  int result = XQConstants.DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_GREATEST;
374  int order = staticContext.getDefaultOrderForEmptySequences();
375  if (order == OrderEmptyMode.EMPTY_LEAST) {
376  result = XQConstants.DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_LEAST;
377  }
378  return result;
379  }
380 
381  /** \brief Sets the default order for empty sequences in the static context.
382  *
383  * @param i - the default order for empty sequences. One of: XQConstants.DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_GREATEST, XQConstants.DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_LEAST.
384  * @throw XQException - the specified order for empty sequences is different from XQConstants.DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_GREATEST, XQConstants.DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_LEAST
385  */
386  @Override
387  public void setDefaultOrderForEmptySequences(int i) throws XQException {
388  if (!((i == XQConstants.DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_GREATEST) || (i==XQConstants.DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_LEAST))) {
389  throw new XQException("Invalid order specified.");
390  }
391  int result = OrderEmptyMode.EMPTY_GREATEST;
392  if (i == XQConstants.DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_LEAST) {
393  result = OrderEmptyMode.EMPTY_LEAST;
394  }
395  staticContext.setDefaultOrderForEmptySequences(result);
396  }
397 
398  /** \brief Gets the boundary-space policy defined in the static context.
399  *
400  * @return the boundary-space policy value. One of: XQConstants.BOUNDARY_SPACE_PRESERVE, XQConstants.BOUNDARY_SPACE_STRIP.
401  */
402  @Override
403  public int getBoundarySpacePolicy() {
404  int result = XQConstants.BOUNDARY_SPACE_PRESERVE;
405  int boundary = staticContext.getBoundarySpacePolicy();
406  if (boundary == BoundarySpaceMode.STRIP_SPACE) {
407  result = XQConstants.BOUNDARY_SPACE_STRIP;
408  }
409  return result;
410  }
411 
412  /** \brief Sets the boundary-space policy in the static context.
413  *
414  * @param i - boundary space policy. One of: XQConstants.BOUNDARY_SPACE_PRESERVE, XQConstants.BOUNDARY_SPACE_STRIP.
415  * @throw XQException - the specified mode is different from XQConstants.BOUNDARY_SPACE_PRESERVE, XQConstants.BOUNDARY_SPACE_STRIP
416  */
417  @Override
418  public void setBoundarySpacePolicy(int i) throws XQException {
419  if (!((i == XQConstants.BOUNDARY_SPACE_PRESERVE) || (i==XQConstants.BOUNDARY_SPACE_STRIP))) {
420  throw new XQException("Invalid boundary specified.");
421  }
422  int result = BoundarySpaceMode.PRESERVE_SPACE;
423  if (i == XQConstants.BOUNDARY_SPACE_STRIP) {
424  result = BoundarySpaceMode.STRIP_SPACE;
425  }
426  staticContext.setBoundarySpacePolicy(result);
427  }
428 
429  /** \brief Gets the preserve part of the copy-namespaces mode defined in the static context.
430  *
431  * @return construction mode value. One of: XQConstants.COPY_NAMESPACES_MODE_PRESERVE, XQConstants.COPY_NAMESPACES_MODE_NO_PRESERVE.
432  */
433  @Override
435  int result = XQConstants.COPY_NAMESPACES_MODE_NO_PRESERVE;
436  int preserve = staticContext.getCopyNamespacesModePreserve();
437  if (preserve == PreserveMode.PRESERVE) {
438  result = XQConstants.COPY_NAMESPACES_MODE_PRESERVE;
439  }
440  return result;
441  }
442 
443  /** \brief Sets the preserve part of the copy-namespaces mode in the static context.
444  *
445  * @param i - ordering mode value. One of: XQConstants.COPY_NAMESPACES_MODE_PRESERVE, XQConstants.COPY_NAMESPACES_MODE_NO_PRESERVE.
446  * @throw XQException - the specified mode is different from XQConstants.COPY_NAMESPACES_MODE_PRESERVE, XQConstants.COPY_NAMESPACES_MODE_NO_PRESERVE
447  */
448  @Override
449  public void setCopyNamespacesModePreserve(int i) throws XQException {
450  if (!((i==XQConstants.COPY_NAMESPACES_MODE_PRESERVE) || (i==XQConstants.COPY_NAMESPACES_MODE_NO_PRESERVE))) {
451  throw new XQException("The specified mode is invalid.");
452  }
453  int inherit = staticContext.getCopyNamespacesModeInherit();
454  int preserve = PreserveMode.NO_PRESERVE;
455  if (i==XQConstants.COPY_NAMESPACES_MODE_PRESERVE) {
456  preserve = PreserveMode.PRESERVE;
457  }
458  staticContext.setCopyNamespacesMode(preserve, inherit);
459  }
460 
461  /** \brief Gets the inherit part of the copy-namespaces mode defined in the static context.
462  *
463  * @return construction mode value. One of: XQConstants.COPY_NAMESPACES_MODE_INHERIT, XQConstants.COPY_NAMESPACES_MODE_NO_INHERIT.
464  */
465  @Override
467  int result = XQConstants.COPY_NAMESPACES_MODE_NO_INHERIT;
468  int inherit = staticContext.getCopyNamespacesModeInherit();
469  if (inherit == InheritMode.INHERIT) {
470  result = XQConstants.COPY_NAMESPACES_MODE_INHERIT;
471  }
472  return result;
473  }
474 
475  /** \brief Sets the inherit part of the copy-namespaces mode in the static context.
476  *
477  * @param i - ordering mode value. One of: XQConstants.COPY_NAMESPACES_MODE_INHERIT, XQConstants.COPY_NAMESPACES_MODE_NO_INHERIT.
478  * @throw XQException - the specified mode is different from XQConstants.COPY_NAMESPACES_MODE_INHERIT, XQConstants.COPY_NAMESPACES_MODE_NO_INHERIT
479  */
480  @Override
481  public void setCopyNamespacesModeInherit(int i) throws XQException {
482  if (!((i==XQConstants.COPY_NAMESPACES_MODE_INHERIT) || (i==XQConstants.COPY_NAMESPACES_MODE_NO_INHERIT))) {
483  throw new XQException("The specified mode is invalid.");
484  }
485  int preserve = staticContext.getCopyNamespacesModePreserve();
486  int inherit = InheritMode.NO_INHERIT;
487  if (i==XQConstants.COPY_NAMESPACES_MODE_INHERIT) {
488  inherit = InheritMode.INHERIT;
489  }
490  staticContext.setCopyNamespacesMode(preserve, inherit);
491  }
492 
493  /** \brief Gets the Base URI, if set in the static context, else the empty string.
494  *
495  * @return the base URI, if set, else the empty string. Cannot be null..
496  */
497  @Override
498  public String getBaseURI() {
499  if (baseURI==null) {
500  return staticContext.getBaseURI();
501  } else {
502  return baseURI;
503  }
504  }
505 
506  /** \brief Sets the Base URI in the static context, specify the empty string to make it undefined.
507  *
508  * @param URI - the new baseUri, or empty string to make it undefined. Cannot be null.
509  * @throw XQException - if a null base uri is specified
510  */
511  @Override
512  public void setBaseURI(String URI) throws XQException {
513  isNullXQException(URI);
514  staticContext.setBaseURI(URI);
515  baseURI = URI;
516  }
517 
518  /** \brief Gets the value of the binding mode property.
519  * By default an XQJ implementation operates in immediate binding mode.
520  *
521  * @return the binding mode. One of XQConstants.BINDING_MODE_IMMEDIATE, orXQConstants.BINDING_MODE_DEFERRED.
522  */
523  @Override
524  public int getBindingMode() {
525  return binding;
526  }
527 
528  /** \brief Sets the binding mode property.
529  * By default an XQJ implementation operates in immediate binding mode.
530  *
531  * @param i - the binding mode. One of: XQConstants.BINDING_MODE_IMMEDIATE, orXQConstants.BINDING_MODE_DEFERRED.
532  * @throw XQException - the specified mode is different from XQConstants.BINDING_MODE_IMMEDIATE, XQConstants.BINDING_MODE_DEFERRED
533  */
534  @Override
535  public void setBindingMode(int i) throws XQException {
536  if (!((i==XQConstants.BINDING_MODE_DEFERRED) || (i==XQConstants.BINDING_MODE_IMMEDIATE))) {
537  throw new XQException("The specified mode is invalid.");
538  }
539  binding = i;
540  }
541 
542  /** \brief Gets the value of the holdability property.
543  *
544  * @return the type of a result's holdability. One of: XQConstants.HOLDTYPE_HOLD_CURSORS_OVER_COMMIT, or XQConstants.HOLDTYPE_CLOSE_CURSORS_AT_COMMIT.
545  */
546  @Override
547  public int getHoldability() {
548  return holdability;
549  }
550 
551  /** \brief Sets the holdability property.
552  *
553  * @param i - the holdability of the result. One of: XQConstants.HOLDTYPE_HOLD_CURSORS_OVER_COMMIT, or XQConstants.HOLDTYPE_CLOSE_CURSORS_AT_COMMIT.
554  * @throw XQException - the specified holdability is different from XQConstants.HOLDTYPE_HOLD_CURSORS_OVER_COMMIT, XQConstants.HOLDTYPE_CLOSE_CURSORS_AT_COMMIT
555  */
556  @Override
557  public void setHoldability(int i) throws XQException {
558  if (!((i==XQConstants.HOLDTYPE_HOLD_CURSORS_OVER_COMMIT) || (i==XQConstants.HOLDTYPE_CLOSE_CURSORS_AT_COMMIT))) {
559  throw new XQException ("Invalid holdability parameter.");
560  }
561  holdability = i;
562  }
563 
564  /** \brief Gets the value of the language type and version property.
565  * By default an XQJ implementation's default is XQConstants.LANGTYPE_XQUERY.
566  *
567  * @return the language type and version. One of: XQConstants.LANGTYPE_XQUERY, or XQConstants.LANGTYPE_XQUERYX or a negative value indicating a vendor specific query language type and version.
568  */
569  @Override
571  return queryLang;
572  }
573 
574  /** \brief Sets the input query language type and version.
575  * When this is set to a particular language type and version, then the query is assumed to be in that language and version.
576  *
577  * @param i - the query language type and version of the inputs. One of: XQConstants.LANGTYPE_XQUERY (default), or XQConstants.LANGTYPE_XQUERYX. A negative number indicates a vendor specific query language type and version.
578  * @throw XQException - the specified langtype is different from XQConstants.LANGTYPE_XQUERY, XQConstants.LANGTYPE_XQUERYX and is not negative
579  */
580  @Override
581  public void setQueryLanguageTypeAndVersion(int i) throws XQException {
582  if (!((i==XQConstants.LANGTYPE_XQUERY) || (i==XQConstants.LANGTYPE_XQUERYX))) {
583  throw new XQException ("Invalid holdability parameter.");
584  }
585  queryLang = i;
586  }
587 
588  /** \brief Gets the value of the scrollability property.
589  * By default query results are forward only.
590  *
591  * @return the type of a result's scrollability. One of: XQConstants.SCROLLTYPE_FORWARD_ONLY, or XQConstants.SCROLLTYPE_SCROLLABLE.
592  */
593  @Override
594  public int getScrollability() {
595  return scrollability;
596  }
597 
598  /** \brief Sets the scrollability of the result sequence.
599  * By default query results are forward only.
600  *
601  * @param i - the scrollability of the result. One of: XQConstants.SCROLLTYPE_FORWARD_ONLY, or XQConstants.SCROLLTYPE_SCROLLABLE.
602  * @throw XQException - the specified crollability type is different from XQConstants.SCROLLTYPE_FORWARD_ONLY, XQConstants.SCROLLTYPE_SCROLLABLE
603  */
604  @Override
605  public void setScrollability(int i) throws XQException {
606  if (!((i==XQConstants.SCROLLTYPE_FORWARD_ONLY) || (i==XQConstants.SCROLLTYPE_SCROLLABLE))) {
607  throw new XQException ("Invalid scroll type.");
608  }
609  scrollability = i;
610  }
611 
612  /** \brief Retrieves the number of seconds an implementation will wait for a query to execute.
613  *
614  * @return the query execution timeout value in seconds. A value of 0 indicates no limit.
615  */
616  @Override
617  public int getQueryTimeout() {
618  return 0;
619  }
620 
621  /** \brief Sets the number of seconds an implementation will wait for a query to execute.
622  * If the implementation does not support query timeout it can ignore the specified timeout value. It the limit is exceeded, the behavor of the query is the same as an execution of a cancel by another thread.
623  *
624  * @param i - the query execution timeout value in seconds. A value of 0 indicates no limit
625  * @throw XQException - if the passed in value is negative
626  */
627  @Override
628  public void setQueryTimeout(int i) throws XQException {
629  if (i<0) {
630  throw new XQException("Value can't be negative.");
631  }
632  }
633 
634  /** \brief Returns a StaticCollectionManager.
635  *
636  * 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.
637  * The collection manager provides a set of functions for managing collections and their contents.
638  *
639  * @return ZorbaXQStaticCollectionManager The collection manager responsible for managing collections of this Sequence.
640  * @throw XQException - if the object is closed
641  */
643  if (lStaticCollectionManager==null) {
644  lStaticCollectionManager = new ZorbaXQStaticCollectionManager(staticContext.getStaticCollectionManager());
645  }
646  return lStaticCollectionManager;
647  }
648 
649  private void isNullXQException(Object value) throws XQException {
650  if (value==null) {
651  throw new XQException("Parameter shouldn't be null");
652  }
653  }
654 
655 }