StreamingDataSet.java

  1. /*
  2.  *
  3.  * The DbUnit Database Testing Framework
  4.  * Copyright (C)2002-2004, DbUnit.org
  5.  *
  6.  * This library is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU Lesser General Public
  8.  * License as published by the Free Software Foundation; either
  9.  * version 2.1 of the License, or (at your option) any later version.
  10.  *
  11.  * This library is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  * Lesser General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Lesser General Public
  17.  * License along with this library; if not, write to the Free Software
  18.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.  *
  20.  */
  21. package org.dbunit.dataset.stream;

  22. import org.dbunit.dataset.AbstractDataSet;
  23. import org.dbunit.dataset.DataSetException;
  24. import org.dbunit.dataset.ITable;
  25. import org.dbunit.dataset.ITableIterator;
  26. import org.dbunit.dataset.ITableMetaData;
  27. import org.slf4j.Logger;
  28. import org.slf4j.LoggerFactory;

  29. /**
  30.  * Dataset that consumes producer asynchronously.
  31.  *
  32.  * @author Manuel Laflamme
  33.  * @author Last changed by: $Author$
  34.  * @version $Revision$ $Date$
  35.  * @since Apr 18, 2003
  36.  */
  37. public class StreamingDataSet extends AbstractDataSet
  38. {

  39.     /**
  40.      * Logger for this class
  41.      */
  42.     private static final Logger logger = LoggerFactory.getLogger(StreamingDataSet.class);

  43.     private IDataSetProducer _source;
  44.     private int _iteratorCount;

  45.     public StreamingDataSet(IDataSetProducer source)
  46.     {
  47.         _source = source;
  48.     }

  49.     ////////////////////////////////////////////////////////////////////////////
  50.     // AbstractDataSet class

  51.     protected ITableIterator createIterator(boolean reversed)
  52.             throws DataSetException
  53.     {
  54.         logger.debug("createIterator(reversed={}) - start", Boolean.valueOf(reversed));

  55.         if (reversed)
  56.         {
  57.             throw new UnsupportedOperationException(
  58.                     "Reverse iterator not supported!");
  59.         }

  60.         if (_iteratorCount > 0)
  61.         {
  62.             throw new UnsupportedOperationException(
  63.                     "Only one iterator allowed!");
  64.         }

  65.         _iteratorCount++;
  66.         return new StreamingIterator(_source);
  67.     }

  68.     ////////////////////////////////////////////////////////////////////////////
  69.     // IDataSet interface

  70.     /**
  71.      * Not supported.
  72.      * @throws UnsupportedOperationException
  73.      */
  74.     public String[] getTableNames() throws DataSetException
  75.     {
  76.         throw new UnsupportedOperationException();
  77.     }

  78.     /**
  79.      * Not supported.
  80.      * @throws UnsupportedOperationException
  81.      */
  82.     public ITableMetaData getTableMetaData(String tableName) throws DataSetException
  83.     {
  84.         logger.debug("getTableMetaData(tableName={}) - start", tableName);

  85.         throw new UnsupportedOperationException();
  86.     }

  87.     /**
  88.      * Not supported.
  89.      * @throws UnsupportedOperationException
  90.      */
  91.     public ITable getTable(String tableName) throws DataSetException
  92.     {
  93.         logger.debug("getTable(tableName={}) - start", tableName);

  94.         throw new UnsupportedOperationException();
  95.     }

  96. }