db-jdo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy Jefferson <a...@jpox.org>
Subject Re: Embedded collections of non-PC objects
Date Fri, 15 Jul 2005 07:06:02 GMT
> > Is it possible to default the value of the <field> serialized
> > attribute to "true" for embedded non-PC types? That would immediately
> > solve our current Collection, Set, and Map issues, without having
> > extra stuff in the metadata file.

Hi Craig,

Having gone back to the original problem report, I'll give my interpretation 
of what the various embedded attributes means (and what I've implemented), 
and you can tell me where I've gone wrong :-)


Example 1 : Collection of BigDecimal
1. Basic collection
<field name="myfield">
    <collection element-type="java.math.BigDecimal"/>
    <join/>
</field>
This creates 2 tables - 1 for the class owning "myfield", and 1 join table to 
contain the elements. If <join> is omitted then an error should be thrown 
(though i'm not sure if JPOX currently flags this up)

2. Serialised collection
<field name="myfield" serialized="true">
    <collection element-type="java.math.BigDecimal"/>
    <join/>
</field>
This creates 1 tables, with a BLOB column for "myfield" containing all 
elements.

embedded-element has no effect with this example because the element 
(BigDecimal) is already embedded (in the join table), and has no way of not 
being embedded.


================================


Example 2 : Collection of PC
1. Basic collection with join
<field name="myfield">
    <collection element-type="MyElement"/>
    <join/>
</field>
This creates 3 tables - 1 for the class owning "myfield", 1 join table and 1 
for the element class.

2. Basic collection with FK
<field name="myfield">
    <collection element-type="MyElement"/>
</field>
This creates 3 tables - 1 for the class owning "myfield", 1 for the element 
class (with FK back to the owner table).

3. Embedded element
<field name="myfield">
    <collection element-type="MyElement" embedded-element="true"/>
    <join/>
</field>
This creates 3 tables - 1 for the class owning "myfield", and 1 join table 
containing the elements (columns aligned with the fields of the PC element).

4. Embedded element (fully specified)
<field name="myfield">
    <collection element-type="MyElement" embedded-element="true"/>
    <join/>
    <element>
        <embedded>
            ... (full spec of field mappings)
        </embedded>
    </element>
</field>
This creates 3 tables - 1 for the class owning "myfield", and 1 join table 
containing the (embedded) elements (columns aligned with the mappings 
specified in the <embedded> section above.

5. Embedded collection
<field name="myfield" embedded="true">
    <collection element-type="MyElement"/>
</field>
No idea what is expected here .. maybe the same as "serialised" below ?

6. Serialised collection
<field name="myfield" serialized="true">
    <collection element-type="MyElement"/>
</field>
This creates 1 table, with 1 BLOB column for "myfield" to include the 
serialised collection.

================================

Example 3 : PC with PC field
1. Basic 1-1
<field name="myfield" persistence-modifier="persistent"/>
This creates 2 tables, one for each class, with a FK

2. Embedded PC
<field name="myfield" persistence-modifier="persistent" embedded="true">
</field>
This creates 1 table, with all fields of the PC having their own columns in 
the table of the owner PC. Not actually implemented in JPOX (though it will 
be fast to do)

3. Embedded PC (fully specified)
<field name="myfield" persistence-modifier="persistent">
    <embedded>
        .... (mappings for other PC class)
    </embedded>
</field>
This creates 1 table, with the fields of the other PC having their own columns 
in the table of the owner PC

4. Serialised PC
<field name="myfield" persistence-modifier="persistent" serialised="true"/>
Not yet implemented. I'd assume we just dump the whole of the PC into a BLOB 
column, but don't see much use for this :-)

================================


There are complete details of all of these in the JPOX online docs, showing 
the classes, the MetaData, and the resultant DB schema.
http://www.jpox.org/docs/1_1/serialised.html
http://www.jpox.org/docs/1_1/embedded.html
http://www.jpox.org/docs/1_1/relationships_1_N_collection.html
http://www.jpox.org/docs/1_1/relationships_1_1.html


If there's some misunderstanding above of what the spec wants, I'd rather know 
it now :-)

> <spec>
> The embedded attribute specifies whether the field should be stored
> as part of the containing instance instead of as its own instance in
> the datastore. It must be specified or default to "true" for fields
> of primitive types, wrappers, java.lang, java.math, java.util,
> collection, map, and array types specified above; and "false"
> otherwise. 
> </spec>

I'm ok with this statement for all types *except* Collections/Maps. 
Collections/Maps have methods therefore I can't see why they should be 
"embedded" by default - they have methods (that we can mimic in JDOQL) 
therefore we want to query them. Arrays don't have methods (that we can mimic 
in JDOQL) therefore they can be embedded (in a BLOB column). Really depends 
on what "embedded" means at <field> level ... is it serialised or something 
else ?



-- 
Andy

Mime
View raw message