@Test public void testTypeConversionClob() throws Exception { BufferManager bm = BufferManagerFactory.getStandaloneBufferManager(); String str = "hello world"; Clob clob = (Clob) ConnectorWorkItem.convertToRuntimeType(bm, new InputStreamFactory() { @Override public InputStream getInputStream() throws IOException { return new ByteArrayInputStream(str.getBytes(Streamable.CHARSET)); } }, DataTypeManager.DefaultDataClasses.CLOB, null); assertEquals(str, clob.getSubString(1, str.length())); }
static Object convertToRuntimeType(BufferManager bm, Object value, Class<?> desiredType, CommandContext context) throws TransformationException { if (desiredType != DataTypeManager.DefaultDataClasses.XML || !(value instanceof Source)) { if (value instanceof DataSource) { final DataSource ds = (DataSource)value; try { InputStream initial = ds.getInputStream(); InputStream other = null; try { other = ds.getInputStream(); } catch (IOException e) { } if (other != null && initial != other) { initial.close(); other.close(); if (value instanceof InputStreamFactory) { return asLob((InputStreamFactory)value, desiredType); } return asLob(new InputStreamFactory() { @Override public InputStream getInputStream() throws IOException { return ds.getInputStream(); } }, desiredType); } FileStore fs = bm.createFileStore("bytes"); FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); SaveOnReadInputStream is = new SaveOnReadInputStream(initial, fsisf); if (context != null) { context.addCreatedLob(fsisf); } return asLob(is.getInputStreamFactory(), desiredType); } catch (IOException e) { throw new TransformationException(QueryPlugin.Event.TEIID30500, e, e.getMessage()); } } if (value instanceof InputStreamFactory) { return asLob((InputStreamFactory)value, desiredType); } if (value instanceof GeometryInputSource) { GeometryInputSource gis = (GeometryInputSource)value; try { InputStream is = gis.getEwkb(); if (is != null) { if (desiredType == GeographyType.class) { return GeometryUtils.geographyFromEwkb(context, is); } return GeometryUtils.geometryFromEwkb(is, gis.getSrid()); } } catch (Exception e) { throw new TransformationException(e); } try { Reader r = gis.getGml(); if (r != null) { if (desiredType == GeographyType.class) { return GeometryUtils.getGeographyType(GeometryUtils.geometryFromGml(r, gis.getSrid())); } return GeometryUtils.geometryFromGml(r, gis.getSrid()); } } catch (Exception e) { throw new TransformationException(e); } } } if (value instanceof Source) { if (!(value instanceof InputStreamFactory)) { if (value instanceof StreamSource) { StreamSource ss = (StreamSource)value; InputStream is = ss.getInputStream(); Reader r = ss.getReader(); if (is == null && r != null) { is = new ReaderInputStream(r, Streamable.CHARSET); } final FileStore fs = bm.createFileStore("xml"); final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); value = new SaveOnReadInputStream(is, fsisf).getInputStreamFactory(); if (context != null) { context.addCreatedLob(fsisf); } } else if (value instanceof StAXSource) { StAXSource ss = (StAXSource)value; try { final FileStore fs = bm.createFileStore("xml"); final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); value = new SaveOnReadInputStream(new XMLInputStream(ss, XMLSystemFunctions.getOutputFactory(true)), fsisf).getInputStreamFactory(); if (context != null) { context.addCreatedLob(fsisf); } } catch (XMLStreamException e) { throw new TransformationException(e); } } else { StandardXMLTranslator sxt = new StandardXMLTranslator((Source)value); SQLXMLImpl sqlxml; try { sqlxml = XMLSystemFunctions.saveToBufferManager(bm, sxt, context); } catch (TeiidComponentException e) { throw new TransformationException(e); } catch (TeiidProcessingException e) { throw new TransformationException(e); } return new XMLType(sqlxml); } } return new XMLType(new SQLXMLImpl((InputStreamFactory)value)); } return DataTypeManager.convertToRuntimeType(value, desiredType != DataTypeManager.DefaultDataClasses.OBJECT); }
ConnectorWorkItem implements ConnectorWork { static Object convertToRuntimeType(BufferManager bm, Object value, Class<?> desiredType, CommandContext context) throws TransformationException { if (desiredType != DataTypeManager.DefaultDataClasses.XML || !(value instanceof Source)) { if (value instanceof DataSource) { final DataSource ds = (DataSource)value; try { InputStream initial = ds.getInputStream(); InputStream other = null; try { other = ds.getInputStream(); } catch (IOException e) { } if (other != null && initial != other) { initial.close(); other.close(); if (value instanceof InputStreamFactory) { return asLob((InputStreamFactory)value, desiredType); } return asLob(new InputStreamFactory() { @Override public InputStream getInputStream() throws IOException { return ds.getInputStream(); } }, desiredType); } FileStore fs = bm.createFileStore("bytes"); FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); SaveOnReadInputStream is = new SaveOnReadInputStream(initial, fsisf); if (context != null) { context.addCreatedLob(fsisf); } return asLob(is.getInputStreamFactory(), desiredType); } catch (IOException e) { throw new TransformationException(QueryPlugin.Event.TEIID30500, e, e.getMessage()); } } if (value instanceof InputStreamFactory) { return asLob((InputStreamFactory)value, desiredType); } if (value instanceof GeometryInputSource) { GeometryInputSource gis = (GeometryInputSource)value; try { InputStream is = gis.getEwkb(); if (is != null) { if (desiredType == GeographyType.class) { return GeometryUtils.geographyFromEwkb(context, is); } return GeometryUtils.geometryFromEwkb(is, gis.getSrid()); } } catch (Exception e) { throw new TransformationException(e); } try { Reader r = gis.getGml(); if (r != null) { if (desiredType == GeographyType.class) { return GeometryUtils.getGeographyType(GeometryUtils.geometryFromGml(r, gis.getSrid())); } return GeometryUtils.geometryFromGml(r, gis.getSrid()); } } catch (Exception e) { throw new TransformationException(e); } } } if (value instanceof Source) { if (!(value instanceof InputStreamFactory)) { if (value instanceof StreamSource) { StreamSource ss = (StreamSource)value; InputStream is = ss.getInputStream(); Reader r = ss.getReader(); if (is == null && r != null) { is = new ReaderInputStream(r, Streamable.CHARSET); } final FileStore fs = bm.createFileStore("xml"); final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); value = new SaveOnReadInputStream(is, fsisf).getInputStreamFactory(); if (context != null) { context.addCreatedLob(fsisf); } } else if (value instanceof StAXSource) { StAXSource ss = (StAXSource)value; try { final FileStore fs = bm.createFileStore("xml"); final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); value = new SaveOnReadInputStream(new XMLInputStream(ss, XMLSystemFunctions.getOutputFactory(true)), fsisf).getInputStreamFactory(); if (context != null) { context.addCreatedLob(fsisf); } } catch (XMLStreamException e) { throw new TransformationException(e); } } else { StandardXMLTranslator sxt = new StandardXMLTranslator((Source)value); SQLXMLImpl sqlxml; try { sqlxml = XMLSystemFunctions.saveToBufferManager(bm, sxt, context); } catch (TeiidComponentException e) { throw new TransformationException(e); } catch (TeiidProcessingException e) { throw new TransformationException(e); } return new XMLType(sqlxml); } } return new XMLType(new SQLXMLImpl((InputStreamFactory)value)); } return DataTypeManager.convertToRuntimeType(value, desiredType != DataTypeManager.DefaultDataClasses.OBJECT); } }
ConnectorWorkItem implements ConnectorWork { static Object convertToRuntimeType(BufferManager bm, Object value, Class<?> desiredType, CommandContext context) throws TransformationException { if (desiredType != DataTypeManager.DefaultDataClasses.XML || !(value instanceof Source)) { if (value instanceof DataSource) { final DataSource ds = (DataSource)value; try { InputStream initial = ds.getInputStream(); InputStream other = null; try { other = ds.getInputStream(); } catch (IOException e) { } if (other != null && initial != other) { initial.close(); other.close(); if (value instanceof InputStreamFactory) { return asLob((InputStreamFactory)value, desiredType); } return asLob(new InputStreamFactory() { @Override public InputStream getInputStream() throws IOException { return ds.getInputStream(); } }, desiredType); } FileStore fs = bm.createFileStore("bytes"); FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); SaveOnReadInputStream is = new SaveOnReadInputStream(initial, fsisf); if (context != null) { context.addCreatedLob(fsisf); } return asLob(is.getInputStreamFactory(), desiredType); } catch (IOException e) { throw new TransformationException(QueryPlugin.Event.TEIID30500, e, e.getMessage()); } } if (value instanceof InputStreamFactory) { return asLob((InputStreamFactory)value, desiredType); } if (value instanceof GeometryInputSource) { GeometryInputSource gis = (GeometryInputSource)value; try { InputStream is = gis.getEwkb(); if (is != null) { if (desiredType == GeographyType.class) { return GeometryUtils.geographyFromEwkb(context, is); } return GeometryUtils.geometryFromEwkb(is, gis.getSrid()); } } catch (Exception e) { throw new TransformationException(e); } try { Reader r = gis.getGml(); if (r != null) { if (desiredType == GeographyType.class) { return GeometryUtils.getGeographyType(GeometryUtils.geometryFromGml(r, gis.getSrid())); } return GeometryUtils.geometryFromGml(r, gis.getSrid()); } } catch (Exception e) { throw new TransformationException(e); } } } if (value instanceof Source) { if (!(value instanceof InputStreamFactory)) { if (value instanceof StreamSource) { StreamSource ss = (StreamSource)value; InputStream is = ss.getInputStream(); Reader r = ss.getReader(); if (is == null && r != null) { is = new ReaderInputStream(r, Streamable.CHARSET); } final FileStore fs = bm.createFileStore("xml"); final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); value = new SaveOnReadInputStream(is, fsisf).getInputStreamFactory(); if (context != null) { context.addCreatedLob(fsisf); } } else if (value instanceof StAXSource) { StAXSource ss = (StAXSource)value; try { final FileStore fs = bm.createFileStore("xml"); final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); value = new SaveOnReadInputStream(new XMLInputStream(ss, XMLSystemFunctions.getOutputFactory(true)), fsisf).getInputStreamFactory(); if (context != null) { context.addCreatedLob(fsisf); } } catch (XMLStreamException e) { throw new TransformationException(e); } } else { StandardXMLTranslator sxt = new StandardXMLTranslator((Source)value); SQLXMLImpl sqlxml; try { sqlxml = XMLSystemFunctions.saveToBufferManager(bm, sxt, context); } catch (TeiidComponentException e) { throw new TransformationException(e); } catch (TeiidProcessingException e) { throw new TransformationException(e); } return new XMLType(sqlxml); } } return new XMLType(new SQLXMLImpl((InputStreamFactory)value)); } return DataTypeManager.convertToRuntimeType(value, desiredType != DataTypeManager.DefaultDataClasses.OBJECT); } ConnectorWorkItem(AtomicRequestMessage message, ConnectorManager manager); }
ConnectorWorkItem implements ConnectorWork { static Object convertToRuntimeType(BufferManager bm, Object value, Class<?> desiredType, CommandContext context) throws TransformationException { if (desiredType != DataTypeManager.DefaultDataClasses.XML || !(value instanceof Source)) { if (value instanceof DataSource) { final DataSource ds = (DataSource)value; try { InputStream initial = ds.getInputStream(); InputStream other = null; try { other = ds.getInputStream(); } catch (IOException e) { } if (other != null && initial != other) { initial.close(); other.close(); if (value instanceof InputStreamFactory) { return asLob((InputStreamFactory)value, desiredType); } return asLob(new InputStreamFactory() { @Override public InputStream getInputStream() throws IOException { return ds.getInputStream(); } }, desiredType); } FileStore fs = bm.createFileStore("bytes"); FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); SaveOnReadInputStream is = new SaveOnReadInputStream(initial, fsisf); if (context != null) { context.addCreatedLob(fsisf); } return asLob(is.getInputStreamFactory(), desiredType); } catch (IOException e) { throw new TransformationException(QueryPlugin.Event.TEIID30500, e, e.getMessage()); } } if (value instanceof InputStreamFactory) { return asLob((InputStreamFactory)value, desiredType); } if (value instanceof GeometryInputSource) { GeometryInputSource gis = (GeometryInputSource)value; try { InputStream is = gis.getEwkb(); if (is != null) { if (desiredType == GeographyType.class) { return GeometryUtils.geographyFromEwkb(context, is); } return GeometryUtils.geometryFromEwkb(is, gis.getSrid()); } } catch (Exception e) { throw new TransformationException(e); } try { Reader r = gis.getGml(); if (r != null) { if (desiredType == GeographyType.class) { return GeometryUtils.getGeographyType(GeometryUtils.geometryFromGml(r, gis.getSrid())); } return GeometryUtils.geometryFromGml(r, gis.getSrid()); } } catch (Exception e) { throw new TransformationException(e); } } } if (value instanceof Source) { if (!(value instanceof InputStreamFactory)) { if (value instanceof StreamSource) { StreamSource ss = (StreamSource)value; InputStream is = ss.getInputStream(); Reader r = ss.getReader(); if (is == null && r != null) { is = new ReaderInputStream(r, Streamable.CHARSET); } final FileStore fs = bm.createFileStore("xml"); final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); value = new SaveOnReadInputStream(is, fsisf).getInputStreamFactory(); if (context != null) { context.addCreatedLob(fsisf); } } else if (value instanceof StAXSource) { StAXSource ss = (StAXSource)value; try { final FileStore fs = bm.createFileStore("xml"); final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); value = new SaveOnReadInputStream(new XMLInputStream(ss, XMLSystemFunctions.getOutputFactory(true)), fsisf).getInputStreamFactory(); if (context != null) { context.addCreatedLob(fsisf); } } catch (XMLStreamException e) { throw new TransformationException(e); } } else { StandardXMLTranslator sxt = new StandardXMLTranslator((Source)value); SQLXMLImpl sqlxml; try { sqlxml = XMLSystemFunctions.saveToBufferManager(bm, sxt, context); } catch (TeiidComponentException e) { throw new TransformationException(e); } catch (TeiidProcessingException e) { throw new TransformationException(e); } return new XMLType(sqlxml); } } return new XMLType(new SQLXMLImpl((InputStreamFactory)value)); } return DataTypeManager.convertToRuntimeType(value, desiredType != DataTypeManager.DefaultDataClasses.OBJECT); } ConnectorWorkItem(AtomicRequestMessage message, ConnectorManager manager); static void initLanguageBridgeFactory(LanguageBridgeFactory factory,
            CommandContext context, SourceCapabilities capabilities); @Override AtomicRequestID getId(); @Override void cancel(boolean abnormal); synchronized AtomicResultsMessage more(); synchronized void close(); synchronized void execute(); static AtomicResultsMessage createResultsMessage(List<?>[] batch); @Override String toString(); @Override boolean isDataAvailable(); @Override CacheDirective getCacheDirective(); @Override boolean isForkable(); @Override boolean isThreadBound(); @Override int hashCode(); @Override boolean equals(Object obj); void logCommand(Object... command); void setTracingSpan(Span span); Span getTracingSpan(); }
