gpt4 book ai didi

javax.xml.xquery.XQSequence类的使用及代码示例

转载 作者:知者 更新时间:2024-03-19 15:26:40 26 4
gpt4 key购买 nike

本文整理了Java中javax.xml.xquery.XQSequence类的一些代码示例,展示了XQSequence类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XQSequence类的具体详情如下:
包路径:javax.xml.xquery.XQSequence
类名称:XQSequence

XQSequence介绍

[英]This interface represents a sequence of items as defined in the XDM. The sequence may be materialized or non-materialized.

The next method is useful to position the XQSequence over the next item in the sequence. If the scrollability is XQConstants.SCROLLTYPE_SCROLLABLE, then the previous method can be called to move backwards. In the case of a forward only sequence, the get methods may be only called once per item. To perform multiple gets on an item, extract the item first from the sequence using the getItem method and then operate on the XQItem object.

XQPreparedExpression expr = conn.prepareExpression("for $i .."); 
XQSequence result = expr.executeQuery(); 
// create the ItemTypes for string and integer 
XQItemType strType = conn.createAtomicType(XQItemType.XQBASETYPE_STRING); 
XQItemType intType = conn.createAtomicType(XQItemType.XQBASETYPE_INT); 
// positioned 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(); 
... 
}

In a sequence, the cursor may be positioned on an item, after the last item or before the first item. The getPosition method returns the current position number. A value of 0 indicates that it is positioned before the first item, a value of count() + 1 indicates that it is positioned after the last item, and any other value indicates that it is positioned on the item at that position.

For example, a position value of 1 indicates that it is positioned on the item at position 1.

The isOnItem method may be used to find out if the cursor is positioned on the item. When the cursor is positioned on an item, the next method call will move the cursor to be on the next item.

See also: Section 12 Serialization, XQuery API for Java (XQJ) 1.0, which describes some general information applicable to various XQJ serialization methods.
[中]此接口表示XDM中定义的一系列项。序列可以是物化的或非物化的。
next方法可用于将XQSequence放置在序列中的下一项上。如果可滚动性为XQConstants.SCROLLTYPE_SCROLLABLE,则可以调用previous方法向后移动。对于仅向前的序列,每个项只能调用一次get方法。要对一个项目执行多个get,请首先使用getItem方法从序列中提取该项目,然后对XQItem对象进行操作。

XQPreparedExpression expr = conn.prepareExpression("for $i .."); 
XQSequence result = expr.executeQuery(); 
// create the ItemTypes for string and integer 
XQItemType strType = conn.createAtomicType(XQItemType.XQBASETYPE_STRING); 
XQItemType intType = conn.createAtomicType(XQItemType.XQBASETYPE_INT); 
// positioned 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(); 
... 
}

按顺序,光标可能位于某个项目上,最后一个项目之后或第一个项目之前。getPosition方法返回当前位置号。值0表示它位于第一个项目之前,count() + 1表示它位于最后一个项目之后,任何其他值表示它位于该项目的该位置。
例如,位置值为1表示它位于项目的位置1。
isOnItem方法可用于确定光标是否位于项目上。当光标定位在一个项目上时,next方法调用会将光标移动到下一个项目上。
另请参见:第12节序列化,XQuery API for Java(XQJ)1.0,其中描述了适用于各种XQJ序列化方法的一些一般信息。

代码示例

代码示例来源:origin: dsukhoroslov/bagri

public static Map<String, Object> mapFromSequence(XQSequence cs) throws XQException {
  Map<String, Object> result;
  synchronized (cs) {
    if (cs.isScrollable()) {
      cs.beforeFirst();
      result = new HashMap<>(cs.count());
    } else {
      result = new HashMap<>();
    }
    
    while (cs.next()) {
      XQSequence pair = (XQSequence) cs.getObject();
      pair.beforeFirst();
      pair.next();
      String key = pair.getAtomicValue();
      pair.next();
      Object value = pair.getObject();
      result.put(key, value);
    }
  }
    return result;
}

代码示例来源:origin: dsukhoroslov/bagri

