This content has been marked as final. Show 9 replies
There are quite a few ways in which you may do the bulk loading within Coherence:
Option1 (not recommended): Get all the rows from DB, convert into javaObject and put it into the cache
Option2 (for small set of data): Get all the cache keys from DB and use EP as invokeAll(keys, PreloadRequest.INSTANCE);
Option3 (for large set of data): Get all the cache keys from DB, create buckets for keys based on key ownership and then pass this bucket to each of the key owners for loading it.
You don't have to use but you may use it. Let me explain how option 2 will work:
- Execute a query against the DB "select key from xxx";
- Put the above results in a java Set "keys"
- Execute myCache.invokeAll(keys, PreloadRequest.INSTANCE);
On executing step 3, coherence will check if the key exists in the Cluster and if not available then it will invoke the load/loadAll method of the CacheStore interface. You need to implement RW backing map for your cache scheme.
Thanks for the reply.I used option1 to get the data from the DB and put it in the cache.
Now all my data is available in the cache.I am querying the cache as below by using the filter.
String s2="getLocName = ?1 and getQ1 = ?2 and getQ2 = ?3 and getQ3 = ?4 and getQ4 = ?5 and getQ5 = ?6";
Set setKeys = cache.keySet(f3);
Iterator itr = setKeys.iterator();
But here i am getting two or more rows from the DB which is matching with the filter. Here my requirement is to select the best match(Like DVM in SOA).So how can i perform it on cache.So how can i use "order by" in coherence.
Thanks for the reply.Here we want the "orderby" by Q5,Q4,Q3,Q2,Q1(But not in ascending order or descending order). Here Q5,Q4,Q3,Q2,Q1 are columns from DB.
I saw some examples on using comparator.They all are arranging the list with ascending or descending order based on some filed(like age element).
So,here in my case how to proceed with the comparator?