use of org.teiid.core.types.InputStreamFactory 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());
}
use of org.teiid.core.types.InputStreamFactory 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());
}
use of org.teiid.core.types.InputStreamFactory in project teiid by teiid.
the class TestSaveOnReadInputStream method testSave.
@Test
public void testSave() throws IOException {
SaveOnReadInputStream soris = getSaveOnReadInputStream();
InputStreamFactory isf = soris.getInputStreamFactory();
InputStream is = isf.getInputStream();
assertEquals("hello world", new String(ObjectConverterUtil.convertToByteArray(is), Streamable.CHARSET));
InputStream is2 = isf.getInputStream();
assertEquals("hello world", new String(ObjectConverterUtil.convertToByteArray(is2), Streamable.CHARSET));
}
use of org.teiid.core.types.InputStreamFactory 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));
}
use of org.teiid.core.types.InputStreamFactory in project teiid by teiid.
the class ResultSetImpl method createInputStreamFactory.
private InputStreamFactory createInputStreamFactory(Streamable<?> type) {
final StreamingLobChunckProducer.Factory factory = new StreamingLobChunckProducer.Factory(this.statement.getDQP(), this.requestID, type);
InputStreamFactory isf = new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return new LobChunkInputStream(factory.getLobChunkProducer());
}
};
return isf;
}
Aggregations