Class Exporter

java.lang.Object
chemaxon.jchem.db.Exporter
All Implemented Interfaces:
chemaxon.jchem.db.Transfer

@PublicAPI public class Exporter extends Object implements chemaxon.jchem.db.Transfer
This class is a tool for exporting molecules from database tables into an OutputStream object. The OutputStream can represent a file, the standard output, etc.
  • Constructor Details

    • Exporter

      public Exporter()
  • Method Details

    • setConnectionHandler

      public void setConnectionHandler(ConnectionHandler conh)
      Setter for property connectionHandler. The ConnectionHandler must represent an open connection to the database.
      Parameters:
      conh - the new ConnectionHandler to use
    • getConnectionHandler

      public ConnectionHandler getConnectionHandler()
      Getter for property connectionHandler.
      Returns:
      the ConnectionHandler
    • setTableName

      public void setTableName(String tname)
      Sets the name of the table to export from.
      Parameters:
      tname - the table name
    • getTableName

      public String getTableName()
      Gets the name of the table to export from.
      Returns:
      the table name
    • setFieldList

      public void setFieldList(String fieldList)
      Sets the list of fields to be exported. The list of fields to be exported separated by spaces. For example: "cd_id cd_molweight". One doesn't have to specify "cd_structure", the structure is always exported.
      If not set (or null) all the fields are exported or only defaults, depending on the value set by setDefaults.
      Parameters:
      fieldList - field names as described above
    • getFieldList

      public String getFieldList()
      Returns the specified list of fields.
      Returns:
      the field list in the form setFieldList(String)}
    • setConditions

      public void setConditions(String conditions)
      An SQL WHERE condition can be specified here. For example: "WHERE CD_ID<1000" exports the first 999 molecules.
      If null or empty string, all molecules in table selected for export.
      Parameters:
      conditions - sql condtion to use
    • getConditions

      public String getConditions()
      Returns the SQL WHERE statement, if specified.
      Returns:
      sql condition
    • setIDList

      public void setIDList(int[] list)
      Sets the list of allowed cd_id values, only these rows will be exported.
      Parameters:
      list - the list. If set to null, no filtering will be performed.
      Since:
      JChem 2.3.4
    • getIDList

      public int[] getIDList()
      Returns the list of allowed cd_id values.
      Returns:
      the list, or null, if no filterig is performed.
      Since:
      JChem 2.3.4
      See Also:
    • setOutputStream

      public void setOutputStream(OutputStream os)
      Sets the OutputStream object to export to.
      Parameters:
      os - the output stream
    • getOutputStream

      public OutputStream getOutputStream()
      Gets the OutputStream object to export to.
      Returns:
      the output stream
    • setFormat

      public void setFormat(int format)
      Sets the format of the export. It can be one of the following constants:
      • Transfer.MOLFILE
      • Transfer.SDFILE
      • Transfer.SMILES
      • Transfer.SMARTS
      • Transfer.CXSMILES
      • Transfer.CXSMARTS
      • Transfer.RDFILE
      • Transfer.MRV
      • Transfer.INCHI
      • Transfer.MOL2FILE
      Parameters:
      format - one of the above
    • getFormat

      public int getFormat()
      Gets the format of the export. It can be one of the following constants:
      • Transfer.MOLFILE
      • Transfer.SDFILE
      • Transfer.SMILES
      • Transfer.SMARTS
      • Transfer.CXSMILES
      • Transfer.CXSMARTS
      • Transfer.RDFILE
      • Transfer.MRV
      • Transfer.INCHI
      • Transfer.MOL2FILE
      Returns:
      the current format code
    • setDefaults

      public void setDefaults(boolean b)
      Sets if only default fields will be exported.
      Default fields: cd_id, cd_structure plus user defined fields (fields not beginning with "cd_").
      Set true to export only default fields, false to export all fields.
      For SMILES export no fields are exported by default.
      Note: Only effective when fieldList is null.
      Parameters:
      b - control default field export
    • isDefaults

      public boolean isDefaults()
      Gets if only default fields are to be exported.
      Returns:
      the current value
    • setSelectStatement

      public void setSelectStatement(String sql)
      Sets a custom SQL SELECT statement to be used as the basis of the export.

      By using this method one can

      • add data fields from other tables to the exported structures
      • specify the order of the output
      The first field in the result set must be the column that contains the structure source: this is the cd_structure column for JChem tables.
      The other fields in the statement are exported as data fields if the output format supports it (e.g: SDFile, Marvin Document).
      The name of the data fields will match the name of the table coulmns unless otherwise specified by setOutputFieldNames(String).

      Example: SELECT STRUCTURES.CD_STRUCTURE, STRUCTURES.CD_ID, BIODATA.TOXICITY FROM STRUCTURES, BIODATA WHERE STRUCTURES.CD=BIODATA.CD_ID AND BIODATA.ACTIVITY>23.4 ORDER BY STRUCTURES.MOLWEIGHT

      If a custom select statement is specified, the following methods have no effect:

      Parameters:
      sql - the SQL statement. If set to null, a standard SELECT statement is generated by JChem for the export (default).
      Since:
      JChem 3.1
    • setOutputFieldNames

      public void setOutputFieldNames(String fieldNames)
      Specify the names of the data fields in the output file.
      Parameters:
      fieldNames - the names of the fields in order, separated by spaces. If set to null or less field names specified than exported, the name of the database field will be used fo the unspecified ones.

      Only effective if a SELECT statement is specified by setSelectStatement(String).

      Since:
      JChem 3.1
    • getOutputFieldNames

      public String[] getOutputFieldNames()
      Get the names of the data fields in the output file.
      Returns:
      the names of the data fields in the output file
    • setOutputFieldConversion

      public void setOutputFieldConversion(String fieldNameConversion)
      Set the DB field name / user defined name conversion rules. It overrides the setOutputFieldNames(String) settings.
      Parameters:
      fieldNameConversion - DB column name and chosen name pairs separated by colons and packed between pipes. Example: "|dbColumnName1:outputName1|dbColumnName2:outputName2|dbColumnName3:outputName3|". Can be null, user defined field conversion will be ignored in this case.
    • getOutputFieldConversion

      public Map<String,String> getOutputFieldConversion()
      Get the DB field name / user defined name conversion rules.
      Returns:
      the currently set db column name / output field name pairs in a map.
    • writeNext

      public boolean writeNext() throws TransferException
      Writes the next molecule to the outputstream, this method is useful if one wants to track the progress of the export.
      Returns:
      true, if a molecule was successfully exported
      false, if there's no more molecule to export
      Throws:
      TransferException - if some exception is encountered
    • writeAll

      public int writeAll() throws TransferException
      Exports all the (remaining) molecules.
      Returns:
      the number of molecules exported
      Throws:
      TransferException - if some exception is encountered