How to add "permanent cache" in the application using Jchem

User 73ad691ca3

18-03-2013 12:51:15

Dear Chemaxon Team,


We want to know how to implement the Permanent cache in our application. Our application uses WCF service for performing the inserting structures to the structure table.


1). we have already imported some 5 lakh structures from an SD file using the Jchem Manager Tool (using import option). 


How can we add the permanent cache to these structures which are already imported to the jchem structure table using the Jchem Manager Tool?   


2). So Further we are going to register the compounds through the application.  Our application is consuming a WCF service where the WCF service calls the Jchem .Net APIs to insert the structures to the Jchem table. 


So how can we implement the permanent cache to the structures which we are going to register through the above said application (WCF service using Jchem .Net API to insert the structures to the Jchem table)?


------------------------------------------------------------------------------------------------------------------------------------- 


Here is the sample code the WCF service uses to insert the structure: 


int cd_id=-1;


UpdateHandler uh = new UpdateHandler(conh, UpdateHandler.INSERT, structureTableName, additionalColumns);


uh.setDuplicateFiltering(UpdateHandler.DUPLICATE_FILTERING_ON);


uh.setStructure(structure);


cd_id = uh.execute(true);


------------------------------------------------------------------------------------------------------------------------------------


As mentioned in the below chemaxon link, how can we implement the permanent cache in our application.


http://www.chemaxon.com/jchem/doc/dev/java/intro/index.html#cachereg



Note:


    Our main requirement is how to add or implement the permanent cache in the application.


   you can provide us the sample code for jchem .net api. 


Please reply us ASAP.


 


Thanks & Regards,


D. Senthil kumar vijai.

ChemAxon 9c0afc9aaf

18-03-2013 17:51:23

Hi,


It is important to note, that cache registration belongs to the application that performs the search.


Any application can insert/modify/delete the structures using our API without having to care about cache registration (unless they also search).


If you do not run your searches in transactions, then at the first search of the service restart the cache is automatically registered (as temporary) and usually no need to care about this.


If you run your searches in transactions, use method #2 in the search application once, outside the transaction, before the first search:


 


String identifier = "unique_cache_identifier";
CacheRegistrationUtil cru = new CacheRegistrationUtil(ch);
cru.registerPermanentCache(identifier);

 


If you just want a non-changing cache ID, but the searches do not run in transaction, it's enough to set the ID before the first search:


 


String identifier = "unique_cache_identifier";
CacheRegistrationUtil.setPermanentCacheID(identifier);


Best regards,


Szilard

 

User 73ad691ca3

19-03-2013 14:10:38

Dear  szilard,


Thanks for your reply...


As you mentioned, i have included the below code for registering the permanent cache.


We are calling the below method from the .Net WCF service. So when the WCF service calls the method, we are getting the cacheid; then we will check whether the unique permanent cache id is already registered; if the id is not registered, we will register the unique permanent cache id. Then we will call the jchem search to search the structure, and will get the cd_ids for those same structure.


Is this way of registering the permanent cache is correct or not?


Please reply us ASAP, if we need to do anything further for registering the permanent cache.


-----------------sample code-using jchem .net api------------------------------------------------


wcf service will call the GetCdIdsByStructure method:


public static class Searcher

    public static int[] GetCdIdsByStructure(JChemSearchOptions searchOptions, ConnectionHandler conh, string tableName, string molStr)
    {
        //-->register permanent cache
        String identifier = "unique_cache_identifier";
        string cacheId = CacheRegistrationUtil.getCacheID();
        if (cacheId != identifier)
        {
            CacheRegistrationUtil.setPermanentCacheID(identifier);
        }
        //-->register permanent cache
       
        int[] cd_ids = null;
        try
        {
            JChemSearch searcher = new JChemSearch();
            searcher.setConnectionHandler(conh);
            searcher.setStructureTable(tableName);
            searcher.setSearchOptions(searchOptions);
            searcher.setRunMode(JChemSearch.RUN_MODE_SYNCH_COMPLETE);


            //-->to search in a new thread
            JavaThread thread = new JavaThread();
            thread.RunNew();
            //-->to search in a new thread


            searcher.setQueryStructure(molStr);
            searcher.run();
            cd_ids = searcher.getResults();
            searcher.cleanResults();    //clean


            return cd_ids;
        }
        catch
        {
            throw;
        }
    }


}


---------------------------------------------------------------------------------------------------


 


Thanks & Regards,


D. Senthil kumar vijai.


 


 

ChemAxon 9c0afc9aaf

19-03-2013 14:42:13

Hi,


A loosely related thing that caught my eye earlier:


Here is the sample code the WCF service uses to insert the structure: 

Please don't forget to call UpdateHandle.close() after finished inserting.


The posted search code looks OK to me, it could be also substituted with one line:


CacheRegistrationUtil.setPermanentCacheID(identifier)


Of course the identifier can be any unique string (e.g "my_great_search_service" ), not just as the one specified in the example :)


Szilard

ChemAxon 9c0afc9aaf

21-03-2013 08:39:16

PS:


Of course it is enough to deal with cache registration or set the cache ID once at the start up of your application.


This way all searches will use it within the same JVM, less chance of setting different values at different places, which should be a problem.


If the application does not have a definite entry point (service) it is OK to set it multiple times / places,  but it's best to use a static constant to pervent setting different values  within the same application.


Szilard

User 73ad691ca3

26-03-2013 09:52:58

Dear Szilard,


Thanks for your reply...


 


Thanks & Regards,


D. Senthil kumar vijai.