Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you are constrained to use an SQL database and you need to do efficient type-aware (not merely string) queries on the attributes (like list all items with category shirt having size between 4 and 8), then the structure of the database is the hard part. The Java will follow from that. If I understand correctly, you will need something like this:</p> <pre><code>categories: id : integer (pk) name : varchar attributes: id : integer (pk) of_category : integer (fk -&gt; categories.id) name : varchar type : char(1) // 'N' for number, 'S' for string, etc. items: id : integer (pk) of_category : integer (fk -&gt; categories.id) number_values: value : number of_item : integer (pk, fk -&gt; items.id) of_attribute : integer (pk, fk -&gt; attributes.id) string_values: value : varchar of_item : integer (pk, fk -&gt; items.id) of_attribute : integer (pk, fk -&gt; attributes.id) ... additional table for each attribute type </code></pre> <p>Now for the example query:</p> <pre><code>select * from categories c, items i, attributes a, number_values v where c.name = 'shirt' and a.of_category = c.id and a.name = 'size' and a.id = v.of_attribute and i.id = v.of_item and v.value between 4 and 8 </code></pre> <p>Hairy multiple joins are the price to be paid for runtime-defined attrbutes. </p> <p>Once you have the tables right, modeling them as Java maps is straightforward. There is redundancy in the structure above: for example the character "type" field in the attribute rows. Consider triggers to make consistency checks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload