Package org.teiid.core.types

Examples of org.teiid.core.types.ClobType


     * @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 {
        ClobType source = (ClobType)value;
       
        try {
            BufferedReader reader = new BufferedReader (source.getCharacterStream());
            StringBuffer contents = new StringBuffer();
           
            int chr = reader.read();
            while (chr != -1 && contents.length() < DataTypeManager.MAX_STRING_LENGTH) {
                contents.append((char)chr);
View Full Code Here


                  //transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); //$NON-NLS-1$
                  // Feed the resultant I/O stream into the XSLT processor
          transformer.transform(xmlParam, new StreamResult(writer));
        }
      });
      return new ClobType(new ClobImpl(result.getStreamFactory(), -1));
    } finally {
      Util.closeSource(styleSource);
      Util.closeSource(xmlSource);
    }
    }
View Full Code Here

  public void testLobPeristence() throws Exception{
   
    BufferManagerImpl buffMgr = BufferManagerFactory.createBufferManager();
    FileStore fs = buffMgr.createFileStore("temp");
   
    ClobType clob = new ClobType(new ClobImpl(new InputStreamFactory() {
      @Override
      public InputStream getInputStream() throws IOException {
        return new ReaderInputStream(new StringReader("Clob contents One"),  Charset.forName(Streamable.ENCODING));
      }
     
    }, -1));
   
    BlobType blob = new BlobType(new BlobImpl(new InputStreamFactory() {
      @Override
      public InputStream getInputStream() throws IOException {
        return new ReaderInputStream(new StringReader("Blob contents Two"),  Charset.forName(Streamable.ENCODING));
      }
     
    }));   
   
    LobManager lobManager = new LobManager();
    lobManager.updateReferences(new int[] {0,1}, Arrays.asList(clob, blob));
    lobManager.persist(fs);
   
    Streamable<?>lob = lobManager.getLobReference(clob.getReferenceStreamId());
    assertTrue(lob.getClass().isAssignableFrom(ClobType.class));
    ClobType clobRead = (ClobType)lob;
    assertEquals(ClobType.getString(clob), ClobType.getString(clobRead));
    assertTrue(clobRead.length() != -1);
   
    lob = lobManager.getLobReference(blob.getReferenceStreamId());
    assertTrue(lob.getClass().isAssignableFrom(BlobType.class));
    BlobType blobRead = (BlobType)lob;
    assertTrue(Arrays.equals(ObjectConverterUtil.convertToByteArray(blob.getBinaryStream()), ObjectConverterUtil.convertToByteArray(blobRead.getBinaryStream())));
View Full Code Here

    public static Clob toChars(BlobType value, String encoding) {
      Charset cs = getCharset(encoding);
    BlobInputStreamFactory bisf = new BlobInputStreamFactory(value.getReference());
      ClobImpl clob = new ClobImpl(bisf, -1);
      clob.setCharset(cs);
      return new ClobType(clob);
    }
View Full Code Here

   
   
  @Test public void testInvokeXslTransform() throws Exception {
        CommandContext c = new CommandContext();
        c.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
        ClobType result = (ClobType)helpInvokeMethod("xsltransform", new Class<?>[] {DataTypeManager.DefaultDataClasses.XML, DataTypeManager.DefaultDataClasses.XML},
            new Object[] {DataTypeManager.transformValue("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Catalog><Items><Item ItemID=\"001\"><Name>Lamp</Name><Quantity>5</Quantity></Item></Items></Catalog></Catalogs>", DataTypeManager.DefaultDataClasses.XML),
            DataTypeManager.transformValue("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:template match=\"@*|node()\"><xsl:copy><xsl:apply-templates select=\"@*|node()\"/></xsl:copy></xsl:template><xsl:template match=\"Quantity\"/></xsl:stylesheet>", DataTypeManager.DefaultDataClasses.XML)}, c);
       
        String xml = ObjectConverterUtil.convertToString(result.getCharacterStream());
        assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Catalog><Items><Item ItemID=\"001\"><Name>Lamp</Name></Item></Items></Catalog></Catalogs>", xml);
    }
