Search in sources :

Example 1 with FileStore

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

the class XMLSystemFunctions method saveToBufferManager.

/**
 * This method saves the given XML object to the buffer manager's disk process
 * Documents less than the maxMemorySize will be held directly in memory
 */
public static SQLXMLImpl saveToBufferManager(BufferManager bufferMgr, XMLTranslator translator, CommandContext context) throws TeiidComponentException, TeiidProcessingException {
    boolean success = false;
    // $NON-NLS-1$
    final FileStore lobBuffer = bufferMgr.createFileStore("xml");
    final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(lobBuffer, Streamable.ENCODING);
    try {
        Writer writer = fsisf.getWriter();
        final ExtendedWriter ew = new ExtendedWriter(writer, fsisf);
        translator.translate(ew);
        ew.close();
        success = true;
        return createSQLXML(fsisf, ew, context);
    } catch (IOException e) {
        throw new TeiidComponentException(QueryPlugin.Event.TEIID30444, e);
    } catch (TransformerException e) {
        throw new TeiidProcessingException(QueryPlugin.Event.TEIID30445, e);
    } finally {
        if (!success && lobBuffer != null) {
            lobBuffer.remove();
        }
    }
}
Also used : FileStore(org.teiid.common.buffer.FileStore) FileStoreInputStreamFactory(org.teiid.common.buffer.FileStoreInputStreamFactory) TeiidComponentException(org.teiid.core.TeiidComponentException) XMLEventWriter(javax.xml.stream.XMLEventWriter) TransformerException(javax.xml.transform.TransformerException) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 2 with FileStore

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

the class TestFileStorageManager method testSetLength.

@Test
public void testSetLength() throws Exception {
    FileStorageManager sm = getStorageManager(null, null);
    // $NON-NLS-1$
    String tsID = "0";
    FileStore store = sm.createFileStore(tsID);
    store.setLength(1000);
    assertEquals(1000, sm.getUsedBufferSpace());
    store.setLength(200);
    assertEquals(200, sm.getUsedBufferSpace());
    store.setLength(1000);
    assertEquals(1000, sm.getUsedBufferSpace());
}
Also used : FileStore(org.teiid.common.buffer.FileStore) Test(org.junit.Test)

Example 3 with FileStore

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

the class TestFileStorageManager method testWrite.

@Test
public void testWrite() throws Exception {
    FileStorageManager sm = getStorageManager(null, null);
    // $NON-NLS-1$
    String tsID = "0";
    FileStore store = sm.createFileStore(tsID);
    writeBytes(store);
    assertEquals(2048, sm.getUsedBufferSpace());
    store.remove();
    assertEquals(0, sm.getUsedBufferSpace());
}
Also used : FileStore(org.teiid.common.buffer.FileStore) Test(org.junit.Test)

Example 4 with FileStore

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

the class TestFileStorageManager method testMaxSpace.

@Test(expected = IOException.class)
public void testMaxSpace() throws Exception {
    FileStorageManager sm = getStorageManager(null, null);
    sm.setMaxBufferSpace(1);
    // $NON-NLS-1$
    String tsID = "0";
    // Add one batch
    FileStore store = sm.createFileStore(tsID);
    writeBytes(store);
}
Also used : FileStore(org.teiid.common.buffer.FileStore) Test(org.junit.Test)

Example 5 with FileStore

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

the class TestFileStorageManager method testMaxSpaceSplit.

@Test(expected = IOException.class)
public void testMaxSpaceSplit() throws Exception {
    FileStorageManager sm = getStorageManager(null, null);
    sm.setMaxBufferSpace(1);
    // $NON-NLS-1$
    String tsID = "0";
    SplittableStorageManager ssm = new SplittableStorageManager(sm);
    FileStore store = ssm.createFileStore(tsID);
    try {
        writeBytes(store);
    } finally {
        assertEquals(0, sm.getUsedBufferSpace());
    }
}
Also used : FileStore(org.teiid.common.buffer.FileStore) Test(org.junit.Test)

Aggregations

FileStore (org.teiid.common.buffer.FileStore)24 Test (org.junit.Test)14 FileStoreInputStreamFactory (org.teiid.common.buffer.FileStoreInputStreamFactory)7 InputStream (java.io.InputStream)5 IOException (java.io.IOException)4 FileStoreOutputStream (org.teiid.common.buffer.FileStore.FileStoreOutputStream)4 TeiidComponentException (org.teiid.core.TeiidComponentException)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3 Reader (java.io.Reader)2 Writer (java.io.Writer)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FilterReader (java.io.FilterReader)1 ObjectInput (java.io.ObjectInput)1 ObjectInputStream (java.io.ObjectInputStream)1 OutputStream (java.io.OutputStream)1 SQLException (java.sql.SQLException)1 Lock (java.util.concurrent.locks.Lock)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 DataSource (javax.activation.DataSource)1