Class CsvFileSink

java.lang.Object
edu.ie3.datamodel.io.sink.CsvFileSink
All Implemented Interfaces:
DataSink, InputDataSink, OutputDataSink

public class CsvFileSink extends Object implements InputDataSink, OutputDataSink
Sink that provides all capabilities to write UniqueEntitys to .csv-files. Be careful about using methods other than persistJointGrid(JointGridContainer) because all other methods do not check for duplicate entries but only dump the data they received. In contrast, when using persistJointGrid(JointGridContainer), all nested entities get extracted first and then dumped individually without any duplicate lines.
Since:
19.03.20
  • Constructor Details

    • CsvFileSink

      public CsvFileSink(String baseFolderPath)
    • CsvFileSink

      public CsvFileSink(String baseFolderPath, FileNamingStrategy fileNamingStrategy, boolean initFiles, String csvSep)
      Create an instance of a csv file sink that can be used to persist Unique entities. This implementation processes in sequential order. To parallelize this process one might consider starting several sinks and use them for specific entities.
      Parameters:
      baseFolderPath - the base folder path where the files should be put into
      fileNamingStrategy - the data sink file naming strategy that should be used
      initFiles - true if the files should be created during initialization (might create files, that only consist of a headline, because no data will be written into them), false otherwise
      csvSep - the csv file separator that should be use
    • CsvFileSink

      public CsvFileSink(String baseFolderPath, ProcessorProvider processorProvider, FileNamingStrategy fileNamingStrategy, boolean initFiles, String csvSep)
      Create an instance of a csv file sink that can be used to persist Unique entities. This implementation processes in sequential order. To parallelize this process one might consider starting several sinks and use them for specific entities. Be careful when providing your own ProcessorProvider because if you're not 100% sure that it knows about all entities you're going to process exceptions might occur. Therefore it is strongly advised to either use a constructor without providing the ProcessorProvider or provide a general ProcessorProvider by calling ProcessorProvider()
      Parameters:
      baseFolderPath - the base folder path where the files should be put into
      processorProvider - the processor provided that should be used for entity serialization
      fileNamingStrategy - the data sink file naming strategy that should be used
      initFiles - true if the files should be created during initialization (might create files, that only consist of a headline, because no data will be written into them), false otherwise
      csvSep - the csv file separator that should be use
  • Method Details

    • persistAll

      public <T extends UniqueEntity> void persistAll(Collection<T> entities)
      Description copied from interface: DataSink
      Should implement the entry point of a data sink to persist multiple entities in a collection. By default this method should take care about the extraction process of nested entities (if any) of input entities and use Extractor accordingly. For a faster method that neglects the nested objects persistence and only persists the uuid of the nested * objects (if any), instead of the object itself use InputDataSink.persistAllIgnoreNested(java.util.Collection<C>)
      Specified by:
      persistAll in interface DataSink
      Type Parameters:
      T - bounded to be all unique entities. Handling of specific entities is normally then executed by a specific EntityProcessor
      Parameters:
      entities - a collection of entities that should be persisted
    • persist

      public <T extends UniqueEntity> void persist(T entity)
      Description copied from interface: DataSink
      Should implement the entry point of a data sink to persist an entity. By default this method should take care about the extraction process of nested entities (if any) of input entities and use Extractor accordingly. For an faster method e.g. that neglects the nested objects persistence and only persists the uuid of the nested objects (if any), instead of the object itself use InputDataSink.persistIgnoreNested(C)
      Specified by:
      persist in interface DataSink
      Type Parameters:
      T - bounded to be all unique entities. Handling of specific entities is normally then executed by a specific EntityProcessor
      Parameters:
      entity - the entity that should be persisted
    • persistIgnoreNested

      public <C extends InputEntity> void persistIgnoreNested(C entity)
      Description copied from interface: InputDataSink
      Should implement the entry point of a data sink to persist an input entity. In contrast to DataSink.persist(C) and InputDataSink.persistIncludeNested(C), this method should not take care about the extraction process of nested entities (if any) but only persist the uuid of the nested entity. This might speed up things a little bit because of missing if-/else-clauses but can also lead to missing persisted data that should be persisted, but is not e.g. nested types that are not available anymore afterwards. It might be useful especially for all entities without nested entities. For all doubts about if the provided entity contains needed nested data or not DataSink.persist(UniqueEntity) is the recommended method to be used.
      Specified by:
      persistIgnoreNested in interface InputDataSink
      Type Parameters:
      C - bounded to be all input entities. Handling of the entities is normally then executed by a InputEntityProcessor
      Parameters:
      entity - the entity that should be persisted
    • persistAllIgnoreNested

      public <C extends InputEntity> void persistAllIgnoreNested(Collection<C> entities)
      Description copied from interface: InputDataSink
      Should implement the entry point of a data sink to persist multiple input entities in a collection. In contrast to DataSink.persistAll(Collection) and InputDataSink.persistAllIncludeNested(java.util.Collection<C>), this method should not take care about the extraction process of nested entities (if any) but only persist the uuid of the nested entity. This might speed up things a little bit because of missing if-/else-clauses but but can also lead to missing persisted data that should be persisted, but is not e.g. nested types that are not available anymore afterwards. It might be useful especially for all entities without nested entities. For all doubts about if the provided entity contains needed nested data or not DataSink.persistAll(Collection) is the recommended method to be used.
      Specified by:
      persistAllIgnoreNested in interface InputDataSink
      Type Parameters:
      C - bounded to be all unique entities. Handling of the entities is normally then executed by a InputEntityProcessor
      Parameters:
      entities - the entities that should be persisted
    • persistIncludeNested

      public <C extends InputEntity> void persistIncludeNested(C entity)
      Description copied from interface: InputDataSink
      Should offer a clear alternative to InputDataSink.persistIgnoreNested(C) if the nested entities of an input entity are supposed to be persisted as well. However this might take longer as additional entities have to be extracted and persisted.
      Specified by:
      persistIncludeNested in interface InputDataSink
      Type Parameters:
      C - bounded to be all input entities. Handling of specific entities is normally then executed by a specific InputEntityProcessor
      Parameters:
      entity - the entity that should be persisted including its nested entities
    • persistAllIncludeNested

      public <C extends InputEntity> void persistAllIncludeNested(Collection<C> entities)
      Description copied from interface: InputDataSink
      Should offer a clear alternative to InputDataSink.persistAllIgnoreNested(java.util.Collection<C>) if the nested entities of the input entities are supposed to be persisted as well. However this might take longer as additional entities have to be extracted and persisted.
      Specified by:
      persistAllIncludeNested in interface InputDataSink
      Type Parameters:
      C - bounded to be all unique entities. Handling of the entities is normally then executed by a InputEntityProcessor
      Parameters:
      entities - the entities that should be persisted including its nested entities
    • persistJointGrid

      public void persistJointGrid(JointGridContainer jointGridContainer)
      Description copied from interface: InputDataSink
      Should implement the entry point of a data sink to persist a whole JointGridContainer
      Specified by:
      persistJointGrid in interface InputDataSink
      Parameters:
      jointGridContainer - the JointGridContainer that should be persisted
    • shutdown

      public void shutdown()
      Description copied from interface: DataSink
      Shutdown this sink and do all cleanup operations (e.g. closing of the DataConnector) here
      Specified by:
      shutdown in interface DataSink
    • persistTimeSeries

      public <E extends TimeSeriesEntry<V>, V extends Value> void persistTimeSeries(TimeSeries<E,V> timeSeries)
      Description copied from interface: DataSink
      Should implement the handling of a whole time series. Therefore the single entries have to be extracted and persisted accordingly.
      Specified by:
      persistTimeSeries in interface DataSink
      Type Parameters:
      E - Type of entry in the time series
      V - Type of actual value, that is inside the entry
      Parameters:
      timeSeries - Time series to persist