@Override
public void write(ObjectDataOutput out, XQSequence sequence) throws IOException {
  try {
    List<XQItemAccessor> items;
    synchronized (sequence) {
      if (sequence.isScrollable()) {
        sequence.beforeFirst();
        items = new ArrayList<>(sequence.count());
      } else {
        items = new ArrayList<>();
      }
      while (sequence.next()) {
        Object value = sequence.getObject();
        if (value instanceof XQItemAccessor) {
          items.add((XQItemAccessor) value);
        } else {
          items.add(sequence.getItem());
        }
      }
    }
    logger.trace("write; writing {} items", items.size());
    out.writeObject(items);
  } catch (XQException ex) {
    throw new IOException(ex);
  }
}

代码示例来源:origin: dsukhoroslov/bagri

@Override
public void close() {
  try {
    xqs.close();
  } catch (XQException ex) {
    logger.error("close", ex);
  }
}

代码示例来源:origin: dsukhoroslov/bagri

@SuppressWarnings({ "rawtypes", "unchecked" })
private List getList(XQSequence xqc) throws XQException {
  ArrayList list = new ArrayList();
  boolean hasNext = xqc.isOnItem();
  if (!hasNext) {
    hasNext = xqc.next();
  }
  while (hasNext) {
    list.add(xqc.getItem());
    hasNext = xqc.next();
  }
  return list;
}

代码示例来源:origin: dsukhoroslov/bagri

@Override
public Item next() throws XPathException {
  try {
    if (xqs.next()) {
      return convertXQItem(xqs.getItem(), config);
    }
  } catch (XQException ex) {
    throw new XPathException(ex);
  }
  return null;
}

代码示例来源:origin: dsukhoroslov/bagri

@Override
public void deleteDocument(String uri) throws XQException {
  String query = "declare namespace bgdb=\"http://bagridb.com/bdb\";\n" +
      "declare variable $uri external;\n" + 
      "let $uri := bgdb:remove-document($uri)\n" + 
      "return $uri\n";
  XQPreparedExpression xqpe = xqConn.prepareExpression(query);
  xqpe.bindString(new QName("uri"), uri, xqConn.createAtomicType(XQItemType.XQBASETYPE_ANYURI));
  XQSequence xqs = xqpe.executeQuery();
  String result = null;
  try {
    if (xqs.next()) {
      result = xqs.getAtomicValue();
    }
    if (!uri.equals(result)) {
      throw new XQException("got no result from bgdb:remove-document function");
    }
  } finally {
    xqpe.close();
    xqs.close();
  }
}

代码示例来源:origin: dsukhoroslov/bagri

xqpe.bindSequence(new QName("props"), xqc.createSequence(props.iterator()));
XQSequence xqs = xqpe.executeQuery();
if (xqs.next()) {
  long id = xqs.getLong();
  xqpe.close();
  xqs.close();
  return id;
} else {
  xqpe.close();
  xqs.close();
  throw new XQException("no response from store-document function");

代码示例来源:origin: dsukhoroslov/bagri

private long storeXmlDocument(String fileName) throws XQException {
  
  String dName = "..\\..\\etc\\samples\\tpox\\";
  String xml;
  try {
    xml = readTextFile(dName + fileName);
  } catch (IOException ex) {
    throw new XQException(ex.getMessage());
  }
  String query = "declare namespace bgdb=\"http://bagridb.com/bdb\";\n" +
      "declare variable $sec external;\n\n" + 
      //"return bgdb:store-document($sec)\n";
      "for $id in bgdb:store-document($sec)\n" +
      "return $id\n";
  XQPreparedExpression xqpe = xqc.prepareExpression(query);
  xqpe.bindString(new QName("sec"), xml, xqc.createAtomicType(XQItemType.XQBASETYPE_STRING));
  XQSequence xqs = xqpe.executeQuery();
  if (xqs.next()) {
    long result = xqs.getLong();
    xqpe.close();
    return result;
  } else {
    xqpe.close();
    throw new XQException("no response from store-document function");
  }
}

代码示例来源:origin: dsukhoroslov/bagri

String result = null;
try {
  if (xqs.next()) {
    result = xqs.getAtomicValue();
  xqs.close();

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com