Search in sources :

Example 16 with ReaderInputStream

use of org.teiid.core.util.ReaderInputStream in project teiid by teiid.

the class TestLobManager method testInlining.

@Test
public void testInlining() throws Exception {
    BufferManager buffMgr = BufferManagerFactory.getStandaloneBufferManager();
    FileStore fs = buffMgr.createFileStore("temp");
    ClobType clob = new ClobType(new ClobImpl(new InputStreamFactory() {

        @Override
        public InputStream getInputStream() throws IOException {
            return new ReaderInputStream(new StringReader("small"), Charset.forName(Streamable.ENCODING));
        }
    }, 5));
    assertEquals(StorageMode.OTHER, InputStreamFactory.getStorageMode(clob));
    LobManager lobManager = new LobManager(new int[] { 0 }, fs);
    lobManager.updateReferences(Arrays.asList(clob), ReferenceMode.CREATE);
    assertEquals(StorageMode.MEMORY, InputStreamFactory.getStorageMode(clob));
}
Also used : ClobType(org.teiid.core.types.ClobType) ReaderInputStream(org.teiid.core.util.ReaderInputStream) StringReader(java.io.StringReader) InputStreamFactory(org.teiid.core.types.InputStreamFactory) ClobImpl(org.teiid.core.types.ClobImpl) Test(org.junit.Test)

Example 17 with ReaderInputStream

use of org.teiid.core.util.ReaderInputStream in project teiid by teiid.

the class TestLobManager method testLobPeristence.

@Test
public void testLobPeristence() throws Exception {
    BufferManager buffMgr = BufferManagerFactory.getStandaloneBufferManager();
    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));
        }
    }));
    BlobType blobEmpty = new BlobType(new BlobImpl(new InputStreamFactory() {

        @Override
        public InputStream getInputStream() throws IOException {
            return new ByteArrayInputStream(new byte[0]);
        }
    }));
    FileStore fs1 = buffMgr.createFileStore("blob");
    FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs1, Streamable.ENCODING);
    FileStoreOutputStream fsos = fsisf.getOuputStream();
    byte[] b = new byte[DataTypeManager.MAX_LOB_MEMORY_BYTES + 1];
    fsos.write(b);
    fsos.close();
    BlobType blob1 = new BlobType(new BlobImpl(fsisf));
    assertNotNull(blob1.getReferenceStreamId());
    LobManager lobManager = new LobManager(new int[] { 0, 1, 2, 3 }, fs);
    lobManager.setMaxMemoryBytes(4);
    List<?> tuple = Arrays.asList(clob, blob, blob1, blobEmpty);
    lobManager.updateReferences(tuple, ReferenceMode.CREATE);
    assertNotNull(blob1.getReferenceStreamId());
    lobManager.persist();
    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())));
    lobManager.updateReferences(tuple, ReferenceMode.REMOVE);
    assertEquals(0, lobManager.getLobCount());
}
Also used : FileStoreOutputStream(org.teiid.common.buffer.FileStore.FileStoreOutputStream) InputStreamFactory(org.teiid.core.types.InputStreamFactory) ClobType(org.teiid.core.types.ClobType) ReaderInputStream(org.teiid.core.util.ReaderInputStream) BlobType(org.teiid.core.types.BlobType) ByteArrayInputStream(java.io.ByteArrayInputStream) StringReader(java.io.StringReader) ClobImpl(org.teiid.core.types.ClobImpl) BlobImpl(org.teiid.core.types.BlobImpl) Test(org.junit.Test)

Example 18 with ReaderInputStream

use of org.teiid.core.util.ReaderInputStream in project teiid by teiid.

the class PreparedStatementImpl method setClob.

void setClob(Object parameterIndex, final Reader reader) throws SQLException {
    if (reader == null) {
        this.setObject(parameterIndex, null);
        return;
    }
    final ReaderInputStream readerInputStream = new ReaderInputStream(reader, Charset.forName(Streamable.ENCODING));
    this.setObject(parameterIndex, new ClobImpl(new InputStreamFactory() {

        @Override
        public InputStream getInputStream() throws IOException {
            return readerInputStream;
        }
    }, -1));
}
Also used : ReaderInputStream(org.teiid.core.util.ReaderInputStream) InputStreamFactory(org.teiid.core.types.InputStreamFactory) ClobImpl(org.teiid.core.types.ClobImpl)

Aggregations

ReaderInputStream (org.teiid.core.util.ReaderInputStream)18 StringReader (java.io.StringReader)9 Test (org.junit.Test)9 InputStream (java.io.InputStream)5 SQLException (java.sql.SQLException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IOException (java.io.IOException)4 Blob (java.sql.Blob)4 Clob (java.sql.Clob)4 SQLXML (java.sql.SQLXML)4 Response (javax.ws.rs.core.Response)4 WebClient (org.apache.cxf.jaxrs.client.WebClient)4 BlobType (org.teiid.core.types.BlobType)4 ClobImpl (org.teiid.core.types.ClobImpl)3 ClobType (org.teiid.core.types.ClobType)3 InputStreamFactory (org.teiid.core.types.InputStreamFactory)3 Charset (java.nio.charset.Charset)2 Properties (java.util.Properties)2 ResourceException (javax.resource.ResourceException)2 XMLStreamException (javax.xml.stream.XMLStreamException)2