Welcome Guest, Not a member yet? Register   Sign In
Connection to DB from library
#3

[eluser]tedward[/eluser]
I appreciate the response, but it doesn't really get me any further.

I'm using an adjancency list to display my categories, their sub-categories, the sub-categories of the sub-categories etc.

The data could look like this:
Code:
+-----+----------------------+-----+
| CID | name                 | PID |
+-----+----------------------+-----+
|   1 | Snowboards           |   0 |
|   9 | Burton               |   1 |
|   5 | Eyewear              |   0 |
|  10 | Rome                 |   1 |
|  30 | Goggles              |   5 |
|  31 | Sunglasses           |   5 |
|  32 | Oakley               |  30 |
|  33 | Anon                 |  30 |
+-----+----------------------+-----+

This allows me to build URLs using the category ID's for all categories that look like this:
Code:
http://localhost/catalog          (top-level)
http://localhost/catalog/1        (Snowboards)
http://localhost/catalog/1/9      (Snowboards > Burton)
http://localhost/catalog/1/10     (Snowboards > Rome)
http://localhost/catalog/5        (Eyewear)
http://localhost/catalog/5/30     (Eyewear > Goggles)
http://localhost/catalog/5/30/32  (Eyewear > Goggles > Burton)
http://localhost/catalog/5/30/33  (Eyewear > Goggles > Anon)
http://localhost/catalog/5/31     (Eyewear > Sunglasses)
Easy.

I'm actually going to build them like this:
Code:
http://localhost/catalog          
http://localhost/catalog/Snowboards
http://localhost/catalog/Snowboards/Burton
http://localhost/catalog/Snowboards/Rome
http://localhost/catalog/Eyewear
http://localhost/catalog/Eyewear/Goggles
http://localhost/catalog/Eyewear/Goggles/Burton
http://localhost/catalog/Eyewear/Goggles/Anon
http://localhost/catalog/Eyewear/Sunglasses

When any of these URLs are requested, I need to map all the category parameters back to their category ID's. This is complicated by the fact that two categories in different locations can have the same name. I'll need to check if the category is unique - if so, return the catID - if not, move up the category structure until I find uniqueness, then return the catID.

I need to have a library class that populates itself with all the catalog data and provides methods to map category name to category ID in the easy (unique) and complicated (non-unique different location) situations. I don't need help with the logic of the methods, but I do need to know if it's ok to connect to the database directly from the library??

Also, this design seems immediately flawed, as every URL of the form shown above will cause the library to read from the DB and repopulate itself. I'd like to find a way to do this once. Java has an 'application scope' where data like this can be stored. Does anyone have any suggestions to persist this data?

I've got virtual hosting that means memory and other resources are shared across many VM's, on the principle that you get resources as you need them, so it doesn't seem polite to secure myself a block of memory with memcached? what do you think.

Sorry to have been so verbose, but a solution to this will no doubt be useful for the community.

Cheers!


Messages In This Thread
Connection to DB from library - by El Forum - 03-03-2008, 05:21 PM
Connection to DB from library - by El Forum - 03-03-2008, 07:59 PM
Connection to DB from library - by El Forum - 03-10-2008, 06:03 PM
Connection to DB from library - by El Forum - 03-10-2008, 06:16 PM



Theme © iAndrew 2016 - Forum software by © MyBB