java.lang.Object
edu.internet2.middleware.grouper.ext.org.apache.ddlutils.io.DatabaseDataIO

public class DatabaseDataIO extends Object
Provides basic live database data <-> XML functionality.
Version:
$Revision: $
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the batch size override.
    Returns a data reader instance configured for the given platform (which needs to be connected to a live database) and model.
    Returns a data writer instance configured to write to the given output stream in the specified encoding.
    getConfiguredDataWriter(Writer output, String xmlEncoding)
    Returns a data writer instance configured to write to the given output writer in the specified encoding.
    Returns a data writer instance configured to write to the indicated file in the specified encoding.
    boolean
    Determines whether batch mode is used for inserting data into the database.
    boolean
    Determines whether the sink delays the insertion of beans so that the beans referenced by it via foreignkeys are already inserted into the database.
    boolean
    Determines whether data io is stopped when an error happens.
    void
    Registers a converter.
    void
    setBatchSize(Integer batchSize)
    Sets the batch size to be used by this object.
    void
    setDetermineSchema(boolean determineSchema)
    Deprecated.
    Will be removed once proper schema support is in place
    void
    setEnsureFKOrder(boolean ensureFKOrder)
    Specifies whether the sink shall delay the insertion of beans so that the beans referenced by it via foreignkeys are already inserted into the database.
    Note that you should careful with setting haltOnErrors to false as this might result in beans not inserted at all.
    void
    setFailOnError(boolean failOnError)
    Specifies whether data io shall be stopped when an error happens.
    void
    setSchemaPattern(String schemaPattern)
    Deprecated.
    Will be removed once proper schema support is in place
    void
    setUseBatchMode(boolean useBatchMode)
    Specifies whether batch mode should be used for inserting data into the database.
    void
    Reads the data from the given input stream and writes it to the database via the given data reader.
    void
    Reads the data from the given input stream and writes it to the database via the given data reader.
    void
    Reads the data from the given input stream and writes it to the database via the given data reader.
    void
    writeDataToDatabase(DataReader dataReader, Reader[] inputs)
    Reads the data from the given input stream and writes it to the database via the given data reader.
    void
    Reads the data from the indicated XML file and writes it to the database via the given data reader.
    void
    writeDataToDatabase(DataReader dataReader, String[] files)
    Reads the data from the specified files and writes it to the database via the given data reader.
    void
    writeDataToDatabase(Platform platform, Database model, InputStream[] inputs)
    Reads the data from the given input streams and writes it to the database to which the given platform is connected.
    void
    writeDataToDatabase(Platform platform, Database model, Reader[] inputs)
    Reads the data from the given input readers and writes it to the database to which the given platform is connected.
    void
    writeDataToDatabase(Platform platform, Database model, String[] files)
    Reads the data from the indicated files and writes it to the database to which the given platform is connected.
    void
    Reads the data from the given input streams and writes it to the database to which the given platform is connected.
    void
    writeDataToDatabase(Platform platform, Reader[] inputs)
    Reads the data from the given input readers and writes it to the database to which the given platform is connected.
    void
    writeDataToDatabase(Platform platform, String[] files)
    Reads the data from the specified files and writes it to the database to which the given platform is connected.
    void
    writeDataToXML(Platform platform, DataWriter writer)
    Writes the data contained in the database to which the given platform is connected, as XML to the given data writer.
    void
    writeDataToXML(Platform platform, Database model, DataWriter writer)
    Writes the data contained in the database to which the given platform is connected, as XML to the given data writer.
    void
    writeDataToXML(Platform platform, Database model, OutputStream output, String xmlEncoding)
    Writes the data contained in the database to which the given platform is connected, as XML to the given output stream (which won't be closed by this method).
    void
    writeDataToXML(Platform platform, Database model, Writer output, String xmlEncoding)
    Writes the data contained in the database to which the given platform is connected, as XML to the given output writer (which won't be closed by this method).
    void
    writeDataToXML(Platform platform, Database model, String path, String xmlEncoding)
    Writes the data contained in the database to which the given platform is connected, as XML to the given output stream (which won't be closed by this method).
    void
    writeDataToXML(Platform platform, OutputStream output, String xmlEncoding)
    Writes the data contained in the database to which the given platform is connected, as XML to the given output stream (which won't be closed by this method).
    void
    writeDataToXML(Platform platform, Writer output, String xmlEncoding)
    Writes the data contained in the database to which the given platform is connected, as XML to the given output writer (which won't be closed by this method).
    void
    writeDataToXML(Platform platform, String path, String xmlEncoding)
    Writes the data contained in the database to which the given platform is connected, as XML to the given output stream (which won't be closed by this method).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DatabaseDataIO

      public DatabaseDataIO()
  • Method Details

    • registerConverter

      public void registerConverter(DataConverterRegistration converterRegistration)
      Registers a converter.
      Parameters:
      converterRegistration - The registration info
    • isFailOnError

      public boolean isFailOnError()
      Determines whether data io is stopped when an error happens.
      Returns:
      Whether io is stopped when an error was detected (true by default)
    • setFailOnError

      public void setFailOnError(boolean failOnError)
      Specifies whether data io shall be stopped when an error happens.
      Parameters:
      failOnError - Whether io should stop when an error was detected
    • getUseBatchMode

      public boolean getUseBatchMode()
      Determines whether batch mode is used for inserting data into the database.
      Returns:
      true if batch mode is used
    • setUseBatchMode

      public void setUseBatchMode(boolean useBatchMode)
      Specifies whether batch mode should be used for inserting data into the database.
      Parameters:
      useBatchMode - true if batch mode shall be used
    • getBatchSize

      public Integer getBatchSize()
      Returns the batch size override.
      Returns:
      The batch size if different from the default, null otherwise
    • setBatchSize

      public void setBatchSize(Integer batchSize)
      Sets the batch size to be used by this object.
      Parameters:
      batchSize - The batch size if different from the default, or null if the default shall be used
    • isEnsureFKOrder

      public boolean isEnsureFKOrder()
      Determines whether the sink delays the insertion of beans so that the beans referenced by it via foreignkeys are already inserted into the database.
      Returns:
      true if beans are inserted after its foreignkey-references
    • setEnsureFKOrder

      public void setEnsureFKOrder(boolean ensureFKOrder)
      Specifies whether the sink shall delay the insertion of beans so that the beans referenced by it via foreignkeys are already inserted into the database.
      Note that you should careful with setting haltOnErrors to false as this might result in beans not inserted at all. The sink will then throw an appropriate exception at the end of the insertion process (method DataSink.end()).
      Parameters:
      ensureFKOrder - true if beans shall be inserted after its foreignkey-references
    • setDetermineSchema

      public void setDetermineSchema(boolean determineSchema)
      Deprecated.
      Will be removed once proper schema support is in place
      Specifies whether DdlUtils should try to find the schema of the tables when reading data from a live database.
      Parameters:
      determineSchema - Whether to try to find the table's schemas
    • setSchemaPattern

      public void setSchemaPattern(String schemaPattern)
      Deprecated.
      Will be removed once proper schema support is in place
      Sets the schema pattern to find the schemas of tables when reading data from a live database.
      Parameters:
      schemaPattern - The schema pattern
    • getConfiguredDataWriter

      public DataWriter getConfiguredDataWriter(String path, String xmlEncoding) throws DdlUtilsException
      Returns a data writer instance configured to write to the indicated file in the specified encoding.
      Parameters:
      path - The path to the output XML data file
      xmlEncoding - The encoding to use for writing the XML
      Returns:
      The writer
      Throws:
      DdlUtilsException
    • getConfiguredDataWriter

      public DataWriter getConfiguredDataWriter(OutputStream output, String xmlEncoding) throws DdlUtilsException
      Returns a data writer instance configured to write to the given output stream in the specified encoding.
      Parameters:
      output - The output stream
      xmlEncoding - The encoding to use for writing the XML
      Returns:
      The writer
      Throws:
      DdlUtilsException
    • getConfiguredDataWriter

      public DataWriter getConfiguredDataWriter(Writer output, String xmlEncoding) throws DdlUtilsException
      Returns a data writer instance configured to write to the given output writer in the specified encoding.
      Parameters:
      output - The output writer; needs to be configured with the specified encoding
      xmlEncoding - The encoding to use for writing the XML
      Returns:
      The writer
      Throws:
      DdlUtilsException
    • writeDataToXML

      public void writeDataToXML(Platform platform, String path, String xmlEncoding) throws DdlUtilsException
      Writes the data contained in the database to which the given platform is connected, as XML to the given output stream (which won't be closed by this method).
      Parameters:
      platform - The platform; needs to be connected to a live database
      path - The path of the output file
      xmlEncoding - The encoding to use for the XML
      Throws:
      DdlUtilsException
    • writeDataToXML

      public void writeDataToXML(Platform platform, Database model, String path, String xmlEncoding)
      Writes the data contained in the database to which the given platform is connected, as XML to the given output stream (which won't be closed by this method).
      Parameters:
      platform - The platform; needs to be connected to a live database
      model - The model for which to retrieve and write the data
      path - The path of the output file
      xmlEncoding - The encoding to use for the XML
    • writeDataToXML

      public void writeDataToXML(Platform platform, OutputStream output, String xmlEncoding)
      Writes the data contained in the database to which the given platform is connected, as XML to the given output stream (which won't be closed by this method).
      Parameters:
      platform - The platform; needs to be connected to a live database
      output - The output stream
      xmlEncoding - The encoding to use for the XML
    • writeDataToXML

      public void writeDataToXML(Platform platform, Database model, OutputStream output, String xmlEncoding)
      Writes the data contained in the database to which the given platform is connected, as XML to the given output stream (which won't be closed by this method).
      Parameters:
      platform - The platform; needs to be connected to a live database
      model - The model for which to retrieve and write the data
      output - The output stream
      xmlEncoding - The encoding to use for the XML
    • writeDataToXML

      public void writeDataToXML(Platform platform, Writer output, String xmlEncoding)
      Writes the data contained in the database to which the given platform is connected, as XML to the given output writer (which won't be closed by this method).
      Parameters:
      platform - The platform; needs to be connected to a live database
      output - The output writer (which needs to be openend with the specified encoding)
      xmlEncoding - The encoding to use for the XML
    • writeDataToXML

      public void writeDataToXML(Platform platform, Database model, Writer output, String xmlEncoding)
      Writes the data contained in the database to which the given platform is connected, as XML to the given output writer (which won't be closed by this method).
      Parameters:
      platform - The platform; needs to be connected to a live database
      model - The model for which to retrieve and write the data
      output - The output writer (which needs to be openend with the specified encoding)
      xmlEncoding - The encoding to use for the XML
    • writeDataToXML

      public void writeDataToXML(Platform platform, DataWriter writer)
      Writes the data contained in the database to which the given platform is connected, as XML to the given data writer.
      Parameters:
      platform - The platform; needs to be connected to a live database
      writer - The data writer
    • writeDataToXML

      public void writeDataToXML(Platform platform, Database model, DataWriter writer)
      Writes the data contained in the database to which the given platform is connected, as XML to the given data writer.
      Parameters:
      platform - The platform; needs to be connected to a live database
      model - The model for which to retrieve and write the data
      writer - The data writer
    • getConfiguredDataReader

      public DataReader getConfiguredDataReader(Platform platform, Database model) throws DdlUtilsException
      Returns a data reader instance configured for the given platform (which needs to be connected to a live database) and model.
      Parameters:
      platform - The database
      model - The model
      Returns:
      The data reader
      Throws:
      DdlUtilsException
    • writeDataToDatabase

      public void writeDataToDatabase(Platform platform, String[] files) throws DdlUtilsException
      Reads the data from the specified files and writes it to the database to which the given platform is connected.
      Parameters:
      platform - The platform, must be connected to a live database
      files - The XML data files
      Throws:
      DdlUtilsException
    • writeDataToDatabase

      public void writeDataToDatabase(Platform platform, InputStream[] inputs) throws DdlUtilsException
      Reads the data from the given input streams and writes it to the database to which the given platform is connected.
      Parameters:
      platform - The platform, must be connected to a live database
      inputs - The input streams for the XML data
      Throws:
      DdlUtilsException
    • writeDataToDatabase

      public void writeDataToDatabase(Platform platform, Reader[] inputs) throws DdlUtilsException
      Reads the data from the given input readers and writes it to the database to which the given platform is connected.
      Parameters:
      platform - The platform, must be connected to a live database
      inputs - The input readers for the XML data
      Throws:
      DdlUtilsException
    • writeDataToDatabase

      public void writeDataToDatabase(Platform platform, Database model, String[] files) throws DdlUtilsException
      Reads the data from the indicated files and writes it to the database to which the given platform is connected. Only data that matches the given model will be written.
      Parameters:
      platform - The platform, must be connected to a live database
      model - The model to which to constrain the written data
      files - The XML data files
      Throws:
      DdlUtilsException
    • writeDataToDatabase

      public void writeDataToDatabase(Platform platform, Database model, InputStream[] inputs) throws DdlUtilsException
      Reads the data from the given input streams and writes it to the database to which the given platform is connected. Only data that matches the given model will be written.
      Parameters:
      platform - The platform, must be connected to a live database
      model - The model to which to constrain the written data
      inputs - The input streams for the XML data
      Throws:
      DdlUtilsException
    • writeDataToDatabase

      public void writeDataToDatabase(Platform platform, Database model, Reader[] inputs) throws DdlUtilsException
      Reads the data from the given input readers and writes it to the database to which the given platform is connected. Only data that matches the given model will be written.
      Parameters:
      platform - The platform, must be connected to a live database
      model - The model to which to constrain the written data
      inputs - The input readers for the XML data
      Throws:
      DdlUtilsException
    • writeDataToDatabase

      public void writeDataToDatabase(DataReader dataReader, String[] files) throws DdlUtilsException
      Reads the data from the specified files and writes it to the database via the given data reader. Note that the sink that the data reader is configured with, won't be started or ended by this method. This has to be done by the code using this method.
      Parameters:
      dataReader - The data reader
      files - The XML data files
      Throws:
      DdlUtilsException
    • writeDataToDatabase

      public void writeDataToDatabase(DataReader dataReader, InputStream[] inputs) throws DdlUtilsException
      Reads the data from the given input stream and writes it to the database via the given data reader. Note that the input stream won't be closed by this method. Note also that the sink that the data reader is configured with, won't be started or ended by this method. This has to be done by the code using this method.
      Parameters:
      dataReader - The data reader
      inputs - The input streams for the XML data
      Throws:
      DdlUtilsException
    • writeDataToDatabase

      public void writeDataToDatabase(DataReader dataReader, Reader[] inputs) throws DdlUtilsException
      Reads the data from the given input stream and writes it to the database via the given data reader. Note that the input stream won't be closed by this method. Note also that the sink that the data reader is configured with, won't be started or ended by this method. This has to be done by the code using this method.
      Parameters:
      dataReader - The data reader
      inputs - The input readers for the XML data
      Throws:
      DdlUtilsException
    • writeDataToDatabase

      public void writeDataToDatabase(DataReader dataReader, String path) throws DdlUtilsException
      Reads the data from the indicated XML file and writes it to the database via the given data reader. Note that the sink that the data reader is configured with, won't be started or ended by this method. This has to be done by the code using this method.
      Parameters:
      dataReader - The data reader
      path - The path to the XML data file
      Throws:
      DdlUtilsException
    • writeDataToDatabase

      public void writeDataToDatabase(DataReader dataReader, InputStream input) throws DdlUtilsException
      Reads the data from the given input stream and writes it to the database via the given data reader. Note that the input stream won't be closed by this method. Note also that the sink that the data reader is configured with, won't be started or ended by this method. This has to be done by the code using this method.
      Parameters:
      dataReader - The data reader
      input - The input stream for the XML data
      Throws:
      DdlUtilsException
    • writeDataToDatabase

      public void writeDataToDatabase(DataReader dataReader, Reader input) throws DdlUtilsException
      Reads the data from the given input stream and writes it to the database via the given data reader. Note that the input stream won't be closed by this method. Note also that the sink that the data reader is configured with, won't be started or ended by this method. This has to be done by the code using this method.
      Parameters:
      dataReader - The data reader
      input - The input reader for the XML data
      Throws:
      DdlUtilsException