I had a requirement on coherence.How to load the cache from the database table.My database contains almost 16000 records and 12 coloumns.Is it require to have a primary key for the table to be loaded in to the cache.
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.
Thanks for the reply.But how to go with option2 & option3.can you please post somelinks on the same. IS it mandatory to use cachestore approach while getting data from the database and putting it in to the coherence.
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";
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?