Search in sources :

Example 1 with LobChunk

use of org.teiid.client.lob.LobChunk in project teiid by teiid.

the class TestLobChunkInputStream method testReadByteArray.

public void testReadByteArray() throws Exception {
    LobChunkProducer chunkProducer = new LobChunkProducer() {

        // $NON-NLS-1$ //$NON-NLS-2$
        Iterator<LobChunk> chuncks = Arrays.asList(new LobChunk("hello ".getBytes(), false), new LobChunk("world".getBytes(), true)).iterator();

        @Override
        public LobChunk getNextChunk() throws IOException {
            return chuncks.next();
        }

        @Override
        public void close() throws IOException {
        }
    };
    LobChunkInputStream stream = new LobChunkInputStream(chunkProducer);
    // $NON-NLS-1$
    assertEquals("hello world", ObjectConverterUtil.convertToString(stream));
}
Also used : LobChunkProducer(org.teiid.client.lob.LobChunkProducer) LobChunk(org.teiid.client.lob.LobChunk) Iterator(java.util.Iterator) LobChunkInputStream(org.teiid.client.lob.LobChunkInputStream)

Example 2 with LobChunk

use of org.teiid.client.lob.LobChunk in project teiid by teiid.

the class LobWorkItem method run.

public void run() {
    LobChunk chunk = null;
    Exception ex = null;
    boolean shouldClose = false;
    try {
        // save for future
        if (stream == null) {
            stream = createLobStream(streamId);
        }
        // now get the chunk from stream
        chunk = stream.getNextChunk();
        parent.dataBytes.addAndGet(chunk.getBytes().length);
        shouldClose = chunk.isLast();
    } catch (TeiidComponentException e) {
        LogManager.logWarning(org.teiid.logging.LogConstants.CTX_DQP, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30027));
        ex = e;
    } catch (IOException | SQLException e) {
        // treat this as a processing exception
        ex = new TeiidProcessingException(e);
    }
    synchronized (this) {
        if (ex != null) {
            resultsReceiver.exceptionOccurred(ex);
            shouldClose = true;
        } else {
            resultsReceiver.receiveResults(chunk);
        }
        resultsReceiver = null;
    }
    if (shouldClose) {
        close();
    }
}
Also used : SQLException(java.sql.SQLException) LobChunk(org.teiid.client.lob.LobChunk) TeiidComponentException(org.teiid.core.TeiidComponentException) IOException(java.io.IOException) TeiidComponentException(org.teiid.core.TeiidComponentException) IOException(java.io.IOException) SQLException(java.sql.SQLException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 3 with LobChunk

use of org.teiid.client.lob.LobChunk in project teiid by teiid.

the class TestResultSet method testXML.

@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);
    // $NON-NLS-1$
    resultsMsg.setColumnNames(new String[] { "x" });
    // $NON-NLS-1$
    resultsMsg.setDataTypes(new String[] { "xml" });
    ResultSetImpl cs = new ResultSetImpl(resultsMsg, statement);
    cs.next();
    assertEquals("<a/>", cs.getString(1));
}
Also used : ResultsFuture(org.teiid.client.util.ResultsFuture) XMLType(org.teiid.core.types.XMLType) ResultsMessage(org.teiid.client.ResultsMessage) LobChunk(org.teiid.client.lob.LobChunk) Test(org.junit.Test)

Example 4 with LobChunk

use of org.teiid.client.lob.LobChunk in project teiid by teiid.

the class TestByteLobChunk method testSerialization.

public void testSerialization() throws Exception {
    // $NON-NLS-1$
    String testString = "This is test string for testing ByteLobChunk";
    LobChunk chunk = new LobChunk(testString.getBytes(), true);
    LobChunk result = UnitTestUtil.helpSerialize(chunk);
    assertTrue(Arrays.equals(chunk.getBytes(), result.getBytes()));
    assertTrue(result.isLast());
}
Also used : LobChunk(org.teiid.client.lob.LobChunk)

Example 5 with LobChunk

use of org.teiid.client.lob.LobChunk in project teiid by teiid.

the class TestByteLobChunk method testGetBytes.

public void testGetBytes() {
    // $NON-NLS-1$
    String testString = "This is test string for testing ByteLobChunk";
    LobChunk chunk = new LobChunk(testString.getBytes(), false);
    assertEquals(testString, new String(chunk.getBytes()));
    assertFalse(chunk.isLast());
}
Also used : LobChunk(org.teiid.client.lob.LobChunk)

Aggregations

LobChunk (org.teiid.client.lob.LobChunk)5 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 Iterator (java.util.Iterator)1 Test (org.junit.Test)1 ResultsMessage (org.teiid.client.ResultsMessage)1 LobChunkInputStream (org.teiid.client.lob.LobChunkInputStream)1 LobChunkProducer (org.teiid.client.lob.LobChunkProducer)1 ResultsFuture (org.teiid.client.util.ResultsFuture)1 TeiidComponentException (org.teiid.core.TeiidComponentException)1 TeiidProcessingException (org.teiid.core.TeiidProcessingException)1 XMLType (org.teiid.core.types.XMLType)1