org.knime.core.node
Class BufferedDataContainer

java.lang.Object
  extended by org.knime.core.data.container.DataContainer
      extended by org.knime.core.node.BufferedDataContainer
All Implemented Interfaces:
RowAppender

public class BufferedDataContainer
extends DataContainer

DataContainer to be used during a NodeModel's execution. A BufferedDataContainer is special implementation of a DataContainer whose getTable() returns a BufferedDataTable, i.e. the return value of each NodeModel's execute method.

Use a BufferedDataContainer when new data is acquired during the execution or if it does not pay off to reference a node's input data (it does pay off when you only append a column to the input data, for instance). Please see the ExecutionContext for more details on how to create BufferedDataTable's.

To get a quick start how to use a BufferedDataTable, see the following code:

 protected final BufferedDataTable[] execute(
      final BufferedDataTable[] data, final ExecutionContext exec)
      throws Exception {
  // the DataTableSpec of the final table
  DataTableSpec spec = new DataTableSpec(
          new DataColumnSpecCreator("A", StringCell.TYPE).createSpec(),
          new DataColumnSpecCreator("B", DoubleCell.TYPE).createSpec());
  // init the container
  BufferedDataContainer container = exec.createDataContainer(spec);

  // add arbitrary number of rows to the container
  DataRow firstRow = new DefaultRow(new RowKey("first"), new DataCell[]{
      new StringCell("A1"), new DoubleCell(1.0)
  });
  container.addRowToTable(firstRow);
  DataRow secondRow = new DefaultRow(new RowKey("second"), new DataCell[]{
      new StringCell("B1"), new DoubleCell(2.0)
  });
  container.addRowToTable(secondRow);

  // finally close the container and get the result table.
  container.close();
  BufferedDataTable result = container.getTable();
  ...

 

For a more detailed explanation refer to the description of the DataContainer class.

Author:
Bernd Wiswedel, University of Konstanz
See Also:
DataContainer, ExecutionContext

Field Summary
 
Fields inherited from class org.knime.core.data.container.DataContainer
DEF_GZIP_COMPRESSION, DEF_MAX_CELLS_IN_MEMORY, MAX_CELLS_IN_MEMORY, PROPERTY_CELLS_IN_MEMORY
 
Constructor Summary
BufferedDataContainer(DataTableSpec spec, boolean initDomain, Node node, SingleNodeContainer.MemoryPolicy policy, boolean forceCopyOfBlobs, int maxCellsInMemory, Map<Integer,ContainerTable> globalTableRepository, Map<Integer,ContainerTable> localTableRepository)
          Creates new container.
 
Method Summary
protected  int createInternalBufferID()
          Get an internal id for the buffer being used.
protected  Map<Integer,ContainerTable> getGlobalTableRepository()
          Returns the table repository from this workflow.
protected  Map<Integer,ContainerTable> getLocalTableRepository()
          Returns the local repository of tables.
 BufferedDataTable getTable()
          Returns the content of this container in a BufferedDataTable.
protected static ContainerTable readFromZipDelayed(ReferencedFile zipFileRef, DataTableSpec spec, int bufID, Map<Integer,ContainerTable> bufferRep)
          Just delegates to DataContainer.readFromZipDelayed( ReferencedFile, DataTableSpec, int, Map) This method is available in this class to enable other classes in this package to use it.
 
Methods inherited from class org.knime.core.data.container.DataContainer
addRowKeyForDuplicateCheck, addRowToTable, cache, cache, close, createTempFile, getBufferedTable, getTableSpec, isClosed, isContainerTable, isForceCopyOfBlobs, isOpen, readFromStream, readFromZip, setBufferCreator, setForceCopyOfBlobs, setMaxPossibleValues, size, writeToStream, writeToZip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufferedDataContainer

BufferedDataContainer(DataTableSpec spec,
                      boolean initDomain,
                      Node node,
                      SingleNodeContainer.MemoryPolicy policy,
                      boolean forceCopyOfBlobs,
                      int maxCellsInMemory,
                      Map<Integer,ContainerTable> globalTableRepository,
                      Map<Integer,ContainerTable> localTableRepository)
Creates new container.

Parameters:
spec - The table spec.
initDomain - Whether or not the spec's domain shall be used for initialization.
node - The owner of the outcome table.
forceCopyOfBlobs - The property whether to copy any blob cell
maxCellsInMemory - Number of cells to be kept in memory, if negative use user settings (according to node) being added, see DataContainer.setForceCopyOfBlobs(boolean).
globalTableRepository - The global (WFM) table repository for blob (de)serialization.
localTableRepository - The local (Node) table repository for blob (de)serialization.
See Also:
DataContainer.DataContainer(DataTableSpec, boolean)
Method Detail

createInternalBufferID

protected int createInternalBufferID()
Get an internal id for the buffer being used. This ID is used in conjunction with blob serialization to locate buffers. Blobs that belong to a Buffer (i.e. they have been created in a particular Buffer) will write this ID when serialized to a file. Subsequent Buffers that also need to serialize Blob cells (which, however, have already been written) can then reference to the respective Buffer object using this ID.

An ID of -1 denotes the fact, that the buffer is not intended to be used for sophisticated blob serialization. All blob cells that are added to it will be newly serialized as if they were created for the first time.

This implementation returns -1.

Overrides:
createInternalBufferID in class DataContainer
Returns:
-1 or a unique buffer ID.

getGlobalTableRepository

protected Map<Integer,ContainerTable> getGlobalTableRepository()
Returns the table repository from this workflow. Get the map of buffers that potentially have written blob objects. If m_buffer needs to serialize a blob, it will check if any other buffer has written the blob already and then reference to this buffer rather than writing out the blob again.

If used along with the ExecutionContext, this method returns the global table repository (global = in the context of the current workflow).

This implementation does not support sophisticated blob serialization. It will return a new HashMap<Integer, Buffer>().

Overrides:
getGlobalTableRepository in class DataContainer
Returns:
The map bufferID to Buffer.
See Also:
DataContainer.getLocalTableRepository()

getLocalTableRepository

protected Map<Integer,ContainerTable> getLocalTableRepository()
Returns the local repository of tables. It contains tables that have been created during the execution of a node. Get the local repository. Overridden in BufferedDataContainer

Overrides:
getLocalTableRepository in class DataContainer
Returns:
A local repository to which tables are added that have been created during the node's execution.

getTable

public BufferedDataTable getTable()
Returns the content of this container in a BufferedDataTable. The result can be returned, e.g. in a NodeModel's execute method. Get reference to table. This method throws an exception unless the container is closed and has therefore a table available.

Overrides:
getTable in class DataContainer
Returns:
Reference to the table that has been built up.

readFromZipDelayed

protected static ContainerTable readFromZipDelayed(ReferencedFile zipFileRef,
                                                   DataTableSpec spec,
                                                   int bufID,
                                                   Map<Integer,ContainerTable> bufferRep)
Just delegates to DataContainer.readFromZipDelayed( ReferencedFile, DataTableSpec, int, Map) This method is available in this class to enable other classes in this package to use it.

Parameters:
zipFileRef - Delegated.
spec - Delegated.
bufID - Delegated.
bufferRep - Delegated.
Returns:
DataContainer.readFromZipDelayed( ReferencedFile, DataTableSpec, int, Map)


Copyright, 2003 - 2010. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.