chemaxon.jchem.db
Class Exporter

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

public class Exporter
extends java.lang.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.

Author:
Szilard Dorant

Field Summary
 
Fields inherited from interface chemaxon.jchem.db.Transfer
JTF, MOLFILE, MRV, RDFILE, RXNFILE, SDFILE, SMILES
 
Constructor Summary
Exporter()
           
 
Method Summary
 java.lang.String getConditions()
          Returns the SQL WHERE statement, if specified.
 ConnectionHandler getConnectionHandler()
          Getter for property connectionHandler.
 java.lang.String getDelimiter()
          Gets the field delimiter character between columns for JTF format output.
 java.lang.String getEol()
          Gets the End Of Line character(s).
 java.lang.String getFieldList()
          Returns the specified list of fields.
 int getFormat()
          Gets the format of the export.
 int[] getIDList()
          Returns the list of allowed cd_id values.
 java.io.OutputStream getOutputStream()
          Gets the OutputStream object to export to.
 java.lang.String getQuotation()
          Gets the field enclosing character for JTF format output.
 java.lang.String getTableName()
          Gets the name of the table to export from.
 boolean isDefaults()
          Gets if only default fields are to be exported.
 boolean isJtfWithStructure()
          Gets, wheter exported JTF will contain structure information.
 void setConditions(java.lang.String conditions)
          An SQL WHERE condition can be specified here.
 void setConnectionHandler(ConnectionHandler conh)
          Setter for property connectionHandler.
 void setDefaults(boolean b)
          Sets if only default fields will be exported.
 void setDelimiter(java.lang.String delimiter)
          Sets the field delimiter character between columns for JTF format output.
 void setEol(java.lang.String eol)
          Sets the End Of Line character(s), system dependent.
 void setFieldList(java.lang.String fieldList)
          Sets the list of fields to be exported.
 void setFormat(int format)
          Sets the format of the export.
 void setIDList(int[] list)
          Sets the list of allowed cd_id values, only these rows will be exported.
 void setJtfWithStructure(boolean b)
          Specifies, wheter exported JTF will contain structure information.
 void setOutputFieldNames(java.lang.String fieldNames)
          Specifies the names of the data fields in the output file.
 void setOutputStream(java.io.OutputStream os)
          Sets the OutputStream object to export to.
 void setQuotation(java.lang.String quotation)
          Sets the field enclosing character for JTF format output.
 void setSelectStatement(java.lang.String sql)
          Sets a custom SQL SELECT statement to be used as the basis of the export.
 void setTableName(java.lang.String tname)
          Sets the name of the table to export from.
 int writeAll()
          Exports all the (remaining) molecules.
 boolean writeNext()
          Writes the next molecule to the outputstream, this method is useful if one wants to track the progress of the export.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Exporter

public Exporter()
Method Detail

setConnectionHandler

public void setConnectionHandler(ConnectionHandler conh)
Setter for property connectionHandler. The ConnectionHandler must represent an open connection to the database.


getConnectionHandler

public ConnectionHandler getConnectionHandler()
Getter for property connectionHandler.


setTableName

public void setTableName(java.lang.String tname)
Sets the name of the table to export from.


getTableName

public java.lang.String getTableName()
Gets the name of the table to export from.


setFieldList

public void setFieldList(java.lang.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.
The field names in the output file match the name of the table fields by default, can be overridden by setOutputFieldNames(String).


getFieldList

public java.lang.String getFieldList()
Returns the specified list of fields.


setConditions

public void setConditions(java.lang.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.


getConditions

public java.lang.String getConditions()
Returns the SQL WHERE statement, if specified.


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:
setIDList(int[])

setOutputStream

public void setOutputStream(java.io.OutputStream os)
Sets the OutputStream object to export to.


getOutputStream

public java.io.OutputStream getOutputStream()
Gets the OutputStream object to export to.


setFormat

public void setFormat(int format)
Sets the format of the export. It can be one of the following constants:


getFormat

public int getFormat()
Gets the format of the export. It can be one of the following constants:


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.


isDefaults

public boolean isDefaults()
Gets if only default fields are to be exported.


setEol

public void setEol(java.lang.String eol)
Sets the End Of Line character(s), system dependent. Examples: If not specified (null), the system default value is used.


setSelectStatement

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

By using this method one can

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 (except when setJtfWithStructure(false) is used, in this case the structure field should be omitted).
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(java.lang.String fieldNames)
Specifies 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

getEol

public java.lang.String getEol()
Gets the End Of Line character(s).


setDelimiter

public void setDelimiter(java.lang.String delimiter)
Sets the field delimiter character between columns for JTF format output.
If not specified (null), the default value is TAB ("\t").


getDelimiter

public java.lang.String getDelimiter()
Gets the field delimiter character between columns for JTF format output.


setQuotation

public void setQuotation(java.lang.String quotation)
Sets the field enclosing character for JTF format output.
If not specified (null), the default value is: "


getQuotation

public java.lang.String getQuotation()
Gets the field enclosing character for JTF format output.


setJtfWithStructure

public void setJtfWithStructure(boolean b)
Specifies, wheter exported JTF will contain structure information.


isJtfWithStructure

public boolean isJtfWithStructure()
Gets, wheter exported JTF will contain structure information.


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

writeAll

public int writeAll()
             throws TransferException
Exports all the (remaining) molecules.

Returns:
the number of molecules exported
Throws:
TransferException