Package chemaxon.jchem.db
Class Exporter
java.lang.Object
chemaxon.jchem.db.Exporter
- All Implemented Interfaces:
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.
-
Field Summary
Fields inherited from interface chemaxon.jchem.db.Transfer
CXSMARTS, CXSMILES, INCHI, MOL2FILE, MOLFILE, MRV, RDFILE, RXNFILE, SDFILE, SMARTS, SMILES
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns the SQL WHERE statement, if specified.Getter for property connectionHandler.Returns the specified list of fields.int
Gets the format of the export.int[]
Returns the list of allowed cd_id values.Get the DB field name / user defined name conversion rules.String[]
Get the names of the data fields in the output file.Gets the OutputStream object to export to.Gets the name of the table to export from.boolean
Gets if only default fields are to be exported.void
setConditions
(String conditions) An SQL WHERE condition can be specified here.void
Setter for property connectionHandler.void
setDefaults
(boolean b) Sets if only default fields will be exported.void
setFieldList
(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
setOutputFieldConversion
(String fieldNameConversion) Set the DB field name / user defined name conversion rules.void
setOutputFieldNames
(String fieldNames) Specify the names of the data fields in the output file.void
Sets the OutputStream object to export to.void
setSelectStatement
(String sql) Sets a custom SQL SELECT statement to be used as the basis of the export.void
setTableName
(String tname) Sets the name of the table to export from.int
writeAll()
Exports all the (remaining) molecules.boolean
Writes the next molecule to the outputstream, this method is useful if one wants to track the progress of the export.
-
Constructor Details
-
Exporter
public Exporter()
-
-
Method Details
-
setConnectionHandler
Setter for property connectionHandler. The ConnectionHandler must represent an open connection to the database.- Parameters:
conh
- the newConnectionHandler
to use
-
getConnectionHandler
Getter for property connectionHandler.- Returns:
- the
ConnectionHandler
-
setTableName
Sets the name of the table to export from.- Parameters:
tname
- the table name
-
getTableName
Gets the name of the table to export from.- Returns:
- the table name
-
setFieldList
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 bysetDefaults
.- Parameters:
fieldList
- field names as described above
-
getFieldList
Returns the specified list of fields.- Returns:
- the field list in the form
setFieldList(String)
}
-
setConditions
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
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 tonull
, 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
Sets the OutputStream object to export to.- Parameters:
os
- the output stream
-
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
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 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 bysetOutputFieldNames(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 tonull
, a standard SELECT statement is generated by JChem for the export (default).- Since:
- JChem 3.1
-
setOutputFieldNames
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 tonull
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
Get the names of the data fields in the output file.- Returns:
- the names of the data fields in the output file
-
setOutputFieldConversion
Set the DB field name / user defined name conversion rules. It overrides thesetOutputFieldNames(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 benull
, user defined field conversion will be ignored in this case.
-
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
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
Exports all the (remaining) molecules.- Returns:
- the number of molecules exported
- Throws:
TransferException
- if some exception is encountered
-