Search in sources :

Example 1 with FileStoreOutputStream

use of org.teiid.common.buffer.FileStore.FileStoreOutputStream in project teiid by teiid.

the class TestFileStorageManager method testClose.

@Test
public void testClose() throws Exception {
    FileStorageManager sm = getStorageManager(null, null);
    FileStore store = sm.createFileStore("0");
    FileStoreOutputStream fsos = store.createOutputStream(2);
    fsos.write(new byte[100000]);
    fsos.close();
    fsos.close();
}
Also used : FileStore(org.teiid.common.buffer.FileStore) FileStoreOutputStream(org.teiid.common.buffer.FileStore.FileStoreOutputStream) Test(org.junit.Test)

Example 2 with FileStoreOutputStream

use of org.teiid.common.buffer.FileStore.FileStoreOutputStream 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 3 with FileStoreOutputStream

use of org.teiid.common.buffer.FileStore.FileStoreOutputStream in project teiid by teiid.

the class TextAgg 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 {
        FileStoreOutputStream fs = this.result.getOuputStream();
        fs.close();
        if (fs.bytesWritten()) {
            return new BlobType(new BlobImpl(result));
        }
        return new BlobType(new SerialBlob(Arrays.copyOf(fs.getBuffer(), fs.getCount())));
    } catch (IOException e) {
        throw new TeiidProcessingException(QueryPlugin.Event.TEIID30422, e);
    } catch (SQLException e) {
        throw new TeiidProcessingException(QueryPlugin.Event.TEIID30423, e);
    }
}
Also used : 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) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 4 with FileStoreOutputStream

use of org.teiid.common.buffer.FileStore.FileStoreOutputStream 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 5 with FileStoreOutputStream

use of org.teiid.common.buffer.FileStore.FileStoreOutputStream in project teiid by teiid.

the class TestFileStorageManager method testGrowth.

@Test
public void testGrowth() throws Exception {
    FileStorageManager sm = getStorageManager(null, null);
    FileStore store = sm.createFileStore("0");
    FileStoreOutputStream fsos = store.createOutputStream(1 << 15);
    assertTrue(fsos.getBuffer().length < 1 << 15);
    fsos.write(1);
    fsos.write(new byte[1 << 14]);
    fsos.flush();
    assertEquals(1 + (1 << 14), fsos.getCount());
    assertEquals(1 << 15, fsos.getBuffer().length);
}
Also used : FileStore(org.teiid.common.buffer.FileStore) FileStoreOutputStream(org.teiid.common.buffer.FileStore.FileStoreOutputStream) Test(org.junit.Test)

Aggregations

FileStoreOutputStream (org.teiid.common.buffer.FileStore.FileStoreOutputStream)6 Test (org.junit.Test)4 FileStore (org.teiid.common.buffer.FileStore)3 BlobImpl (org.teiid.core.types.BlobImpl)3 BlobType (org.teiid.core.types.BlobType)3 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 SerialBlob (javax.sql.rowset.serial.SerialBlob)2 TeiidProcessingException (org.teiid.core.TeiidProcessingException)2 ClobImpl (org.teiid.core.types.ClobImpl)2 ClobType (org.teiid.core.types.ClobType)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 StringReader (java.io.StringReader)1 InputStreamFactory (org.teiid.core.types.InputStreamFactory)1 ReaderInputStream (org.teiid.core.util.ReaderInputStream)1