You are viewing a plain text version of this content. The canonical link for it is here.
Posted to graffito-dev@incubator.apache.org by Sandro Böhme <sa...@gmx.de> on 2005/08/28 20:31:50 UTC
Re: [jira] Created: (GRFT-37) Final JCR Mapping Document PROPOSAL
// mapping structure
Christophe Lombart wrote:
>2005/8/27, Sandro Böhme <sa...@gmx.de>:
>
>
>>Oliver Kiessler wrote:
>>
>>
>>
>>>>>Here is a simplification of the Sandro proposal....
>>>>>
>>>>>
>>>>I'm more for a mapping file similar to this:
>>>> <mapping>
>>>> <classAttributes
>>>>packageName="org.apache.portals.graffito.jcr.testmodel"
>>>>className="CmsObject"/>
>>>> <nodeTypeAttributes nodeTypeName="graffito:CmsObject">
>>>> <supertype>nt:base</supertype>
>>>> </nodeTypeAttributes>
>>>> <subitemMapping propertyName="objectId" parameterType="long"
>>>>jcrPropertyDefinition name="graffito:parentId" />
>>>> </mapping>
>>>>
>>>>
>>>>
>>>>
>
>ahh ok for this one. I spoke the first mapping file (whith
>getter/setter). The first one was too verbose.
>
>
One goal of my proposal is, to split the class descriptors
(classAttributes) and the node type
descriptors (nodeTypeAttributes) of the mapping tag into two tags. This
way the user knows
exactly if an xml-attribute belongs to a class or a node type. I also
used the term "mapping"
for a tag because I think as we map in both directions it cannot be
"class-mapping" or
"nodetype-mapping" or something similar.
>A couple of minors change I would like to add :
>* group on the same attribute the pck name and the class name. Why are
>split them into 2 attributes ?
>
>
+1 Whatever you prefer here.
>* Rename some tags to be more explicit for the end-user :
>-ClassAttribute into classdescriptor or something like
>that."Attribute" is not really appropriate here.
>
>
+1
>- subItemMapping into fielddescriptor or something like that. As
>
>
+1
>explained in the proposal doc, we need to map simple fieds, bean
>fields and collection. So, we need to use different tags for that.
>
>
Where do you see the difference between field and a bean-field?
>I have not yet thinking about the nt tags.
>
>Oho, I think both proposal becomes more and more similar. That's good :-)
>
>
Absolutely. I would be glad if we find a mapping structure we are all
happy with.
Regards,
Sandro
>
>
>
Re: [jira] Created: (GRFT-37) Final JCR Mapping Document PROPOSAL // mapping structure
Posted by Christophe Lombart <ch...@gmail.com>.
2005/8/28, Sandro Böhme <sa...@gmx.de>:
> Where do you see the difference between field and a bean-field?
See the GenericConverter class (eg. The insert method)
> We could add a "type" attribute to the field-descriptor or the sub-tag
> (<java-method/>) of it. It can contain not
> only primitive types but also custom java classes that have a mapping
> defined in the mapping file. This already
> works in my prototype (The "Folder" has a "Document").
>
>
I'm not sure this kind of attribute is necessary. See the following example :
<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.A"
jcrNodeType="nt:unstructured" >
<!-- add here field descriptor -->
<bean-descriptor fieldName="b" jcrName="b" proxy="false" />
</class-descriptor>
<class-descriptor
className="org.apache.portals.graffito.jcr.testmodel.B" jcrNodeType=
"nt:unstructured" >
<!-- Field-descriptor is used to map simple attributes to jcr property -->
<field-descriptor fieldName="b1" jcrName="b1" />
<field-descriptor fieldName="b2" jcrName="b2" />
</class-descriptor>
Re: [jira] Created: (GRFT-37) Final JCR Mapping Document PROPOSAL
// mapping structure
Posted by Sandro Böhme <sa...@gmx.de>.
Sandro Böhme wrote:
> explained in the proposal doc, we need to map simple fieds, bean
>
>> fields and collection. So, we need to use different tags for that.
>>
>>
> Where do you see the difference between field and a bean-field?
>
<Quote>
There are 4 "types" for attributes/fields :
* Simple fields : primitive data types and simple objects (String, Long,
Double, ...)
* Bean fields : One class can contain an 1..1 association to another
bean. In this case, the attribute is a custom object.
* Collection fields : One class can contain an 1..n association to a
collection of beans (or Map). The m..n association will be also supported.
* Reference field : One good example to understand the "reference" type
is the Folder concept. A folder "B" can have an attribute called
"parentFolder" which is a simple field pointing to the parent folder "A"
. Of course, in a JCR repository, it is a nonsense for persist this
"parentFolder" attribute into a "B" subnode.</Quote>
We could add a "type" attribute to the field-descriptor or the sub-tag
(<java-method/>) of it. It can contain not
only primitive types but also custom java classes that have a mapping
defined in the mapping file. This already
works in my prototype (The "Folder" has a "Document").
With the interface of the AtomicTypeConverter the user should be able to
define a custom mapping for
java classes that use bean property types not supported by the JCR.
I used it to define a custom (build in) mapping for java.util.Date
because the JCR only knows "Calendar".
This way the custom java classes can reuse the date type as their bean
types and the custom converter
knows how to convert the data. The converters are registered in the
factory. As soon as the object to
item component or the item to object component hit a registered class
which is to be persisted it will
use the registered custom converter to do the real conversion.
That's the java.util.Date example:
private AtomicTypeConverter utilDateTypeConverter = new
AtomicTypeConverter(){
public String getPropertyType(){
return PropertyType.TYPENAME_DATE;
}
public Value getJcrValueFromJavaObject(Object propValue){
if (propValue==null) return null;
Calendar calendar = Calendar.getInstance();
calendar.setTime((java.util.Date)propValue);
return this.getValueFactory().createValue(calendar);
}
public Object getJavaObjectFromJcr(Node node, String
jcrPropName) throws ValueFormatException, PathNotFoundException,
RepositoryException{
Calendar calendar = node.getProperty(jcrPropName).getDate();
Date date = calendar.getTime();
return date;
}
public Class[] getJavaTypes() {
Class[] javaTypes ={java.util.Date.class};
return javaTypes;
}
};
Regards,
Sandro