org.teiid.core.types.XMLType类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(159)

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

XMLType介绍

[英]This class represents the SQLXML object along with the Streamable interface. NOTE that this representation of XML does not become unreadable after read operations.
[中]此类表示SQLXML对象以及可流化接口。请注意,这种XML表示形式在读操作后不会变得不可读。

代码示例

代码示例来源:origin: teiid/teiid

public static XMLType xmlPi(String name, String content) {
  int start = 0;
  char[] chars = content.toCharArray();
  while (start < chars.length && chars[start] == ' ') {
    start++;
  }
  XMLType result = new XMLType(new SQLXMLImpl("<?" + name + " " + content.substring(start) + "?>")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  result.setType(Type.PI);
  return result;
}

代码示例来源:origin: org.jboss.teiid/teiid-engine

private static XMLEventReader getXMLEventReader(StAXSource source) throws XMLStreamException {
  XMLEventReader reader = source.getXMLEventReader();
  if (reader == null) {
    XMLInputFactory inputFactory = XMLType.getXmlInputFactory();
    reader = inputFactory.createXMLEventReader(source.getXMLStreamReader());
  }
  return reader;
}

代码示例来源:origin: org.teiid/teiid-common-core

public String getEncoding() {
  if (encoding == null) {
    this.encoding = getEncoding(this);
  }
  return encoding;
}

代码示例来源:origin: teiid/teiid

@Override
  protected Object readObject(ObjectInput in, List<Object> cache, byte version) throws IOException, ClassNotFoundException {
    XMLType xt = new XMLType();
    xt.readExternal(in, (byte)1);
    return xt;
  }
}

代码示例来源:origin: org.jboss.teiid/teiid-engine

@Override
  public StAXSource getStaxSource() throws SQLException {
    try {
      XMLEventReader eventReader = getXMLEventReader(v.getSource(StAXSource.class));
      eventReader = XMLType.getXmlInputFactory().createFilteredReader(eventReader, declarationOmittingFilter);
      return new StAXSource(eventReader);
    } catch (XMLStreamException e) {
      throw new SQLException(e);
    }
  }
};

代码示例来源:origin: org.teiid/teiid-engine

