Modifying Structure Tables¶
Contents¶
Inserting or Modifying Rows¶
JChem provides the chemaxon.jchem.db.TableUpdateHandler class for updating and inserting rows in structure tables. A structure table contains fixed columns (cd_...) and, optionally, additional columns that have been defined explicitly.
Java example:
ConnectionHandler connHandler;
int id; // cd_id value of compound
// Additional columns:
String name;
Float stock;
String comments;
...
int updateMode = isInsertion ? TableUpdateHandler.INSERT : TableUpdateHandler.UPDATE;
TableUpdateHandler uh = new TableUpdateHandler(connHandler, updateMode,
tableName, "name, stock, comments");
try {
uh.setStructure(structureSourceString);
if (!isInsertion) {
uh.setID(id);
}
uh.setValueForAdditionalColumn(1, name);
uh.setValueForAdditionalColumn(2, stock);
uh.setValueForAdditionalColumn(3, comments);
uh.execute();
} finally {
uh.close();
}
Deleting Rows¶
The deleteRows method of the TableUpdateHandler class is suggested for deleting rows from structure tables. It also increments updateCounter for the given table in JChemProperties, which is important when caching is used during structure search.
Example:
Other Methods¶
Other useful methods of TableUpdateHandler:
| getStructureTables | Retrieves the name of all structure tables. |
|---|---|
| createStructureTable | Creates a structure table. |
| dropStructureTable | Removes a structure table. |