User ad15b92aec
13-01-2009 02:13:09
Hello,
I would like to make tables created via the jchem UpdateHandler appear within the tree of data sources and be viewable in IJC, programmatically. Can you please point me in the direction of example code to or instructions on how to go about doing this?
Thank you very much.
ChemAxon e189db4705
13-01-2009 03:32:04
We use DFNewType to create any data model artefact like entities, fields, etc (
http://www.chemaxon.com/instantjchem/ijc_latest/docs/user/help/htmlfiles/ijc_terminology.html).
List can be obtained from parent container. So new types for creating entities are produced by entities' parent: DFSchema. DFNewTypes are used for creating new objects (including database artefacts: tables, columns, etc), or just for promotion of existing db tables to IJC entity.
If jchem table already exists in database it must be promoted to DFEntity also using a specific DFNewType. In general it would be simpler to use a new type which creates also database jchem table together with entity.
Anyway the code which can do jchem table promotion to entity is:
Code: |
DFSchema schema = ...
final DFNewType entityNewTypeForExistingJchemTable = DIFUtilities.findFirstAppropriateNewType(
schema.getEntities().getNewTypes(),
true,
new Class[] { JChemEntityCapability.class },
new Class[0]);
assert entityNewTypeForExistingJchemTable != null;
DFNewTypeOptions opt = entityNewTypeForExistingJchemTable.getOptions();
if (!(opt instanceof DFNewTypeWellKnownOptions.ExistingJChemEntity)) {
System.out.println("Something is wrong, the options should be of this type!");
}
DFNewTypeWellKnownOptions.ExistingJChemEntity options = (DFNewTypeWellKnownOptions.ExistingJChemEntity) opt;
options.setNewDFItemNameSafe("My new promoted entity");
options.setTableName("TEST1"); // set your table name here
options.setIdFieldColumn("CD_ID"); // could be verified in code using options.getAvailableIDColumns()
UIBackgroundRunnerRW runner = new UIBackgroundRunnerRW(schema.getLockable(), "Promoting jchem table to entity", false) {
@Override
public void phase1InRequestProcessor() {
entityNewTypeForExistingJchemTable.create(getEnvironment());
}
};
runner.start();
|
Let us know please if it works for you.
Petr
ChemAxon e189db4705
13-01-2009 03:40:11
.... and if you want to create a default data tree for this new entity, then the trivial way is to replace the part of the code from previous post with this:
Code: |
public void phase1InRequestProcessor() {
// It's expected that this new type creates only one entity.
Collection<DFEntity> newEntity = entityNewTypeForExistingJchemTable.create(getEnvironment());
// Utility to create a datatree for entity the simple way. DFNewTypes can be used as well.
DIFUtilities.createDataTreeForEntity(newEntity.iterator().next(), getEnvironment());
} |
ChemAxon fa971619eb
13-01-2009 07:59:42
User ad15b92aec
14-01-2009 19:45:48
Things are working as intended now with table promotion, thank you for the help.
I would now like to go from using statically declared values for my ConnectionHandler and any DataSources to being able to pull out the DataSource attached to a given IJC entity. I didn't notice any methods to pull this out of entity or entitydataprovider, and your BaseDataSource doesn't implement lookup.provider (might not be a bad idea, it's guaranteed to be there). I poked around the dif core/api for a while but I'm at a loss again.
ChemAxon fa971619eb
14-01-2009 20:10:49
The fact that you haven't been able to do this is to some extent a good sign to us! We have tried to ensure that the APIs are as safe as possible, and giving access to the raw database connection clearly has the potential to do no end of harm, hence whey we have tried to avoid it and instead provide controlled access through the APIs.
But the point you raise is a very fair question. There should be a way to bend the rules, as long as you accept that what you do is up to you and you could break anything/everything if you do strange things like drop tables that are in use .....
Your suggestion of putting the DataSource and/or ConnectionHandler into Lookup does sound sensible, as only people who know what they are doing are going to find it there.
Can you let us think about this a bit and then suggest a solution. There are definitely "back door" solutions to this, we just need to work out which solution is best.
Tim
ChemAxon fa971619eb
14-01-2009 20:22:16
p.s. we'd love to hear what you are wanting to do with the IJC APIs.
Maybe its something we should be supporting directly?
Tim
User ad15b92aec
15-01-2009 03:27:23
We're working on a drug discovery pipeline suite which integrates advanced graph mining and query techniques, a chemical space explorer for libraries, some stuff related to pharmacophore prediction, etc. Basically a workflow toolkit for medicinal chemists.