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));
}
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());
}
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()));
}
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());
}
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")));
}
Aggregations