Search in sources :

Example 31 with ClobType

use of org.teiid.core.types.ClobType 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 32 with ClobType

use of org.teiid.core.types.ClobType 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 33 with ClobType

use of org.teiid.core.types.ClobType in project teiid by teiid.

the class TestTupleBuffer method testLobHandling.

@Test
public void testLobHandling() throws Exception {
    // $NON-NLS-1$
    ElementSymbol x = new ElementSymbol("x");
    x.setType(DataTypeManager.DefaultDataClasses.CLOB);
    List<ElementSymbol> schema = Arrays.asList(x);
    // $NON-NLS-1$
    TupleBuffer tb = BufferManagerFactory.getStandaloneBufferManager().createTupleBuffer(schema, "x", TupleSourceType.PROCESSOR);
    tb.setInlineLobs(false);
    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()));
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) ClobType(org.teiid.core.types.ClobType) SerialClob(javax.sql.rowset.serial.SerialClob) Test(org.junit.Test)

Example 34 with ClobType

use of org.teiid.core.types.ClobType in project teiid by teiid.

the class TestConnectorWorkItem method testLobs.

@Test
public void testLobs() throws Exception {
    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    final List<Object> result = Arrays.asList(AutoGenDataService.CLOB_VAL);
    final ExecutionFactory<Object, Object> ef = new ExecutionFactory<Object, Object>() {

        @Override
        public boolean isSourceRequired() {
            return false;
        }

        @Override
        public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
            return new ResultSetExecution() {

                private boolean returned;

                @Override
                public void execute() throws TranslatorException {
                }

                @Override
                public void close() {
                }

                @Override
                public void cancel() throws TranslatorException {
                }

                @Override
                public List<?> next() throws TranslatorException, DataNotAvailableException {
                    if (returned) {
                        return null;
                    }
                    returned = true;
                    return result;
                }
            };
        }
    };
    ConnectorManager cm = new // $NON-NLS-1$ //$NON-NLS-2$
    ConnectorManager(// $NON-NLS-1$ //$NON-NLS-2$
    "FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
    "FakeConnector") {

        public ExecutionFactory getExecutionFactory() {
            return ef;
        }

        public Object getConnectionFactory() {
            return null;
        }
    };
    cm.start();
    ef.setCopyLobs(true);
    AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1);
    // $NON-NLS-1$
    requestMsg.setCommand(helpGetCommand("SELECT CLOB_COLUMN FROM LOB_TESTING_ONE", EXAMPLE_BQT));
    requestMsg.setBufferManager(bm);
    ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm);
    cwi.execute();
    AtomicResultsMessage message = cwi.more();
    List[] resutls = message.getResults();
    List<?> tuple = resutls[0];
    ClobType clob = (ClobType) tuple.get(0);
    assertEquals(StorageMode.MEMORY, InputStreamFactory.getStorageMode(clob));
    assertTrue(message.supportsImplicitClose());
    result.set(0, AutoGenDataService.CLOB_VAL);
    ef.setCopyLobs(false);
    cwi = new ConnectorWorkItem(requestMsg, cm);
    cwi.execute();
    message = cwi.more();
    resutls = message.getResults();
    tuple = resutls[0];
    clob = (ClobType) tuple.get(0);
    assertEquals(StorageMode.OTHER, InputStreamFactory.getStorageMode(clob));
    assertFalse(message.supportsImplicitClose());
    result.set(0, new ClobImpl(new InputStreamFactory() {

        @Override
        public InputStream getInputStream() throws IOException {
            return new ByteArrayInputStream(new byte[0]);
        }

        @Override
        public StorageMode getStorageMode() {
            // TODO: introduce an explicit streaming
            return StorageMode.FREE;
        }
    }, -1));
    requestMsg.setCopyStreamingLobs(true);
    cwi = new ConnectorWorkItem(requestMsg, cm);
    cwi.execute();
    message = cwi.more();
    resutls = message.getResults();
    tuple = resutls[0];
    clob = (ClobType) tuple.get(0);
    // switched from FREE to PERSISTENT
    assertEquals(StorageMode.PERSISTENT, InputStreamFactory.getStorageMode(clob));
    assertFalse(message.supportsImplicitClose());
}
Also used : ExecutionFactory(org.teiid.translator.ExecutionFactory) BufferManager(org.teiid.common.buffer.BufferManager) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) InputStreamFactory(org.teiid.core.types.InputStreamFactory) ClobType(org.teiid.core.types.ClobType) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) ByteArrayInputStream(java.io.ByteArrayInputStream) AtomicResultsMessage(org.teiid.dqp.message.AtomicResultsMessage) List(java.util.List) ArrayList(java.util.ArrayList) QueryExpression(org.teiid.language.QueryExpression) ClobImpl(org.teiid.core.types.ClobImpl) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) Test(org.junit.Test)

Example 35 with ClobType

use of org.teiid.core.types.ClobType in project teiid by teiid.

the class TestFunctionLibrary method testToBytes2.

@Test
public void testToBytes2() throws Exception {
    // $NON-NLS-1$
    Blob result = (Blob) helpInvokeMethod("to_bytes", new Class<?>[] { DefaultDataClasses.CLOB, DefaultDataClasses.STRING }, new Object[] { new ClobType(new SerialClob("68656C6C6F20776F726C64".toCharArray())), "HEX" }, null);
    assertEquals("hello world", new String(ObjectConverterUtil.convertToCharArray(result.getBinaryStream(), -1, "ASCII")));
}
Also used : ClobType(org.teiid.core.types.ClobType) SerialBlob(javax.sql.rowset.serial.SerialBlob) Blob(java.sql.Blob) SerialClob(javax.sql.rowset.serial.SerialClob) Test(org.junit.Test)

Aggregations

ClobType (org.teiid.core.types.ClobType)49 Test (org.junit.Test)31 ClobImpl (org.teiid.core.types.ClobImpl)20 Expression (org.teiid.query.sql.symbol.Expression)16 SQLException (java.sql.SQLException)8 InputStreamFactory (org.teiid.core.types.InputStreamFactory)8 IOException (java.io.IOException)7 BlobType (org.teiid.core.types.BlobType)6 Reader (java.io.Reader)4 Blob (java.sql.Blob)4 ArrayList (java.util.ArrayList)4 SerialBlob (javax.sql.rowset.serial.SerialBlob)4 SerialClob (javax.sql.rowset.serial.SerialClob)4 BlobImpl (org.teiid.core.types.BlobImpl)4 XMLType (org.teiid.core.types.XMLType)4 FunctionExecutionException (org.teiid.api.exception.query.FunctionExecutionException)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3 BlobInputStreamFactory (org.teiid.core.types.InputStreamFactory.BlobInputStreamFactory)3 SQLXMLImpl (org.teiid.core.types.SQLXMLImpl)3 ReaderInputStream (org.teiid.core.util.ReaderInputStream)3