Dear Rhino,
I agree, the table is small as per your thoughts. Though for us, it is abig
table.
Yah, basically it is alook up kind of data. FOr example the role
categories, the function ids, the action ids etc for a particular user. When
the user logs in, we need to check the entitlement, whether this user is
permitted to go for this function or not. Thats why we are caching it. Our
priority is not for memory concumption, but execution time. Thats why we
cant have a look up from servlet through an EJB or DAO kind of thing.
Any thoughts to share with? After contemplating a bit, what I am thinking is
this:- Assume that first four columns, col1...col4 are primary keys out of
the total 12 columns. My search or lookup is always based on the primary
key, i.e the first four columns. So I will have the startup init method in
one of the servlets, where I will create two strings. First one is
"col1__col2__col3__col4" (lets say the key)and second one is
"col5:col6:col7:col8:...col12" (lets say the value).Then I will populate a
hashtable with key and value.
Whenever a search is needed, I would first construct the key and look for
it.Once I get the value, I will STringTokenize it and use it wherever
required.
In case I need a search for only col1( may be in future), I would have
another hashtable to maintain col1_...col4.
Is this fine? Please comment. Thanks
Best regards,
Ravi
>> Hi all,
>>
[quoted text clipped - 38 lines]
> --
> Rhino
Arvind - 15 May 2006 23:47 GMT
> Dear Rhino,
>
[quoted text clipped - 25 lines]
>
> Is this fine? Please comment. Thanks
The first thing to do is to create an Object that encapsulates these 12
columns i.e. attributes of that row.
Second this is (assuming for a second that your keying col1...col4 key
is good enough), store the "object" that you created in the previous
step as value of the hashtable - dont get into the business of
stringtokenizing etc, they are costly and round-about way of doing the
things at hand.
Now to your actual problem, if your primary keys and index are setup
correctly, a database query should not run for more than tens of
milliseconds - granted that there are some exceptions too. Since you
seem to indicate user-specific data, dont see the value of losing the
ability to do SQL like queries in return for 10 millis of time. And
actually, when you scale up with number of users, the memory will kinda
get abused, but the database can easily scale up to a high concurrent
query load.
--
Arvind
Patricia Shanahan - 16 May 2006 00:06 GMT
...
> Any thoughts to share with? After contemplating a bit, what I am thinking is
> this:- Assume that first four columns, col1...col4 are primary keys out of
[quoted text clipped - 4 lines]
> "col5:col6:col7:col8:...col12" (lets say the value).Then I will populate a
> hashtable with key and value.
...
I don't recommend encoding as String and tokenizing. It makes everything
quite unnecessarily complicated. You would need to either impose a
prohibition on "_" as data, or do some quoting.
It would be simpler to create classes for the keys and values. You would
need to write good, consistent, equals and hashCode methods for the key
class.
Also, don't ignore the database idea. It scales to almost any size, and
minimizes the amount of change in your program that is required to
support additional look-up methods.
Patricia