public static Object serialize(XMLSerialize xs, XMLType value) throws TransformationException {
  Type type = value.getType();
  final Charset encoding;
  if (xs.getEncoding() != null) {
      value = new XMLType(new StAXSQLXML(sourceProvider, encoding));
      value.setType(type);
    value = new XMLType(new StAXSQLXML(sourceProvider, encoding));
    value.setType(Type.DOCUMENT);
    try {
      InputStream is = null;
      if (!Charset.forName(value.getEncoding()).equals(encoding)) {
        is = new ReaderInputStream(value.getCharacterStream(), encoding);
      } else {
        is = value.getBinaryStream();					
  if (!Charset.forName(value.getEncoding()).equals(encoding)) {

代码示例来源:origin: org.teiid/teiid-engine

int read = -1;
  if (r == null) {
    r = xml.getCharacterStream();
case DOCUMENT: //filter the doc declaration
  XMLEventReader eventReader = null;
  XMLInputFactory inputFactory = XMLType.getXmlInputFactory();
  if (r != null) {
    if (!(r instanceof BufferedReader)) {
    StAXSource staxSource = xml.getSource(StAXSource.class);
    eventReader = staxSource.getXMLEventReader();
    if (eventReader == null) {
case TEXT:
  if (r == null) {
    r = xml.getCharacterStream();

代码示例来源:origin: teiid/teiid

@Test public void testReferencePersistence() throws Exception {
  String testString = "<foo>this is an xml value test</foo>"; //$NON-NLS-1$
  SQLXMLImpl xml = new SQLXMLImpl(testString); 
  
  XMLType xv = new XMLType(xml);
  xv.setReferenceStreamId(null);
  
  // now force to serialize
  XMLType read = UnitTestUtil.helpSerialize(xv);
      
  assertEquals(testString, read.getString());
}

代码示例来源:origin: teiid/teiid

@Test public void testXMLValue() throws Exception {
  String testString = "<foo>this is an xml value test</foo>"; //$NON-NLS-1$
  SQLXMLImpl xml = new SQLXMLImpl(testString); 
  
  XMLType xv = new XMLType(xml);
  assertEquals(testString, xv.getString());
}

代码示例来源:origin: teiid/teiid

@Test public void testXMLValuePersistence() throws Exception {
  String testString = "<foo>this is an xml value test</foo>"; //$NON-NLS-1$
  SQLXMLImpl xml = new SQLXMLImpl(testString); 
  
  XMLType xv = new XMLType(xml);
  String key = xv.getReferenceStreamId();
  
  // now force to serialize
  XMLType read = UnitTestUtil.helpSerialize(xv);
      
  // make sure we have kept the reference stream id
  assertEquals(key, read.getReferenceStreamId());
  
  // and lost the original object
  assertNull(read.getReference());
}

代码示例来源:origin: teiid/teiid

private Object evaluateXMLSerialize(List<?> tuple, XMLSerialize xs)
    throws ExpressionEvaluationException, BlockedException,
    TeiidComponentException, FunctionExecutionException {
  XMLType value = (XMLType) internalEvaluate(xs.getExpression(), tuple);
  if (value == null) {
    return null;
  }
  try {
    if (!xs.isDocument()) {
      return XMLSystemFunctions.serialize(xs, value);
    }
    if (value.getType() == Type.UNKNOWN) {
      Type type = StringToSQLXMLTransform.isXml(value.getCharacterStream());
      value.setType(type);
    }
    if (value.getType() == Type.DOCUMENT || value.getType() == Type.ELEMENT) {
      return XMLSystemFunctions.serialize(xs, value);
    }
  } catch (SQLException e) {
     throw new FunctionExecutionException(QueryPlugin.Event.TEIID30334, e);
  } catch (TransformationException e) {
     throw new FunctionExecutionException(QueryPlugin.Event.TEIID30335, e);
  }
   throw new FunctionExecutionException(QueryPlugin.Event.TEIID30336, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30336));
}

代码示例来源:origin: org.jboss.teiid/teiid-engine

if (doc != null && doc.isFinished()) {
  this.env.setDocumentInProgress(null);
  XMLType xml = new XMLType(doc.getSQLXML());
      reader = xml.getCharacterStream();
    } catch (SQLException e) {
       throw new TeiidComponentException(QueryPlugin.Event.TEIID30194, e);

代码示例来源:origin: teiid/teiid

@Test public void testLength() throws Exception {
    String testString = "<foo>this is an xml value test</foo>"; //$NON-NLS-1$
    SQLXMLImpl xml = new SQLXMLImpl(testString); 
    
    XMLType xv = new XMLType(xml);
    assertEquals(36, xv.length());
    
    xml = new SQLXMLImpl(new InputStreamFactory() {
      @Override
      public InputStream getInputStream() throws IOException {
        return new ByteArrayInputStream("<bar/>".getBytes(Streamable.CHARSET));
      }
    }); 
    
    xv = new XMLType(xml);
    try {
      xv.length();        
      fail();
    } catch (SQLException e) {
      
    }
  }
}

代码示例来源:origin: teiid/teiid

@Test public void testXML() throws Exception {
  StatementImpl statement = createMockStatement(ResultSet.TYPE_FORWARD_ONLY);
  ResultsFuture<LobChunk> future = new ResultsFuture<LobChunk>();
  future.getResultsReceiver().receiveResults(new LobChunk("<a/>".getBytes(Charset.forName("UTF-8")), true));
  XMLType result = new XMLType();
  Mockito.stub(statement.getDQP().requestNextLobChunk(0, 0, result.getReferenceStreamId())).toReturn(future);
  ResultsMessage resultsMsg = new ResultsMessage();
  result.setEncoding("UTF-8");
  resultsMsg.setResults(new List<?>[] {Arrays.asList(result)});
  resultsMsg.setLastRow(1);
  resultsMsg.setFirstRow(1);
  resultsMsg.setFinalRow(1);
  resultsMsg.setColumnNames(new String[] {"x"}); //$NON-NLS-1$
  resultsMsg.setDataTypes(new String[] {"xml"}); //$NON-NLS-1$
  ResultSetImpl cs = new ResultSetImpl(resultsMsg, statement);
  cs.next();
  assertEquals("<a/>", cs.getString(1));
}

代码示例来源:origin: org.teiid/teiid-engine

public static Object evaluate(XMLType value, XMLCast expression, CommandContext context) throws ExpressionEvaluationException {
  Configuration config = new Configuration();
  Type t = value.getType();
  try {
    Item i = null;
        throw new FunctionExecutionException();
      case TEXT:
        i = new StringValue(value.getString());
        break;
      case UNKNOWN:
      case DOCUMENT:
      case ELEMENT:
        StreamSource ss = value.getSource(StreamSource.class);
        try {
          i = config.buildDocument(ss);

代码示例来源:origin: org.teiid/rest-service

private InputStream handleResult(String charSet, Object result) throws SQLException {
  if (result == null) {
    return null; //or should this be an empty result?
  }
  if (result instanceof SQLXML) {
    if (charSet != null) {
      XMLSerialize serialize = new XMLSerialize();
      serialize.setTypeString("blob"); //$NON-NLS-1$
      serialize.setDeclaration(true);
      serialize.setEncoding(charSet);
      serialize.setDocument(true);
      try {
        return ((BlobType)XMLSystemFunctions.serialize(serialize, new XMLType((SQLXML)result))).getBinaryStream();
      } catch (TransformationException e) {
        throw new SQLException(e);
      }
    }
    return ((SQLXML)result).getBinaryStream();
  }
  else if (result instanceof Blob) {
    return ((Blob)result).getBinaryStream();
  }
  else if (result instanceof Clob) {
    return new ReaderInputStream(((Clob)result).getCharacterStream(), charSet==null?Charset.defaultCharset():Charset.forName(charSet));
  }
  return new ByteArrayInputStream(result.toString().getBytes(charSet==null?Charset.defaultCharset():Charset.forName(charSet)));
}

代码示例来源:origin: teiid/teiid

@Test public void testTypeConversion() throws Exception {
  BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
  
  String str = "hello world";
  
  Object source = new StreamSource(new StringReader(str));
  XMLType xml = (XMLType) ConnectorWorkItem.convertToRuntimeType(bm, source, DataTypeManager.DefaultDataClasses.XML, null);
  assertEquals(str, xml.getString());
  
  source = new StAXSource(XMLType.getXmlInputFactory().createXMLEventReader(new StringReader("<a/>")));
  xml = (XMLType) ConnectorWorkItem.convertToRuntimeType(bm, source, DataTypeManager.DefaultDataClasses.XML, null);
  XMLInputFactory in = XMLType.getXmlInputFactory();
  XMLStreamReader reader = in.createXMLStreamReader(new StringReader(xml.getString()));
  assertEquals(XMLEvent.START_DOCUMENT, reader.getEventType());
  assertEquals(XMLEvent.START_ELEMENT, reader.next());
  assertEquals("a", reader.getLocalName());
  assertEquals(XMLEvent.END_ELEMENT, reader.next());
  
  byte[] bytes = str.getBytes(Streamable.ENCODING);
  source = new InputStreamFactory.BlobInputStreamFactory(BlobType.createBlob(bytes));
  BlobType blob = (BlobType) ConnectorWorkItem.convertToRuntimeType(bm, source, DataTypeManager.DefaultDataClasses.BLOB, null);
  
  assertArrayEquals(bytes, ObjectConverterUtil.convertToByteArray(blob.getBinaryStream()));
}

代码示例来源:origin: org.jboss.teiid/teiid-engine

} else {
  XMLType x = (XMLType)lob;
  String s = x.getString();
  x.setReference(new SQLXMLImpl(s));
((XMLType)lob).setReference(new SQLXMLImpl(isf));

代码示例来源:origin: teiid/teiid

@Test public void testGoodElement() throws Exception {
  String xml = "<customer>\n" + //$NON-NLS-1$
          "<name>ABC</name>" + //$NON-NLS-1$
          "<age>32</age>" + //$NON-NLS-1$
         "</customer>"; //$NON-NLS-1$
  
  StringToSQLXMLTransform transform = new StringToSQLXMLTransform();
    XMLType xmlValue = (XMLType)transform.transformDirect(xml);
  assertEquals(xml.replaceAll("[\r]", ""), xmlValue.getString().replaceAll("[\r]", ""));
  assertEquals(XMLType.Type.ELEMENT, xmlValue.getType());
}

代码示例来源:origin: org.teiid/teiid-common-core

/**
 * This method transforms a value of the source type into a value
 * of the target type.
 * @param value Incoming value of source type
 * @return Outgoing value of target type
 * @throws TransformationException if value is an incorrect input type or
 * the transformation fails
 */
public Object transformDirect(Object value) throws TransformationException {
  XMLType source = (XMLType)value;
  Reader reader = null;
  try {       
    char[] result = new char[DataTypeManager.MAX_STRING_LENGTH];
    reader = source.getCharacterStream();
    int read = reader.read(result);
    return new String(result, 0, read);
  } catch (SQLException e) {
     throw new TransformationException(CorePlugin.Event.TEIID10080, e, CorePlugin.Util.gs(CorePlugin.Event.TEIID10080, new Object[] {getSourceType().getName(), getTargetType().getName()}));
  } catch (IOException e) {
     throw new TransformationException(CorePlugin.Event.TEIID10080, e, CorePlugin.Util.gs(CorePlugin.Event.TEIID10080, new Object[] {getSourceType().getName(), getTargetType().getName()}));
  } finally {
    try {
      if (reader != null) {
        reader.close();
      }
    } catch (IOException e) {
    }
  }
}

相关文章