ConnectorWorkItem implements ConnectorWork { static Object convertToRuntimeType(BufferManager bm, Object value, Class<?> desiredType, CommandContext context) throws TransformationException { if (desiredType != DataTypeManager.DefaultDataClasses.XML || !(value instanceof Source)) { if (value instanceof DataSource) { final DataSource ds = (DataSource)value; try { InputStream initial = ds.getInputStream(); InputStream other = null; try { other = ds.getInputStream(); } catch (IOException e) { } if (other != null && initial != other) { initial.close(); other.close(); if (value instanceof InputStreamFactory) { return asLob((InputStreamFactory)value, desiredType); } return asLob(new InputStreamFactory() { @Override public InputStream getInputStream() throws IOException { return ds.getInputStream(); } }, desiredType); } FileStore fs = bm.createFileStore("bytes"); FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); SaveOnReadInputStream is = new SaveOnReadInputStream(initial, fsisf); if (context != null) { context.addCreatedLob(fsisf); } return asLob(is.getInputStreamFactory(), desiredType); } catch (IOException e) { throw new TransformationException(QueryPlugin.Event.TEIID30500, e, e.getMessage()); } } if (value instanceof InputStreamFactory) { return asLob((InputStreamFactory)value, desiredType); } if (value instanceof GeometryInputSource) { GeometryInputSource gis = (GeometryInputSource)value; try { InputStream is = gis.getEwkb(); if (is != null) { if (desiredType == GeographyType.class) { return GeometryUtils.geographyFromEwkb(context, is); } return GeometryUtils.geometryFromEwkb(is, gis.getSrid()); } } catch (Exception e) { throw new TransformationException(e); } try { Reader r = gis.getGml(); if (r != null) { if (desiredType == GeographyType.class) { return GeometryUtils.getGeographyType(GeometryUtils.geometryFromGml(r, gis.getSrid())); } return GeometryUtils.geometryFromGml(r, gis.getSrid()); } } catch (Exception e) { throw new TransformationException(e); } } } if (value instanceof Source) { if (!(value instanceof InputStreamFactory)) { if (value instanceof StreamSource) { StreamSource ss = (StreamSource)value; InputStream is = ss.getInputStream(); Reader r = ss.getReader(); if (is == null && r != null) { is = new ReaderInputStream(r, Streamable.CHARSET); } final FileStore fs = bm.createFileStore("xml"); final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); value = new SaveOnReadInputStream(is, fsisf).getInputStreamFactory(); if (context != null) { context.addCreatedLob(fsisf); } } else if (value instanceof StAXSource) { StAXSource ss = (StAXSource)value; try { final FileStore fs = bm.createFileStore("xml"); final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); value = new SaveOnReadInputStream(new XMLInputStream(ss, XMLSystemFunctions.getOutputFactory(true)), fsisf).getInputStreamFactory(); if (context != null) { context.addCreatedLob(fsisf); } } catch (XMLStreamException e) { throw new TransformationException(e); } } else { StandardXMLTranslator sxt = new StandardXMLTranslator((Source)value); SQLXMLImpl sqlxml; try { sqlxml = XMLSystemFunctions.saveToBufferManager(bm, sxt, context); } catch (TeiidComponentException e) { throw new TransformationException(e); } catch (TeiidProcessingException e) { throw new TransformationException(e); } return new XMLType(sqlxml); } } return new XMLType(new SQLXMLImpl((InputStreamFactory)value)); } return DataTypeManager.convertToRuntimeType(value, desiredType != DataTypeManager.DefaultDataClasses.OBJECT); } ConnectorWorkItem(AtomicRequestMessage message, ConnectorManager manager); static void initLanguageBridgeFactory(LanguageBridgeFactory factory,
            CommandContext context, SourceCapabilities capabilities); @Override AtomicRequestID getId(); @Override void cancel(boolean abnormal); synchronized AtomicResultsMessage more(); synchronized void close(); synchronized void execute(); static AtomicResultsMessage createResultsMessage(List<?>[] batch); @Override String toString(); @Override boolean isDataAvailable(); @Override CacheDirective getCacheDirective(); @Override boolean isForkable(); @Override boolean isThreadBound(); @Override int hashCode(); @Override boolean equals(Object obj); void logCommand(Object... command); void setTracingSpan(Span span); Span getTracingSpan();  }