use of org.teiid.core.types.ClobImpl in project teiid by teiid.
the class TestWSTranslator method testJSONHeaderInvalid.
@Test(expected = TranslatorException.class)
public void testJSONHeaderInvalid() throws Exception {
HashMap<String, List<String>> vals = new HashMap<String, List<String>>();
BinaryWSProcedureExecution.parseHeader(vals, new ClobImpl("[]"));
}
use of org.teiid.core.types.ClobImpl in project teiid by teiid.
the class TestWSTranslator method testJSONHeader.
@Test
public void testJSONHeader() throws Exception {
HashMap<String, List<String>> vals = new HashMap<String, List<String>>();
BinaryWSProcedureExecution.parseHeader(vals, new ClobImpl("{\"a\":1, \"b\":[\"x\",\"y\"]}"));
assertEquals(2, vals.size());
assertEquals(vals.get("b"), Arrays.asList("x", "y"));
assertEquals(vals.get("a"), Arrays.asList("1"));
}
use of org.teiid.core.types.ClobImpl in project teiid by teiid.
the class FunctionMethods method concat.
public static ClobType concat(CommandContext context, ClobType str1, ClobType str2) throws IOException, SQLException {
BufferManager bm = context.getBufferManager();
// $NON-NLS-1$
FileStore fs = bm.createFileStore("clob");
FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING);
boolean remove = true;
try (Reader characterStream = str1.getCharacterStream();
Reader characterStream2 = str2.getCharacterStream()) {
Writer writer = fsisf.getWriter();
int chars = ObjectConverterUtil.write(writer, characterStream, -1, false);
chars += ObjectConverterUtil.write(writer, characterStream2, -1, false);
writer.close();
if (fsisf.getStorageMode() == StorageMode.MEMORY) {
// detach if just in memory
byte[] bytes = fsisf.getMemoryBytes();
return new ClobType(new ClobImpl(new String(bytes, Streamable.ENCODING)));
}
remove = false;
context.addCreatedLob(fsisf);
return new ClobType(new ClobImpl(fsisf, chars));
} finally {
if (remove) {
fs.remove();
}
}
}
use of org.teiid.core.types.ClobImpl in project teiid by teiid.
the class StringAgg method getResult.
/**
* @see org.teiid.query.function.aggregate.AggregateFunction#getResult(CommandContext)
*/
public Object getResult(CommandContext commandContext) throws TeiidProcessingException {
if (this.result == null) {
this.result = buildResult(commandContext);
}
try {
this.result.getWriter().close();
FileStoreOutputStream fs = this.result.getOuputStream();
fs.close();
if (binary) {
if (fs.bytesWritten()) {
return new BlobType(new BlobImpl(result));
}
return new BlobType(new SerialBlob(Arrays.copyOf(fs.getBuffer(), fs.getCount())));
}
if (fs.bytesWritten()) {
return new ClobType(new ClobImpl(result, -1));
}
return new ClobType(new ClobImpl(new String(Arrays.copyOf(fs.getBuffer(), fs.getCount()), Streamable.ENCODING)));
} catch (IOException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30422, e);
} catch (SQLException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30423, e);
}
}
use of org.teiid.core.types.ClobImpl 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));
}
Aggregations