View Full Code Here

    String string = result.getSubString(1, (int)result.length());
    assertEquals("hello world", string);
  }
 
  @Test public void testToBytes() throws Exception {
    Blob result = (Blob)helpInvokeMethod("to_bytes", new Class<?>[] {DefaultDataClasses.CLOB, DefaultDataClasses.STRING}, new Object[] { new ClobType(new SerialClob("hello world".toCharArray())), "UTF32" }, null); //$NON-NLS-1$
    assertEquals(44, result.length()); //4 bytes / char
  }
View Full Code Here

    String string = result.getSubString(1, (int)result.length());
    assertEquals("68656C6C6F20776F726C64", string);
  }
 
  @Test public void testToBytes2() throws Exception {
    Blob result = (Blob)helpInvokeMethod("to_bytes", new Class<?>[] {DefaultDataClasses.CLOB, DefaultDataClasses.STRING}, new Object[] { new ClobType(new SerialClob("68656C6C6F20776F726C64".toCharArray())), "HEX" }, null); //$NON-NLS-1$
    assertEquals("hello world", new String(ObjectConverterUtil.convertToCharArray(result.getBinaryStream(), -1, "ASCII")));
  }
View Full Code Here

    Blob result = (Blob)helpInvokeMethod("to_bytes", new Class<?>[] {DefaultDataClasses.CLOB, DefaultDataClasses.STRING}, new Object[] { new ClobType(new SerialClob("68656C6C6F20776F726C64".toCharArray())), "HEX" }, null); //$NON-NLS-1$
    assertEquals("hello world", new String(ObjectConverterUtil.convertToCharArray(result.getBinaryStream(), -1, "ASCII")));
  }
 
  @Test(expected=FunctionExecutionException.class) public void testToBytes3() throws Exception {
    helpInvokeMethod("to_bytes", new Class<?>[] {DefaultDataClasses.CLOB, DefaultDataClasses.STRING}, new Object[] { new ClobType(new SerialClob("a".toCharArray())), "BASE64" }, null); //$NON-NLS-1$
  }
View Full Code Here

  @Test public void testLobHandling() throws Exception {
    ElementSymbol x = new ElementSymbol("x"); //$NON-NLS-1$
    x.setType(DataTypeManager.DefaultDataClasses.CLOB);
    List<ElementSymbol> schema = Arrays.asList(x);
    TupleBuffer tb = new TupleBuffer(new FakeBatchManager(), "x", schema, LobManager.getLobIndexes(schema), 32); //$NON-NLS-1$
    ClobType c = new ClobType(new SerialClob(new char[0]));
    TupleBatch batch = new TupleBatch(1, new List[] {Arrays.asList(c)});
    tb.addTupleBatch(batch, false);
    assertNotNull(tb.getLobReference(c.getReferenceStreamId()));
  }
View Full Code Here

  private void initReader() throws ExpressionEvaluationException,
      BlockedException, TeiidComponentException, TeiidProcessingException {
   
    setReferenceValues(this.table);
    ClobType file = (ClobType)getEvaluator(Collections.emptyMap()).evaluate(table.getFile(), null);
    if (file == null) {
      return;
    }
   
    //get the reader
    try {
      this.systemId = "Unknown"; //$NON-NLS-1$
      if (file.getReference() instanceof ClobImpl) {
        this.systemId = ((ClobImpl)file.getReference()).getStreamFactory().getSystemId();
        if (this.systemId == null) {
          this.systemId = "Unknown"; //$NON-NLS-1$
        }
      }
      Reader r = file.getCharacterStream();
      if (!(r instanceof BufferedReader)) {
        reader = new BufferedReader(r);
      } else {
        reader = (BufferedReader)r;
      }
View Full Code Here

TOP

Related Classes of org.teiid.core.types.ClobType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.