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 Artem Melentyev <am...@gmail.com> on 2006/08/09 15:27:13 UTC
jcr-mapping contribution
Hello.
I'm Google Summer of Code student ( http://code.google.com/soc ) in
XWiki organization ( http://xwiki.org/ .com )
I am writing JCR Store backend for XWiki. (XWiki works only on Hibernate
for now)
I'm using ObjectConverter directly without PersistenceManager (it is too
high-level, and I don't want to add jcrpath field to beens).
I would like to contribute my small changes. patch relatively svn trunk
is attached.
Interface problems if same name siblings used (1,2):
1) ObjectConverter.insert method don't returns created Node and
impossible find it, if where are many nodes with same name.
I offer:
public Node insert(Session session, Node parentNode, String nodeName,
Object object);
2) ObjectConverter.update method uses "parentNode.getNode(nodeName)",
but if there are many nodes with same name?
I added following method:
public void update(Session session, Node objectNode, Object object)
3) I want to store descendants of some class A, the same as A, without
putting descendants classes in mappings. How to make it?
I write in ObjectConverterImpl additional methods insert and update with
additional parameter Class objclass. Maybe there is a way better?
Bugs:
4) ObjectConverter.retrieveSimpleFields method:
in if (classDescriptor.usesNodeTypePerHierarchyStrategy() &&
classDescriptor.hasDiscriminator())
writed:
String value = node.getProperty(propertyName).getValue().getString();
Why only String? I have a exceptions because it. I think should be:
Value propValue = node.getProperty(propertyName).getValue();
AtomicTypeConverter converter =
getAtomicTypeConverter(fieldDescriptor, initializedBean, fieldName);
Object fieldValue = converter.getObject(propValue);
ReflectionUtils.setNestedProperty(initializedBean, fieldName, fieldValue);
5) ManageableCollectionUtil.getManageableCollection:
Why I can't store non standard, but Collection or Set compatible
classes? (ex: from org.apache.commons.collections)
i write following. It works fine for me:
...
if (object instanceof Vector) {
ManageableVector manageableVector = new ManageableVector();
manageableVector.addAll((Collection) object);
return manageableVector;
}
if (object instanceof Set) {
return new ManageableSet((Set) object);
}
if (object instanceof Collection) {
ManageableArrayList manageableArrayList = new ManageableArrayList();
manageableArrayList.addAll((Collection) object);
return manageableArrayList;
}
...
--
Artem Melentyev. UralSU, CS401.
Re: jcr-mapping contribution
Posted by Christophe Lombart <ch...@gmail.com>.
Hi Artem,
Sorry for the delay - Here some comments.
On 8/9/06, Artem Melentyev <am...@gmail.com> wrote:
> I'm using ObjectConverter directly without PersistenceManager (it is too
> high-level, and I don't want to add jcrpath field to beens).
Right - Some users want to define the path field and others not.
We should try to solve the solution on the PersistenceManager level
(not on ObjectConverter level). The PeristenceManager API is more
stable. ObjectConverter will maybe changes to support new features.
I'm just wondering why it is not acceptable to add an ID in your
"main" objects. I'm ok that aggregated objects do not need an ID (path
and later UUID) but not the main objects.
Can you clarrify this point - thanks ?
>
> I would like to contribute my small changes. patch relatively svn trunk
> is attached.
>
> Interface problems if same name siblings used (1,2):
> 1) ObjectConverter.insert method don't returns created Node and
> impossible find it, if where are many nodes with same name.
> I offer:
> public Node insert(Session session, Node parentNode, String nodeName,
> Object object);
>
This is not necessary if we solve your problem on the
PersistenceManager level but that's not a problem to return the
inserted node.
> 2) ObjectConverter.update method uses "parentNode.getNode(nodeName)",
> but if there are many nodes with same name?
> I added following method:
> public void update(Session session, Node objectNode, Object object)
>
>
Is it not working with nodename like 'mynode[2] ?
> 3) I want to store descendants of some class A, the same as A, without
> putting descendants classes in mappings. How to make it?
> I write in ObjectConverterImpl additional methods insert and update with
> additional parameter Class objclass. Maybe there is a way better?
>
In this case, how to map the fields/beans and collections defined in
the descendant class ? We can use the reflection to get the ancestor
and see if a class descriptor exists . If defined, we can use the
ancestor classdescriptor otherwise loop on the ancestor hierarchy
until we found a class descriptor (just an idea).
> Bugs:
> 4) ObjectConverter.retrieveSimpleFields method:
> in if (classDescriptor.usesNodeTypePerHierarchyStrategy() &&
> classDescriptor.hasDiscriminator())
> writed:
> String value = node.getProperty(propertyName).getValue().getString();
>
> Why only String? I have a exceptions because it. I think should be:
>
Right your code is more robust. I will apply this patch
For which field type and value you get the exception ?
>
>
> 5) ManageableCollectionUtil.getManageableCollection:
> Why I can't store non standard, but Collection or Set compatible
> classes? (ex: from org.apache.commons.collections)
Not yet used by the team :-) I will apply this patch thanks
--
Best regards,
Christophe
Re: jcr-mapping contribution
Posted by Christophe Lombart <ch...@gmail.com>.
Aterm,
Thank you very much for your contribution. I'm on vacation until
September. I will review your patch and suggestions ASAP (probably the
first week of september).
If you know someone interested to integrated xwiki with the complete
Graffito stack, I will be very happy to discuss on that Topic. A
couple of month ago I reviewed Xwiki and I think it should be possible
to make a " Xwiki Graffito application".
Kind regards,
Christophe
On 8/9/06, Artem Melentyev <am...@gmail.com> wrote:
> Hello.
>
> I'm Google Summer of Code student ( http://code.google.com/soc ) in
> XWiki organization ( http://xwiki.org/ .com )
> I am writing JCR Store backend for XWiki. (XWiki works only on Hibernate
> for now)
>
> I'm using ObjectConverter directly without PersistenceManager (it is too
> high-level, and I don't want to add jcrpath field to beens).
>
> I would like to contribute my small changes. patch relatively svn trunk
> is attached.
>
> Interface problems if same name siblings used (1,2):
> 1) ObjectConverter.insert method don't returns created Node and
> impossible find it, if where are many nodes with same name.
> I offer:
> public Node insert(Session session, Node parentNode, String nodeName,
> Object object);
>
> 2) ObjectConverter.update method uses "parentNode.getNode(nodeName)",
> but if there are many nodes with same name?
> I added following method:
> public void update(Session session, Node objectNode, Object object)
>
>
> 3) I want to store descendants of some class A, the same as A, without
> putting descendants classes in mappings. How to make it?
> I write in ObjectConverterImpl additional methods insert and update with
> additional parameter Class objclass. Maybe there is a way better?
>
> Bugs:
> 4) ObjectConverter.retrieveSimpleFields method:
> in if (classDescriptor.usesNodeTypePerHierarchyStrategy() &&
> classDescriptor.hasDiscriminator())
> writed:
> String value = node.getProperty(propertyName).getValue().getString();
>
> Why only String? I have a exceptions because it. I think should be:
>
> Value propValue = node.getProperty(propertyName).getValue();
> AtomicTypeConverter converter =
> getAtomicTypeConverter(fieldDescriptor, initializedBean, fieldName);
> Object fieldValue = converter.getObject(propValue);
> ReflectionUtils.setNestedProperty(initializedBean, fieldName, fieldValue);
>
>
> 5) ManageableCollectionUtil.getManageableCollection:
> Why I can't store non standard, but Collection or Set compatible
> classes? (ex: from org.apache.commons.collections)
> i write following. It works fine for me:
> ...
> if (object instanceof Vector) {
> ManageableVector manageableVector = new ManageableVector();
> manageableVector.addAll((Collection) object);
> return manageableVector;
> }
> if (object instanceof Set) {
> return new ManageableSet((Set) object);
> }
> if (object instanceof Collection) {
> ManageableArrayList manageableArrayList = new ManageableArrayList();
> manageableArrayList.addAll((Collection) object);
> return manageableArrayList;
> }
> ...
>
>
> --
> Artem Melentyev. UralSU, CS401.
>
>
>
> Index: src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java
> ===================================================================
> --- src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java (revision 429285)
> +++ src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java (working copy)
> @@ -113,39 +113,22 @@
> if (object == null) {
> return null;
> }
> -
> if (object instanceof ManageableCollection) {
> return (ManageableCollection) object;
> -
> }
> - if (object.getClass().equals(ArrayList.class)) {
> - ManageableArrayList manageableArrayList = new ManageableArrayList();
> - manageableArrayList.addAll((Collection) object);
> -
> - return manageableArrayList;
> - }
> -
> - if (object.getClass().equals(Vector.class)) {
> - ManageableVector manageableVector = new ManageableVector();
> - manageableVector.addAll((Collection) object);
> -
> - return manageableVector;
> - }
> -
> - if (object.getClass().equals(HashSet.class)) {
> + if (object instanceof Vector) {
> + ManageableVector manageableVector = new ManageableVector();
> + manageableVector.addAll((Collection) object);
> + return manageableVector;
> + }
> + if (object instanceof Set) {
> return new ManageableSet((Set) object);
> }
> -
> - if (object.getClass().equals(Collection.class)
> - || object.getClass().equals(List.class)) {
> - ManageableArrayList manageableArrayList = new ManageableArrayList();
> - manageableArrayList.addAll((Collection) object);
> -
> - return manageableArrayList;
> + if (object instanceof Collection) {
> + ManageableArrayList manageableArrayList = new ManageableArrayList();
> + manageableArrayList.addAll((Collection) object);
> + return manageableArrayList;
> }
> - if (object.getClass().equals(Set.class)) {
> - return new ManageableSet((Set) object);
> - }
> }
> catch (Exception e) {
> throw new JcrMappingException("Impossible to create the manageable collection", e);
> Index: src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
> ===================================================================
> --- src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java (revision 429285)
> +++ src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java (working copy)
> @@ -139,9 +139,10 @@
> * @see org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter#insert(javax.jcr.Session,
> * javax.jcr.Node, java.lang.String, java.lang.Object)
> */
> - public void insert(Session session, Node parentNode, String nodeName, Object object) {
> - ClassDescriptor classDescriptor = mapper.getClassDescriptorByClass(object.getClass());
> -
> +
> + public Node insert(Session session, Node parentNode, String nodeName, Object object, Class objclass) {
> + ClassDescriptor classDescriptor = mapper.getClassDescriptorByClass(objclass);
> +
> String jcrNodeType = classDescriptor.getJcrNodeType();
> if ((jcrNodeType == null) || jcrNodeType.equals("")) {
> jcrNodeType = PersistenceConstant.NT_UNSTRUCTURED;
> @@ -198,7 +199,12 @@
> storeSimpleFields(session, object, classDescriptor, objectNode);
> insertBeanFields(session, object, classDescriptor, objectNode);
> insertCollectionFields(session, object, classDescriptor, objectNode);
> + return objectNode;
> }
> +
> + public Node insert(Session session, Node parentNode, String nodeName, Object object) {
> + return insert(session, parentNode, nodeName, object, ReflectionUtils.getBeanClass(object));
> + }
>
> /**
> * @see org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter#update(javax.jcr.Session,
> @@ -226,22 +232,28 @@
> */
> public void update(Session session, Node parentNode, String nodeName, Object object) {
> try {
> - ClassDescriptor classDescriptor = mapper.getClassDescriptorByClass(ReflectionUtils.getBeanClass(object));
> Node objectNode = parentNode.getNode(nodeName);
> + update(session, objectNode, object, ReflectionUtils.getBeanClass(object));
> + } catch (PathNotFoundException e) {
> + throw new PersistenceException("Impossible to update the object: " + nodeName + " at node : " + parentNode, e);
> + } catch (RepositoryException e) {
> + throw new org.apache.portals.graffito.jcr.exception.RepositoryException("Impossible to update the object: "
> + + nodeName + " at node : " + parentNode, e);
> + }
> + }
> + public void update(Session session, Node node, Object object) {
> + update(session, node, object, ReflectionUtils.getBeanClass(object));
> + }
> + public void update(Session session, Node objectNode, Object object, Class objclass) {
> + ClassDescriptor classDescriptor = mapper.getClassDescriptorByClass(objclass);
>
> - checkNodeType(session, classDescriptor);
> + checkNodeType(session, classDescriptor);
>
> - checkCompatiblePrimaryNodeTypes(session, objectNode, classDescriptor, false);
> + checkCompatiblePrimaryNodeTypes(session, objectNode, classDescriptor, false);
>
> - storeSimpleFields(session, object, classDescriptor, objectNode);
> - updateBeanFields(session, object, classDescriptor, objectNode);
> - updateCollectionFields(session, object, classDescriptor, objectNode);
> - } catch (PathNotFoundException pnfe) {
> - throw new PersistenceException("Impossible to update the object: " + nodeName + " at node : " + parentNode, pnfe);
> - } catch (RepositoryException re) {
> - throw new org.apache.portals.graffito.jcr.exception.RepositoryException("Impossible to update the object: "
> - + nodeName + " at node : " + parentNode, re);
> - }
> + storeSimpleFields(session, object, classDescriptor, objectNode);
> + updateBeanFields(session, object, classDescriptor, objectNode);
> + updateCollectionFields(session, object, classDescriptor, objectNode);
> }
>
> /**
> @@ -562,8 +574,12 @@
> if (null == initializedBean) {
> initializedBean = ReflectionUtils.newInstance(classDescriptor.getClassName());
> }
> - String value = node.getProperty(propertyName).getValue().getString();
> - ReflectionUtils.setNestedProperty(initializedBean, fieldName, value);
> + // Why only string?: String value = node.getProperty(propertyName).getValue().getString();
> + Value propValue = node.getProperty(propertyName).getValue();
> + AtomicTypeConverter converter = getAtomicTypeConverter(fieldDescriptor, initializedBean, fieldName);
> + Object fieldValue = converter.getObject(propValue);
> +
> + ReflectionUtils.setNestedProperty(initializedBean, fieldName, fieldValue);
> } else {
> throw new PersistenceException("Class '" + classDescriptor.getClassName()
> + "' have not a discriminator property.");
> Index: src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.java
> ===================================================================
> --- src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.java (revision 429285)
> +++ src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.java (working copy)
> @@ -101,7 +101,7 @@
> * @param object the object to insert
> * @throws PersistenceException when it is not possible to insert the object
> */
> - public void insert(Session session, Node parentNode, String nodeName, Object object) throws PersistenceException;
> + public Node insert(Session session, Node parentNode, String nodeName, Object object) throws PersistenceException;
>
> /**
> * Update the object
>
>
>
>
--
Best regards,
Christophe