Search in sources :

Example 16 with ClobImpl

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("[]"));
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) ClobImpl(org.teiid.core.types.ClobImpl) Test(org.junit.Test)

Example 17 with 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"));
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) ClobImpl(org.teiid.core.types.ClobImpl) Test(org.junit.Test)

Example 18 with ClobImpl

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();
        }
    }
}
Also used : ClobType(org.teiid.core.types.ClobType) FileStore(org.teiid.common.buffer.FileStore) FileStoreInputStreamFactory(org.teiid.common.buffer.FileStoreInputStreamFactory) FilterReader(java.io.FilterReader) Reader(java.io.Reader) BufferManager(org.teiid.common.buffer.BufferManager) ClobImpl(org.teiid.core.types.ClobImpl) Writer(java.io.Writer)

Example 19 with ClobImpl

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);
    }
}
Also used : ClobType(org.teiid.core.types.ClobType) BlobType(org.teiid.core.types.BlobType) SQLException(java.sql.SQLException) SerialBlob(javax.sql.rowset.serial.SerialBlob) FileStoreOutputStream(org.teiid.common.buffer.FileStore.FileStoreOutputStream) IOException(java.io.IOException) BlobImpl(org.teiid.core.types.BlobImpl) ClobImpl(org.teiid.core.types.ClobImpl) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 20 with ClobImpl

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));
}
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)

Aggregations

ClobImpl (org.teiid.core.types.ClobImpl)28 ClobType (org.teiid.core.types.ClobType)21 InputStreamFactory (org.teiid.core.types.InputStreamFactory)14 IOException (java.io.IOException)10 Test (org.junit.Test)10 BlobImpl (org.teiid.core.types.BlobImpl)8 SQLException (java.sql.SQLException)7 BlobType (org.teiid.core.types.BlobType)6 SQLXMLImpl (org.teiid.core.types.SQLXMLImpl)6 Blob (java.sql.Blob)5 List (java.util.List)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 Reader (java.io.Reader)3 BigInteger (java.math.BigInteger)3 Clob (java.sql.Clob)3 SQLXML (java.sql.SQLXML)3 HashMap (java.util.HashMap)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3